
// Make newform 5290.2.a.z in Magma, downloaded from the LMFDB on 25 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_z();".
// 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_z();".
// 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], [0, 1, 0, 0], [1, 0, 0, 0], [-1, 0, 0, 1], [-2, -2, 0, 0], [-1, -1, -1, -3], [-1, -1, 0, 1], [-1, 0, -1, -1], [0, 0, 0, 0], [1, 4, 0, 1], [-2, 1, 1, 2], [-4, -4, 2, 0], [-1, -2, -1, 0], [-3, 4, 0, 0], [-2, 0, -1, 3], [0, 3, -1, 2], [-1, -3, -2, -7], [-1, 1, 3, 3], [0, 0, 3, -4], [7, 0, 4, 3], [-3, 3, 5, 2], [-11, -3, 0, -4], [5, -2, 2, -6], [-10, 6, 2, 4], [-5, 0, -7, -2], [0, -4, -4, 4], [5, -5, 1, -7], [-9, -2, -3, 2], [-4, -4, -3, -1], [-9, -1, 2, 1], [1, 9, 0, 8], [-7, -5, 4, 1], [-13, 1, 2, -1], [-3, 1, -4, -5], [5, 9, 0, 10], [-1, -9, 3, -11], [-4, 10, 0, 10], [4, -2, -2, 8], [7, 5, 2, -2], [0, 0, 7, -1], [4, 11, -3, 5], [-3, 1, 3, -1], [2, 4, -7, -3], [-5, 1, -1, 8], [7, -13, -3, -7], [7, 1, 4, 0], [4, 5, -7, -1], [13, -3, 1, -3], [-7, -2, 8, -4], [-7, 3, 2, -6], [3, -8, 3, -3], [2, 8, 6, 4], [6, 10, -6, 3], [-1, 11, 3, 14], [5, -16, -1, -9], [-4, 4, -8, 2], [-9, 1, -1, 5], [-12, 4, -4, 6], [6, -8, 3, -11], [6, 7, 4, -6], [-2, 0, -9, 2], [3, -1, -3, -1], [6, 15, 0, 16], [7, -10, -12, -5], [-4, 7, 13, -1], [-3, 9, -6, 12], [20, -3, -3, -3], [0, 17, -1, 13], [-6, 0, 2, 5], [-8, 14, 4, 6], [-11, 1, 3, -4], [-2, 6, 9, -3], [2, 11, -5, -6], [-6, -5, -9, -2], [11, 4, -5, -3], [-1, 9, 5, -3], [-2, -4, -6, -14], [9, -7, -6, 2], [-4, 3, -12, 6], [-9, 12, -6, 6], [11, -3, 5, 0], [-15, -1, -2, -10], [-9, -3, -7, -3], [8, -16, -8, -12], [-7, -2, 8, 3], [-2, -3, -14, -8], [-8, -18, 3, -6], [15, 0, 5, -16], [13, -11, 7, -7], [-8, 0, 10, 8], [7, -6, -5, 8], [-4, -4, -9, 9], [9, -17, 1, -15], [-15, -10, -3, -18], [0, -11, 7, -9], [10, -4, 4, 6], [17, 6, 10, 17], [-10, -14, 8, -14], [7, -2, 7, 0], [-3, 4, -8, 17], [0, -17, -8, -7], [-14, -9, 7, -2], [9, -4, 4, 8], [-10, -5, -6, 0], [9, -11, 5, -16], [15, 0, -9, -7], [0, -1, 12, 12], [-23, -3, -3, 0], [-4, 3, -17, 10], [-15, -2, -9, 16], [-3, -9, 8, -2], [11, 0, 8, -7], [1, 3, -10, 5], [2, -6, 10, 8], [0, 6, 3, 9], [2, -5, 14, 10], [9, 0, -13, 6], [15, 17, -9, 11], [-31, 3, 2, -6], [13, 5, 9, 2], [14, 14, 9, 13], [5, -6, -15, 3], [6, -15, -3, -14], [14, 14, 6, 5], [-35, -8, 1, -4], [-2, -4, -5, -15], [-3, 13, 0, 24], [4, 11, 7, 14], [8, -14, -2, 0], [14, 11, 3, 8], [-23, 12, 5, 10], [0, 1, -11, -4], [21, -29, -13, -13], [-5, -8, 0, -11], [13, 4, 4, -18], [8, -22, 0, -16], [0, -14, -12, -18], [21, -6, -8, 4], [-15, 12, -8, 17], [29, -10, 6, -18], [-16, -19, 17, -5], [-17, 25, 5, 19], [4, -16, 7, -9], [9, 4, 0, -6], [-7, -11, -5, -15], [-1, -9, 11, -17], [-13, -3, 3, -3], [15, 3, -1, 14], [-9, 3, -6, 25], [11, -21, -10, 0], [12, -6, -12, 2], [10, 8, 8, -18], [10, 19, 6, 12], [4, 0, -3, 19], [15, -8, 6, -12], [-11, 9, -1, 7], [9, -1, -20, 4], [-10, -6, -4, -10], [9, -15, 10, -9], [4, -2, -11, 17], [14, 3, 20, 10], [-9, -2, 1, -4], [-13, 11, -13, 23], [-21, -10, -7, -7], [-11, 14, 5, -10], [-6, -8, -14, 6], [-3, -31, 1, -25], [24, -6, 4, -8], [-2, 9, -8, 10], [-1, -1, -18, 6], [7, -11, 1, 4], [-6, 4, -16, 4], [-12, -6, 22, -4], [-8, 7, -17, -9], [4, 14, 10, 2], [-20, 5, -16, -4], [-5, -4, 7, -18], [-10, 8, -16, -12], [6, -3, -11, 4], [-12, 10, 6, 8], [14, -8, 3, -7], [-15, -6, 7, 13], [-8, -8, 1, -7], [22, 9, 0, 15], [21, -2, 14, -3], [-34, -16, 10, 0], [30, 24, -9, 15], [12, -6, -3, 8], [13, -20, 2, -24], [11, 22, 6, 29], [29, -4, 3, -11], [16, 12, 8, 27], [18, 4, 4, 24], [-32, 17, 7, 4], [-17, -20, 4, 16], [1, -7, 10, -11], [-12, 16, 2, -6], [11, -3, 5, 11], [3, 32, -5, 4], [-5, -35, 1, -25], [-7, -3, 9, -7], [-25, 6, 6, 7], [18, 0, 3, -13], [2, -8, 26, 2], [17, -20, -13, 3], [8, -30, 8, -32], [0, -28, -4, -28], [-14, -7, -6, 3], [8, -8, -7, 2], [11, -2, -5, -20], [9, 4, 23, 11], [-9, -28, 10, 9], [2, 15, -19, -6], [-7, 8, 9, 2], [-18, 18, -2, -6], [-2, 16, -10, 31], [22, -10, 2, -10], [-16, -8, 1, -16], [-43, 2, -2, -13], [-16, 8, -6, 10], [2, -14, 8, -4], [-5, -1, 4, 6], [9, -14, -18, 6], [26, 7, 7, 10], [0, 16, 18, 21], [-13, -19, 21, -15], [-9, 8, 15, 12], [2, 0, -6, 24], [-12, 10, -6, -28], [-14, -19, 3, 19], [-39, 9, -2, 22], [37, -5, 17, -24], [6, -10, 5, 11], [31, 22, -2, 8], [-1, 4, 15, -14], [3, 1, -1, 27], [4, -4, 14, -5], [-12, -7, -5, -8], [-6, -18, -4, -2], [-31, 21, 5, 25], [-12, 34, 2, 22], [-13, 17, 20, 1], [-7, -7, -3, -9], [10, 6, -18, 0], [11, 4, 27, -9], [40, -6, -2, 0], [29, 13, -4, 2], [5, 15, -5, -20], [16, 14, -18, -2], [-46, 9, 11, 0], [-40, -5, -5, 10], [-16, 32, -2, 21], [-41, 9, -3, -19], [-16, 9, -16, -15], [26, -2, 3, -1], [1, -15, -6, -23], [-20, 0, -8, 8], [20, -8, 11, -22], [-33, 27, 0, 18], [0, -2, -4, -30], [-4, -26, -4, -40], [-24, 18, -5, 8], [-6, -3, 1, -2], [-25, 11, 1, 7], [-31, 11, -3, 22], [25, 12, -3, 3], [22, -8, 12, -18], [-22, -31, 2, -23], [6, 4, 20, -8], [16, 14, 1, -9], [-10, -17, -3, 10], [11, 24, -12, 14], [-16, -10, -2, -10], [-18, 22, 16, 16], [47, 9, 13, 14], [-12, 20, -4, 18], [12, -12, 4, -22], [17, 13, 15, 13], [-46, 12, -8, 5], [-39, -1, -3, 0], [7, -9, 18, -20], [-14, 2, 0, -14], [4, 4, -20, 24], [-6, -2, 6, -10], [8, 19, -10, 6], [-48, -11, -1, -4], [44, 22, -10, -2], [13, -25, -3, 19], [-8, 33, -15, 34], [9, -20, -10, -24], [-35, -1, 13, -11], [8, -12, -9, -20], [5, -21, -15, 8], [41, -15, -13, 2], [3, -27, -4, -30], [-10, -8, -9, 3], [-36, 6, 10, 14], [4, -14, 0, 24], [3, 21, -18, 15], [-42, 1, -6, 3], [8, -21, 9, -7], [-11, 18, 10, -3], [-15, -1, 6, 28], [8, -11, -6, 26], [-3, 17, 9, 4], [23, 21, 7, 12], [2, 19, -14, -10], [11, 21, -24, 24], [-29, -13, -9, -19], [-3, -1, 21, 13], [-40, 10, -8, -10], [-39, -7, 14, 8], [-22, -19, 0, -2], [24, 10, -2, -5], [-26, 25, 3, 14], [30, -3, 8, 20], [1, 6, 19, -26], [-11, 29, 13, 21], [24, 13, 7, 9], [-5, -30, -2, 20], [-1, -48, 7, -27], [-20, -21, 1, -27], [-16, -21, -3, -12], [51, 3, 12, -6], [-12, -22, -2, -38], [-38, -6, -22, 1], [-24, 15, 30, -1], [40, -9, -16, 6], [-16, 19, -5, 36], [-13, -9, 11, -21], [15, -13, 17, -15], [18, -18, -7, -9], [2, 3, 3, -26], [22, 28, -22, 11], [10, 54, -4, 40], [-20, 24, -2, 5], [-32, 4, 6, 6], [-9, -29, -14, -23], [-13, 16, 10, 30], [14, -3, -23, -2], [8, -18, 18, -8], [-16, 23, -1, -21], [-30, -3, -19, 2], [25, -1, 5, 31], [-23, 10, -4, -21], [-29, 24, -1, -18], [28, -31, -1, 12], [20, 20, 6, -15], [1, -13, 21, 3], [16, -45, -9, 0], [-6, -14, -14, 14], [19, 15, 9, 26], [-16, -11, -17, -32], [44, 6, -8, 4], [17, -11, 28, -10], [-42, 7, -12, 9], [10, 22, -35, -1], [-8, -6, -8, -22], [12, 6, 12, -4], [-6, 20, 3, -11], [-3, -19, -7, -17], [-35, 0, 8, -6], [-9, 17, -13, -7], [-7, -34, 19, -37], [-4, 5, 4, -32], [-29, 36, 3, -7], [25, 23, -1, 13], [-29, 28, 26, 13], [-36, 12, 4, -5], [3, 2, 7, 8], [25, -22, 21, -28], [16, 4, -12, -8], [-39, 7, -16, 2], [-9, -17, 10, -30], [-11, 15, -1, 49], [18, -24, 0, -24], [-47, 33, 16, 20], [-29, -24, -3, 12], [20, 6, -18, 1], [29, 22, 1, 9], [-27, 15, -1, 33], [32, 6, -2, 2], [17, 11, -4, 14], [-9, -12, -17, 27], [48, 0, -2, 6], [37, 13, -9, 27], [17, -22, -4, -19], [3, -41, -8, 8], [-10, -12, 2, 20], [-33, 5, 13, -3], [32, -8, 6, -5], [15, 23, 0, -14], [12, 19, 7, 41], [-12, -8, -34, 16], [-76, 16, 6, 6], [0, -13, 21, 3], [6, 0, 19, 17], [-32, -2, -4, 1], [-15, 10, -25, -1], [1, -50, 0, -39], [-18, -13, -17, -30], [7, -1, 11, -14], [25, 32, -18, -1], [0, 8, -12, -28], [-8, -3, 31, -12], [27, 10, 10, 15], [-46, -8, 14, 14], [19, -2, 20, 40], [-20, -2, -5, 40], [12, 3, 11, -25], [72, 20, 0, 16], [-51, -7, -9, -5], [37, -6, 12, 28], [31, 23, -17, 26], [-11, -9, -26, 27], [-36, -1, 23, 8], [7, -29, 15, -19], [-20, 8, 21, -11], [11, -5, 12, 23], [-8, 16, 24, 20], [22, -24, 5, -25], [18, -25, 17, -14], [8, 4, -2, -30], [-23, -19, 6, 3], [-24, -4, -20, -28], [3, -17, 18, 26], [-30, 32, -15, 52], [28, -20, -1, -2], [-9, 3, -4, 35], [-29, 5, -15, 23]];
    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_z();".
// 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_z(: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_z();".
// 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_z( : 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, 0, -4, 0, 1]>,<7,R![-2, -4, 2, 4, 1]>,<11,R![-32, -32, 8, 8, 1]>],Snew);
    return Vf;
end function;