
// Make newform 72.8.a.d in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_72_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_72_8_a_d();".
// 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_72_8_a_d();".
// 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_72_a();"
function MakeCharacter_72_a()
    N := 72;
    order := 1;
    char_gens := [55, 37, 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_72_a_Hecke(Kf)
    return MakeCharacter_72_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+1)]];
    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], [0], [82], [-456], [2524], [-10778], [11150], [4124], [-81704], [-99798], [-40480], [-419442], [-141402], [-690428], [682032], [-1813118], [966028], [1887670], [2965868], [2548232], [-1680326], [4038064], [5385764], [6473046], [-6065758], [-9700686], [4101592], [-72900], [9558406], [-9338898], [-35979392], [676052], [29584134], [-31908444], [11660258], [-17629528], [6346582], [80423436], [-114767256], [63375546], [11322756], [-5226498], [85030080], [115091522], [138521874], [-21961352], [-61020836], [-42244832], [239102004], [-46788914], [-345224858], [-234412816], [-109557102], [394031180], [-319063810], [-219358520], [148032794], [-369934096], [-395859554], [597760022], [80579732], [-754529934], [820472316], [-653502984], [663587274], [354718026], [-305543452], [35496498], [190594476], [860863638], [1045444190], [-763303128], [-1386919280], [477105470], [-392467660], [-2104092288], [1260194770], [-981297562], [-909981426], [-35560854], [-2653598988], [-1121127922], [1063442864], [-705962030], [1485064584], [722153228], [1229684926], [-88555078], [-210937382], [-3297749968], [-88287324], [4515072992], [3313376344], [4016936124], [2709759804], [-304578888], [188201994], [-4149632890], [2513603620], [-1324162602], [558047372], [3303310906], [122011396], [-500924618], [-6987017100], [-8165725246], [-8531817956], [1711749838], [4773624600], [789997738], [-1826520160], [-6903393970], [5692351206], [-4285939004], [-561602360], [-5174447234], [-10437405396], [971623496], [7252233882], [-3819244956], [10788130334], [-6348326558], [-8825663246], [-4923306116], [-5684492164], [1705665738], [4521894638], [3092057296], [14462190696], [3154153238], [15423628748], [15951987880], [6139635984], [-14281838146], [-14753597962], [19759196162], [-10137033390], [-12788236004], [7386168106], [-15374171482], [9778821124], [-18346980222], [-31696041976], [6128446604], [-12465213770], [18223734024], [-24861896866], [-29676112554], [11477237844], [-21348534944], [-7927532922], [-7320447250], [-3549880900], [-5806344136], [17824033444], [-18770269808], [37584407464], [19237236638], [1047315930], [7978610106], [4269431940], [10604815542], [-16509037960], [24609411996], [25388583246], [-18758497128], [-3597919712], [-13428724274], [48881545106], [-52935673022], [45412915020], [-11450301450], [-27546145336], [4500244090], [-17682620944], [-15786253546], [-151513708], [-44535077262], [-42746711528], [52094383046], [-41194248256], [34519105172], [10536031086], [-35096222778], [-69453091248], [-14612351070], [23759771542], [-33031118772], [-88316706278], [41828396160], [-33859355774], [-24596134308], [14086651804], [68276727466], [62159497716], [-100734857434], [4113184210], [-37687943882], [70988881598], [6269064840], [-42552214822], [95149945136], [7781442014], [91187639842], [116352177084], [-89125249782], [-97754453248], [-74187934380], [-111087389050], [-55576479452], [62467483506], [19404713058], [113765564968], [121489035116], [42628853480], [-69042594982], [-11202708784], [-46706284850], [-80970957288], [132252625770], [-180172651954], [123957341640], [3998682750], [-154077148048], [-200969756316], [1282085150], [73126192278], [60927009696], [-63660652392], [-166905613700], [112005911622], [-186991666820], [188299112000], [6830416198], [-141665101212], [28510490576], [-41441604430], [97977482530], [118401501740], [160709482408], [-6097810236], [-21719896396], [-206739140552], [41986348006], [283025810574], [-186079785256], [3745176544], [151946611572], [186325944580], [-15365532112], [207569397174], [-114199427010], [277615368200], [2749392442], [-204866551206], [-162884821980], [152318496350], [-61625533100], [-149207581518], [-116027133302], [133048889728], [-118150001964], [-335998549202], [107075111766], [31468438174], [-272642566132], [114892826810], [-325198443850], [66766905332], [276969186578], [-114694726874], [-110675379364], [-303272078294], [-422594734304], [-2340404846], [185862081608], [146844052044], [-244701937930], [103278950266], [229755481828], [-310843685600], [-465061378280], [-89041824776], [341336868974], [304141294820], [-192842374832], [324262653746], [518194216098], [-280745998360], [-215270319010], [225133324666], [368305655364], [107549708662], [363823715676], [333364104294], [267626646442], [71237689952], [293428179714], [-531886510836], [114670061036], [556185596858], [81918215642], [536911513136], [17693225380], [318273262548], [-117465993694], [112754116284], [-188374561786], [-423966552904], [76073289134], [-489691253232], [251039473506], [-359269126114], [328524018316], [217709957608], [-673195012774], [459647217924], [433734708288], [193614449090], [-478116024114], [-603920053796], [-253881696854], [-604188226966], [-367519531616], [592999795174], [-258886191342], [-351259552980], [107614808340], [-196587962720], [-221357809422], [80461941574], [-888472753974], [835151489856], [2887052052], [749396213604], [-134175080148], [-289054547690], [500739989982], [281925423770], [851361930000], [1018181570494], [973410257910], [119637230418], [587695623480], [457075449130], [199026561652], [-413285830002], [-765954473468], [935527344432], [1169796957314], [300835028076], [-862689147334], [-764736077990], [-250832571216], [577508799326], [1062857876054], [-809344101536], [481431640124], [-278919140882], [-362330997192], [444920989742], [380412694278], [666170589072], [-231285957652], [445520425228], [708819522522], [-1212273218118], [552969622648], [623177433130], [-1543423066828], [-731715500220], [1114726860272], [1494919844674], [-512994784952], [-272401294858], [-211997590044], [-116845869024], [-1688874972446], [-127914826578], [79097995466], [723793885770], [643654257350], [953558869224], [-185223294114], [1000418689612], [377218221096], [1348264276368], [949574105150], [-1748081892812], [1704927838848], [575820207490], [-1072747799342], [221743286364], [-327049820772], [469877633880], [-976209903254], [1644378990432], [-716502049242], [1917718587524], [265592142850], [-150884550346], [-836718472770], [-906140136656], [396611798], [-366344306894], [1478989511512], [761941792006], [-1059582343314], [1091716777532], [643846831956], [-1805619249550], [-673514896286], [-387522676372], [-1461159496820], [-689212451238], [-1154036437190], [1809313099584], [186119926520], [-2033907934002], [2425883558936], [-2293380238486], [324331383374], [352576913264], [1810337959628], [-1244867651078], [-1720004830822], [-2339151896732], [-263244252522], [-1343596431852], [-1594221043592]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_72_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_72_8_a_d();".
// 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_72_8_a_d(:prec:=1)
    chi := MakeCharacter_72_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_72_8_a_d();".
// 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_72_8_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_72_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![-82, 1]>],Snew);
    return Vf;
end function;