
// Make newform 1.32.a.a in Magma, downloaded from the LMFDB on 20 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_32_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_32_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 := [-4573872, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-12, 24]];
    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 := 32;
    raw_aps := [[19980, -1], [8681580, -432], [-9695609010, 1418560], [15128763788600, 71928864], [-3891176872559388, -29000909200], [37354476525130310, 4661016429888], [8612303914493544690, -45085348093056], [-6185281664011082020, 157805792764560], [948672420994955609640, 18557618179251808], [64288072108608527903670, -234192357384448960], [62866763758980919396832, -2412621171020361600], [-416907603527008455512530, -32224244113578511296], [4362462167831462920335642, -184255453144847033600], [-9198552646889719354186300, 342671050720390776048], [47725481982428095396574160, -513692578237745847616], [97411254236860549491830430, 1204064567949614050368], [-99361631773882756995373260, 44066863235081760754480], [-6028109100556502180578828138, -11293924028102214264000], [-4844070401436128497016123860, 88972104812545561003344], [27892288312517328756439143672, 953870049554263710708000], [31117047966043049375276477690, -158900135892158937624192], [-59582095546649852482106355280, -4664754735614659537824960], [-132431686840784572812678798180, 6271396268534390818352528], [-1077207307123335145801360947990, -26068082391832856589194880], [-4530383997437016307764978602590, 16565775598601516231731584], [-8791393879771179938036512865298, 79779056976143045647745600], [12308620796461795648593023550680, -132718540654129769746254432], [18422235677352642357910628276100, -255439221008141559055646736], [-43512657752217620754893648778010, -144361856133410493663184320], [36415351217255374548675172478610, 412259616739409207392089088], [-98907056805331031759920767137920, 9159794335229744785447540224], [-312899292131453333878936733467668, -6447502809852498355317153200], [-361697228694303195730989348911430, -4059336591488913756301271296], [1616779348284388381173808462428260, -5134887064162921725611617680], [6036308068014339754011629014943550, -11898396352882263761411921600], [-4489507560592339327380664577948248, 40901020366721576563527573600], [-1923733500470541321719671991835850, -349822111081251129705368876736], [-4251303103686457370816199498156340, 235681836737405725486015355088], [-17355053993263333253288230557197160, -665555561703049643672408649056], [33626466647285596365590015300801190, 328340819982094384767657574208], [-10175578138307984928138801611830980, -308879672294894624584570091760], [13415168840223021821403718095959582, -2614169594404206315179152632000], [91875140034966412817958740270428992, 2643698823944797635048052985600], [42814502684358742316070579793712450, -4302557189544493482508243700352], [-262875268504325896172184579762245490, 191018247554565229658052427584], [384718072979787298802471253636961400, 1305420840541301402960139751200], [-1019232550488266823864073649428668388, 21076032735005547217595102067600], [-1255434815347815229765111484054299360, 26680761452728574658789305332608], [149182169543548930252784358141629580, 644754454865610853501740764624], [1710514187365924125449426819383714670, 6053510833669221526553109675840], [3772075924838189545954134111583188570, -65834161172288997653810011615872], [-5475237703867049486612952419587891440, -164448967844954733029815761788480], [-4384432781662453455004212471728536558, 54959017129594404478382183472000], [8586556034248353533810317673018715252, -17375812577725847742218882370000], [36766447067591276747726831615462088450, 101621237080257571448754476990464], [21800874652021320911198857104993147960, 669693631480205573862093409760288], [1363587301153268843713289856148194630, -624186640574550547268667977903040], [-2315911964917059478596651510155219728, 32912947303863794537893842254400], [-60035188499087695242224043215159759170, 378827637988953716861089494901824], [-49090752809893317317919445625508648918, 2342266775821424415132701831062400], [56607018049179099946255659788128123220, -1210408146468791323187273629288272], [43687490328410746653806357367261442350, -965004195276024618380888736527552], [-390847731576564708910474052261716312900, -3507238457013637922978107002141936], [75882224890507201982155606482947125512, -6797135203383632229536286597389600], [244336116672981045174210881951704192010, 10753870589444172120598285806060288], [-320782728170113651523385035156286792810, 12775494565758434661415309752110144], [21703993391307585489337661058624932, -16181349285331193418356710039750800], [1493214789785427400162886897882979957170, -6852778227289845407889959354896896], [-3673991622256517672325194940435052616940, -1470383646893505220978626725800016], [588650721339814912624825319623987397750, 3493737338551542625145180754254400], [-3903941371320995887992713874376678635870, 27687932069899968619264739874272768], [-1020427484587799575192174355970586680360, -99919716525519460878360291919885920], [7584461423580261353029869758289413060240, -37346787381064999652278689650849856], [-1373939844335637939378475696188194741410, -130241015650018033154858317103750592], [-1339034517967455785166052019888690618380, -153978044321328567972930029638161360], [7027573975677510686359448374961413269120, 41329553963480295682395593151190528], [-3564450981669621416338551725124571517490, -357370055363999964881981860638623680], [15289004572695379967258144600956631539910, 106991960908998505449556444057694784], [-7335736029905081906228053601187821766798, -361072945081666236180783559004547200], [8574778412271028949693834441923593688490, 624732822064648806221013771251162880], [-11763978280045728402165665076416288557620, -1091449831872774540241592297592027440], [-3823346672220559235307533805563075402578, 818723553819590133154190639936174400], [52626466125885634116290549680121571031632, 1344608094076657380374087576046916800], [5203582992929115458902238583580930540370, -39253943800858117418101730985478272], [45564112048424445576596712519240893108360, 552527940016823755671090123807057120], [6790603861598141599948240217277219314100, 312038556508366834865295146304224048], [121445887075069445312091830066733699830850, -1143644109320932655675027861678121600], [33988398603654421546729649973589995856250, -708471919441920274788364666243911936], [-44708932272502516678865491309574607222138, -452143876994651284852442448402366400], [114233941148683324367285537226416549414960, -4959571537450356546868699693340382912], [-315380230516930898437483250820944958738660, 386630117073517787858236818827040144], [90811468215578308157470085505505735871520, 5242129248892755655210993217374701440], [284259137854526847796203310129577374450520, 11307190269843175505988108990328166304], [-268919044907512857024071171655933368346108, -10834087661166054895870006616819574800], [-831077814024120800285290405402673145924100, 7023965380249508529060769144864016400], [147544806015601651597219162202500712644680, -873091633392307940127043943881100832], [-543843724185354752742324407848340625101610, -2642321589816775186548169421317104320], [673359581897480944653298029873334767582522, -3948550759396461116219671689303993600], [-1504923998436299913869373160321733509784860, 303631072355319774998239935018461808], [2275590115764803489200039208266872514479542, 1924114609966146968707302811526740800], [3162985139756478410499990474576034450403660, 11551680680915899571528864150901426384], [-4137991222087245651221954742632854909061850, -24319177387164407621135114958125075136], [-1320031668231021439372150349675529013046340, 82927476453869256983172431068966524688], [-889105501830989827546967705166240042753270, 41184275191321368368165924051814613760], [1037496300345925790405764140244985844440372, -176195579371637746790928488656127662800], [-6349116293470666090181058130643362616734270, 13085186967280092831660693377995175424], [8010439380638820001416362281451501500589220, -149085178957695071536664649302320894096], [8481010286443387293081131215187129189814450, 194776422466235834324384276905148341248], [-5828006953226995227325435033724269514751000, 53412957006731831152911839202445890400], [8901581807280196418699193717404407315194602, 226346963070111688906269289242848496000], [-7658835359016092846244775289914837063036000, -254370043950861236140812478381539486336], [212287640200782366625522338674449665187310, -127855025792584673812044108792607403712], [9214230944099493145050053482303076243203290, 195866034912589911346066067844034178944], [10453389758897293542865248411971749585442180, -59113590315831375959277774394194381840], [-10574663667513656593266273427120324561805368, -115376551438937647629346102343593274400], [26371713216347462760827176811923515262061442, -314165644380052246297223941071975798400], [-20028983393403711743938189572685910471943700, 648567965474927594765303970324478740048], [17906267988481959122100854398332052493912760, 544645585969396694035641188109441444384], [-49742340302266926382801525648957980228902970, 586113631265407218384040236709090658368], [60731424479942747670795083268866841916008540, -285815278972498422814209823920596990320], [-31677781254911668006959783135442851148051138, -558637822079799284742194342089685649600], [-18223896499718217336099760062530711692516510, -755864749949814570757408534810977892992], [-59864187700452775164732480194504276705957970, 853876826038793252102140480890205634624], [20479225441570086753289972425443877474449220, -1584698426567040638969508323706026982672], [127819977863151162916874347600028045644658492, 296026762613748634592803611374790819600], [-10710508379718413689238509937155803429137898, -805245812551116238746727196081412753600], [66292435694342326965507722039486238503285390, 3092583379182453637677220203384414396480], [-157698898663285026939225082814595899906803920, -1261145306007482708064927574359380495040], [-145939973181348471850403726388713344483540120, -5468675695553285609117015956555556604576], [-20862921390337892816872598063427205319051530, -4240058774181585962226940724366719553472], [4848420871648597591484350079038059403461260, 6739266491599130982235802254193374176720], [-170103844394784948470203148958510226319154600, 1845320420332287295145501149330084486048], [506958734959465339704520568286868227143163152, 2313932408826428783710812964241547518400], [94957520256825095000056063739087444031005150, -2258991942304764343926471703398197574336], [-1056924579470406917115899189812087694438838, -652122205988066414255671320074421382400], [31183303263816446189591310682743199668112130, 13051759291659249490573926218084586648960], [-541203298193603433889379449371258146299711410, 5600109612563271340211825835689628499008], [-145224629229731392065235518602556227672710180, 12900144002114626821867194138695351772304], [297730070777660637781951885854296589559395510, -10182470161493960243020289877355519630016], [-660117930665393273935209997365565126722331110, -8460228536150541416580475931834281893120], [-795472324274305621267400288629961564508368188, 12273828482056662558510301921774158313200], [533481608397980504406306379505258299813637022, 14969300841189031847007960404524947329600], [1089809433398681062494085140222887308493221640, -22870745227116890287303571407224035656992], [1630006561927694163900099703735767908240380980, 9964315263240983674526798668300569605424], [-1536081708819806968429585237779419275102708330, 12870591514692277145760942536369701074240], [2307862670155502702446296239203639864575738360, -27488316190145831454585957643037649645280], [-494840454972427891326246332761767283966659970, -58140278339905344113963802100770183248832], [-71081400651460206020758456217136891112828950, 15528631487821550713215124096276223646464], [1506195316538121374419402377889061003443441940, 57319109947274518594888286883944664872880], [-613052513796995876507008189759776960697945440, 64384220610117698439144579231449391228288], [-1593095394549728882198721823036448439979410970, 19599565442485000754648636775069415055424], [-2288904622750851138456436623452526418528734318, -64881927264980666413267134110289442521600], [1108711800214217209352298635135265851086545020, 39758007846707905243555968593404911398928], [2497287027573362107732380549019000319944568520, 10858190680774399501181814550884198951904], [-3966192088710095017427940295596427338750943900, 80580554008740393888161355010575359908464], [557456126387704583784213475403694586772902512, 231841062326891832059739884400905830644800], [1571990947833189056579360627165432097808589480, -241410503911670806758291611244745877031840], [-6508164894596850065487917877002394126994185630, -64108574338373296182671600289486399468160], [12272781981422815555215781559360874495517878170, -41444809190947605460022916007497866234496], [-14373062137797821822756255172621505795634900058, -9642930085765019084845151389973379531200], [9569832952441272107133626267313006931128153660, 256326543858125828330437484744695472243984], [524388954470152173251888688692056387626101130, -158023276521629950439346301431131069720832], [-22129432003852015935438053575385956943063821960, -222209900985374701426289020107880706194656], [-2265059921150446572168921955586263844234897628, -373768742964316359608423881494844361389200], [1732363599903236438731844627844642225085646130, 352935276194937987425070541480542623511424], [-1336598308870092292251598260048723846465641880, -272981901137232486500155903934404937191072], [-21390089568564588696624497257697283972923082208, 249450967453543457286940880751678578889600], [33111091040065178952689699987845590298220313710, 28255281416415486170309022811665103185984]];
    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_32_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_32_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, 32));
    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_32_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_32_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,32,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;