
// Make newform 5290.2.a.h in Magma, downloaded from the LMFDB on 05 September 2025.
// 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_h();".
// 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_h();".
// 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 := [-3, -1, 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 := 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]];
    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, 1], [-1, 0], [-1, 1], [2, 1], [-1, -1], [0, -3], [-1, 1], [0, 0], [0, 0], [-1, -1], [6, 0], [-6, 3], [-4, 4], [2, 4], [0, 6], [2, 4], [-8, 5], [10, 2], [0, 3], [0, 4], [6, 0], [8, -2], [-2, 2], [-8, -1], [-6, 0], [6, -3], [-2, 8], [5, -5], [18, 0], [6, -2], [-12, 0], [7, 5], [0, -10], [3, -3], [-4, 3], [-14, 2], [1, -3], [-2, -10], [-6, 9], [10, -10], [-7, -5], [18, -6], [22, -2], [10, -13], [-16, 4], [-2, 6], [16, -2], [-4, -2], [14, 4], [6, 6], [4, 8], [16, -4], [25, -1], [14, -2], [-6, -9], [-2, -10], [-21, 7], [-2, 12], [-2, 8], [8, -8], [10, -4], [-16, -1], [-12, 0], [1, 11], [3, 3], [-18, -2], [-17, -7], [-28, 1], [0, 2], [12, 6], [-6, 0], [16, -4], [-4, -2], [22, -1], [12, 0], [8, -17], [2, -9], [-14, 2], [17, -3], [0, -12], [-11, -1], [-8, -4], [-5, -7], [-13, 3], [3, 3], [7, 11], [-2, -4], [8, -2], [-6, 14], [20, -14], [6, -18], [22, -14], [10, 2], [2, -4], [19, 5], [-6, 6], [14, -8], [-4, -2], [-32, 4], [-9, 7], [18, 0], [30, 0], [28, -10], [10, -19], [-20, 10], [20, -11], [26, 4], [12, -15], [25, -11], [18, -10], [-40, 4], [16, 5], [-7, 19], [20, -14], [24, -6], [-6, 6], [-28, -2], [11, -17], [32, 4], [0, -15], [6, 10], [-28, 4], [17, 1], [6, 10], [3, 21], [16, 11], [-27, -3], [-22, -11], [0, -18], [12, 2], [15, -3], [-10, 10], [-20, -10], [17, -23], [-28, 16], [34, 2], [34, -10], [16, 14], [-2, 5], [-2, 0], [-30, 6], [2, -4], [-36, 6], [-6, -16], [-12, 18], [17, 9], [12, 12], [18, -10], [-16, 4], [-38, 15], [-12, 24], [23, -13], [-6, 12], [30, 0], [12, -12], [-4, -2], [30, 0], [-17, 5], [-20, -7], [23, -17], [-32, 11], [-34, -4], [30, -9], [-23, -1], [-38, -7], [44, -7], [-14, -8], [-26, 8], [-42, 3], [24, 12], [-44, 12], [42, 6], [-40, 7], [20, -13], [26, -14], [-34, -12], [26, 4], [10, -7], [-1, 13], [26, 14], [-50, -1], [35, -1], [34, -10], [-30, 9], [39, -15], [11, -9], [2, -14], [-22, 11], [-28, 19], [4, -14], [-8, 8], [8, 4], [10, 20], [12, 6], [-9, -3], [24, 0], [-12, -18], [-6, 12], [-16, 22], [-12, -15], [-21, 19], [-6, 7], [-36, 12], [-28, 16], [26, 16], [-34, 10], [48, 3], [27, -21], [32, 2], [-8, 16], [-54, 12], [-13, 1], [6, -6], [-28, 4], [12, -6], [26, -30], [2, -20], [-11, -13], [-38, -4], [32, 2], [20, -20], [-18, -3], [-23, -1], [12, -24], [44, -22], [-11, -1], [39, 3], [1, -25], [42, 6], [-7, 21], [30, -3], [-8, 14], [2, -5], [20, 10], [36, -24], [6, 6], [10, -16], [6, -30], [-44, 5], [54, -18], [-4, -22], [10, 12], [28, -12], [0, -12], [-27, -3], [-32, -6], [15, 9], [-2, 11], [14, 7], [30, -30], [38, 4], [29, 7], [-8, 20], [2, 4], [40, -10], [-28, -5], [-42, 24], [35, 19], [-12, -28], [14, 7], [24, -18], [24, -32], [8, 22], [6, -18], [-6, -3], [12, -27], [-52, 10], [-12, -24], [1, 17], [28, -6], [-30, 24], [-15, 15], [10, -16], [-8, 12], [-2, -8], [24, -33], [46, 4], [-32, -16], [3, -3], [-48, -6], [-46, 16], [18, 21], [-50, 8], [43, -21], [4, -37], [50, -8], [24, 0], [-28, 9], [-18, -15], [-18, 36], [30, 6], [30, -12], [-51, 27], [22, 1], [60, -3], [-8, 32], [-30, 9], [-14, 8], [8, 9], [9, -21], [-52, -8], [8, 4], [-28, 4], [33, 15], [38, -10], [-4, -5], [-17, -19], [26, 4], [30, -35], [30, 18], [1, 11], [12, -36], [20, 21], [41, -5], [-10, 4], [0, -12], [9, 21], [-26, 44], [6, -21], [42, -9], [-40, 19], [20, -14], [-32, -14], [-12, -27], [48, 0], [35, -23], [-23, 37], [11, -35], [6, 18], [-34, 38], [30, -3], [16, -20], [-55, 1], [16, 8], [-59, 5], [-28, 1], [-62, 20], [-26, -15], [78, 3], [-26, 36], [-48, 33], [42, -18], [34, 20], [-46, -14], [18, 6], [22, -6], [-7, -7], [-24, -12], [-36, 12], [-20, 40], [18, -4], [2, -14], [-34, 19], [-10, 16], [-10, -2], [-10, 16], [-77, -7], [-16, -14], [-24, 18], [32, -38], [14, -20], [-42, -12], [46, -25], [96, -1], [46, 0], [42, -33], [0, -24], [34, -40], [-38, 14], [2, 8], [26, -26], [-56, 23], [-24, 18], [-11, 1], [12, 0], [54, -6], [4, -1], [10, -4], [-20, 12], [4, -1], [44, -23], [-10, -16], [-10, 34], [-44, 8], [-20, -28], [-17, -9], [39, 7], [-24, -6], [-13, -23], [-44, 26], [-35, 29], [14, 16], [-20, -24], [-26, 2], [55, -31], [-44, 20], [10, -10], [37, -13], [30, 0], [-2, 22], [-80, -4], [28, 8], [57, -21], [-28, 10], [28, -11], [-10, -26], [-7, -11], [40, -28], [38, -8], [-32, 6], [22, -13], [34, -16], [14, -35], [-13, 49], [24, -12], [-59, 5], [-32, -12], [4, -7], [-45, 21], [-48, 27], [-58, 16], [28, 2], [6, -12], [-18, -14], [-26, -4], [-30, 18], [69, -3], [-2, 0], [48, -15]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5290_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5290_2_a_h();".
// 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_h(: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_h();".
// 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_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5290_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-3, -1, 1]>,<7,R![-3, 1, 1]>,<11,R![3, -5, 1]>],Snew);
    return Vf;
end function;