
// Make newform 1296.4.a.g in Magma, downloaded from the LMFDB on 16 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1296_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_1296_4_a_g();".
// 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_1296_4_a_g();".
// 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_1296_a();"
function MakeCharacter_1296_a()
    N := 1296;
    order := 1;
    char_gens := [1135, 325, 1217];
    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_1296_a_Hecke( : Kf := Kf)
    return MakeCharacter_1296_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 := 4;
    raw_aps := [[0], [0], [9], [31], [-15], [-37], [42], [28], [195], [-111], [205], [-166], [261], [43], [177], [-114], [159], [191], [421], [156], [182], [-1133], [-1083], [1050], [-901], [-387], [-551], [-12], [-502], [1401], [880], [1503], [2661], [121], [2829], [-461], [-2977], [3316], [-681], [3981], [2004], [1274], [1161], [3611], [-2046], [-2996], [-755], [3463], [6225], [-1465], [-2634], [6915], [-1489], [-4620], [-3351], [-603], [1470], [-2072], [7139], [-8427], [457], [5889], [1204], [-3285], [-10057], [-2295], [6679], [2183], [3891], [2795], [-4755], [4608], [-3845], [-8317], [-12560], [12087], [8541], [-13174], [-9603], [11471], [-5973], [-8905], [1416], [10766], [-4349], [-14547], [3330], [8147], [-8031], [-4283], [5460], [429], [11296], [-14673], [-13439], [-17388], [3789], [-9786], [8008], [-2938], [10375], [-3306], [-21093], [-1287], [-15035], [1190], [-17883], [-20118], [-1065], [-20725], [15745], [5042], [10053], [5983], [19696], [10977], [15829], [28224], [-28167], [10737], [10127], [251], [-8451], [-25884], [-6365], [-1122], [4283], [4032], [-24005], [-37501], [880], [1623], [6889], [-12850], [-4611], [-2305], [34902], [-26255], [1437], [-25734], [3220], [-44631], [-24947], [-14964], [-7462], [2697], [-39625], [2973], [45229], [1416], [17555], [-30030], [35740], [747], [20539], [-24123], [-23312], [-18699], [-31234], [-11751], [-25887], [41130], [28645], [-32256], [-9015], [15885], [-34904], [-35341], [-36538], [47637], [43077], [-15325], [-20133], [-6637], [-10799], [-19815], [43387], [25758], [58744], [-43909], [-17177], [22941], [59303], [17010], [-18369], [30609], [34022], [-65165], [53927], [14448], [12446], [-29919], [-8780], [11205], [-72924], [-22839], [-54181], [44603], [34137], [12936], [44241], [-73313], [-84961], [10775], [2940], [-48594], [-46088], [-89433], [-48663], [-32135], [86774], [-23595], [42631], [47385], [31575], [-66337], [-15203], [-38355], [34512], [-77307], [-68293], [46321], [29709], [-50024], [-27393], [47123], [54633], [-72840], [-18797], [42321], [60143], [89908], [56365], [35505], [-81041], [9417], [-8605], [-8010], [-1905], [39480], [29133], [2212], [43297], [-74086], [-35187], [-87855], [19936], [-33021], [35701], [-29160], [39899], [44226], [-4845], [-106153], [-78675], [-61080], [103826], [-29801], [-25326], [5726], [-54557], [-107787], [51455], [75362], [-105579], [81079], [33486], [1713], [42757], [-1875], [-27085], [-52628], [63191], [31417], [35579], [34216], [130311], [115247], [13862], [110385], [-82665], [-79967], [-96675], [-139669], [-128567], [-55116], [-65602], [-41775], [-30305], [-127890], [97329], [-14952], [50961], [-71997], [-48301], [-68703], [41347], [-108495], [62244], [25219], [-51193], [-63954], [85552], [-52137], [-87863], [-26962], [-126519], [-33721], [85623], [119114], [98121], [88758], [-104271], [-171107], [-114000], [144830], [119289], [167523], [42023], [12741], [54367], [-136081], [145110], [-53048], [171837], [-25438], [-3656], [58399], [-83847], [91110], [-52333], [108417], [67135], [93165], [119572], [184884], [188246], [-11835], [59267], [38500], [114407], [69441], [213873], [11551], [32481], [86424], [5978], [-23645], [116181], [32466], [115789], [-193618], [2325], [-125813], [32843], [137046], [50475], [-27132], [-117375], [-169611], [-140617], [89241], [-153396], [65169], [27748], [-93325], [-236007], [62452], [133478], [-31263], [-110516], [-147897], [19881], [209953], [-228142], [255099], [116748], [87542], [-174846], [200531], [-176115], [220305], [-81104], [95229], [37585], [254856], [225079], [180311], [215668], [-21849], [14699], [13473], [-32856], [-126149], [-23871], [155819], [-33908], [44301], [174553], [-60003], [151751], [-150222], [35197], [75525], [118818], [-286076], [167075], [118833], [-4835], [196317], [175331], [210813], [146904], [-138809], [-34861], [-26922], [253752], [141139], [132762], [193527], [86829], [186914], [174033], [-211857], [-204442], [112989], [299613], [136890], [124684], [-192771]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1296_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1296_4_a_g();".
// 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_1296_4_a_g(:prec:=1)
    chi := MakeCharacter_1296_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_1296_4_a_g();".
// 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_1296_4_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1296_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-9, 1]>],Snew);
    return Vf;
end function;