
// Make newform 576.4.a.t in Magma, downloaded from the LMFDB on 22 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_576_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_576_4_a_t();".
// 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_576_4_a_t();".
// 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_576_a();"
function MakeCharacter_576_a()
    N := 576;
    order := 1;
    char_gens := [127, 325, 65];
    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_576_a_Hecke( : Kf := Kf)
    return MakeCharacter_576_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], [10], [4], [-20], [-70], [-90], [140], [-192], [-134], [-100], [170], [110], [532], [-56], [-430], [20], [-270], [-524], [-80], [330], [-1060], [1188], [-1274], [-590], [-798], [1548], [-1324], [-470], [-610], [884], [-500], [1950], [220], [-390], [2100], [2050], [332], [-2744], [3570], [-1380], [-1358], [-3840], [3090], [-1070], [380], [2180], [-668], [4836], [-4334], [2550], [1920], [-1070], [1020], [5630], [-7128], [4650], [-3180], [5330], [7830], [268], [-1950], [2916], [9000], [8890], [1290], [-5300], [-9310], [-2596], [-814], [-7730], [5840], [6636], [-12950], [-6220], [-8672], [7530], [3650], [-11498], [-3590], [-380], [5410], [8280], [-12590], [-15140], [5628], [-5450], [-2710], [-11982], [6068], [-5036], [-4440], [4996], [-10700], [-13980], [13632], [4746], [5838], [8388], [-7078], [8604], [18850], [5412], [-13570], [860], [5010], [16116], [-7170], [9520], [6010], [-24844], [-9990], [-570], [8700], [16340], [-11210], [12828], [-24336], [770], [4140], [-8390], [1730], [23930], [-29892], [-21220], [-21750], [21554], [13000], [-3276], [-21110], [-17980], [-33192], [23900], [-1950], [-8082], [-36494], [28050], [23004], [19410], [-34946], [-28300], [16930], [24772], [12004], [22330], [45280], [26970], [12190], [-9260], [-4832], [-37630], [15630], [12988], [5976], [-15004], [21120], [-25500], [390], [890], [-3022], [-2916], [12990], [-41844], [43900], [8630], [-168], [25580], [47610], [-53246], [-28150], [17220], [-20862], [29240], [-20390], [13900], [9814], [57100], [51882], [-54548], [-16270], [-28564], [-52460], [26930], [-51130], [-53712], [-59446], [-56790], [42868], [-31750], [-23040], [1570], [-44252], [-18620], [-53710], [18476], [-60090], [16930], [-22390], [15230], [3352], [-41166], [32180], [-51470], [-16686], [46300], [37770], [-65900], [-18508], [-14474], [-37340], [-47710], [-83190], [39708], [26196], [4480], [-49350], [18524], [6982], [15416], [-67230], [-57950], [14780], [-82746], [10708], [17316], [10810], [-72090], [33960], [-95204], [-91340], [18410], [-45140], [-32540], [39270], [-44252], [-22984], [-24670], [-25350], [-98580], [2000], [87588], [17340], [-13788], [7314], [-88850], [-46000], [-62276], [89820], [93740], [-72128], [59130], [36398], [15504], [13050], [-950], [-57300], [61362], [99836], [82770], [15850], [11572], [-63924], [19906], [3170], [11910], [66500], [25154], [-81562], [43492], [-9270], [78178], [49556], [-74230], [65580], [2770], [-109668], [89644], [-41774], [23050], [115820], [123048], [51500], [-49616], [-40518], [-81196], [124800], [-153710], [99370], [-37100], [-115250], [117090], [-80964], [48390], [-18460], [-117870], [-53790], [-159980], [-73710], [6540], [53356], [49930], [-58430], [139820], [-108068], [-56380], [-116510], [15564], [-10566], [161040], [17050], [-117552], [-128206], [15542], [-178852], [174936], [-45926], [-16980], [8600], [123250], [-172290], [-50460], [101690], [-11270], [-31652], [174510], [26530], [26940], [152292], [-118816], [-5110], [-62710], [-107870], [174020], [-103012], [66620], [13996], [-31710], [-115250], [101450], [84324], [-161030], [-13730], [-24190], [110140], [167050], [-215340], [-189390], [-94484], [41320], [-44510], [213100], [131690], [125210], [2628], [40026], [21270], [-185520], [-206700], [192710], [126728], [39530], [23478], [241424], [-29780], [38084], [-18710], [145770], [101428], [189610], [106980], [96740], [11472], [-9870], [-138860], [135850], [-102780], [-59680], [-225310], [187830], [-194550], [-189438], [140030], [-221324], [56670], [-72740], [117608], [-258660], [162610], [-14708], [25064], [29090], [-24550], [96900], [-87764], [-112120], [208410], [123380], [200334], [138980], [194170], [-155470], [-46170], [130916], [29310], [53570], [80980], [-169430], [167798], [-231828], [155060], [-110270], [270250], [-86148], [-112980], [217930], [-60982], [130880], [165844], [16630], [-58832], [44290], [-175670], [-20576], [-19860], [10250], [-110870], [-203628], [277670], [197620], [66720]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_576_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_576_4_a_t();".
// 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_576_4_a_t(:prec:=1)
    chi := MakeCharacter_576_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_576_4_a_t();".
// 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_576_4_a_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_576_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-10, 1]>,<7,R![-4, 1]>,<11,R![20, 1]>],Snew);
    return Vf;
end function;