
// Make newform 4332.2.a.e in Magma, downloaded from the LMFDB on 25 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_4332_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_4332_2_a_e();".
// 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_4332_2_a_e();".
// 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;
    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_4332_a();"
function MakeCharacter_4332_a()
    N := 4332;
    order := 1;
    char_gens := [2167, 1445, 3973];
    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_4332_a_Hecke( : Kf := Kf)
    return MakeCharacter_4332_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], [0, -1], [0, -3], [5, 0], [-4, 1], [-1, 2], [0, 0], [-1, 0], [-2, 6], [-4, 5], [2, 0], [-4, -3], [-5, -2], [0, 7], [-7, 8], [6, -8], [12, -2], [-11, -3], [8, 1], [-7, 2], [-1, 6], [-5, 12], [12, -4], [6, -2], [-5, 4], [1, -9], [-11, -4], [-7, -4], [-3, -7], [4, -6], [-1, -6], [5, 1], [-14, 10], [-19, 5], [4, -16], [9, -4], [14, -15], [-8, 0], [0, -8], [-23, 3], [0, 3], [3, -12], [-16, 14], [12, -3], [9, 6], [-19, 6], [-2, -7], [-15, 10], [21, -6], [-16, -6], [-10, 9], [8, -11], [7, -22], [-15, 22], [-20, 10], [17, -18], [-11, 9], [28, 1], [-8, 8], [9, 5], [16, 3], [-11, -2], [-19, 16], [-8, 16], [7, -25], [-9, 2], [0, 9], [-24, 6], [16, -7], [-23, 10], [-6, -17], [15, -6], [-5, 4], [18, 12], [-13, 23], [-23, 18], [13, -10], [7, -6], [30, -2], [17, 4], [1, 3], [13, -27], [12, -14], [-11, 6], [19, -8], [19, 1], [-3, 13], [-3, -13], [-12, -2], [5, -1], [-15, 5], [-25, -2], [12, -16], [1, -8], [14, -11], [16, 3], [-13, 2], [-16, 4], [38, -6], [13, -30], [-22, 10], [13, 1], [-5, -13], [-14, 22], [-1, -28], [-22, 33], [8, -16], [-24, 33], [-9, -7], [-11, -21], [-5, -8], [-36, 16], [-3, -3], [-18, -14], [15, 4], [20, -23], [0, 2], [-23, 14], [7, 0], [-5, -15], [-8, 12], [30, -32], [-26, 7], [3, 8], [-23, 20], [-7, -1], [25, -7], [13, 3], [-29, 20], [9, 11], [7, -34], [13, -27], [29, -16], [-8, -20], [-24, -13], [-5, 7], [27, -15], [12, 19], [-23, 36], [15, 4], [5, 3], [-1, 2], [9, -15], [42, 1], [34, -6], [-12, 24], [7, 18], [9, -35], [27, 0], [13, -6], [-14, 0], [21, 12], [-26, -14], [17, -22], [-17, -5], [-11, -6], [39, 6], [42, -16], [52, 1], [24, 0], [23, -28], [4, 29], [-15, -18], [-18, 22], [8, 22], [-43, 6], [3, -38], [-25, 18], [-8, 6], [-23, 27], [-14, 24], [-3, 11], [27, -20], [-18, 11], [-39, -7], [35, -42], [-38, 7], [-12, 16], [14, -38], [18, 10], [-18, 1], [11, -8], [5, -14], [-19, 7], [-7, 20], [33, 11], [-45, 30], [-24, -10], [-3, -13], [37, -17], [-3, 13], [15, -30], [-39, -4], [26, -19], [-15, -30], [-24, 36], [-6, 15], [-35, 39], [-18, -11], [2, -1], [-5, -29], [31, -10], [42, -34], [-48, 26], [-5, 4], [-25, 30], [-22, 6], [8, -40], [14, -23], [7, 34], [-13, -11], [-57, 17], [11, -21], [10, 13], [11, 12], [-9, 26], [54, 7], [-25, 4], [12, 5], [10, 12], [10, -35], [0, 10], [5, -22], [6, 19], [35, -27], [3, -34], [-27, -26], [-31, 13], [15, -22], [20, -37], [-11, -5], [-15, 13], [13, 0], [-23, 14], [26, -24], [-6, 27], [3, -28], [51, -40], [-3, -8], [-4, 26], [-19, 35], [39, -30], [-2, -2], [-28, -19], [25, 2], [-27, -26], [25, -45], [-24, 28], [-9, -34], [-12, -17], [42, -24], [48, -28], [-13, -6], [-16, -16], [-20, 42], [-40, 23], [-36, 18], [-41, 38], [-39, 12], [18, -15], [-36, 12], [-8, 26], [44, -54], [-53, -6], [10, 7], [61, -15], [7, -9], [-13, 8], [19, -36], [38, -28], [7, 10], [46, -32], [23, -4], [-41, 56], [-28, 33], [60, 0], [-3, 36], [-41, 27], [7, 11], [-22, 43], [29, -35], [25, 3], [-76, 8], [-22, -37], [-49, 10], [5, 42], [-41, 10], [11, 29], [-19, 13], [54, -30], [0, -35], [-8, 12], [-4, 27], [69, -20], [47, 16], [-10, -40], [-58, 20], [-26, 57], [-1, 38], [-58, -16], [-38, 21], [-48, -7], [-68, 19], [-15, -2], [-6, -28], [49, -25], [15, -8], [21, 10], [13, -8], [66, 12], [25, 21], [-43, -19], [8, -17], [-37, 32], [21, -42], [-10, -44], [26, -48], [45, -57], [2, -32], [-31, 24], [-23, 60], [-53, 25], [-55, 54], [-46, -12], [4, 31], [57, 13], [-16, 62], [35, 2], [25, 12], [57, -18], [-17, 18], [21, -33], [-31, 39], [6, 4], [-47, -3], [7, -41], [-55, 18], [8, -40], [-33, 52], [19, -11], [42, -19], [18, -28], [-14, -19], [-56, 24], [46, -27], [49, 20], [59, -24], [-31, -8], [-35, 12], [-23, 25], [-16, -17], [-32, 72], [-15, -4], [13, -55], [47, -63], [18, 26], [33, -71], [46, -43], [39, -36], [-23, -23], [29, -9], [-7, 19], [23, 10], [-18, 30], [-69, 3], [1, 15], [-38, 34], [17, -48], [-21, 6], [78, 14], [-1, 0], [3, 32], [18, -16], [13, -46], [46, -64], [31, -54], [11, -24], [-8, -2], [-13, 0], [32, 30], [46, 23], [-40, 12], [37, -32], [-14, 3], [-11, 34], [-43, 10], [17, -40], [-33, 61], [-21, -35], [-35, 8], [21, 36], [-2, -8], [-17, 29], [-17, 52], [42, -68], [-38, 72], [-65, 24], [-62, 23], [16, -46], [7, -62], [-3, 7], [23, -7], [38, 28], [13, -22], [-77, 16], [21, -40], [-63, 5], [-48, 81], [-66, -23], [37, 18], [-9, 52], [19, -6], [51, 8], [-8, 12], [39, -62], [39, 24], [-16, 29], [14, 24], [-40, -21], [1, 21], [-41, 63], [20, 41], [-31, 2], [8, -13], [13, -28], [-56, -17], [-25, 34], [-50, -22], [-66, 46]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4332_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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