
// Make newform 84.8.a.d in Magma, downloaded from the LMFDB on 13 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_84_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_84_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_84_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
        poly := [-5490, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_84_a();"
function MakeCharacter_84_a()
    N := 84;
    order := 1;
    char_gens := [43, 29, 73];
    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_84_a_Hecke(Kf)
    return MakeCharacter_84_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, 0], [27, 0], [48, -1], [-343, 0], [2070, -17], [4614, 24], [15264, 25], [-352, 78], [19314, 91], [65994, -610], [82692, 198], [190502, 660], [189564, -33], [458108, 60], [457188, -810], [749166, 4176], [446616, 590], [239346, -10326], [56392, -582], [-3192114, -2843], [-716594, 18102], [-2824668, 16734], [-4043340, -6284], [-5056932, -393], [3695086, 42], [-5202228, -13903], [-4786756, 35622], [-16909938, -13437], [17793718, -15192], [-14098542, 14528], [-6148356, 119322], [-23741004, 43916], [13214598, -71926], [11161132, -109236], [31163886, 81456], [29864800, 48348], [51502802, 107514], [24701072, -88698], [-66639204, 5726], [34418748, 159413], [35517978, -109431], [-39224274, 76752], [-49436346, 268653], [10383818, 383628], [5653278, -563024], [-117980704, -180492], [-102819196, 400596], [-187312048, -276240], [-154615776, 641238], [105971638, -728940], [171845334, -391646], [-59536326, 632331], [-215217802, 499326], [-197293152, -867510], [361007508, 546087], [465928410, -257745], [290548728, -332713], [176567772, 890562], [447691406, 709704], [6823062, -520214], [-391500848, 377106], [136960188, 1671897], [67617952, 1010382], [-23814324, -2091922], [180243514, 901944], [600973038, -560340], [9450764, -1315116], [-436537014, -1465740], [717128058, 1051029], [-598320494, 28506], [-521638848, 1100481], [-10996314, 2132537], [-132188080, -1319016], [-580245362, -1016520], [-232005572, -380940], [-612223320, -2919908], [302583714, -1387858], [25003746, -5080518], [-7698666, 2087454], [-99200002, -2259354], [-601934088, -5400006], [-532673922, -5296440], [388178310, 5760597], [-770284726, 3254388], [1844052288, 699036], [-846071094, -5363123], [314850882, 3516560], [978450682, 6889344], [-864488412, 2825201], [3108693460, -1280106], [-2895038640, -1248538], [-248738316, 627670], [1442274536, -11994480], [-1899154830, -4450959], [1607845660, -11370312], [-1996129824, 7951476], [292606248, 8505735], [4998894624, 739581], [-1053295372, -6824664], [-1433131290, 2054040], [-774336768, 4648494], [833715726, -73132], [-3820952424, -12225278], [3819692862, -8098986], [-6883064208, -5051670], [1012576090, 13454868], [-2692510464, 22963042], [-5181597504, -4487511], [-1886442234, -21087423], [-30584062, -21486636], [-68817672, -23480964], [-10096516650, -2593044], [1882270422, -2687390], [-6965489228, 7466376], [5642152196, 7722186], [4899655830, 21791206], [4449238208, 3132918], [7210723716, -3883062], [275937090, 30789114], [-2891556594, -22529105], [10683199546, -13644966], [-4352847814, -8635740], [-1985310684, -42378555], [-3445805982, 5877225], [2493360980, -16368876], [8555378922, 4676798], [-6510364978, -15183408], [-6112782336, 4863576], [5638494556, -17764338], [6602732934, -1695936], [-17170420560, -14541978], [-5523633450, 16283409], [17456837712, 13968264], [2063471646, 40232880], [-11054895732, 29324239], [4786230490, 58293540], [-1682719404, -27501667], [493799964, -13244256], [-12027799812, 12543357], [4995729618, -56071180], [7648799356, 19032084], [-3962418618, -73726556], [-816639932, -37943478], [-13466070762, -5907081], [-5054206442, -29718072], [-11715784116, 18132454], [-26095380982, -4328862], [-11725636404, 84624063], [17950332896, 9634410], [20440315146, -2951461], [-5690089298, 10642620], [-20932045080, 20237253], [-1952107540, -62939136], [-21330992676, -18797610], [-6950146884, -124934724], [7866514182, 54273237], [25181148472, -28689984], [-6654942276, -56920029], [-7729237174, 13138728], [2225565912, -87893449], [48709531518, -7274233], [-39009620790, -4558736], [36201623684, 8923938], [3174265596, -150551580], [44713344390, 9503622], [-5566657848, 97353072], [36290539904, 33381384], [-13485095686, -36830670], [5606245322, -150380364], [-33563814900, -49994391], [44975297766, 69800495], [29528527234, -46150542], [54258868278, 10956417], [-4472458950, 112704048], [-9665553240, -91066836], [-12915797112, -17770687], [-33589181352, -52665834], [51040664322, -14778482], [-52655682772, 28254462], [11595178802, -130834350], [-18937085460, -149944206], [5129101236, -65244980], [-14615795762, 111543936], [13069150896, 196137365], [19730586690, -126508009], [19261864500, 99722373], [38017974774, -1629600], [-79621693588, 29420640], [14992872618, 12780936], [904844160, 129807600], [13968541126, -110114082], [-24930749034, -35072145], [7172016172, -208754784], [8023015092, 62815969], [61031002806, 146511075], [31346245272, -4211855], [53794810970, -181984020], [-86807675594, -64249296], [24674435100, -266086557], [-73787676252, -132048390], [57149477646, 101144292], [-8541266352, 188704872], [100738685462, 92176764], [5815853502, 283220274], [47832470364, 246438180], [39145537932, -318325371], [-60287800000, -48527592], [66782641326, 20558103], [42048963282, -25251756], [40878996704, 246535698], [-23105660254, 29505672], [-68934007992, 158630123], [-3045561480, -268131936], [30297946884, 266816264], [983974692, 137199066], [47698335914, -179456760], [53555928592, 230251416], [85596313992, 130156645], [7071363162, 438921127], [-69267562038, -211168658], [2086615102, -228322008], [44237521708, -332995050], [-43856574534, 209483796], [-37193346752, 357695184], [68983461132, 332015016], [-91244733898, 286353684], [-86879635908, 66487495], [-110130868302, -235921753], [-157630712652, 41303802], [-16032027294, -469227831], [-10728409530, 210763680], [-13202402912, -234758034], [43786759504, 169168704], [-88834144758, 314342040], [75742449992, -55699986], [-91166289216, -124327128], [-107080497986, 357916458], [-188180350218, -112711476], [30341417202, -358064631], [15225276528, 40921652], [-76318946214, -21673367], [23541779180, 719213316], [86461813064, -258775200], [21996982902, 393928392], [-30986883300, 506439259], [-49910286156, 623534730], [58895913204, 378322206], [8040900816, 614984398], [-73396971856, 101296818], [-2070990, 335297439], [68134557958, -467256888], [119736982848, -474405519], [-95931436146, -175972443], [-2013394082, 636898734], [-11907981636, 751495237], [-21562654098, 130601359], [47154458510, -834156072], [137144806992, -173121822], [70595526324, 183085181], [-150223753702, -284428920], [-43494591500, 449819454], [46868037714, 47464757], [135762414358, -164319708], [125501522146, -61831326], [-17218955544, -338618355], [-44814478436, -15374376], [184365537870, 62646228], [221671335792, -454754275], [56050308760, -140888586], [-172198664622, 414489942], [-39370892838, 665538462], [30469860092, 1150104264], [-51824720082, 435764190], [-1536877240, 752020692], [-241182701618, 493213506], [-15274491396, -454209234], [-99522281754, 724492015], [107103013350, -580505448], [27521191282, -525161964], [71417111088, -796476186], [-130029846192, -871135080], [21257779236, -291582318], [-52668902664, -455594280], [-183888950278, -466005822], [-134486184012, -219268632], [-266575310442, 589682605], [91951744002, -297214152], [-26196035154, -1434632816], [-23627922940, 237184410], [11441751348, 1424955303], [-157746668418, -456261444], [-385434205260, -408816492], [365157920070, -581973822], [-241990371216, 1027672922], [208373278310, -306774816], [-61379234292, -855683691], [109213137080, 258931260], [-140527793976, -988235589], [450358733448, 301307574], [-171332119932, -390879804], [213785416498, -1338956652], [-29892557358, 1091740050], [50354436916, -876229290], [-145299489690, 1195010307], [71382640400, -1260489798], [166564714826, 1373667372], [38144015706, 39364541], [6394220510, 82531308], [-28510583274, -2011700807], [543699122702, 701868960], [392300759232, 1166374488], [-156789230142, -312738970], [-198406851522, -715050622], [157755497372, -461775936], [-195473649942, -690957481], [140025380126, -841173474], [-159455752692, 964300632], [61847954922, 548109227], [167505575414, -169985562], [184552764486, -882460842], [172956029240, -1304791134], [-211820990462, -430298268], [-435253070460, -939791559], [-12832316384, 474342456], [2384622018, 256339292], [-525354739666, 381425058], [-123470405128, -2600675742], [656328767176, -353862042], [-287305921626, -1349391299], [-649951951398, -482830430], [207102579110, 1085277792], [-221991960990, -818104718], [-206609047284, 1268012802], [158580293160, -1170375998], [-32719333040, -402356094], [293811941040, 2396141378], [-159001779954, -1806960684], [-312148324908, 357942935], [-301121296138, -1980294222], [-80322161924, -1181661102], [397556256734, 2423246544], [441360980694, 1035944682], [-141381052344, -1978121325], [65827402512, -1183626516], [305316019554, -1817946318], [-192493994490, 442294203], [-427230730570, 216029748], [-23724079492, 634734636], [253107106152, -1670917596], [-187231854564, -2328856863], [-837264964168, 143089242], [58143315794, -1235936316], [-67085515698, 2839290900], [742838994000, 297984840], [-545814748322, -508299744], [196309990392, 1725400105], [674532757920, 979717712], [211297238076, -1079870652], [290271094482, -566251760], [234412975734, -57451271], [45671994670, -2022841152], [-99489181548, -911349341], [886510577478, 1187692661], [386190430326, -537771929], [28832765092, 3185199108], [595307999906, 989476236], [-12223522992, 4039607835], [-118915254276, -4437682410], [474308258914, -267096012], [-272266628214, 4177495369], [-357512617016, 3510804558], [-256573590930, 2986557921], [317000900886, 1509907868], [-171092807372, -3738568830], [995599232422, -772806744], [1277427296484, -37372836], [-347411936574, -2246433617], [672056504266, -2575567284], [-231309358944, -1365988247], [316426925918, -2073237306], [-331784904540, 340068729], [849391415634, 1988992292], [518803939696, 4097076804], [-1077846921702, -1456089852], [-1123808638676, -1057312128], [249027268728, -223771840], [-494067614344, -1749197820], [-1391971879634, -1155395424], [-334740929000, -1076727546], [738977949204, -1472854250], [-375207295438, 3882672504], [-1140061796688, 658172703], [-130756357218, -1614347573], [469207328384, -356810226], [-1098040228146, -1326911875], [-542763530430, 4856814036], [349043468776, -919184460], [277981031544, 498064225], [-697233792888, 2374052934], [-1498406496006, 1784172490], [77133389930, -2493794226], [635510752818, -3595496040], [-1049573668244, 1934797866], [-1116217674132, -1871489713], [350227662384, -2365377585], [816238775288, -2570754648], [-81157115210, 94675176], [85310655882, -4453004844], [-573857699788, 5533756212], [-584841274872, -2734015646], [-442590779174, -1571037204], [-145743510798, 5659241182], [-602259025734, 769504309], [164389956324, -3008559828], [824264846378, 1046495400], [-177600886896, -2571596069], [-9574003230, 3587132575], [617730254212, -729598206], [-1223699768664, -2105711979], [-1756459811580, -1433873326], [274433220546, 2646743026], [695044559618, -119813778], [-290135550834, -44141135], [985883196588, -2434939356], [2398769195618, -70148388], [-899562878916, -4970880859], [-524844595590, 6997264361], [1509322099806, -2978122554], [693712559748, 355131720], [390174683724, -6702351410]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_84_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_84_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_84_8_a_d(:prec:=2)
    chi := MakeCharacter_84_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_84_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_84_8_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_84_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![-85540, -96, 1]>],Snew);
    return Vf;
end function;