
// Make newform 5290.2.a.l in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5290_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_5290_2_a_l();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_5290_2_a_l();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        poly := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_5290_a();"
function MakeCharacter_5290_a()
    N := 5290;
    order := 1;
    char_gens := [2117, 2121];
    v := [1, 1];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

function MakeCharacter_5290_a_Hecke(Kf)
    return MakeCharacter_5290_a();
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..(prec+1)]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 2;
    raw_aps := [[1, 0], [-1, 1], [1, 0], [2, -1], [2, 0], [0, 4], [-1, 5], [-3, 0], [0, 0], [2, -5], [8, -1], [2, -2], [0, 4], [3, 3], [-6, -3], [8, 1], [1, -6], [0, -4], [-5, -5], [0, -5], [-5, 5], [6, -1], [5, 7], [12, 2], [6, 2], [-4, 0], [14, 0], [-8, 4], [0, -3], [7, -5], [14, 1], [3, -4], [11, -7], [-9, -8], [6, 3], [-6, 6], [0, 6], [4, 2], [4, 9], [14, 3], [3, -14], [-14, -6], [-10, 3], [3, -5], [10, -6], [8, -3], [-25, 0], [6, 4], [3, 17], [-2, 9], [1, 3], [-16, -2], [21, 0], [-13, -12], [-1, -11], [-2, -8], [12, 8], [6, 2], [-14, 3], [1, -8], [9, -5], [-14, 8], [1, 5], [-2, -9], [-7, -7], [-10, 7], [11, 14], [11, -13], [-9, 7], [4, -18], [-3, -9], [4, -7], [8, -17], [6, -11], [1, -10], [-18, -10], [6, -20], [-32, 1], [-1, 6], [3, 4], [7, 10], [-30, -5], [-20, -8], [24, -10], [8, 19], [-27, -1], [13, 12], [10, 4], [2, -14], [-10, -6], [12, -6], [22, -7], [-28, 4], [10, 16], [11, -22], [0, -20], [-6, 5], [4, 16], [4, 18], [-22, -3], [-18, -16], [-26, -3], [-5, 5], [-17, -6], [3, 18], [1, -29], [11, 19], [-11, -7], [-6, 25], [12, 24], [-38, 1], [12, 25], [27, 11], [-22, 10], [-8, -19], [-19, -16], [-24, 6], [16, -12], [-10, 5], [-9, -6], [10, 23], [1, 1], [18, -11], [1, 15], [-6, -8], [14, 5], [-4, -29], [26, -3], [-24, -2], [8, 21], [10, 14], [32, 5], [0, 2], [12, -19], [43, 4], [-8, 6], [-4, -4], [7, 3], [10, -9], [27, 14], [-15, -4], [-24, 2], [-36, 3], [-39, -9], [-14, 8], [-2, -14], [-6, 22], [49, 3], [-19, -2], [-4, -17], [-16, 22], [4, -36], [-5, -21], [-14, 15], [23, -3], [34, 8], [-20, -9], [-26, -20], [7, 19], [20, -1], [-35, 9], [-10, -22], [2, -24], [-17, -6], [-18, -12], [-38, 0], [22, -10], [-22, -16], [-11, 22], [-4, -1], [15, 2], [-2, -4], [28, -20], [-9, 19], [6, 8], [-25, 0], [2, -34], [-30, 12], [-2, -11], [32, 8], [4, 33], [-7, 12], [-34, -11], [24, -22], [-16, 27], [20, -10], [28, 23], [-59, -3], [-27, -4], [14, 21], [15, -11], [-17, 1], [30, -12], [-16, 7], [13, -15], [-5, 1], [-16, 16], [16, 10], [6, -24], [46, -8], [-2, -12], [-48, -5], [-36, -3], [16, 10], [-9, -24], [22, 12], [-28, -16], [-26, 12], [-17, -14], [10, -18], [-43, 3], [-26, 7], [-46, 3], [-24, -6], [-24, -4], [-1, 2], [-28, -10], [49, 4], [10, 33], [28, 4], [32, 28], [-68, -1], [-13, 2], [-8, -19], [15, 1], [-2, -28], [14, 12], [-36, -16], [40, 0], [-3, 42], [16, -7], [-23, 0], [-14, -31], [-29, 6], [-28, -22], [-6, -12], [13, 18], [28, -9], [-4, 0], [48, 8], [-10, 16], [27, 20], [-16, -4], [-34, 6], [-15, 43], [-32, 8], [28, -13], [-25, -6], [-10, -20], [8, -11], [8, 29], [43, 6], [18, 32], [-6, -20], [22, 5], [13, 28], [20, 20], [39, -15], [22, 23], [46, 2], [-14, 32], [-17, -13], [54, -19], [-18, 10], [-47, -5], [-9, -32], [-12, 22], [-18, 8], [10, -4], [-46, 13], [4, 37], [-37, 23], [-8, 22], [64, -6], [-47, -21], [-22, -14], [44, 20], [-6, 14], [-11, 32], [13, -10], [4, 1], [18, 6], [52, 22], [8, -2], [-37, 19], [10, -23], [16, -10], [-8, 18], [-2, 57], [7, 4], [0, 18], [-1, -25], [-13, -27], [-3, 20], [-20, 23], [-16, 3], [-10, -32], [38, -12], [-23, -26], [-2, -20], [3, 31], [46, -5], [-30, -9], [17, 43], [-29, 0], [-3, -37], [51, -19], [46, 7], [-28, 22], [0, -16], [-4, -8], [46, 5], [57, 22], [25, 29], [-22, 33], [-33, 38], [-6, -16], [-56, -2], [-27, 27], [-11, 20], [15, -36], [11, 31], [0, -7], [-44, 19], [8, 26], [41, 36], [-48, 16], [15, -41], [24, 7], [44, 6], [-8, 6], [24, -3], [0, 31], [15, -11], [54, 28], [15, -35], [16, 10], [43, -9], [27, -10], [-8, 23], [24, -6], [17, -15], [-30, -7], [6, -48], [58, 23], [30, 6], [-12, -31], [69, -9], [38, 38], [10, -13], [8, 32], [-59, -15], [76, 3], [-10, 46], [46, -3], [32, -18], [10, 15], [-6, 6], [10, -30], [-8, -21], [14, -2], [15, -22], [50, 0], [23, -18], [-61, 3], [-39, -1], [-2, 34], [-24, 25], [27, -34], [22, 10], [54, -26], [-56, 0], [-44, 7], [46, -31], [-26, -22], [-36, -32], [-34, -9], [-6, -32], [-21, -20], [55, -23], [86, 4], [24, 30], [6, 9], [27, 27], [-66, 4], [-14, 50], [18, 33], [-40, 9], [-38, 12], [42, 26], [19, -42], [-66, -13], [59, -12], [-8, -10], [-8, 30], [-13, 37], [-32, -17], [-11, -44], [47, 24], [-28, -5], [18, -13], [49, -9], [-4, 51], [72, 2], [-16, 47], [-40, 37], [6, 12], [-55, 10], [-47, 7], [-41, 16], [-6, -26], [-10, -28], [-3, -71], [-89, 2], [-35, -39], [-10, 11], [-10, -50], [48, -5], [11, 51], [4, 6], [6, 69], [-24, 1], [12, -6], [-17, -36], [-58, -14], [-36, 35], [17, -37], [37, 16], [-43, 10], [20, -16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5290_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5290_2_a_l();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_5290_2_a_l(:prec:=2)
    chi := MakeCharacter_5290_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_5290_2_a_l();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_5290_2_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5290_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 2, 1]>,<7,R![2, -4, 1]>,<11,R![-2, 1]>],Snew);
    return Vf;
end function;