
// Make newform 5472.2.a.x in Magma, downloaded from the LMFDB on 22 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5472_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_5472_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_5472_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 := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_5472_a();"
function MakeCharacter_5472_a()
    N := 5472;
    order := 1;
    char_gens := [4447, 2053, 1217, 3745];
    v := [1, 1, 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_5472_a_Hecke( : Kf := Kf)
    return MakeCharacter_5472_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 := [[0, 0], [0, 0], [-1, -1], [0, 0], [0, -2], [-1, 1], [-2, 2], [1, 0], [-5, 1], [6, 0], [5, 1], [3, 1], [2, 0], [0, 4], [5, 3], [-4, -2], [-10, -2], [0, -2], [-10, 2], [-10, 2], [-4, -2], [-5, 3], [-10, 0], [6, 0], [12, -2], [-5, -1], [-5, -5], [-10, -2], [9, -5], [6, 4], [5, 1], [-10, 4], [-2, -6], [0, -8], [5, 1], [15, -1], [2, 8], [0, -8], [0, 0], [-6, 8], [0, 4], [-7, -5], [-5, -3], [-4, 10], [13, -3], [10, -6], [0, -4], [5, -3], [0, 0], [0, -2], [4, -4], [-15, 3], [0, 10], [-10, 0], [-18, 4], [-15, 3], [-10, 4], [-10, 6], [8, 6], [-2, 0], [-20, -4], [-14, 0], [-10, 6], [5, -5], [-24, -2], [-2, -4], [-10, -2], [2, -4], [-20, 2], [0, -6], [16, -4], [-5, -11], [10, -6], [19, 1], [-10, 6], [-10, 10], [15, -1], [-12, -10], [10, 0], [-4, -10], [0, 14], [15, 9], [-30, -2], [4, 2], [25, 1], [0, 6], [-10, 4], [-2, -4], [-15, 5], [10, -6], [-10, 0], [15, -7], [-5, -1], [10, -8], [-20, 0], [-15, -5], [-16, -10], [10, 12], [10, 14], [12, -10], [-10, -2], [17, 5], [10, -10], [-10, 12], [-20, 0], [-18, 8], [0, 2], [4, -12], [0, -16], [10, 0], [-5, 7], [-14, 8], [28, 0], [-40, -4], [10, 10], [-2, 0], [20, -4], [-5, -15], [21, -7], [20, 4], [15, 5], [4, 2], [12, -2], [-40, 4], [20, 0], [-17, -5], [10, 4], [5, 11], [40, 0], [36, 6], [20, 4], [-30, -2], [-45, 3], [-2, 12], [30, 10], [0, -18], [24, 6], [20, -8], [-8, -18], [-26, -10], [-30, -6], [3, 15], [-10, -18], [20, 16], [-39, -5], [30, 10], [6, -16], [2, -12], [-20, -8], [10, 6], [7, -3], [12, 0], [-20, -8], [20, 4], [-30, -2], [20, 4], [10, -14], [10, -14], [12, -10], [-20, 10], [-10, -20], [6, -16], [0, 0], [-20, -4], [-18, -4], [0, 16], [5, -23], [2, -16], [20, 14], [1, 21], [20, 0], [-43, -5], [5, 11], [16, -2], [-45, -1], [24, 0], [-40, 8], [-15, -3], [-15, 5], [-6, -20], [10, -14], [10, 6], [21, -9], [-22, 4], [5, -5], [41, 5], [17, 11], [0, -4], [-36, -10], [-25, -3], [34, -12], [30, -4], [-10, -2], [38, 0], [0, 22], [-14, 0], [-20, -18], [-4, -18], [48, 8], [-5, -3], [4, -10], [-5, 7], [-37, 13], [10, -4], [20, -6], [-13, -1], [0, 24], [-20, 0], [-16, 20], [-20, -12], [42, 4], [7, -25], [-30, 10], [50, 2], [30, 2], [0, -2], [-40, -8], [30, -12], [-10, 2], [-1, 7], [25, -5], [25, 1], [-34, 0], [-30, -6], [10, 6], [-4, 10], [-6, 16], [50, -10], [15, -5], [20, 10], [-26, -20], [20, 20], [-5, 23], [2, 20], [0, 0], [15, -19], [24, 10], [19, -5], [10, 8], [-10, -6], [-10, -10], [20, 16], [0, -8], [-35, 3], [-34, -4], [45, 7], [-10, -10], [-50, 2], [60, 4], [-45, -7], [2, 16], [-60, 4], [-15, 7], [-34, 0], [-59, 5], [0, 6], [2, -20], [-30, -6], [38, 0], [32, -10], [25, -7], [50, 6], [0, 10], [21, -5], [2, -22], [20, 24], [-44, -10], [-20, 12], [60, 4], [-1, 15], [37, -5], [40, -4], [44, -14], [-20, 20], [-22, -4], [10, 18], [30, 8], [45, 3], [-50, -12], [-40, -14], [-10, 10], [0, 32], [-15, 11], [-23, 15], [-40, -8], [-25, -19], [-26, -8], [-28, -22], [0, -16], [30, 0], [37, -15], [-10, -24], [6, -8], [20, 16], [-31, -1], [-5, 27], [15, -25], [-19, 5], [-30, 22], [20, 20], [14, -8], [18, 28], [-60, 12], [30, 6], [20, -8], [-48, 2], [-20, 20], [25, 3], [5, -13], [-34, -8], [15, -7], [1, 25], [-70, 4], [20, -20], [5, -37], [10, -4], [10, -24], [-20, -4], [-6, 16], [40, -12], [10, -26], [-42, 12], [22, 0], [-15, 17], [-14, -18], [40, -22], [30, -26], [40, 4], [10, 6], [49, -19], [-30, 24], [-32, 10], [-10, -18], [-20, 2], [0, 16], [-10, 24], [-49, 5], [-6, -32], [0, -2], [-20, 4], [-9, 5], [-22, -10], [-40, 10], [45, -15], [-86, -4], [-40, 0], [30, -4], [-10, -38], [-20, -28], [23, -13], [50, 6], [48, -6], [-23, 25], [-55, -3], [15, 21], [6, 8], [5, 7], [30, -8], [-2, 26], [50, -18], [-28, -18], [40, 12], [-50, 2], [20, 8], [-60, 8], [-14, -16], [47, -5], [-15, -35], [0, -2], [-10, 24], [20, -4], [-65, -3], [0, 10], [-30, -6], [42, -12], [20, 4], [-25, 21], [-16, -6], [-30, -22], [12, -18], [-40, 18], [14, 22], [10, 26], [-8, -16], [0, 4], [-10, -6], [40, 8], [32, 22], [40, 20], [-20, -20], [34, 20], [-34, -8], [-30, -8], [40, -16], [-30, -2], [-44, 6], [65, 13], [86, 0], [30, 26], [3, -45], [-39, 15], [-54, 2], [-95, 1], [-2, -12], [-50, 12], [0, 32], [-22, -12], [-70, 8], [60, 12], [70, -12], [-6, -24], [-37, 3], [-30, 22], [-20, 4], [42, -16], [-25, -5], [-20, 36], [35, -9], [18, 6], [-50, -22], [40, -6], [23, 21], [-35, 3], [40, -24], [56, 22], [42, 16], [-30, -30], [20, 12], [20, -4], [35, 25]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5472_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5472_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_5472_2_a_x(:prec:=2)
    chi := MakeCharacter_5472_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_5472_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_5472_2_a_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5472_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-4, 2, 1]>,<7,R![0, 1]>,<11,R![-20, 0, 1]>,<13,R![-4, 2, 1]>,<23,R![20, 10, 1]>],Snew);
    return Vf;
end function;