
// Make newform 5415.2.a.p in Magma, downloaded from the LMFDB on 30 April 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_5415_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_5415_2_a_p();".
// 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_5415_2_a_p();".
// 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 := [-2, 0, 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_5415_a();"
function MakeCharacter_5415_a()
    N := 5415;
    order := 1;
    char_gens := [3611, 2167, 5056];
    v := [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_5415_a_Hecke( : Kf := Kf)
    return MakeCharacter_5415_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, 1], [1, 0], [-1, 0], [2, -1], [0, 1], [-4, -1], [-4, 2], [0, 0], [2, 4], [2, 5], [2, -6], [-4, -5], [6, 1], [2, -1], [6, -4], [-4, 0], [0, -6], [0, 4], [-12, 0], [-4, 6], [-2, 0], [0, 8], [-2, -6], [2, -9], [0, 3], [-2, -2], [-4, 4], [-8, 0], [-6, 2], [-4, -6], [-8, 0], [4, 9], [-14, 0], [4, -2], [2, -4], [2, -14], [-2, -14], [-2, 7], [-10, 0], [-8, 10], [-20, 2], [22, -2], [-8, 7], [8, 5], [-12, -2], [-8, -6], [4, 8], [-12, 4], [2, 12], [4, -4], [-14, 4], [4, -1], [-2, 12], [20, -5], [-4, 2], [-18, -10], [10, -13], [-28, -2], [-6, 12], [2, 9], [2, 3], [12, 14], [12, -14], [-28, -3], [-18, 6], [0, -8], [-10, 2], [-24, -3], [2, 6], [18, 8], [-2, 4], [0, 7], [-18, -1], [0, 7], [-10, -10], [-12, 0], [-2, 12], [30, 4], [-6, -17], [-18, 6], [-8, -19], [26, -8], [-12, 6], [-8, 5], [16, -12], [10, -8], [2, -7], [26, 2], [22, -8], [-18, 7], [22, -4], [0, -27], [0, 2], [12, 7], [-4, -14], [-2, 2], [-14, -13], [6, 13], [-4, 14], [-10, -16], [20, 10], [10, 0], [-14, -20], [-6, 9], [0, 14], [-18, -14], [6, 4], [-18, -8], [-12, 24], [26, 2], [-12, 10], [-6, 22], [-4, 10], [-24, -14], [0, 16], [10, -1], [-18, 17], [14, 22], [0, 30], [20, 0], [-10, -6], [-12, -7], [28, 12], [0, -4], [8, -22], [-6, 4], [-24, -8], [-32, 11], [-6, 1], [10, -8], [-4, -4], [4, 8], [6, 22], [14, 2], [18, -20], [-30, -4], [16, 12], [12, -18], [-8, -2], [38, 8], [4, 8], [26, 18], [10, -9], [-26, -16], [30, 6], [4, -22], [-18, 6], [-4, -24], [-8, 24], [20, 8], [-8, -7], [-22, -18], [14, 23], [8, 0], [-24, -10], [12, 8], [-12, 0], [-26, -18], [18, -26], [2, 11], [10, 2], [20, -10], [-18, -7], [-12, -4], [0, -28], [2, -24], [56, 4], [-42, -6], [26, 20], [-22, -4], [36, 14], [58, 0], [20, 23], [10, 4], [24, 24], [22, -2], [8, 22], [10, 18], [-12, 30], [50, 0], [-54, -3], [-4, -24], [44, 13], [0, 6], [14, -20], [22, 12], [-8, 15], [44, -6], [-30, -2], [-40, -7], [-28, -25], [-2, -36], [-12, 4], [-26, 11], [22, -20], [36, -6], [16, 0], [6, -16], [8, -18], [-54, 8], [22, 23], [-16, 0], [-4, 25], [-18, -16], [-20, -19], [-36, -22], [0, 20], [-26, -12], [46, 6], [-28, 0], [26, -22], [-14, -2], [6, 23], [2, 16], [-32, -2], [-38, 10], [6, -13], [-2, -7], [14, 16], [-8, -14], [-18, -12], [-18, 6], [-38, -9], [30, 17], [-22, 4], [-22, -16], [-16, -18], [12, -10], [4, -20], [-28, -11], [-22, 10], [18, -22], [24, 4], [-14, 23], [10, -11], [38, 0], [-4, 36], [6, -12], [28, 13], [24, 10], [-32, 32], [-28, 20], [30, -33], [14, -38], [12, 28], [28, -23], [46, -19], [-12, 20], [18, 2], [46, 2], [-26, 22], [-22, 4], [26, 10], [-54, 14], [32, -2], [-48, 19], [-12, -36], [24, 8], [-16, -8], [-14, 12], [-12, 0], [-44, -20], [-14, -8], [-24, 5], [-16, -34], [-6, 22], [14, 15], [-50, 18], [4, 12], [-64, 6], [-22, -36], [12, 0], [34, -18], [-16, -2], [-8, -31], [30, 21], [-26, -2], [58, 6], [-10, -30], [16, 23], [-20, -12], [-12, 12], [34, 24], [-46, 0], [30, 9], [44, 17], [18, -16], [36, 28], [16, -12], [-54, 1], [66, 2], [-18, -22], [-56, 8], [4, 50], [-16, 35], [42, -18], [16, -4], [-12, 54], [16, 0], [2, 1], [-34, 16], [-28, -12], [52, -16], [-26, 20], [60, -2], [8, 21], [28, -36], [-10, 20], [20, -11], [-26, 10], [-14, -40], [34, -12], [58, 3], [-20, 14], [-2, 6], [-10, -16], [4, -11], [8, -12], [42, 18], [10, -8], [2, 14], [-2, -26], [30, -9], [-20, -42], [44, 2], [-2, 24], [36, 12], [-60, -14], [42, 20], [-4, 46], [-14, -40], [36, -40], [12, 22], [-54, 18], [-4, -18], [-26, -10], [22, 8], [-24, -20], [-24, -16], [54, -5], [8, 17], [-26, -16], [-2, 7], [-70, 6], [-44, 24], [40, 24], [-8, -60], [0, -28], [-12, -24], [6, -32], [-58, 14], [12, -23], [-30, -22], [12, -10], [30, -26], [-48, 0], [-36, 9], [20, -23], [-48, -10], [-28, 16], [-58, 16], [6, 0], [36, -36], [-40, 34], [14, -41], [16, 3], [10, -20], [-16, -42], [-22, -42], [-24, 37], [-12, 40], [-66, -6], [-26, 3], [-4, -40], [42, -6], [32, 0], [-88, 9], [2, 44], [-26, 50], [-32, 25], [-10, -57], [-8, 14], [2, -39], [-46, -20], [26, -14], [70, -12], [-56, -10], [2, 4], [50, -23], [-58, 20], [18, 26], [4, 4], [24, 45], [66, 13], [20, -38], [28, 31], [-38, -10], [-22, 13], [-2, -30], [-58, -4], [38, -4], [48, -10], [-16, -22], [-60, -6], [-2, -11], [-12, 32], [38, -22], [50, -3], [20, -10], [8, 5], [-12, 11], [52, -6], [-76, -12], [24, 14], [38, -4], [98, 0], [16, -16], [-28, -36], [-2, 24], [20, -16], [-38, -23], [40, 5], [18, -8], [16, -52], [8, -3], [24, -50], [-8, -48], [10, 24], [16, 6], [48, 17]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5415_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5415_2_a_p();".
// 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_5415_2_a_p(:prec:=2)
    chi := MakeCharacter_5415_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_5415_2_a_p();".
// 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_5415_2_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5415_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, 2, 1]>,<7,R![2, -4, 1]>,<11,R![-2, 0, 1]>,<13,R![14, 8, 1]>],Snew);
    return Vf;
end function;