
// Make newform 5290.2.a.u in Magma, downloaded from the LMFDB on 15 May 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_u();".
// 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_u();".
// 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 := [1, 0, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, 0, 1, 0], [0, -4, 0, 1]];
    Rf_basisdens := [1, 1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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, 0, 0], [1, 1, 0, 1], [-1, 0, 0, 0], [1, -1, -1, 1], [0, -1, 0, -3], [-2, 0, 0, -2], [-3, -1, 1, 0], [2, 1, 2, 0], [0, 0, 0, 0], [-3, 3, -1, 1], [7, 1, 1, 1], [-2, -2, 0, -2], [-2, -4, 2, 0], [3, 0, 1, 1], [-1, 3, -1, 1], [-5, -3, 1, 1], [3, 0, 0, 0], [0, -2, -4, -2], [-3, -5, -3, -8], [5, 1, 1, -5], [-4, -1, 1, 5], [1, 1, 7, -3], [-3, -3, -3, 0], [-10, -3, -2, -3], [-4, -1, -6, -3], [-10, -2, 2, -2], [2, -6, 2, 4], [-2, 5, 0, 5], [-9, 5, 1, -1], [-7, 4, -1, 1], [3, 1, 1, -3], [1, -6, -6, -6], [-5, 1, 7, 0], [7, 2, 2, -6], [-5, -3, -1, -5], [8, 0, 2, 4], [-8, 2, 2, 0], [-4, -8, 2, -4], [5, 11, -1, 5], [1, -1, -3, -7], [8, -12, -7, -4], [-14, 2, 2, 0], [-7, -7, 7, 1], [-11, 5, -4, 5], [-2, 0, -6, 10], [-7, 9, 1, 9], [5, -10, -4, 2], [-8, -4, 2, 0], [-5, 6, -7, 9], [5, -1, 1, 1], [-10, 7, -1, 9], [-2, -6, 6, 6], [12, 5, 0, 4], [-14, 1, -2, -2], [3, -3, 4, 1], [-2, -6, 10, 0], [2, 8, 6, 0], [10, -8, 2, -6], [1, -1, -7, -3], [4, 5, 0, 6], [3, 5, -1, -6], [-12, 2, 6, 6], [-1, 7, -2, -1], [-5, 1, -9, -7], [11, 3, 3, -4], [-5, 1, 3, 7], [-3, -8, -6, 0], [-13, 3, 7, 0], [5, 15, -8, 7], [2, 2, 10, -6], [-5, 3, 6, -9], [9, 11, -3, -1], [5, 17, -3, 15], [17, 1, 1, 1], [-8, 4, 0, 11], [-2, 16, 0, 8], [-8, -8, 0, 2], [1, 11, -7, -5], [-2, 15, -2, 12], [-14, -8, 1, 0], [4, 11, -12, 4], [-1, 5, 1, 21], [4, 20, 0, 20], [-14, 5, 0, 3], [15, -13, -11, -5], [1, 1, 4, 5], [-12, -4, 7, -4], [6, 1, 8, 11], [6, -12, 4, 0], [-2, 6, -6, 4], [0, 11, -2, -9], [-5, -1, -1, 9], [-6, -18, 2, 6], [26, 4, 0, 0], [0, -4, -11, 8], [-10, 0, -4, 14], [-5, 5, -5, -11], [-12, -11, 8, 5], [-16, 1, 2, -11], [11, 3, 5, -11], [-12, 22, 0, 22], [-9, 17, -5, 17], [-15, 13, -7, 24], [14, -7, -2, -8], [16, -22, -8, -9], [2, -19, -3, -9], [4, 11, 17, 13], [-13, 3, 4, -5], [-9, 1, 9, -1], [12, 8, -14, 0], [15, 7, 11, 9], [3, 7, 5, -9], [-21, 16, 1, 3], [2, -1, 10, -3], [15, 15, -11, 9], [-20, -4, 4, -5], [0, -7, -6, -15], [-14, -16, 10, -4], [-23, -9, 1, 1], [-20, 6, 4, -5], [-11, -3, 7, 5], [-19, 11, 2, 3], [-7, -21, -1, -7], [4, -13, -5, 1], [6, 8, 10, 12], [-13, -7, -13, -13], [11, 9, -11, 3], [3, -13, -11, 9], [16, 2, 12, 2], [-3, -1, 1, -3], [4, 2, 6, -2], [5, 5, -19, -1], [16, -22, 2, -16], [13, -23, 1, -13], [-14, 8, 1, 4], [-6, -13, -6, -17], [-8, 24, 0, 12], [3, 23, 3, 18], [-15, -23, 3, -1], [0, 2, 3, 10], [3, -6, 16, -14], [-8, -6, -4, -14], [-13, 15, -1, -17], [-21, -22, 9, -3], [12, -2, 4, 4], [2, -6, -16, -6], [-32, 2, 0, -8], [0, -9, 1, 13], [-10, 8, 3, 16], [19, 7, -1, 19], [-16, -6, -6, -20], [4, -19, -4, 5], [-8, 3, -3, -11], [3, -7, -21, -9], [15, -5, -1, -4], [-28, 2, 10, 6], [-1, -7, 3, 5], [8, 8, -4, -16], [21, 12, -5, 5], [5, 23, -7, 27], [-9, 15, 14, 3], [4, -5, -18, -7], [0, 8, -12, 22], [4, 5, -20, 10], [-2, 29, -4, 23], [16, -4, 6, 8], [26, -16, -12, -8], [-8, 20, -2, 8], [30, -10, 6, -9], [5, -23, -13, -5], [16, 17, -8, 8], [-12, -2, -8, -20], [12, -16, -2, -10], [19, -13, 3, -16], [16, 8, -2, 8], [0, -12, -8, -23], [28, -10, -6, -14], [30, -8, -12, -4], [11, -25, 1, -7], [-12, -4, 8, -8], [-25, -17, -1, -21], [-10, 10, 6, -13], [9, 15, -1, -1], [0, 6, -12, 10], [-7, 7, 19, -5], [4, -28, -2, -14], [13, -11, -3, -7], [15, -14, 17, -9], [15, 8, 16, 8], [9, 19, 15, 21], [1, -21, 8, -21], [12, -17, 7, -7], [12, -5, 16, -3], [19, 1, 11, -25], [-1, -12, 9, 13], [27, -6, 9, -13], [8, -9, 16, 3], [6, 8, 0, -18], [30, -3, 12, -9], [32, -18, -14, -10], [24, -10, -14, 6], [-19, 17, 1, -1], [1, 5, -35, 1], [-10, 29, 10, -11], [-18, -14, 10, -7], [-24, -34, 14, -6], [-12, 16, 2, 2], [-16, -26, 12, -18], [-18, -10, 11, 6], [12, -6, 2, -2], [37, 7, -4, -9], [19, -17, 13, -19], [-35, 9, -9, 7], [-8, 9, -22, 5], [-24, 14, -2, -16], [18, 16, -10, 13], [14, 24, 2, 28], [-4, 0, -17, 16], [15, 1, 19, 13], [-12, -12, -6, -38], [0, -18, -2, -8], [37, 1, 11, -9], [-12, 2, -19, 18], [15, 13, -1, 3], [-23, -9, -6, -29], [-2, -18, 12, 2], [14, 7, 8, -3], [18, 10, -4, 0], [0, -14, 0, -38], [-8, 24, -7, 0], [-7, -3, 25, 5], [26, 11, 2, 2], [-19, 11, 3, -17], [-3, 10, -6, 22], [12, 13, 6, -19], [8, -8, -6, 4], [-14, -19, -2, 14], [5, -9, 23, -17], [-16, 20, 0, 0], [20, -18, -2, -12], [8, 19, -10, -17], [-4, -10, 1, -6], [8, -20, -20, -16], [8, 2, 16, 12], [-18, -37, 7, -15], [42, 12, -6, 0], [5, -3, 25, 17], [24, 3, 16, -8], [-28, 7, 20, 5], [-29, -19, 5, 5], [-7, -17, -15, -11], [-34, 7, -2, 6], [-6, -4, 6, -22], [-12, -29, 0, -9], [-7, -21, -15, -11], [12, 10, 3, 14], [-22, 20, 0, 2], [5, -5, 9, -18], [1, 3, -3, 21], [12, 8, 0, -20], [-26, 16, -10, 10], [9, 2, -9, 5], [-23, 7, -21, 1], [24, -14, -8, 4], [-36, -27, 19, -9], [6, 13, -22, -12], [38, 0, 14, 0], [-8, -9, -16, 3], [-12, -11, 10, -15], [-17, -13, -1, -27], [17, 15, 1, 29], [-25, 3, -13, 18], [2, 21, -8, 23], [-2, 12, 12, 22], [-31, -11, -6, -27], [-10, -20, 14, -30], [0, -20, 8, -36], [-24, 18, 16, 0], [28, 10, 20, 17], [32, -2, 12, 15], [25, 7, -3, -9], [-2, -4, -18, 26], [14, -10, 2, -38], [-2, 16, -28, 18], [3, 11, -2, 7], [-1, -15, -13, -15], [2, 17, -4, -9], [24, -2, -10, -16], [-5, 5, 3, 13], [21, 8, -4, -12], [-2, 12, -4, -6], [-5, -19, -5, 4], [0, 33, 15, 35], [-14, -32, 2, -3], [-9, 3, 19, 11], [-13, 27, 29, 5], [16, -16, 16, 18], [-18, -18, 2, 4], [6, -12, 19, -20], [4, -30, 8, -6], [-15, -6, 19, -5], [-31, 17, -3, 21], [11, -5, 5, 19], [38, 21, 3, 15], [-46, -5, 10, 2], [52, 3, 5, -7], [5, 21, 12, 17], [9, 11, 3, 3], [16, 16, -18, 2], [8, 16, -18, -6], [-12, -4, -2, 26], [-43, -3, 3, -15], [34, -2, -26, 5], [-30, -5, 3, -11], [7, -1, 17, -23], [-2, -2, 10, 23], [-6, 24, 8, 8], [-16, -10, -32, -10], [3, 12, 5, 17], [6, 36, 7, 28], [-54, -1, -10, 8], [-15, -2, -1, -17], [9, 7, 19, 27], [21, 31, -3, 39], [-74, -5, -4, -11], [-4, 17, 0, 20], [20, -29, -16, 5], [32, -17, 1, -35], [-5, -15, -35, -11], [-26, 26, 12, 24], [14, 50, -2, 50], [9, 1, 5, -47], [-13, 21, 17, 13], [-24, 29, 25, 3], [-16, 17, -12, -5], [-9, 37, 10, 45], [-6, 40, -10, 40], [-1, 0, -11, 11], [-31, 2, -30, -10], [45, -1, 17, -23], [-34, 36, -6, 40], [-17, 27, 3, 20], [5, 11, -11, 31], [-30, -24, 20, -8], [13, 15, 7, -19], [-24, 6, 10, -18], [17, 11, 7, -25], [-13, -11, -14, 1], [-2, -20, 16, 8], [-43, 9, -9, -21], [-20, 0, 10, 16], [-38, -27, 7, -9], [49, -3, 7, 13], [-8, -24, -4, -26], [1, -7, 7, 21], [8, -6, 24, -6], [-9, -1, -15, -5], [-26, 17, -2, 19], [36, 12, 24, 36], [47, 9, -5, 9], [26, 6, 2, 12], [-17, 14, 14, -14], [20, 12, 0, 30], [8, 27, 0, 38], [-12, -3, 11, -17], [14, -15, -7, 3], [8, -6, -28, 8], [11, -13, 11, -39], [62, -16, 2, -17], [12, -2, 22, -14], [-44, 10, 10, 18], [-6, 36, -2, -4], [-31, -9, -5, -3], [-13, 1, -33, 7], [-50, 14, 14, 8], [20, -12, -28, 0], [-23, -25, -9, -5], [-30, -7, -12, -17], [-4, 42, 4, 25], [-46, -5, 7, 13], [10, -2, 26, -16], [-14, -39, -16, -45], [5, -17, 3, -13], [5, -13, -10, -5], [-16, 1, -24, -25], [-16, -40, 0, -38], [-7, 13, 9, 9], [31, -11, -7, -17], [-8, -5, -10, -17], [8, 8, 28, -6], [22, 37, -14, 14], [-3, 1, -3, 3], [-1, 10, -8, -26], [-6, 18, 26, 22], [-2, 18, -4, 8], [1, 0, -29, -21], [27, 27, -5, 15], [28, -9, 4, -4], [-18, -10, -2, -11], [1, 31, -13, 39], [-7, -9, -13, -15], [-12, 17, 7, 31], [29, -19, 9, -25], [14, 3, 4, 17], [-55, -1, -7, -3], [23, -37, -9, -27], [26, 0, -6, 10], [25, -10, 14, -30], [-49, 9, -25, 34], [-10, -2, 1, 30], [12, -20, -4, -24], [14, -28, 6, -38], [5, 13, -15, -26], [-12, 2, -16, 1], [11, -7, 7, 6], [-21, -15, -23, 11], [58, -2, -6, 12], [-13, -19, -17, -47], [-3, -29, 1, -22], [-30, -10, 10, -18], [-25, -9, 9, 3], [-21, 11, -11, 43], [18, 4, 8, -26], [29, -18, 10, 26], [16, -12, 0, 8], [17, 21, -11, -19], [-3, 28, -9, -11], [-27, -32, 2, -44], [-3, -12, -4, 48], [0, -18, 2, -36]];
    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_u();".
// 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_u(:prec:=4)
    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_u();".
// 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_u( : 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![-8, 32, -12, -4, 1]>,<11,R![4, 0, -28, 0, 1]>],Snew);
    return Vf;
end function;