
// Make newform 1232.2.a.d in Magma, downloaded from the LMFDB on 02 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1232_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_1232_2_a_d();".
// 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_1232_2_a_d();".
// 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_1232_a();"
function MakeCharacter_1232_a()
    N := 1232;
    order := 1;
    char_gens := [463, 309, 353, 673];
    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_1232_a_Hecke( : Kf := Kf)
    return MakeCharacter_1232_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], [-1], [3], [-1], [1], [-4], [-6], [-2], [-3], [-6], [-5], [11], [6], [-8], [0], [-6], [9], [-10], [-5], [-9], [2], [10], [-12], [-3], [-1], [-12], [4], [-6], [20], [-3], [-2], [6], [-3], [-14], [-6], [10], [-13], [-20], [-6], [0], [15], [-7], [27], [14], [18], [16], [-14], [19], [12], [5], [6], [12], [-28], [9], [-6], [30], [30], [16], [8], [12], [-32], [-30], [-20], [0], [-19], [9], [1], [14], [18], [-10], [-3], [-24], [-17], [-4], [-11], [-21], [33], [2], [-6], [14], [-24], [-10], [-12], [11], [-26], [-9], [-9], [8], [-6], [-5], [-15], [12], [-11], [30], [4], [0], [21], [3], [16], [-16], [-8], [30], [-36], [-18], [4], [11], [-12], [6], [0], [8], [-14], [-16], [-30], [19], [-11], [15], [49], [33], [39], [-30], [-49], [-28], [-18], [-12], [-35], [0], [-1], [39], [-17], [-4], [34], [-24], [31], [38], [48], [-40], [-6], [-50], [-21], [30], [-2], [18], [-23], [-36], [-25], [15], [-10], [-12], [13], [12], [-22], [-9], [-20], [42], [-8], [-48], [16], [18], [20], [18], [27], [-36], [-14], [39], [9], [-33], [16], [-28], [20], [-15], [-24], [50], [-30], [8], [13], [51], [-26], [-33], [-38], [-10], [28], [-12], [5], [-48], [-9], [-66], [-16], [-44], [32], [42], [-25], [-66], [43], [18], [42], [9], [32], [-1], [-42], [30], [18], [-8], [14], [-10], [-9], [3], [-11], [6], [-60], [4], [-52], [-39], [1], [-36], [-72], [53], [4], [6], [12], [15], [32], [-14], [21], [-29], [48], [26], [54], [-48], [-8], [-72], [-67], [-38], [4], [-36], [1], [30], [-49], [6], [57], [-63], [-15], [-2], [4], [-43], [-66], [54], [16], [-36], [22], [18], [32], [-48], [63], [-10], [-12], [-6], [-34], [-26], [-45], [20], [-44], [-12], [14], [-16], [-18], [-44], [63], [39], [58], [-36], [-13], [-47], [-82], [40], [50], [7], [-3], [26], [-70], [36], [72], [67], [42], [-46], [-14], [39], [-70], [42], [-71], [72], [-39], [-84], [12], [-60], [-46], [36], [1], [57], [-6], [-44], [-40], [-48], [-38], [12], [-23], [-25], [-15], [-49], [24], [-16], [18], [-6], [18], [-77], [54], [74], [15], [-54], [62], [-66], [-80], [5], [-18], [7], [42], [65], [-47], [19], [54], [72], [-28], [-18], [82], [66], [-38], [-63], [-43], [66], [-67], [52], [89], [-33], [24], [37], [-81], [36], [65], [37], [-12], [69], [4], [-25], [42], [46], [68], [72], [-39], [-30], [84], [-57], [-82], [-54], [33], [72], [-65], [-19], [12], [16], [56], [-69], [52], [-84], [12], [76], [-79], [-36], [54], [-34], [-12], [80], [-30], [-57], [70], [6], [76], [51], [64], [23], [-74], [39], [-55], [-63], [-21], [91], [-63], [86], [88], [-6], [-68], [-36], [-58], [-3], [40], [66], [-24], [70], [-46], [12], [4], [27], [44], [0], [-36], [64], [-22], [87], [-24], [-53], [90], [42], [-21], [-16], [-12], [30], [38], [9], [45], [0], [43], [30]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1232_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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