
// Make newform 1.28.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1_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_1_28_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_1_28_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
        poly := [-4552, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-108, 216]];
    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_1_a();"
function MakeCharacter_1_a()
    N := 1;
    order := 1;
    char_gens := [];
    v := [];
    // 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_1_a_Hecke(Kf)
    return MakeCharacter_1_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 := 28;
    raw_aps := [[-4140, -1], [-643140, -192], [2721793950, -147200], [-87695981800, -7491456], [69083668845972, 9443825600], [-376716900635530, 14413771008], [-14876810165505870, 645319017984], [202282905186342380, -2800373100480], [1464539461560609480, 91869621889408], [-7773339997724279130, 327641521921280], [14272277297233692512, 5259288606220800], [933848602341412283390, 38848100480273664], [4540671849023256127482, 63868156292684800], [2572806302900710886900, -643846246368316992], [-575125744431100535280, -606675609439012096], [53476867795735030379310, -7346878234282881792], [1004810488812013244315940, -6076200302162335040], [73928713346224470185222, 96042884669269920000], [1525789267869049451078780, -325584268219037082816], [-6587599410184669299143208, 684124350799607760000], [2642130406475643286058330, 725630785462476062208], [31407175517860359959089520, 1044068723282136833280], [85903436705027378941588140, -990451547317895545792], [-156736719380552769881747190, 1099873220038538288640], [-326601466698526421441944030, 48318176575689863560704], [-680115927964775351380876098, -78590448843768353708800], [1786345188584079760046325560, 74390434703473813665408], [-2262529711916163844644948300, 65132797844588368158144], [-1021998404269392309336444010, -146712749765234379344640], [217656466964938864933071570, 237598992985282351403008], [-28739519237120278180543181440, 124661749722743916877824], [-3712008344684627060702561988, 2435429673030530752417600], [5385924313431682114288728090, 1093310888322671424318464], [13323181208359810629732099860, -8871668669880000305616960], [187394758274951577622454172750, 5701132012956872215916800], [211662207032513923798906695752, -10106995446530695841500800], [-696429535775019379855553599450, -2747879229458549916147456], [445217934232703090021106155420, 3186678974793227775551808], [667569319437883668360732850680, -2068265214822906689426816], [1958022459017394933225595039830, 51697914264233722728036608], [799889290232080315238204918220, -168142389760978320987856320], [-429940499809740346774433446738, 324733917435579380354976000], [-206420646030134379113629637568, 381849222939764872947891200], [-193159081051671920453069372350, 182816915990291047244164608], [6262317609092067022295329544670, -732544638787193653980362496], [-12090403870979576568377904889000, -254778388970166807824073600], [-17275501150319531840419451139028, 155550128637341160983131200], [-7836536466420465260771986023520, -179560504141098981369057792], [40137997258263774774895961556060, 3730364841234118563205807424], [-7374401596243512884784670996930, -3794158207781050211312613120], [33912304991095936361401399672890, 3075505268647627817514167808], [93761793033130486618331478100560, -6821436335879863502011746560], [-90700557643524256317676765951918, 3184294800469462559884224000], [-131815094339911932572234787566748, -13469639574972480464792136000], [-51363965436078067545135778948350, 5914307621515289039526559744], [-12331654399202129570852836053480, 3472103793281083542070087808], [344762145948322186948894828781430, -26709852846122708724455719680], [519229879305522672650703343938992, -10728983876655302405803411200], [-40038594212079953984906101936690, 99331534321322960795772628224], [656575893862842890020831074066762, -20382162552095928461895539200], [-954794780253627834792071300608060, 40869627842182633533162479808], [-1205492248158306118271584863394050, 106823567878244349811339671808], [1684303343359969755927151081210700, -161933768014995816273350110656], [1482403689921823200612717352639272, 252820016617430810138120444800], [211276384295716471708443698803370, -90442116801892579013876155392], [-1925212838072593552085654798309370, -519755044394381995264469353216], [-7164984428623397262112505184431788, -368485674007302388069761729600], [97935411661944727671541193202290, -237782049012945671222962907136], [-24013673506397313078561027508825980, 333419692174228026864945421504], [16201021516948925888818758121461350, -113745520611547536203566099200], [11365887115275225858644987936850210, -1081371809706996294396737800192], [23435476914185746425685527367658040, 179747367582987478182173804160], [25037756497314392239453641958934480, 683943397656376985691311165184], [5027213281112949928974945040379630, -1759151666849699673551044737792], [-31173636955093753503660061669700380, -393753258822098537347032371520], [40933515100539185606984368698714240, 1396348450047278489617169963008], [61475397158430442274032675090222110, -340985717010730654697959432960], [-145906578772011338076357205637195530, -5128647191394326171395429706496], [-54867211326363058219884384725243598, -9108547277918977102293009574400], [-49432604807064847054032948999014710, 18683486494865628833586596981760], [-243132282975444298708697462701272420, 12923672542784830118484987699520], [151815951445021163987875501572540542, -23986804700835590232732229267200], [-165450357813976769668897677601515888, -22607818188799247171267440262400], [155561887603214115348591702516409490, 10794855467799189633406032926208], [174939688201968964443531490563080360, 37591997317816568186425779872640], [-646009828527830113486392990476190300, -8380344918202269143187093558592], [-1037313926140968181726370687836350, -44704067443297785518489009779200], [760570770024608853508039923004876250, -9571400090109748699659640083456], [707820556503277900600740456243447222, 21531180685150118607755157843200], [-1249046002573167733192458746063230480, 9993038097474976790992022500608], [576750659283065853857976756881211180, 19877668295659615427449436625984], [-872582559648982247104589909663664480, -116708842688903289929611257233920], [-1993293499562290567737442855219314760, -20309119365207935503255560241536], [2215486698985411778279147609574951732, -32548467334587080278422486401600], [1182797855893879886310093651161852300, 111087017723016060814298558260800], [639021543627103300381493563370611560, 192217481126273562186275983579008], [2323454181698144459062306421053253190, -149087044902046198041503364304640], [4530181300308937748447935980316633242, 248229790372323793084956068428800], [-1999759221529028503882971572752295020, -147118025534157976055459734550592], [8552858885760874061162519486166639782, 140582706494300274069879757113600], [10344100739645293863642224578113928220, -131817128914923725945896395708096], [3845356275242135572305771513940622550, -647677054642580689439764937101056], [4876755422578673652146735572496889420, 1079820017314964495196526681465408], [-4096406976570832684519088343810794070, 622011854583223366970521451985920], [16829539501845108255339783338447142692, -1084161674050668816322236270177600], [-4152265045403165347486238562916291390, -32957559162911261619714919090176], [-3318036993966918185693212964130130860, 408918064726686305695189934742464], [-20227374220401869998362616500943006350, -1027997487859162548255764522913792], [47645787992252176076534548696142238600, 3138745959878007800185639484800], [-3422746001340660352881604536415639798, -1405940649601441675658594769216000], [21799796480900540499049116829977044000, 805745102992236016079540966290944], [-2818360599084752890689303725227742530, -4095437850061887250247463379406592], [-53569295234378206824278909540216057670, -835500393465266016833434097609216], [-5781683325745888443452984611309388620, 2041438396818640518213604759350720], [-50081937513647349701198190325481092888, 1569877436592310598985424384483200], [39329784453311694336026843750946014082, 1439598763794884468492088901107200], [-21675942551821244375012247244364488900, -5507258435184703566033362468659392], [70488039435540394283488984362620128920, -4741871865413316656382538429159296], [-126806306150320884814285866392653460490, -2784229594381545323234753268200192], [-26017326059845979965254268069436467860, -10773151516261599849802939400904640], [81409100216918615989526838244097606222, -1404765586638699321628190698387200], [-30667849279250555799657249507477495070, -2262044812588696861650812095713792], [-19009054594716903484306330098061276290, -2381107588718972260832169886302976], [-13162706223649561777188784303728786060, 11826339059281240124138800524585408], [12554686841926136933066374460780457932, -8512526713384848379177543948516800], [-64988043242135328607147548528869522298, 10667949483093816195032595489388800], [-165247480918718000856461410316046360610, 28648429857879946761139299609672960], [33825897920597884777812453460120151280, -17098975052400029710731835734055680], [-453064164394130722429010378430002734840, -11355437808870309129952061042702976], [302025625066532669670436514173401961190, -21076177901726345490211852164379392], [14936854784480925556939473824124922460, -36875107049106430403888001031316160], [270547749001094329516410052912549423800, 50727921773375482754338624832622208], [-596823258623435852777641252531984662448, 10443163413683201484999068468524800], [302520682374830926144471691666832925550, 35846537189864654743213901174694144], [-51279044169888603194198069291666694678, -35570481925758952605042078154572800], [786590837616813790785459812678007836930, 47537235067936365844697785302904320], [-385734428711982844151683994806408982370, -99621815921873916319873155866088192], [-958021275184298181117783257938635280660, 38755271213457516290123471371212864], [-1736407156146290017260001384932273162330, 28258749671096619195575535272399104], [-1820524412965260002456758644846371829510, -25529308245358435597903655899530240], [1177745501650009612006636300183853168372, 108825528460210408158155430664190400], [-1943417809569647956976383832787146466258, 68699945009456506631555058589779200], [179819222960898180120862120527211229480, 137178000053552329248462058979572608], [853424482479776977150995683573503885860, -114515884208454757413254015042170176], [1270538057588071596038981826078930865670, 16827038008297237115542944556519680], [908241750995198387554447001622537260760, 146396508519734225487535627626611840], [598235980097077478933253768934863674510, -108159960899206118139301110325531392], [-1321431592632200763680121788162017308150, -385428179196807656577691104716563456], [-4208121799687283627962066098462011156860, -177258242659589281879297653719442240], [1580577363887450675624296042843698642720, -144619406505025323443780396291246592], [-1055535199878729633217218362824526525290, 307132348549619815281182058299092224], [953391264662589424568154214133915818962, -567526799270048702255220356021299200], [-4769899138914517497162708581217027369460, 185799903601269119364803052354143808], [1732133808720173888366933167857955083240, 360759019055603045215152840495316864], [-6943439634331967885549092132458298552300, 319657800954768040367307980907562944], [8918213943278146361656938896785955668272, -96173813081158723762087760346054400], [11369735997327757984295593130313268990280, -418954979815808495816267030799089280], [3195534582292304201340890581502604787170, -389560942113250487204085865909957120], [-2303707001179373781679646759664551096710, -45177954066592480992575860984705536], [5780278374633971793269200734378613770582, 451358687558724023047824346758841600], [9826254110371612546459489939562366870220, -425481659755030840091109802294453696], [-14650710637387711986533179897776844472790, -405198957885495643532980144301601792], [-6056138862605931781893259594323748010920, -1519180451261780414045609466475295616], [-2687622700479213236834009562272692459308, -1062809515774897668178484891594126400], [1739080408458909010578213365978384551410, 1275366151374912544483031064417601024], [-15282378755667121615598231021041121696760, 1578913047809334112265634487246337408], [14595927634889401692876170038633232592032, -137744920405398033177569605676044800], [20136185891738106654285981349337230987070, 1711799123084848390798650202440424704]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1_28_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_1_28_a_a(:prec:=2)
    chi := MakeCharacter_1_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 28));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_1_28_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_1_28_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,28,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;