
// Make newform 5290.2.a.x in Magma, downloaded from the LMFDB on 27 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_x();".
// 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_x();".
// 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 := [9, 6, -7, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [3, -4, -2, 1], [-4, -1, 1, 0]];
    Rf_basisdens := [1, 1, 3, 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, 1, 0], [1, 0, 0, 0], [-1, 1, -2, 0], [-2, -1, 1, 0], [-1, 1, -1, 0], [-3, -1, 0, 1], [-2, 3, -1, -1], [0, 0, 0, 0], [-1, 0, -1, 1], [-3, 1, 0, 2], [-2, 0, -1, 2], [1, -3, 4, -1], [0, 0, 4, 0], [3, -2, 0, -1], [-7, 2, -1, -1], [-1, -2, -1, 3], [-10, 1, -2, 0], [-3, 0, -1, -3], [-3, 1, -3, -1], [-1, 2, 2, -1], [6, -2, 5, 2], [1, 0, 1, -1], [1, 0, -5, -1], [-3, 1, 4, -1], [3, 0, 6, -3], [-7, 1, 3, -3], [-3, 0, 0, -3], [3, -1, 1, -2], [6, -6, 6, 0], [8, 0, -1, 4], [8, -2, -1, 0], [-6, -1, 0, 1], [0, -2, -10, 0], [-5, -3, 7, -4], [-1, 5, -5, 3], [-6, 2, 2, 4], [6, 1, -3, -1], [9, -2, 3, -1], [-4, -1, -4, 2], [-2, 2, -8, 0], [-5, -5, -3, 4], [-14, 0, 1, 2], [-2, 6, 3, 0], [4, -7, -2, 0], [-12, -2, 1, 2], [-5, 2, 4, 3], [-5, 0, -6, -3], [6, -4, 3, -2], [4, 0, -12, 2], [-8, -2, 13, -2], [6, -4, 12, 4], [-10, -4, -8, 2], [4, 3, 7, -1], [-10, 10, -1, 0], [3, -7, 3, 1], [6, -6, -6, 0], [-5, 1, -8, 4], [8, 2, -4, 2], [-17, -2, -2, 1], [10, 2, 5, -6], [4, -8, -2, -2], [-2, 7, 1, -8], [-12, -2, 6, 2], [8, -5, 6, -3], [3, -3, 3, 6], [-12, 8, -3, -2], [-10, -1, -6, -1], [8, -1, -7, 2], [-3, -10, 11, -1], [15, 4, 0, -1], [0, 4, -12, 2], [16, -6, 2, 2], [-6, -6, -4, 6], [-10, 7, 1, -6], [12, -4, 6, 4], [0, 1, 0, 8], [6, 5, -8, 6], [-6, -10, -9, 4], [-16, 7, 0, 5], [-6, 2, 6, -2], [5, -1, 7, 2], [-3, 0, 21, -3], [6, -1, 2, -5], [9, -5, 4, -8], [-14, 5, -11, -3], [6, -5, 0, -1], [-14, 4, 2, -2], [-6, -2, 6, 2], [3, -4, -4, -1], [-4, -6, 8, 4], [11, -8, 8, 3], [-6, 8, -11, 6], [2, 2, 2, -4], [-2, -2, 1, -8], [-19, 9, -4, -2], [-10, -2, 20, 0], [8, 4, -4, 6], [17, 0, -11, 7], [-26, 8, 0, -2], [12, -3, -3, 3], [-2, 8, 1, -6], [4, 10, 7, -2], [-17, 0, -11, -1], [14, -7, -9, 2], [-3, 16, -7, -3], [20, 5, -7, 2], [-15, -2, 3, -1], [7, 9, 7, -7], [0, 7, -16, -3], [3, -10, -5, 9], [-12, 8, -7, -2], [-1, 3, 8, 1], [-8, -3, 5, 5], [8, 2, -12, -4], [-13, 4, 2, -9], [22, -2, 0, 4], [7, 10, 7, -5], [15, 5, -9, 4], [16, -4, -14, 0], [10, 9, 12, -10], [-15, -4, 12, -5], [-8, 4, 19, -2], [-8, -3, 7, 5], [0, -2, -6, 2], [11, -9, 5, 4], [-12, 3, 10, 6], [19, -7, -14, -6], [23, 1, -5, -3], [-13, 10, 1, -3], [-9, -6, -20, 5], [3, -3, -18, 0], [-4, -4, 9, 8], [7, -10, -4, 3], [-2, -1, 4, -15], [-24, -4, -11, 4], [-11, -2, -11, 1], [20, -4, 19, 2], [26, 2, -4, 2], [-7, -5, 8, 3], [-3, -4, 12, -11], [17, 6, -16, 7], [-16, 0, -10, -2], [-2, -2, -20, -2], [-28, 8, -2, 6], [-8, 0, 7, 2], [7, 7, 9, -4], [32, -4, -1, -4], [-12, -10, -2, 6], [-9, 14, 6, 1], [26, -1, -16, 2], [-16, 12, -4, 4], [-14, -1, -11, 9], [4, 14, -11, 0], [-1, 8, 10, -1], [-17, -4, 7, 3], [1, -8, -6, -5], [20, -2, -4, 6], [-2, -11, 0, 7], [24, -5, 6, -4], [-14, -9, 13, -1], [-21, -3, 12, -9], [31, -12, 1, -7], [28, 1, -5, 4], [16, -1, -8, -3], [-29, 13, -11, 1], [-29, 7, -5, -5], [-6, 2, -26, 0], [-1, 6, -11, 1], [-4, 13, 2, -6], [20, 0, 14, 4], [-25, 8, -19, -7], [-4, -10, -4, 14], [5, -9, 10, 1], [-17, 5, 13, -3], [-8, 2, -2, 6], [12, 8, 8, 2], [8, 4, 23, 0], [3, 15, -23, 3], [29, 5, 3, -4], [24, -16, 15, 4], [16, -11, 7, -2], [21, -5, -3, 2], [-18, -2, 12, -4], [-35, 1, -5, 1], [11, -5, 17, -6], [-5, 17, -15, 4], [21, 12, -1, -3], [13, -1, 16, -9], [-9, 5, 3, 1], [-34, 6, -18, -6], [-6, -14, 18, 2], [2, 8, 16, -4], [18, -8, 3, 2], [-19, 12, -19, -5], [12, -11, 0, 11], [17, 14, -29, 5], [-23, 6, -1, -1], [12, -6, 6, 18], [12, 4, -3, 2], [-28, 13, -10, -6], [-17, -15, 22, -4], [2, 17, 2, -4], [-10, 4, -12, 6], [10, -18, 10, -4], [40, -18, 16, 8], [5, 8, 28, -7], [-4, -9, -19, 16], [6, 5, 0, 1], [-34, -8, -7, 6], [7, 2, -3, 7], [2, 8, -4, -4], [-5, -21, 0, 8], [4, 6, 4, -10], [24, -6, -6, 6], [-2, -10, -1, -6], [-12, 0, 19, -4], [36, -10, -6, 4], [-11, 9, 10, 2], [-12, 14, 0, -8], [0, -10, 3, -2], [-20, 2, -7, 6], [1, 1, -8, 1], [-9, -13, -4, 4], [4, -8, -14, 10], [8, 10, -13, 6], [-10, 5, -4, -19], [3, -13, 24, -8], [19, 7, -18, 4], [9, 4, -9, -7], [9, -7, 37, 0], [2, -21, 19, 4], [-1, 8, 16, 5], [-27, 1, 0, -13], [6, 20, -19, -2], [22, 4, -8, 4], [4, 2, -6, -6], [9, 12, 6, 3], [-20, 10, -14, 10], [-5, 21, 7, -7], [8, 2, -4, 2], [15, 20, 9, -11], [14, 4, -4, 0], [-3, -8, -6, 5], [-53, 6, 1, -1], [-15, 7, -36, 2], [12, -16, 3, -2], [4, 3, 7, -13], [-14, -13, 21, -12], [27, -13, 27, 7], [-24, 2, 11, 4], [-13, -14, 5, -3], [-13, -3, 20, -2], [-10, 4, -30, -6], [-30, 8, 6, 4], [22, -22, 4, 6], [22, 11, -16, 6], [25, -6, -15, 5], [-21, 9, -21, -12], [36, 8, 13, 0], [-11, 9, 3, -7], [-13, 8, -25, -7], [-2, -8, 4, 10], [20, -26, 15, 6], [9, 8, -30, 7], [14, -3, -9, 10], [-14, -13, 16, 0], [-15, -4, -3, -11], [1, -8, 20, -5], [-1, 3, 11, -20], [14, -14, 5, 0], [-2, 6, 17, 8], [14, 1, 22, -3], [-6, -6, 23, 6], [8, 4, -7, 0], [25, 12, 5, -5], [-28, -7, 29, -16], [-27, 0, 26, -5], [-18, 8, 5, 10], [2, 5, 5, -7], [25, -16, 22, 3], [2, -18, -9, 10], [-53, 5, 7, 9], [-4, 14, -12, -4], [4, -27, 19, -1], [3, 15, 3, 3], [-18, 2, 14, -14], [-39, -8, 12, -7], [-15, 9, 13, -7], [-5, -5, 34, -5], [-6, 10, -24, 8], [-20, 0, -11, -10], [-19, -14, 17, 3], [-34, 1, 11, -9], [28, -19, 6, -8], [-20, 15, -14, 2], [1, 16, -37, 1], [10, 11, 10, -18], [6, 0, 30, -12], [12, 5, 19, -12], [-30, 11, -22, -11], [-33, 4, -3, 5], [-7, 2, -18, -1], [6, 8, -24, -8], [10, -5, -3, 13], [12, -10, -27, -2], [42, -13, 3, 10], [-35, 15, -15, 2], [37, 2, 4, -3], [-6, 3, -18, 0], [54, -10, 6, 4], [-17, 25, -11, -2], [-33, 14, -12, -5], [-42, -5, 11, 0], [3, -11, 0, -4], [1, 10, 14, -5], [-20, 2, -11, 12], [5, 9, -40, -2], [6, -12, -26, 6], [5, -3, -22, 13], [-8, 15, -3, -4], [-23, -1, -24, 9], [-9, 2, -15, 25], [28, -28, 9, -2], [-9, 27, -6, -15], [2, 0, 10, -14], [58, 1, -1, 1], [20, 5, 27, -17], [-53, 9, 4, 2], [-18, 2, 24, -8], [8, 2, -19, -4], [-24, -3, -12, -6], [-34, 20, -20, -6], [18, -11, 3, 5], [2, 30, -8, -2], [8, -3, 11, 13], [26, -3, 16, -14], [14, -4, -10, 14], [7, -9, -2, 17], [-15, 23, -17, 1], [10, -6, -14, 14], [-25, 13, 20, -3], [23, 2, -1, -13], [-13, -18, 18, -5], [1, 26, -32, 3], [9, 28, -21, 5], [-13, 6, 32, 1], [26, -5, -25, -9], [-40, 18, -31, -14], [3, 4, -33, 5], [-31, 22, -33, -13], [10, 4, 20, 0], [-28, 10, 29, 0], [-43, 7, 1, 3], [-4, -2, -12, 6], [4, -2, -8, 10], [-27, 16, -15, -13], [8, 21, -31, 13], [-7, -28, 11, 5], [-3, 6, 33, 9], [-8, -14, 18, 4], [6, 16, 0, -10], [7, -8, -11, 1], [-20, 9, 13, -16], [26, 9, 15, -6], [14, 24, -10, 4], [-18, 7, -6, 26], [4, 2, 2, 6], [23, 2, 10, -7], [-17, 10, 4, -5], [7, 2, 25, -9], [23, 0, -4, -17], [30, 3, -30, -6], [21, 0, 28, 3], [47, 13, -11, -2], [-45, 18, -27, -3], [26, 0, 17, -2], [53, -9, 0, 7], [7, 6, 22, 5], [10, -12, 40, 2], [-12, 3, 12, 6], [-19, -5, -34, 3], [13, -24, -11, 11], [3, 0, 0, 9], [8, -10, 30, 8], [-14, -4, -32, -6], [-41, -15, 40, -10], [-21, 15, -9, -18], [13, -12, -31, -1], [29, 23, -16, -4], [33, -16, -1, 1], [-39, -3, -9, 0], [12, 6, 33, -6], [-10, -4, -10, 2], [-35, 12, -8, 5], [-50, -11, -4, 7], [-38, 10, -25, 4], [-7, 12, -31, 7], [40, 1, -27, 1], [-2, 8, 10, -12], [-56, 18, -25, -8], [9, -26, 18, -7], [-12, -8, 16, 2], [10, -5, 4, -5], [-33, 22, 0, 11], [17, 15, 19, -1], [-14, 30, -36, -4], [-22, 9, -28, -5], [39, -2, -19, 5], [-34, 14, -7, -28], [-36, -6, 0, -12], [-30, 9, 6, 0], [-14, -10, 31, -12], [-18, 1, -11, 2], [14, 9, -6, -17], [-56, 4, -11, -2], [27, 13, 0, -10], [3, 4, 21, -1], [33, -1, 0, -5], [27, -17, 12, 20], [-52, 27, -10, -8], [-11, -8, 0, 7], [-32, -12, -5, 14], [-37, 0, 2, -17], [28, 10, 22, -14], [0, -12, 6, 6], [-33, 24, -15, 3], [-16, -9, -4, -11], [-25, -10, -19, 11], [25, -1, -23, 3]];
    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_x();".
// 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_x(: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_x();".
// 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_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5290_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![7, -10, -7, 2, 1]>,<7,R![-1, -10, -15, 2, 1]>,<11,R![-9, 18, 29, 10, 1]>],Snew);
    return Vf;
end function;