
// Make newform 121.12.a.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_121_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_121_12_a_b();".
// 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_121_12_a_b();".
// 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_121_a();"
function MakeCharacter_121_a()
    N := 121;
    order := 1;
    char_gens := [2];
    v := [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_121_a_Hecke(Kf)
    return MakeCharacter_121_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 := 12;
    raw_aps := [[24], [252], [4830], [16744], [0], [577738], [6905934], [-10661420], [18643272], [-128406630], [-52843168], [-182213314], [-308120442], [17125708], [2687348496], [-1596055698], [-5189203740], [-6956478662], [-15481826884], [9791485272], [-1463791322], [-38116845680], [29335099668], [-24992917110], [75013568546], [-81742959102], [-225755128648], [-90241258356], [-73482676310], [-85146862638], [262717201024], [-631528759932], [-297198746214], [-596793577940], [1115433620850], [824447297848], [1315116754406], [-357832759588], [-2754833892216], [950387449578], [1681384224780], [-996774496018], [2762403350592], [-5442387685442], [2876091504354], [728391402200], [6793168439188], [7334863021472], [1359839565924], [-11824411223170], [17563353448518], [7139577462960], [231306909358], [12983053545252], [23961192565506], [24273728464488], [25837706543670], [3767932360528], [16418932005874], [-21035722907082], [-16713176326532], [23926858987458], [-15311092828556], [49875160575912], [-99480832756438], [83369248359366], [-63584021925868], [-121001428335986], [155661561078204], [25643022194650], [24909815245602], [-157584150853560], [-177901220129584], [55161734023378], [146463116322980], [231449571733632], [-149871571611810], [208110680273846], [-133407937691598], [206167580638390], [73403515193820], [171111932338622], [71775829446768], [99881248225682], [29031220908760], [328369848718692], [-612368143631550], [-303483032911706], [729307946668938], [122188164073712], [-617380683662484], [-1050837984850080], [-219909971761864], [483863128068108], [-108877719272500], [-506588355787752], [85753393288710], [927574652509722], [21818651341228], [1695266465052058], [-752144751323996], [-187489032934806], [-244971285916812], [-1352425875836970], [-1432228477996772], [-877659324192574], [-2434250501782764], [303318212278158], [-1701984261329400], [-2339216023326602], [2496072486898144], [-2473009012516862], [24336777156666], [4225450805148020], [-4263261111420568], [1008295928583042], [303982416160892], [3435828424131096], [-1185387156769098], [2265102374509140], [-5330121520762738], [-4741198635421922], [1413071638641474], [-3031157627077068], [-2747313442193908], [-5727465442629702], [698326457818910], [9709787093595120], [2464686886685576], [-7912852398754982], [8406936179151460], [-1362869794471992], [6817220120892752], [-667048975014994], [7744079729695638], [-2524111226919170], [-11145268112466978], [-13227104255899436], [2302477758246246], [-5604717670694010], [5085164185024588], [-279110773799022], [-13526517861603928], [-272543929352676], [18045917610367430], [-7961834707368360], [14982644001390898], [22256130175851894], [5442366024533060], [10810987426382112], [28102437759471274], [4222089494633682], [516091995437132], [-5719060466578536], [-84377784300844], [-11009058285505488], [4863513801242680], [3575343976258530], [-38637331724206586], [34899727878407658], [-28512291118415604], [-40033434235820202], [-18495304308397016], [-21487665696030828], [-8738799717564174], [11892426157508232], [23440857788319392], [21400415987399554], [14140474408719790], [8078051360921262], [-42528288409872420], [34207078423817222], [33856535119992168], [507848971551718], [27795420604049840], [48441354070159050], [56138975103853948], [73012153687609662], [56162522430471688], [81179501100647530], [-5380494736339264], [-77024435087490492], [2546880577469342], [-10923890478627546], [-92196634930293648], [-76282732502064690], [-85547077943632166], [36742572673913372], [53641048259107270], [-54523034470945152], [20876892586070402], [-52590819714899412], [-116697071931372628], [122494499424362982], [86056689528016164], [2878690157960442], [73822176828562798], [118382969342459462], [-25973741240755266], [-25175824528928472], [34556111298796170], [-96853991509314032], [-97333934158120114], [-27757672778617250], [39109462218377460], [135007856619237126], [-82794023701285120], [-223708171768385532], [-5265838935480090], [-18923199374555308], [-117469716286125746], [-78846086185459698], [11784308009492552], [-88647386281464444], [125808503629718280], [-144714561723993478], [-102809950955292176], [-285644496387694962], [-163537829982478584], [196859773581251622], [174876313468034818], [-213406636978039400], [-55717118878059390], [-271888846659237328], [-104108137326063276], [162070659080889970], [179070471608612682], [-23293555842569760], [-322034036820363896], [230903632595257548], [-202030730963640298], [323442360856836340], [-158698437565988672], [-180857182053864282], [-235533333971868268], [-170248660454225136], [-165378643075901710], [-334135658998193742], [-213116200924093500], [476924719920845112], [-36258681148338228], [522177048125960668], [-202897891307151208], [374749863918346550], [332593258493253198], [-79166676518738760], [323869708717387616], [-629402289485400228], [-533246752885760180], [-163920106568642832], [736690791654640954], [154309482257902398], [696665133161600856], [209974774840430810], [324467080045680138], [474829628364424980], [247650775353935822], [80127562399310524], [432622863808652286], [-425435383886684906], [443672411583273088], [-783908098402030716], [-744395722271551070], [52168997437356058], [-584929452554797854], [-478764084368107300], [-140532976832634090], [432172135498346922], [-1207441533568463972], [-31468229833181982], [60777123608161142], [173728410346777196], [-80100173165450998], [-906953636358956960], [1046000472838835374], [-166762667958770968], [-1033946260987641564], [265615055999900410], [-885926205657451802], [1340944800260709588], [1359221509248320928], [724121338179408632], [-1366640117231440296], [554630006297373538], [1516929367824367084], [560785631554377072], [-627667342289012878], [-1519681136190507726], [485004486669833480], [833656399631897310], [753254560123714902], [-218008976866769844], [797299928451938838], [96512411979860268], [-1403886618827040182], [1509130927955617050], [1576547535884713952], [1191086518875594222], [-2367686150854772580], [1057044478038759364], [232614830125358758], [-956846140414627446], [1159913672832202000], [1402929054144294252], [-1052878119158691388], [2275183008948284066], [127060804069605876], [2071731462351740630], [-1012023726160667160], [2722920217955345698], [-505912698732795312], [-2021329164414412530], [3283050595335017118], [2266007308066602332], [1274343425156256264], [3289642282104575110], [-158709304481046900], [-337378582827563712], [1416137431218375362], [1465518247189968270], [1105489850967458068], [1108518137948219786], [2804391299529802458], [-3463100174643824608], [-2374739016704889402], [-748574531821704238], [-329304135430137220], [-1504698519284375548], [734375677248992544], [413454523613321538], [-237367114094598422], [-4050534454013085114], [-2459605637721727040], [-4711450875401202492], [1092473614545936748], [1632809598977285316], [-4585901454785962330], [628080207184208478], [-2576891159506126918], [-5149296600220505936], [1763474583246042542], [3803023559519536746], [-3293242646717484510], [1935759074318741912], [-4453349333033099418], [2077478945181949860], [475419892965703742], [1987684329979279796], [4162506794825649648], [4900064311361706606], [3211231815759983428], [3654889872475339226], [1223273902173160182], [-1800367748864715632], [-1654589186259370190], [-3203465535213333642], [1351404402506138400], [-4542041100095889012], [3140640535918815534], [-5710507548408146328], [720328274240714914], [-5364128248837234842], [-5222106100169329104], [-7351248419578278660], [3206250804831191516], [-2865419128908086278], [7121007272344093674], [-7120152451033953752], [6355258870352588278], [1991669049075442332], [-4696122362164123660], [4434652445250764208], [-8521114247515109550], [438519160270695448], [1913928974652300806], [-3264960493988516820], [-8994533473522096992], [-1425395558872959842], [113176769876990190], [10097549632653285334], [-8569888075041317178], [2619756690013041882], [-10759285429307033096], [12511791856728560094], [-1293318750144504860], [3015453546236553912], [-9847468035602606128], [-3760740008891563474], [-2284498010918400932], [4682686209313854336], [9087382919634031490], [6791255198037006942], [4924312409974943700], [2355679442443926956], [4451292769759962312], [-3525580318347621962], [4439132239175982880], [-643463887435409670], [-6739260155572267468], [3528635716645443858], [-13974829490146631750], [3686225267000680002], [16173458448420615184], [-6946595043256816374], [-6438089460190558590], [-1698750468442331192], [15727785362604812246], [-5585169287182718802], [1929034750587535052], [-10647813092968971780], [5632029353354755918], [7113964905399254514], [-5711856392554102908], [-17303308971799733852], [6547684690837717894], [-18169082447429234538], [-9760782655842540480], [-4114158894745559464], [3204127474514879346], [-10843789086536614152], [16293686169352771110], [-186485610881843966], [11492925925933776], [-4309562682404824740], [-6590558703175741798], [-6510772456911838794], [-15340050266367016788], [2725836408128808630], [9165605508054055172], [9117808694571255000]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_121_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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