
// Make newform 576.6.a.n in Magma, downloaded from the LMFDB on 24 November 2024.
// 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_6_a_n();".
// 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_6_a_n();".
// 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)
    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 := 6;
    raw_aps := [[0], [0], [-16], [12], [-448], [206], [1952], [-1064], [3712], [-4080], [5324], [9690], [-9120], [-16552], [-14208], [21776], [31616], [13154], [-27056], [9728], [9046], [-58292], [-86336], [75072], [76046], [-134064], [-176444], [-58752], [-125362], [-101568], [-312572], [328192], [-16992], [-319152], [514480], [-210292], [198626], [-445224], [-324480], [-605712], [-157824], [216918], [917376], [-368638], [-509808], [-513452], [-1029040], [-502892], [-649920], [547142], [349888], [-1689472], [375630], [414016], [-1237888], [117760], [1265488], [-1582060], [-40234], [50048], [387424], [-327408], [2025552], [1701120], [-231990], [-1326960], [200032], [-548322], [-1537344], [-94494], [3296576], [-1296384], [3575116], [3619690], [2571352], [3763584], [5870768], [-2183342], [1938912], [-5919930], [4104000], [5314630], [-2640256], [5354050], [3537108], [-762176], [-6851552], [-3672490], [1546160], [3135620], [-1237440], [-4251136], [-909188], [-7216128], [4556640], [7106304], [-663216], [9098720], [9950552], [-8847810], [534472], [631664], [-11134912], [-8252960], [-2464944], [6947666], [8577536], [2861248], [-13140096], [-14911238], [3546116], [5911258], [-9937536], [-10812064], [2019580], [-9125984], [-2469432], [6909824], [-9459024], [10726656], [17241322], [13353010], [-8756944], [-6404032], [-23091752], [-2096688], [17018566], [7786240], [-5224452], [-25169186], [-22277552], [-5051264], [-1025316], [13448278], [2993696], [14055170], [-26647728], [5556968], [20229680], [-27239776], [-28083352], [-17337456], [-26654692], [19463296], [-12879682], [-12192768], [-15497654], [20040288], [22528104], [3236992], [-26207790], [3833984], [14014936], [-18770176], [-13324984], [-12869504], [5505820], [35777504], [-44706630], [-14182992], [-46541184], [-16104096], [33394628], [-4811712], [14578272], [50444544], [57411388], [46327514], [-18917122], [-25192528], [10695936], [29506146], [16987520], [-6739034], [41901020], [-15381760], [-17676992], [36399024], [38804308], [6175858], [18255308], [43247296], [-29040954], [3319680], [-76799616], [-40629840], [25077566], [30561120], [15662470], [56660736], [38193214], [83447424], [6236480], [35066096], [46125312], [85981952], [-17766590], [-82941346], [-14035072], [-44453376], [-85133072], [21847796], [-61998026], [-7424498], [-110479680], [-56568048], [-28772716], [-44706240], [-50602816], [15285608], [-2807022], [-4951248], [-89556812], [-54372224], [100918016], [20516618], [110320460], [-2765792], [-17456256], [82890480], [46948582], [127524276], [136184160], [-136165756], [86643648], [-87068342], [-104730432], [-32613120], [-48138780], [54256640], [126063438], [-103251736], [48877604], [-64878464], [-165080760], [18160640], [-77612770], [36106544], [31235392], [-47864192], [-67376064], [-35261120], [36498076], [51380978], [-116234496], [83310080], [-5400260], [-115736448], [-25404064], [101808128], [42394206], [24166464], [71475584], [-5907290], [11529936], [20436096], [-196464170], [-128656528], [-178864176], [158501914], [-129921164], [93264768], [70741862], [3783234], [-166226336], [-53198528], [132704176], [-41093056], [51449416], [136467760], [49205330], [87716464], [90568342], [-7507364], [-199821746], [-141190444], [8352192], [83754178], [233538538], [-8290432], [-149563136], [229928500], [159368320], [236654842], [159287656], [241071616], [-239214226], [-95742864], [-36731764], [-82822720], [-214774480], [-66715776], [42793792], [-76732032], [120216306], [86178224], [5033252], [-198238512], [84302784], [-101263928], [-95249446], [139714288], [134590940], [-319448320], [244426296], [103961438], [-11378112], [330061390], [-56626432], [146831962], [-84714624], [-93398832], [-257843680], [85146296], [21951232], [-67441786], [270368256], [247466496], [-207549394], [-281496000], [154165088], [248834218], [-988016], [192630700], [-164135072], [105747198], [224024760], [77762136], [-180220928], [148648176], [-61564498], [-224241552], [-130436748], [-222734208], [-28157616], [-175900224], [-153620158], [436187328], [261345590], [-20900988], [-148973110], [265283040], [-262179504], [-299398428], [-161205424], [-268741312], [274549734], [417721664], [226228992], [495227344], [275116008], [-168950698], [-507977968], [187959828], [-417118742], [197457152], [355239808], [517276672], [354144160], [17945856], [413963770], [-15077952], [111183744], [546690496], [-288164752], [-257257974], [229824912], [142144300], [-147769862], [127345600], [-581526696], [-181649920], [59006096], [-419808740], [-284572226], [200521536], [-54785664], [-315452702], [-532357152], [-478985098], [530094192], [338991776], [44671404], [362833536], [-267622936], [299399808], [-264850500], [-608135498], [-611553424], [79281024], [452870206], [-279652432], [-167695104], [128164344], [591552384], [-246874298], [-364242540], [747392736], [57509752], [42179696], [-450020510], [-326179104], [-657739868], [215044064], [-35010160], [-279848468], [-312166738], [303468000], [-660872264], [-133288128], [655528226], [6791408], [-33501632], [208326392], [38335350], [-534421360], [-661971072], [62061068], [66069984], [-449726464], [-412172624], [499418938], [696962048], [620724544], [-605261606], [665582992], [-229667776], [146476608], [56022120], [-131647616]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_576_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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