
// Make newform 4232.2.a.j in Magma, downloaded from the LMFDB on 27 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_4232_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_4232_2_a_j();".
// 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_4232_2_a_j();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_4232_a();"
function MakeCharacter_4232_a()
    N := 4232;
    order := 1;
    char_gens := [3175, 2117, 2121];
    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_4232_a_Hecke( : Kf := Kf)
    return MakeCharacter_4232_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], [3], [0], [2], [0], [-5], [6], [-6], [0], [9], [3], [8], [3], [8], [7], [2], [4], [10], [-8], [7], [9], [6], [14], [-16], [-6], [6], [-14], [-14], [0], [-2], [5], [-9], [-4], [-23], [-14], [7], [-12], [-11], [4], [-10], [-3], [0], [16], [-7], [-27], [-20], [8], [8], [10], [20], [15], [-13], [4], [-10], [-13], [-6], [5], [-8], [-23], [18], [-4], [-12], [4], [-17], [20], [-2], [-19], [-8], [-12], [-7], [-11], [18], [10], [-4], [4], [12], [4], [31], [24], [25], [-28], [22], [-36], [16], [5], [-9], [6], [-38], [1], [16], [-6], [-38], [17], [-7], [-1], [-10], [-15], [-8], [-18], [-43], [-19], [-8], [-44], [24], [-26], [33], [15], [22], [-24], [13], [40], [-2], [18], [4], [40], [40], [44], [-33], [39], [-50], [42], [-5], [22], [29], [4], [42], [-14], [16], [36], [14], [29], [6], [-4], [12], [41], [28], [-8], [-40], [-42], [2], [-5], [-54], [-57], [12], [54], [-30], [-14], [23], [-17], [49], [18], [18], [-36], [27], [10], [50], [-10], [7], [-4], [-6], [7], [-42], [-47], [26], [0], [14], [0], [-50], [-22], [3], [-12], [-43], [10], [-24], [41], [-26], [25], [11], [-34], [22], [-7], [-20], [9], [-6], [-36], [-38], [18], [-30], [-35], [48], [31], [24], [-52], [10], [-48], [-40], [-16], [-4], [28], [-63], [-36], [24], [13], [-64], [-24], [-31], [-20], [-49], [-29], [-7], [-33], [19], [-36], [2], [0], [24], [23], [-3], [20], [51], [-21], [-16], [33], [30], [-45], [3], [36], [-3], [-2], [4], [-14], [26], [-40], [26], [36], [62], [28], [72], [27], [-15], [-16], [55], [11], [-49], [6], [43], [59], [18], [38], [52], [30], [-48], [-58], [46], [-30], [-75], [44], [16], [-55], [13], [-40], [-28], [58], [62], [54], [46], [24], [36], [-14], [-67], [37], [-34], [0], [-6], [-39], [-29], [-40], [2], [20], [36], [-51], [56], [-44], [-82], [4], [60], [-34], [10], [-28], [66], [6], [-62], [66], [-2], [29], [-38], [-10], [75], [-7], [33], [58], [6], [46], [-43], [-32], [-37], [-36], [80], [-4], [-22], [19], [-30], [-22], [-31], [30], [-42], [5], [71], [-16], [-33], [-52], [-2], [-33], [-36], [-84], [92], [88], [-59], [60], [-10], [73], [-61], [-19], [-19], [22], [-3], [20], [-54], [-5], [-8], [-61], [48], [50], [-46], [-60], [-48], [11], [36], [-14], [64], [-57], [73], [30], [-62], [-50], [26], [-66], [32], [-87], [-8], [28], [45], [33], [-24], [-67], [21], [3], [-60], [62], [13], [84], [27], [2], [44], [99], [-43], [20], [38], [-12], [39], [12], [70], [-4], [47], [-50], [-87], [-43], [-74], [92], [54], [-10], [54], [-49], [52], [-62], [-16], [-16], [-54], [62], [-30], [-1], [33], [66], [-74], [-45], [39], [-10], [-47], [-94], [60], [23], [3], [-12], [10], [18], [-51], [-24], [-64], [-36], [40], [38], [16], [-72], [-84], [-35], [-1], [54], [-70], [-97], [19]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4232_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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