
// Make newform 144.16.a.j in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_144_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_144_16_a_j();".
// 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_144_16_a_j();".
// 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_144_a();"
function MakeCharacter_144_a()
    N := 144;
    order := 1;
    char_gens := [127, 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_144_a_Hecke(Kf)
    return MakeCharacter_144_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 := 16;
    raw_aps := [[0], [0], [114810], [3034528], [-103451700], [-104365834], [-997689762], [-4934015444], [8324920200], [-104128242846], [296696681512], [-178337455666], [1790882416086], [2863459422772], [4332907521600], [-9732317104422], [-13514837176500], [5352663511190], [53233909720108], [-20229661643400], [26264166466106], [339031361615128], [131684771045076], [39352148322678], [1128750908801474], [-37952841646518], [207297034803952], [-1996916424450084], [13560287430710], [708793726473294], [1230213691452760], [7948358663135700], [17813104378885398], [-3899408979365084], [3487261020992394], [-6857123367527408], [36983550739590614], [-7425352410201668], [-14736477840451800], [-34003921380160254], [38127604372411716], [-51412399028168146], [67556819305280256], [-20723535041701246], [-17124405090220278], [105743289010769008], [313093105415521180], [-335017421112670760], [467560434596992836], [361185847078402910], [-361787480334552186], [-1068421466081672304], [-1005880905461877838], [1747660725639158076], [277264028372899326], [1733027782186595400], [51127071611870034], [-208455388042190744], [3297231489219247694], [3983275627823919702], [2190510992135652244], [5271828889113088458], [-4770665635740963140], [-6466655053798780200], [-6001290916004682934], [953942926372810914], [5290708225748983108], [6224091232465949042], [-3220351184813723556], [-6174072414603070090], [6142665745143477822], [-5811034740391639656], [277147412192213656], [23049810444843986078], [13439690713595024836], [26415142971160396800], [-39527481866174536326], [2828895630756644486], [46368085050027127806], [-11709223060065410806], [-42010158909475520700], [-15971838017103814210], [-97636453701534972000], [-69145547938116219502], [-54899007629774006432], [38050416037054976316], [-1119937923914054706], [-97073378621042665318], [97816539537650636130], [21715899646761475432], [-198442740143161397772], [-37866103330572615216], [-38926469914415133824], [140515953456399674844], [153702802036419319996], [5622645909943499112], [-329307427651506526686], [-171774691187896377738], [159414111416092140340], [47412097410738622790], [280985626221573283036], [349641543771367811874], [268215364169513082804], [795690712374180967398], [-884470144164006418220], [315722143952664273794], [733396890191567852796], [325571463526754276910], [661172632207579669224], [-249466578916192435222], [-1089168506723986371272], [199450366978180006766], [-421127222003179850010], [1272718693187247521284], [342884489459899475248], [-1000753945406654965170], [135729277989846435772], [2154617867614779783288], [2061011052200171337666], [-1613094071947656102588], [1608876842927029216094], [1672937649996966180578], [-726999591126677493318], [2859085319288623634124], [-1712744252980801988564], [895519345176190105506], [-3996416519073015829378], [-266669153589302301600], [1694471472946915444816], [3162386368459530392294], [-2013811680650183681492], [2114114301964084250568], [-4950872878302528745160], [-4858787939126156327986], [3690920307004927958022], [-2338147271379881159422], [5206815110816071777674], [1921955997240024091468], [623880373158914477010], [-5728583662357207638474], [-4800140750898906605516], [-8897753268285649088838], [1399459724996911300240], [6613432903214945715564], [4147351056718798855142], [9578110364006117513496], [-8153607980916852977698], [15355223751924396165126], [4876166406888332621476], [-4766667091106388995808], [15794369333891910147494], [11278909966267353189294], [-4483072749374817329108], [-8562464010560314681800], [-7346377514348012194508], [-11899938843638775301008], [-19262917598818994397776], [-8781094485192734672946], [-23542405059945580473958], [23165994525982295376642], [20257756620274001937732], [16635087576290294070822], [21079436860185360230608], [-30926116556669798380116], [-7857253427480056157826], [12798107216203074249048], [53938456910265101386696], [-19967824628596036611538], [-46095677374917212882062], [29471212479561145158282], [-17797760275772356758228], [-35750042213548015674826], [60087625702871624114664], [47707482107818265598650], [6334838086113649613176], [-33396315225042238650282], [-60435165085183184061548], [38351978902785710795418], [27987303776914479741424], [17709521602897228677446], [80153180530669698409384], [14780756185483028633988], [-38139186294514696106050], [-118093278686401897686522], [90221136399991312597200], [-14452072580912041590486], [62079839921825734905254], [77579667828387710719756], [48246235027731170483834], [-8627940697824488461824], [-23641608922632109620286], [-127129795045556547226404], [-71455035550722550308452], [-428223153697392890670], [124105823827882939603188], [-42588227150993788589658], [99497770392760450965650], [-157713498208455936217018], [98482869506266180299390], [252041659093248821333928], [-122434109118290567408862], [211466054894154196683112], [-43228730624248631647474], [-143617085344934759473054], [-198338222071317186630900], [-60966529881975882317790], [-359996757791904606702440], [-95669684045806514150076], [-83447114236664191362330], [213983042678054468188468], [71806127645884369119986], [-271999193314982473229142], [-423727795376812062241472], [-468866768251159942399380], [245350554332770019783928], [-373274731927152157536934], [304917375701158975949560], [-574896776551912809794274], [-397419979875890582198952], [41292351425877278148402], [128230119127035207971390], [149009547150011807870560], [59149765950020460708270], [789948156884649594609256], [271942056175483555951764], [-840241414549823675061922], [-549053704683060440937738], [-68701292801319284377200], [-549386718584744412003440], [275084338579950876725148], [-30996837778848902772874], [-484836541494624485235380], [-721120151836602599900744], [874140769714257727528902], [1128311753002583505446644], [-436246062070925200113408], [361210524668687232376850], [537736715095978028405322], [539092007583716820360252], [269277058574413533115992], [-658530033806849650490892], [197754457773797000620180], [-323260254146662479797024], [1525773773881330019293862], [-1163001899344405096097778], [338894400724692924309288], [-286232835419916981216536], [375120662237342061537684], [1655624195848200028964452], [-308332743312713009872752], [143110667444561367248486], [721596672981173495330334], [-1581794939279413440204936], [969611969340947765614394], [481265302522951263275922], [1885082510462520581282628], [-329775099637466000068594], [2263790139508394422510516], [-90767702968740105262614], [957821875012638765167114], [-1281474174330354559534760], [1121211387690083524022676], [-386700966636163633499362], [-2690067701642972378904682], [-2174375105582900643093234], [109013466556175743692844], [-1297409807120007721459230], [-2300028450910068621862122], [-860847546737399003542172], [-280710999864199080545862], [-1523045884234866954064954], [3178091685384389757736060], [175872099572386505217002], [-1415872118611230187843640], [-2229374312258960924279278], [1957952365453230817528096], [-2251251639100952241576612], [-3640923571586074441699498], [2429023310078099046824378], [2574793540229831688740100], [-3120790682289803109491184], [-1388818458554238459641360], [-4158230436935601373148664], [-362767255846144386239410], [-1354177167519275130733292], [-6310288490838218503299216], [-3828899593489008240019438], [-4754282167886109365097174], [-4340399405303027019103472], [-6611119377114514664715714], [-3000837880396249861362270], [-5258137646581613464955580], [-554936356304983496244522], [3774672579916793647278300], [2847225704009206762647398], [-6245763657678043714552782], [-569464579041075860979656], [-7585219217648039256753126], [3849483751735240232459100], [3540712309246610827770076], [5707130923522601577673850], [3214771876805131403142786], [3619072903050382729653880], [1575880439115018136941156], [-8377131617480786011429628], [2442327821274482993912258], [4150692817573026008229036], [-4559934680691931007146474], [-11650963403665694433252408], [2958982100312330248698062], [1832056834159032087181776], [2070973134188736791932026], [13746521286314753366891694], [3843932294446724788722844], [-6899586905685692447680824], [4433216075598734173547354], [-1091556448592214209096028], [12310994798058187153695504], [-6272080343801211741904510], [3766173532535499696175470], [-17095874332476350912541284], [-12452850818464509302905366], [16988791533787407307197474], [-420204096653326094856728], [6043613711555267018164758], [8528733041497677925982642], [9141283285011430708044220], [21740356220216022163271428], [-528686726741783386666464], [-6639566900327227039603302], [9535553511226484132079542], [20234530992736608832541778], [20014416580415963951650552], [7725769782639385392744180], [-2807842052987301299619548], [6843087986336919477976572], [-6041193567359915928813226], [-9304611883346090901302274], [-24400451370692038775272486], [5844281062926848307755560], [11421967778352357772609982], [-29416124368635958414749786], [-14449207213264329345749718], [14544108880886781356104240], [-9412507723458403759366014], [-9210830180972549774063004], [-28884313121925682661997922], [8402750011906535377218148], [6563376630528570176958528], [-7163677367569734668191494], [-10119204995992746409587620], [28522757809098337122010010], [6581843705492095075228338], [-26866408096019691147168056], [-28069702713898451344373794], [30782406986349155801594838], [15839984509445257621117248], [1641653929282727328510492], [20815047080581562463325182], [31230974516708351240528856], [9354947880517349745355310], [-8049310409286190733344602], [-17467360524707016625585200], [25051084497151760391229500], [39623508073166572464270316], [16800354041499730583995034], [-6729551123166731883117390], [44934798833197247636613376], [-10674360993511885585331734], [34871379588408249772303236], [-42847903847018245881320876], [59628321399371943916476336], [10746453920034070114079322], [42937485633273482675560240], [46886366343915684405919046], [-47255261669452482898719084], [-1321260861198550623767712], [-27339889425652559027342878], [45109145292748854792027102], [41762361662250498199981802], [75185765182126849941735762], [-365845244431247963172138], [44486418788428798749718096], [85523980831248406723510494], [-2588576584252298633051492], [-51968699970867286183796184], [-63253908207330113932029128], [81061820240857169550723182], [28470793892913815577224884], [31852280095056979613406192], [-27981564162763618719918142], [-29833150718000486104559142], [-85198287534720536249462052], [-51013208065200053761823636], [44635606168760698166218104], [24676497202677083838144074], [24823160135824237578188152], [40148916948821822166123222], [18413337351851886599720980], [-413852283189582629539926], [-64583944674984987956227114], [64658561716778860085905710], [-31285914093854690969585144], [7774855599190035106184262], [15576640353679829359189770], [102162651288648008036723296], [55787176709512213376854838], [-35739037551576692181656994], [-81622179331187308352548148], [94371932692638322313801028], [82867160122336850898074546], [-123907693558962474044428182], [-103900582684417306445607780], [299594159336722835394556], [-68209145129378251910032486], [-98476569878000581076920974], [39914467620708742015355136], [-16851946637923514881724864], [61224040037751773627801214], [-94210583149865368342945752], [81503204641097286592013682], [-45115927217196769805152498], [-48387738278492323795948656], [-90190951144836292268377188], [-32148506780473421197096774], [113833254415580808942884946], [-144394541203954546578922572], [-168881921150500117826637066], [21634353534074558330402980], [-143468909150090108155945176]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_144_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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