
// Make newform 1.30.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_30_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_30_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 := [-12837, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-96, 192]];
    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 := 30;
    raw_aps := [[4320, -1], [-2483820, 552], [-8738894250, -116000], [-1510156341400, -67855536], [-1027690259794308, -10592091400], [8569685589666110, -113971542048], [-332397963953874990, 19090509870144], [616084722726077540, 142801363479240], [-9294215252187189960, -351986937759248], [498048208882880797710, -63411615083585440], [-543629332090962015328, 195576850719316800], [49439063879668069155830, -1363639917490075296], [-53349918629805012878838, -2173657014743715200], [255320216557487015683100, -19178453595369039048], [-2260553835554912897519760, -16406150082376208416], [-8070772314833395125331770, -294880492732932927648], [-41748645757830075138031380, 2189027298629008520920], [-7938381471615089812056658, -2479131441018773748000], [12234377217064422445391060, 5378721492652656197544], [-94214214126680033604788568, -12386621366762915454000], [497936360648784266526040490, 43882241745783908204352], [-3609230426293867898911821040, -15071111181393825443040], [1105423112624077761847334820, 253116950749653742369352], [2936482373300484681981015930, 162884738427910800924480], [54824991109735998546613502690, 1856120923313331641918784], [-1218727112362951756294455498, 2197530896887230815727200], [-1160609830284192682334228920, -6119687505612214618987248], [-350241445442890679491061518500, -5460847852168627264376136], [69951244633586075303938096670, -27756689110110954103762080], [423226021569081509711888671410, 17110053162377874403005952], [1831140930334181852658535829120, -75260884236273797741035776], [-1742176050364380150984539906028, -26666915961945178859581400], [738819889837673844517625143530, 549796633882596121632792704], [4676114230765678000713401289980, 311602124309252609510367480], [-30854138833472508260966000770650, -1221566556761107432546829600], [20735045310559364713090947328952, 1381929366275846129588713200], [8284296528806359409071207326350, -808959312414081153130031136], [-16283539759203028209638075672140, -1298688722197658055439895448], [141206057828536060143471356935560, 1535446047677991401434528144], [214867209563968565183794303652190, -7692008883773311909714754848], [-592119429438855891730292871631740, -3129469052694020862474587640], [-110045723052752000113281998344378, 29620236721226461270101036000], [-1019499380684144611470013944564288, 2792400131954039707642659200], [994930291139093764879839186867650, -42142410159290918467560646848], [-1692251003782150751990471277125610, 52030127113853855460103778784], [1471677689773801776648062640405800, -26668111239879903450644842800], [-1582138280759188390871253114847708, 122212004966789141695601104200], [7820958706366788269451630570201440, -540670019259542658592102371648], [-6905360970841573072943586132787980, -880196954102359227003341508376], [7660325260881704591996390868841910, 118947695422049076634934830560], [-1944131617581820583515107329304630, 983799948810308408067137247552], [-31277942624562030471796167787776720, -659677130539110938272132073120], [3195372117793080014953639377760562, 1189844754559014721617716904000], [-57762591686964144896148770607377748, 1862692551731865296352196455000], [-40563905776630840085375830947652350, 2059040452787973139791235416064], [87536731609369335860108576163245160, -5533244931597885186644421558448], [22541246420359419481514611479459390, 11833476032231831853292030201440], [-229532045117947100031150741640472368, -6492452413128221032465748623200], [129127820671530317450914457295378470, 9377504298397331065287852457824], [-69960902003362694304372939487419078, -20657645939732260170648492875200], [256676219376512895750236089696467020, -12279860232422491435916177561448], [-633124207445531517929284355809283850, 11899269614380326202158316867552], [48614013734688080906777871889175300, -26945849863934164553625796281336], [692570414117749731133462475921899992, -50750843211684617481830824533200], [-2176557547482071894576366766989380390, 23477863385739944182933512001152], [1760376186233669417886451956799873710, 33571630748341459434199244085344], [1639074379676035800047403285266026172, 2949156504762238111207718273400], [-832844723932741750081190055579685870, 100814268127954652785907588047104], [-1194042401468203392526776623424031860, -259347693645290090557145851235816], [1818344802570523120890357356329782350, 128108690236260539146805674140000], [1021169736498541663565800813252853730, 479351638084006717228967573687552], [-5222388732379704597647313360733623480, -373798888171114440293328895088880], [-6048928388771738245016238820502543440, -416168112507745049452165542346656], [13572269415267045373291026271297712390, -674142745628613084381084200607648], [14878232138463550879303916491207362860, -13937012309967862665757032924840], [-15905370483986913838999436819236836480, 463557902200784971371186057309952], [-27247197249667101956813326099740937770, 957344753204708407353499928816480], [12181743941655853397673062688863411390, 2551701092736142832187352380549984], [-55820525216563630754619666824076647598, -1244779350479748816045811483006400], [53705577245765862004990108736557654970, -1460064506780508152539327869790080], [-36074449614981240045037670409765296460, 762178506074857487880230372846440], [33990709526074930800631768068981892982, -3007928893668975615835930874983200], [-234346458668797967278034804426628269328, -1728858097342016538970590625946400], [104832894239817654121366512713634928370, 710628764231129313169918707020352], [-198252846696997410190461495353865617320, 6132634766959708707464610553823280], [68460771112849352039264275336696046700, -8934567920973966669948864472958248], [270604560333956437478661259391772422850, 7451358971467336911057569920852800], [-441793601552088388926567333849754600150, -4259097495815104844607399858366336], [156834946055701091271594657300105580542, -19659252705397966958291284061648800], [406717404308875155140754541708984188560, 5955614957439580579887084612805152], [43506303771640861418424266870433172260, 43435118562194969957996212815094344], [197999018049899174727467804903107198560, -16739248637840551900575185406840640], [-786029989424754931284893189059496113720, 12173509587892827707597164450124304], [95664787668757238362817529698484450012, -32349807322220232359564456175158600], [1533038330758091446796639053790815612100, 18036815296625400288514232191192200], [908608692913395851055329364710772137880, 25900858143448754604359550013643952], [14040584809538123435516008446423362670, 3891379567729004604484751406961120], [2412316309583918696233381664042610891882, -48277902879047046349289595851299200], [-2540055012651679373153308406407524675460, -63719099722415127754758219055978248], [448298104246890730113349644087630018062, 146870829304832294222091827414565600], [-3234795000973760780484971127559041389260, 104352701566482275773116998481940584], [-4416969844598710646441506207764511030050, 3144461031546319758933529340650464], [-2283547068745932168372675759317927993340, -135119158516217309573962312223904248], [-3852627788679839575141040433353792015910, 568768515835935474593452768341530240], [5046848459758409761080923772708062993132, -194917299374063575148571531636546600], [-9427974168616605539307724920733409533630, -302472629951842912844870948266488576], [-6362741873997294690460763065081467569220, -41002375320554796268656311207017096], [13465280316003968059551824689566751410450, -404264286878253122699307045156699648], [16157004372118498441065931395338779092600, 647008485865630681415928642763750000], [-16154016693326339241777640992932981886598, -65074105774518286725867010397688000], [-7025803942552775082548222803481312768800, -956459836987281435852337337299100736], [20555856505803592874505750802249723648310, 267395464105947177222495525373462752], [2493359925989766577630774896501156795210, -72254979815098132261596286048081856], [-3903797314164167259388334648486412433060, -1855874358136696137170817278519993160], [-13232604060451224870865536639083469578728, 2555722916418294906695757528825121200], [8271676773143571458228773155470036805762, -2282310497054653544020059836460548800], [18558151563306230359059464012708679252500, 3673547528652812748016789703122330152], [-8921027767160150250853887706878692161560, 98420054412899771944571248668757584], [64295263372459704562445808074204151261630, -1466586580757017730709910806460396448], [5089555462493241570536583656182072968420, -881780288923921910761629060043130680], [-91178070949049871945779043691812337312858, -206660750978118426076203470257543200], [-48206370466910443002069825321057703967710, 1556640790101258160936047444597356352], [135864130061638887703309316418087303959670, -2155768119183162825803551310376969376], [72780239125097506728874436650039674737820, 3514221412039575227746733021343325752], [155131973182723759044851002920379074414212, 4545513016356049139317707607189192200], [13770796538318552205335961867781785990702, -1352048986693662797110004490933223200], [145520876102807211288717990249663227918870, -10352582806655994016417537266029342880], [-12396011694062942736389112584367647925360, 877919502946779710622431979832619040], [-8289798107198482555513385270127925091080, -13792225504194667648269015751752210576], [-330412393860695255051233102566309900001330, 2341292621267774885016482030156653152], [66550857425560273149433702330808805070580, -23117662124738132734787741687582282520], [59354018398595461983898960555017825011400, -7612265568601727961650523036844913648], [-399288086592005741862316381006512471920848, 11307062740550109001192509131181160800], [-498851683759238694953703229786851143568250, 16998710864536938347115096037233111264], [-285308848487856635191527802871559431110758, -33314279029141999766550504998989500800], [-598350618777498001748113975484531772410110, -9740824453790950235574945118016698560], [351764952396130857982796348087312653391190, -1743829316750235389666422331173580448], [846086428555006989769211681021998648257380, -1785482722744530767830225150882800696], [-195342161325141601640447959102207602900210, 19827162937326627209922067164312777184], [691627828351941613495315202392164842696970, 71871659401767244386940024577802645120], [863483079313191176076590736163998260587292, -2124417485814288097981264273126470600], [767175329400002477168650176606580178083782, -34858391741557199198495492015879888800], [-613384349660953247625054154638677672248360, 48914418966755494667734040421209743152], [-739021686527916950441094714299375672719380, 109497678345534267531669918120628286424], [-41370886376323780020072439171833339249490, 44592624017891796418868432103339310560], [-246483777088607316343963966510562092984920, -62060064166158407518305190147323292720], [-349581065509552916871678325668838457442970, -99220916959576848956452081624682866848], [4164207436013149233256129989953070020873850, 26729834492061337228581667681712872064], [1180608102791583039298917424243105288654220, -109163667182711847337305156019045461480], [-137855314531998699066762895048101693265440, 259803210207273631342398402282017698752], [751979782636002255268447446255388048221470, 114838284157905001466983890111803747424], [3593345555573889823969433771914816382630322, -115827642804783674074125834134753683200], [-819921647853382429019665678875714257461180, 223186864200267583170459966159823164552], [70823734285927891196064671072323335641880, -56020198400240082498136464876641942096], [-10173053721473586437983376995283974024375300, -152448249594287348331043863369119580936], [-1586064599024131422969032144111856789356208, 211297751601300080126896090959561821600], [6719507445131513855971914295973423754912440, -19853806166780518707835234951239935760], [14301542971526227734918604666714501629829410, 108802376319566286896056290551877604160], [-11395726252499213402045210967458722535780470, -338625152225861757833347061376744098496], [7276872309533271467524581296631576700909662, -97869459978109287898573493469302218400], [-10761757975397188758682315035827834311617660, 358526787913462720461035031000491602184], [4945443930200190622501779657574561712835930, 374588524211595687179622378470588468352], [15823598225808729475689377769113887571768360, 486963072223157562922104035504039438544], [-30025396055015108825159676206152394874601668, -190072484762904486518307287780827787400], [13713339362809907849712527136196804769281170, 317393494597293094792165398501365775424], [-27019290199905183145764110783798073559670280, 681954227941974359241088741404669840752], [3432654366856086901295364445986229038626912, -1052743960542885236587701594503631892800], [2579106208280667349036659421082252422315190, 859648321260176299669978064315300921184]];
    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_30_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_30_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, 30));
    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_30_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_30_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,30,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;