
// Make newform 1152.2.a.l in Magma, downloaded from the LMFDB on 29 April 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1152_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_1152_2_a_l();".
// 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_1152_2_a_l();".
// 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_1152_a();"
function MakeCharacter_1152_a()
    N := 1152;
    order := 1;
    char_gens := [127, 901, 641];
    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_1152_a_Hecke( : Kf := Kf)
    return MakeCharacter_1152_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], [0], [2], [4], [6], [-6], [0], [-4], [-4], [10], [2], [2], [8], [12], [12], [4], [2], [4], [4], [-10], [-6], [-12], [-2], [-6], [-4], [-10], [12], [-2], [14], [14], [-12], [-6], [-4], [-16], [10], [-14], [-16], [-16], [16], [12], [14], [-24], [-2], [-12], [-18], [-12], [-2], [4], [-10], [-10], [-16], [14], [20], [14], [8], [28], [-2], [-2], [14], [20], [-4], [-12], [0], [-26], [-28], [-28], [-2], [-36], [-14], [14], [20], [-22], [-14], [-8], [8], [0], [10], [-30], [2], [4], [-2], [-12], [-14], [6], [12], [-22], [2], [0], [22], [20], [-4], [18], [-12], [-36], [36], [-28], [-38], [40], [38], [8], [40], [12], [-30], [-20], [-26], [20], [-18], [4], [-2], [-2], [2], [-18], [-28], [2], [-30], [40], [12], [8], [-20], [10], [-30], [-24], [12], [16], [-12], [6], [4], [42], [-34], [-28], [-24], [26], [38], [2], [-18], [36], [40], [24], [42], [32], [4], [-22], [28], [-34], [-20], [26], [18], [16], [24], [-14], [-18], [-48], [8], [0], [-16], [-38], [18], [26], [0], [12], [-22], [-34], [-4], [-30], [-8], [26], [-6], [58], [-8], [4], [50], [-24], [-38], [-14], [-2], [-44], [48], [6], [-22], [10], [36], [30], [-2], [56], [-40], [46], [-4], [54], [0], [18], [36], [-4], [-24], [-28], [14], [54], [30], [22], [-64], [-48], [-26], [-42], [-2], [36], [36], [6], [-36], [-42], [16], [-2], [24], [-10], [52], [60], [-38], [-46], [2], [0], [48], [22], [30], [-22], [14], [20], [-54], [46], [-36], [-26], [-60], [62], [40], [22], [-2], [16], [12], [-6], [-64], [-20], [28], [12], [68], [26], [-46], [-58], [-36], [66], [20], [52], [56], [-18], [30], [60], [-22], [44], [36], [22], [28], [-44], [-22], [78], [28], [70], [50], [-38], [44], [-40], [-74], [16], [48], [34], [-44], [74], [-62], [-62], [46], [-60], [26], [-2], [-60], [-36], [38], [52], [82], [-16], [-72], [30], [-8], [82], [78], [-40], [12], [-34], [-12], [-6], [0], [-10], [-68], [-76], [8], [6], [-88], [-14], [68], [-40], [46], [-12], [-2], [-36], [-78], [40], [12], [34], [48], [-48], [26], [12], [-60], [14], [-26], [-52], [-42], [76], [26], [-14], [-22], [0], [-24], [48], [-48], [-50], [48], [-50], [36], [12], [-76], [50], [6], [-10], [-42], [-54], [74], [76], [22], [4], [-84], [-66], [-28], [-60], [36], [-56], [-30], [52], [6], [-70], [6], [64], [-28], [18], [0], [-62], [30], [-24], [-12], [84], [46], [12], [90], [90], [44], [-88], [-48], [-52], [-54], [-18], [-4], [8], [-30], [26], [-58], [-32], [-30], [-22], [-82], [-40], [-96], [-6], [-2], [-36], [52], [-14], [-24], [-68], [-64], [72], [-14], [14], [-6], [-40], [-80], [-38], [26], [38], [-30], [-4], [2], [78], [98], [-16], [-4], [70], [72], [100], [80], [38], [-20], [72], [42], [66], [-36], [64], [-70], [8], [12], [-74], [-68], [20], [78], [-96], [-36]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1152_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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