
// Make newform 588.8.a.a in Magma, downloaded from the LMFDB on 31 May 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_588_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_588_8_a_a();".
// 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_588_8_a_a();".
// 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_588_a();"
function MakeCharacter_588_a()
    N := 588;
    order := 1;
    char_gens := [295, 197, 493];
    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_588_a_Hecke( : Kf := Kf)
    return MakeCharacter_588_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 := 8;
    raw_aps := [[0], [-27], [-270], [0], [-5724], [4570], [36558], [-51740], [22248], [-157194], [103936], [-94834], [-659610], [-75772], [-405648], [-1346274], [1303884], [-1833782], [1369388], [2714040], [-2868794], [-1129648], [-5912028], [897750], [-13719074], [-1933038], [-4761272], [2210436], [-20092858], [7940754], [-22739488], [22778388], [41698746], [6194716], [-5416578], [70844360], [79080106], [-24449140], [-35553816], [-102794022], [-41558724], [33501250], [49080384], [60448322], [5004558], [221134888], [-71664100], [-26144000], [34099380], [-227427854], [56906010], [302715792], [25369582], [14654412], [23465214], [425583288], [393061626], [-58955984], [-21597346], [-334717974], [-326806484], [728964306], [126039364], [715768056], [291195958], [42428502], [-547256668], [-185332174], [1297110996], [622135786], [-620687394], [606882456], [1405384528], [-1129248322], [1635149492], [227684736], [-623119986], [1495834], [-306500814], [-356868074], [2284281972], [263134670], [1490529168], [-1105390802], [-296352872], [358944372], [-3419482878], [-2858275270], [-962699526], [601892624], [-1720599516], [537261984], [-4496210056], [3329173764], [-2049857284], [-776491272], [4566792042], [2211592518], [2341539676], [2354970518], [3414933644], [-479293146], [-6503021820], [-4516247286], [2473754420], [531720766], [-8171104932], [1599227982], [-8803296216], [-8212347818], [-5091919616], [-7012818226], [4637135898], [-1339167236], [-11235380248], [9823803714], [-3562395692], [-5911190136], [-770538042], [4952706012], [1203185122], [13082272610], [14937960978], [-9504153468], [-1878926588], [-10659148074], [-15846448594], [17848243728], [-14112349064], [5553243562], [9726138380], [837461592], [-3054215248], [17725000958], [-1282680522], [-15077765378], [-12673665486], [1466843236], [14962924746], [10626300954], [24430594300], [26856767646], [5829138344], [-13176118476], [-19963398518], [-21943306296], [21310189474], [-4659955434], [1684203820], [1086323616], [11144291078], [37884469230], [15813099836], [15217090488], [-15239522524], [-14944664592], [-16529148088], [25817045598], [18342780454], [6333459930], [20195775036], [48617240202], [12377800280], [17059670172], [39694489074], [75539736], [-29902583872], [-12425438798], [-18512245486], [-43015164318], [-28058637708], [38662687498], [51323405112], [51080915066], [43213660144], [-683716842], [57715433684], [48589809390], [-48512946680], [-54583002566], [35569406048], [-23816256876], [-28163149906], [13253080518], [58576774320], [-24709961790], [29611950038], [68228297716], [-87295184998], [-72589855104], [19793887102], [33963466212], [53120534876], [72361434186], [66612444876], [-63319748058], [37360915922], [79721635190], [87435577278], [111856834440], [-42870204666], [-209471504], [-53499630494], [-44211466274], [18970571196], [-63082590102], [-99348700256], [-34608876372], [76128605946], [58715755612], [-17641996174], [-18826458750], [-58922250232], [8743412268], [20407358376], [23009981350], [-137285520016], [126959802894], [18694462824], [-36823190922], [-23890490098], [149233929304], [-34472781630], [212806866512], [-25179638940], [137589130526], [-143537283306], [-135993075552], [80080625416], [80517045060], [-86649841402], [-82365154940], [221720894240], [-157214277702], [17893901596], [200022882192], [-199372001330], [-122998552002], [60773184468], [-205191199512], [-267668475588], [183439473292], [-129787218776], [136882210022], [-137209168242], [285909850008], [-214853200640], [-187468626636], [124466435780], [-135815319216], [-108766141834], [-111900904002], [282836030904], [218344530118], [-115717245894], [-140504377572], [-58066590178], [269762400748], [119295948690], [87492701302], [94390451168], [281573421804], [13494229522], [182500187050], [-19835815842], [-22424440652], [-105298601562], [176440889142], [38926488308], [-194986747314], [-194782485926], [-211893852772], [-436703721002], [-211923877696], [-30843635090], [291917882584], [-375437290572], [-68194177930], [-288305163142], [-350994918492], [243928382688], [-172225460488], [-98265563208], [-109219585262], [-253067552228], [107043175728], [149961067442], [557461699902], [-207144278024], [241966693854], [26124975846], [26613368964], [-131327027190], [292271687964], [-321767338906], [423395009226], [-157237903040], [311568562530], [-122041970676], [30961002388], [502110533446], [-354612377466], [616747245392], [303038593308], [623857046996], [-660155197534], [-245631712572], [-361360837190], [59746008456], [-365638902994], [369863754768], [531776562750], [692497237410], [429832539020], [538936587288], [-347432771162], [-186164051004], [224375073408], [239084000830], [-80418747726], [819880147300], [647389503146], [166468728906], [-415697063488], [192597935706], [-793935898514], [83939423276], [410970238444], [-237664847520], [178314947694], [-225009655546], [-796984844778], [367773739744], [738291336660], [-195404138332], [-521124356052], [107667489302], [-1075110472098], [-699062833562], [-745306664816], [-33154170178], [-463381451190], [-448280903502], [-212325945448], [413026164342], [235792023948], [-976497505742], [-444325937212], [-527641272720], [998660532834], [-909847724780], [-98418263878], [156721465926], [-805501819664], [696449130590], [164144996694], [-405562383648], [-760954630788], [-216257260590], [534600261576], [312178374446], [-120052579194], [-882249336720], [-952732865772], [298369676980], [360069837530], [-1139754907494], [867807891224], [843567292970], [571960027980], [383910831676], [-80482960368], [-712629723042], [-78698485352], [409961229110], [-80220935196], [-1298950216992], [-806678338274], [1206539595630], [-260742049610], [-577637797014], [155122750458], [124118383112], [-1252079313246], [-353148444236], [-360989343576], [1057223851568], [-566703155198], [-150195743884], [-1821697407936], [1262880795266], [-587278259982], [1239342473700], [1162753648996], [-964129440600], [-1311614579734], [920337497920], [1669246092774], [1932881068292], [-994023346338], [-812729660342], [1086601164930], [-2143195552624], [343469833110], [1320109393554], [127187998216], [-21989684794], [-47053995822], [-885751107644], [-183986289324], [-1066825994354], [966021633918], [-1792781078508], [-794346376180], [2075765530970], [1278854527770], [-1099190620224], [1887000711016], [-1714094330994], [1755344349144], [-788497433226], [-551194672718], [576855172368], [854341241292], [-601786297082], [460983523194], [-2624733005796], [-468033587478], [-5007093140], [-2543398080840]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_588_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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