
// Make newform 5376.2.a.z in Magma, downloaded from the LMFDB on 15 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5376_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_5376_2_a_z();".
// 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_5376_2_a_z();".
// 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, 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_5376_a();"
function MakeCharacter_5376_a()
    N := 5376;
    order := 1;
    char_gens := [2815, 5125, 1793, 4609];
    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_5376_a_Hecke( : Kf := Kf)
    return MakeCharacter_5376_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], [1, 0], [-1, 1], [1, 0], [1, 1], [4, 0], [-1, 3], [0, 2], [3, 1], [4, 2], [2, 0], [-2, 0], [-1, -5], [-2, -4], [4, 0], [0, -2], [-8, 0], [2, -6], [-4, 6], [5, -5], [12, -2], [-2, -6], [-6, 2], [-7, -3], [8, -6], [-13, 1], [14, 0], [3, 3], [4, 4], [-4, 6], [2, 10], [6, -6], [0, 2], [-4, -4], [-8, 6], [8, -4], [-2, 6], [8, -2], [6, 6], [3, -11], [-5, -9], [12, 4], [23, 1], [-14, -6], [-6, -12], [8, 0], [14, -8], [12, -4], [6, -10], [4, 4], [-6, -4], [19, 5], [-4, -2], [6, 10], [9, -3], [1, 3], [-21, 1], [22, -4], [10, 4], [22, 4], [8, -6], [-19, 3], [-8, -10], [-4, -16], [-6, 4], [-8, -6], [6, 4], [-6, -16], [-15, 1], [2, -10], [27, -5], [27, -3], [0, 8], [12, 0], [-22, 4], [-18, -6], [-24, -2], [2, -10], [4, -10], [16, 14], [-16, -4], [-18, -12], [-1, -3], [14, 12], [0, 8], [9, -11], [-20, 2], [-10, 12], [-19, -1], [-10, 18], [10, 6], [-4, 20], [-8, 0], [15, 7], [-2, 8], [6, 6], [-15, -9], [-9, 3], [8, 4], [26, 0], [20, 14], [-28, 2], [12, 20], [-22, -8], [-12, 6], [10, 20], [-10, -10], [-7, 5], [-3, 3], [2, 0], [-12, -20], [-28, 8], [32, -2], [4, -8], [-26, -2], [-40, -2], [-16, 14], [-6, -22], [-18, -8], [7, 7], [30, -6], [-6, 18], [-33, 1], [1, -19], [-4, -12], [6, 16], [-4, 4], [14, 2], [10, -20], [40, 4], [-4, -6], [35, -3], [-12, 4], [16, 0], [-15, 1], [10, 0], [-9, 21], [20, -4], [-13, 5], [-24, 10], [0, 12], [36, 10], [10, -6], [21, -15], [12, 12], [-6, 22], [-6, 14], [1, 1], [-20, -18], [-39, 7], [16, -4], [21, -7], [-6, -4], [-18, 14], [-2, -8], [-1, -19], [-4, -4], [-29, -9], [26, -8], [-7, -29], [-11, 9], [6, 12], [-38, 2], [12, -12], [-6, -28], [16, -12], [32, 12], [-14, -10], [34, 14], [33, 11], [11, 11], [6, -6], [-27, -13], [-50, -6], [-4, -12], [45, -7], [16, -2], [14, -16], [-46, 0], [-22, 14], [-6, -18], [12, -16], [34, 16], [1, 21], [27, -19], [-3, 15], [32, -8], [0, 8], [14, 22], [-10, 6], [-4, 18], [17, -11], [-22, -20], [-43, -1], [-55, -7], [21, -7], [-18, -26], [10, 8], [27, -5], [-12, -24], [-18, 12], [28, 12], [20, 4], [28, -18], [-8, 12], [-19, -21], [32, 0], [33, 5], [6, -16], [28, 14], [-34, 8], [21, -1], [8, 28], [16, 20], [-12, -20], [-14, 4], [-24, -12], [37, -3], [-43, 7], [32, -10], [16, -8], [26, -20], [24, 6], [4, 12], [2, 2], [-14, 28], [-21, -5], [-19, -25], [-30, -8], [-35, 13], [24, -8], [-12, -10], [-8, 0], [-52, 10], [-32, -6], [24, 16], [-12, -14], [-10, -8], [33, 13], [-38, 18], [-55, 13], [-48, 12], [-12, 12], [-34, -8], [-23, -3], [10, -18], [26, 16], [-54, 2], [24, -22], [35, -15], [-8, -16], [-27, 1], [-9, 37], [28, 14], [-45, -7], [-57, -5], [10, -32], [20, -2], [-39, -1], [-2, 0], [-54, 2], [11, -21], [8, -24], [14, 26], [57, 1], [-16, 28], [6, -8], [31, 15], [-48, -14], [6, -32], [-54, 14], [26, -20], [-20, -6], [8, 4], [12, 2], [26, -4], [-13, -9], [-26, -24], [-34, -26], [54, 6], [-28, 8], [2, -2], [-28, -32], [10, 18], [-4, -16], [3, 25], [2, 28], [-2, 12], [70, -4], [-3, 41], [50, 0], [10, -26], [-44, -14], [48, 16], [-20, -8], [51, -19], [8, 16], [15, -27], [22, 30], [68, -8], [22, -20], [12, -10], [42, -22], [-19, 33], [20, -26], [10, 0], [39, -5], [16, 12], [-25, 1], [-54, 4], [8, 20], [-66, 4], [-22, -8], [-22, -12], [21, 15], [20, -30], [24, -32], [-5, 9], [16, 34], [36, 18], [24, 2], [-6, 22], [-3, 11], [52, -16], [-12, -30], [-32, -2], [64, 10], [-44, -22], [-67, 3], [6, 28], [8, 24], [30, -8], [6, 28], [-24, 4], [16, 10], [-4, 8], [-28, -24], [17, 5], [8, 38], [-22, 16], [-20, 8], [-18, -12], [-21, -7], [-12, 24], [24, 10], [-3, -31], [28, 16], [-30, 12], [36, -20], [43, 1], [-28, -14], [-46, -10], [-30, -16], [48, -8], [16, -4], [29, 1], [30, -6], [-8, -8], [8, 18], [33, -5], [-16, -28], [63, -9], [47, 5], [-33, 15], [-32, -8], [-10, 26], [39, 13], [70, 14], [-22, 6], [-39, 9], [-20, 26], [31, 1], [-26, 0], [6, 20], [-10, -4], [18, -26], [-15, -21], [-10, 16], [-11, -3], [-48, 10], [35, -11], [48, 18], [-44, 0], [18, -16], [32, -4], [82, 10], [-16, 36], [52, 28], [-24, 42], [-12, 28], [14, -38], [75, -3], [23, 31], [-52, -10], [29, -33], [-34, 20], [32, 8], [-3, 13], [-32, -6], [76, 2], [26, -30], [-44, -2], [-10, -18], [-9, 35], [19, -7], [16, -16], [-10, -16], [30, -24], [64, 4], [4, -24], [-66, 12], [-36, 18], [55, -21], [74, -16], [-26, -6], [51, 9], [39, 21], [42, -36], [13, -19], [4, 12], [-24, 2], [-14, 14], [13, -17], [54, -30], [58, -12], [-3, 19], [-91, 1], [-10, 0], [24, 24], [-46, 34]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5376_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5376_2_a_z();".
// 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_5376_2_a_z(:prec:=2)
    chi := MakeCharacter_5376_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_5376_2_a_z();".
// 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_5376_2_a_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5376_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-2, 2, 1]>,<11,R![-2, -2, 1]>,<13,R![-4, 1]>,<19,R![-12, 0, 1]>,<29,R![4, -8, 1]>],Snew);
    return Vf;
end function;