
// Make newform 1.24.a.a in Magma, downloaded from the LMFDB on 24 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_24_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_24_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 := [-36042, -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 := 24;
    raw_aps := [[540, -1], [169740, 48], [36534510, 15040], [-679592200, 985824], [428400984132, -38671600], [2188054661030, -1268350272], [127014073798770, 23522231424], [2130300489980, -137218594320], [-4072356539504280, 106334043808], [10409216800811670, -6804021206080], [68857008588500192, 14814525283200], [-448860632204483890, -173410338010176], [-1147217738584157478, 559210547795200], [-875380384309927900, 240142500532368], [7879872108828390480, -3634099566813376], [-70143626700823398210, -1360721746009152], [140436494985670385940, -31045701436426160], [-90226446258251111818, 82865402983800000], [877116581715778812620, 131620903771013424], [1527516755097071664312, -167496041649300000], [-4031704126938803074630, 117939335115835008], [3122458407279819990320, 1561010165657737920], [3437997041209249488060, -2448003171672996112], [3197546543086535002410, 304549203196268160], [-15573644423127015250270, -21536924763862843776], [92333101723466467151502, 9637026978392292800], [-9114293711217124345960, 5103740769235076448], [510685166865416163300, 13121554247787675024], [115535273538875128625990, -37607319888789418560], [151369422312248795526930, 43928537334986902528], [1844577166487603692499840, 104440182400324237824], [1751774025245478818801292, -193345336260507419600], [1610157495614499797548410, 620788030780280148224], [-2109730253202768078100540, 353901787344925439760], [8205179085384012460806750, -1558087650188962068800], [-4380068370770203333421848, 1787198874643554544800], [7600575101844572374332950, 1625952167430568300224], [-24440418765769116832534420, -367962874544252104272], [2971203118569319595877720, 3241545865633944445024], [28261326142806479644548870, 16646621362508402518208], [44233123454077397557309020, -11905867603694652366480], [-2035658280898116992670658, -10903744716265900296000], [112357119847039559004439872, 43405096612114460268800], [-197490037079648553008809150, 15211027827035660055168], [-245018462420068578226901970, -31812409487251638509376], [160643115850222939628243000, -62825200331128338362400], [-104350743631034237039561668, 152015617124783647426800], [409603468482931532450738720, 214778732537075429294208], [-1985616566040633646421832660, -35986565974015231920976], [236722416776370160511033870, -192384846542342798671680], [279673645746964137126966810, 419594187454109140994688], [1842466766112930030834422160, -163075454466461882824640], [210660620076121336426546322, -363706539188460792624000], [-1943621205522509883690872748, 475835650006873197426000], [-4527156622478763698004945150, 126659577084161461633024], [5984769366959102149896447480, -871215196940967366237472], [3181576436641494176991333030, 557255604577701177938880], [8552546415403363119688921712, -740077022088858214900800], [3832999153917005177177562590, 2003379073215678654450624], [11044850769346173898494158442, 300793056566018238723200], [-23873327622550379701063457740, 520211510094274563899088], [9992161180757905622708057550, -4833450575506351813888832], [-29291729935651263072946737700, -3895889537438411086674576], [17691010296798166743293372232, -4080168812241429671352800], [7129605931705965190781773130, -4056328906046304138646272], [5437694058332308200640593270, 1833031096370403399257024], [101360778613659063449960658692, 13455303280288293955971600], [-16503729773993127204069315790, -32401953238984514755186176], [129818479465632890039835528180, 3460482050833886065027024], [47531416537656996296208171350, -5557168287327401768116800], [-171354382654794530272054486110, 43251939466139345798670848], [-289979276562354602445300633960, -9695796288797369881587360], [-155180263719553092859856612080, 69758579929796441262748224], [-93350670389562241561771852930, 43212306203709238732713408], [467400209673770183965884350420, 42755570949626055038160720], [-347567726324766950240087111040, 141374719247112744357657088], [-113122708967079624349643398290, -209150317804530906326194240], [13347138663522603599200584230, 746004233270717550949824], [-47179832445665070832061181198, 95317609285088202943926400], [-161010175868699367306197234710, 145186514892120777775223040], [2214077843244995324455155939180, -111158451910213197934218320], [569058501391491213874068579662, -255967238734194496534804800], [2114040030144094742308914282192, -42907550170516526149329600], [-1567001108815958952935983071790, -245275149980412910478397312], [-887615178550818534497756106040, 241154293859922540582704160], [-1451680403116039187226161006700, 140256400779730350606501968], [-688998591340107105595425148350, -675312864395710715723068800], [1845054114629794594488499912250, 64929621179611129270305024], [4415216712662712095194655748582, 76502220130900540862244800], [-4156855910739182315837368893520, -772302369488708460156939072], [-862598292484852746940690371780, -442512995262591466207535376], [2346033042069085773833666476320, 982232305488378954029141120], [2850680006420374386612899764760, -437042451432277023039958176], [-3747867830050829500576290032028, -746985916407657314760268400], [2518182555413400056108510294300, 3352047079014281059024345200], [11672775949061036109112715516040, -1121781546585308824039702752], [-16588051388836043740753628628810, 1010771807508071578854005440], [-11926102377689199703847517100038, -2347909025373245313712300800], [-13472933288004955570254022414780, -4547171098291064930203902192], [3278983123215213035300881820822, -1323256548736118986368033600], [-18533172369460440715412251808020, 1802638558352473721958408624], [18838642907713145811434882626950, -1143984320957527970370374976], [26226385854824541578740305935580, 1027737125926018732675420528], [-26103636872652636333462168556470, -9481594537466632121011966720], [-46581683175065983477982191511788, 8851836967940165399293611600], [-28654256871646989863213339710, -3499580763509281753463870976], [69385790477119067217682413241860, 2694644660467171540422865424], [10625796681543439547952491276850, -3564145622958992570103340032], [80792806304991190743390732258600, 17434628074873640426012279200], [5484119038078698718467224917802, 17399886370344014172700176000], [-24355760893393258074572305372000, 1750635272568651047050333824], [31456578492914402515373356454030, -2655804560294698583266251072], [-88282599591375047627024012867430, 30911657662487617560417437824], [69082734441861551810676270570980, -35836498207509067858145105520], [-222863661369579935972838609263608, 17577977281236462555712800], [-68209372947717122797101358513278, 45389782020090746744272092800], [92376890304809496185391601013900, -12123032023983488869791713232], [-97597865066151820788250028451720, -61442992770266761990118834976], [-64697039618142288907934808520410, -4632466288786450068046962752], [55399562514314741202294295318140, 20035239132723634941592659440], [240434708692185544831379934066782, -8420912175801108051684820800], [276852387817797873171762153564770, 56588984290723321794460295808], [-138895431402493939023314884773810, 54636796342319113021084581824], [177192257944383576739094694436260, -104137969871247766811618336112], [-390329104678006202733074722206628, -72099043057003668160504813200], [-250918533606972395017966150873098, -170619308308365089675049172800], [-480449680015704270174696370182610, 50371024431979104748603899840], [584061145364613889525367254664880, 27475059771175904488302962880], [858273553756407884670170635139240, -86596049796416927208833249376], [-774738436399739824946139246696490, -169666540704594560314379368512], [-597957105568452955118931985257940, -196325984614154198908006409040], [-164188738696570953470111055277800, 62357608487592538077250531168], [538825462433747443554853511921552, 195176024225674775175511771200], [-562294914413131536237938984258050, -219426728555685305463660000576], [952922536983440414772191362777482, 212501489114390271784095980800], [1950478006923734615332956869238530, -158970897593524957648806645120], [-380016811131430760746047101670930, -101813398679807235731078601792], [-852069138478776692361597937998340, 487744608438621054486303447024], [1944383599306447168298508170331030, -81153451674513495672108666176], [618599666818711266065523606038490, -699687899171589362530150920960], [2751123174225482469355896113751332, -327766953698811508770960044400], [-1617740150685146112228938324316738, 302791218781919429657800932800], [2652607721404520693977309574075720, 696155041322725717481532837408], [-1564748410633912658113085719124460, -449159814836113169531203436976], [2061535770935793259571158342596470, 925699122945959094279586595520], [256662718861852504301136722514360, 108646887023632976388746132960], [-4653886868381671688783297054861410, -978637133880134417092523660352], [2149642224832989014177418743236650, 883291850067557891364010759424], [2303019012851366680931385071217140, -914058450400295731007706150960], [-7813242376760823330007854347418720, 568833452887151766399225740928], [3925290318213556892870064329605190, -1009380153522976548874280179776], [12884177257037969925188965456180242, 178558855338373717850600563200], [3049502725202585959374829827317660, -340974352726837823078118068112], [-6849703812504206872243362657621240, 87935491911910873328479630624], [1692030273758107503185781516719300, 1038285596111309671631078436624], [-15449844671666219685359972684721168, 122168559411123632534315518400], [-6169194568406402861131164984772120, 2035884984271691728328821176480], [14631556807682464132744663020527970, 582262882035750914877702216320], [-9495643695845857555548045057498790, -1461517782976847273231031278976], [18275825283141616146332791515734022, -2322708382625384477793472001600], [-3217122449816727553891372296826020, -5753743593054100317868161682576], [-2123827551453799021023271293901110, 4796179336372422037520759970048], [-13494272596401588620694869561684680, -1499513105006223261506369618976], [264903549141686917278970542996612, 7414288897602840108063188432400], [5679078286484938202676140479565490, -1327212382050266823951665941376], [3453334116774316370556160639233960, -2565774528419843210604181359712], [14364724954765873839890725883754272, -2559335465959561499987096035200], [-12166614854581341133412885097264370, 1650376995415907267394144114624]];
    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_24_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_24_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, 24));
    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_24_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_24_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,24,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;