
// Make newform 5440.2.a.bd in Magma, downloaded from the LMFDB on 21 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5440_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_5440_2_a_bd();".
// 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_5440_2_a_bd();".
// 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 := [-4, -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_5440_a();"
function MakeCharacter_5440_a()
    N := 5440;
    order := 1;
    char_gens := [511, 4421, 2177, 1601];
    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_5440_a_Hecke( : Kf := Kf)
    return MakeCharacter_5440_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, -1], [-1, 0], [0, -2], [-4, 0], [-2, -1], [1, 0], [0, -1], [0, 2], [-2, 3], [4, 1], [2, 2], [-6, 4], [4, -2], [-4, -1], [-2, 1], [-8, 3], [-10, 1], [-4, -2], [12, -3], [6, -5], [0, 0], [4, -4], [-2, -3], [6, -3], [-6, 8], [-8, 0], [-4, 8], [6, 1], [-10, 5], [-12, 1], [-4, 2], [10, 0], [-4, 8], [2, -2], [0, 6], [2, -8], [4, 4], [0, -2], [18, 0], [-12, 8], [-6, -4], [0, 0], [-14, -4], [2, -6], [-12, -1], [12, -6], [4, -3], [24, -3], [-6, 8], [14, -3], [8, 6], [2, 4], [-4, 0], [2, 0], [-12, -5], [-10, 5], [-16, 0], [26, -4], [14, 1], [16, -3], [14, 1], [-28, 4], [-8, 0], [-6, 0], [-6, -10], [0, 9], [-18, 3], [-8, -1], [10, 2], [2, 8], [16, -2], [8, 10], [-6, 12], [-4, -4], [4, 5], [2, -6], [-6, -6], [26, -6], [-10, 3], [-20, -2], [18, -10], [0, 8], [18, -8], [-8, 16], [28, 0], [-22, 2], [-6, -4], [18, -8], [-4, 7], [-12, -8], [-36, -1], [0, -10], [0, 1], [-4, -2], [8, -12], [-22, 2], [18, 10], [4, 14], [-30, 0], [32, -1], [-34, -1], [-20, 6], [14, -7], [20, 2], [10, -6], [-12, 2], [2, -4], [-16, 10], [18, -10], [8, 14], [6, 7], [14, -3], [4, 2], [40, 0], [-14, -4], [20, 8], [-4, -3], [18, 8], [-24, -7], [18, -14], [-18, 15], [10, 12], [-8, -13], [20, -4], [10, -22], [6, -17], [-28, 5], [-44, -1], [2, 8], [8, -11], [16, 2], [-4, 11], [6, -21], [10, -12], [14, -1], [10, -12], [16, -17], [2, -8], [-22, 16], [-12, 6], [-18, 13], [-16, 6], [-20, 8], [-6, 6], [-12, -9], [-38, -4], [30, -11], [8, -17], [-32, 8], [26, 10], [2, -12], [12, 6], [16, -26], [16, 1], [0, 0], [16, 2], [2, -24], [2, -18], [30, -1], [40, 5], [34, 2], [-40, 8], [8, 3], [-22, -2], [32, 2], [4, -15], [-22, 4], [-54, -2], [10, 0], [-8, -5], [18, 4], [44, -3], [-38, 4], [24, 10], [2, -14], [4, -2], [-10, -13], [-12, 19], [-6, 2], [12, 7], [12, -10], [18, -2], [-14, 18], [-16, 16], [18, -14], [-6, 14], [-20, 2], [-30, 22], [0, -12], [18, 4], [32, 5], [-32, 7], [10, 2], [-8, -3], [42, 0], [26, 2], [10, 10], [-18, 23], [-4, -19], [-14, -16], [4, -11], [10, 8], [14, 7], [44, 0], [-14, 12], [0, -16], [4, 0], [-46, 10], [-32, -7], [-10, -19], [-14, -6], [24, 16], [-28, -6], [-20, 21], [2, -18], [-12, -11], [30, 15], [16, -10], [30, -21], [-22, 4], [-44, 3], [2, 0], [40, 2], [-52, -2], [34, -10], [14, 1], [52, -11], [4, -9], [-4, 8], [30, -1], [12, 10], [56, -2], [6, -5], [4, -2], [16, 8], [-22, 14], [-30, -10], [4, -18], [-8, -16], [-40, -7], [-4, 0], [24, -16], [26, 2], [-2, -25], [-28, -1], [-8, -6], [12, -26], [-4, -4], [-28, 25], [-18, -9], [-38, -2], [-4, 5], [26, -12], [14, -29], [-8, 13], [-26, 27], [12, 0], [26, -16], [26, 8], [8, -10], [-28, 0], [42, -20], [-54, 2], [-10, -7], [-28, 16], [-14, 8], [-50, 9], [-32, 9], [-22, 12], [-10, 5], [4, -12], [2, -14], [16, 4], [-30, 12], [4, -5], [-20, -4], [-22, 18], [30, 9], [32, -9], [32, -8], [-36, -7], [-16, -10], [-62, 10], [-36, -8], [-8, 10], [22, -27], [-30, 6], [40, 8], [6, -3], [46, 3], [-48, 7], [2, 10], [-4, 16], [2, 20], [22, -15], [8, 18], [6, -5], [-36, 12], [-4, -10], [50, 2], [54, -11], [-4, -21], [-8, 17], [20, 18], [2, 8], [-28, 14], [-42, 21], [-32, 14], [-18, -15], [0, 8], [-6, -12], [-22, -22], [-12, 36], [-36, 29], [-2, 25], [-40, -11], [-16, 32], [-78, -4], [-10, -3], [20, 4], [-50, 17], [-22, 26], [-32, 24], [30, 1], [-2, -33], [20, 0], [-32, -15], [-16, 0], [-22, 4], [2, 28], [18, 20], [-16, -16], [-20, 10], [-36, 8], [12, -24], [-14, -28], [34, 0], [26, 12], [16, 16], [54, -9], [-38, 24], [-26, 7], [-16, -26], [-62, -8], [28, 10], [26, -32], [-44, 10], [20, -7], [-38, 20], [-28, 0], [58, -4], [-6, -6], [24, -18], [50, -6], [66, 2], [-48, 4], [-28, 18], [-30, -20], [44, -19], [42, -4], [-78, 2], [-64, 12], [-20, -8], [12, 2], [-14, 26], [50, 8], [-12, 3], [-6, -24], [-40, 9], [-12, 14], [-40, 30], [10, -16], [40, -24], [26, -2], [-60, 8], [12, -13], [42, -22], [38, 1], [74, -12], [-42, -7], [-14, -14], [-32, -14], [30, 11], [20, 16], [-48, -6], [8, -2], [10, 32], [-16, -27], [16, -20], [26, -2], [34, 18], [-72, 7], [-76, 0], [-32, -18], [10, 28], [-48, 28], [-22, 16], [-28, 26], [-22, 24], [18, 4], [-30, 40], [-12, -19], [22, 11], [-14, 14], [-8, 12], [-34, 15], [-14, -32], [12, 30], [-4, -14], [-18, 19], [-58, 3], [4, -22], [36, -20], [26, 12], [46, 3], [-16, 24], [32, 14], [14, -5], [-68, -15], [-46, 28], [-62, 2], [8, 2], [-48, 1], [-26, 19], [-42, -3], [52, -36], [-70, -8], [-56, 7], [-8, 8]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5440_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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