
// Make newform 45.10.a.b in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_45_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_45_10_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_45_10_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_45_a();"
function MakeCharacter_45_a()
    N := 45;
    order := 1;
    char_gens := [11, 37];
    v := [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_45_a_Hecke(Kf)
    return MakeCharacter_45_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 := 10;
    raw_aps := [[4], [0], [-625], [-7680], [86404], [-149978], [207622], [716284], [-1369920], [3194402], [-2349000], [18735710], [29282630], [-1516724], [-615752], [-4747430], [-60616076], [-126745682], [-111182652], [175551608], [-61233350], [234431160], [-118910388], [316534326], [242912258], [653802714], [1404202496], [1838535108], [-933452146], [92853382], [1738192888], [2497296252], [7962264894], [-2855652604], [9633834218], [-5382921008], [519433766], [9412392644], [-9372409680], [-12357301998], [666039820], [5272067030], [29389595264], [-14874618382], [-4986747414], [14552696512], [51540674060], [46127213192], [37583273180], [-64108194474], [-69657841986], [-66582489344], [-44165857934], [-83623574172], [86527376118], [96153502016], [10950513586], [78028730536], [65684034654], [64490563926], [96313264572], [-81630823734], [-29558244188], [39907073784], [185371029194], [-268894623982], [-429099282588], [-20259756926], [-29278318028], [70513210798], [65734962918], [-581702288616], [-417069858696], [-76041683234], [-179179695740], [795018191016], [179533434714], [-343729726778], [-772080445938], [260632163546], [560165889116], [168321099094], [-448383294960], [-1084849433246], [460548375760], [13209512388], [691889120158], [-373134728150], [1459396112658], [134213354376], [36453146588], [-882279896160], [509839804688], [1521310094372], [703413058924], [-378018352], [-1320565194206], [1318532420630], [-1692114439364], [-1863685505730], [437241684580], [709146230322], [-37747154628], [356270174406], [3879324111476], [-4288762827262], [-4432452909372], [5101038700934], [704599188008], [-1738792315174], [-578292498392], [3745954535518], [3948746073534], [3422533154276], [5847549222112], [-2666709413010], [96871558596], [-44736794768], [-4953854067694], [5850767266300], [-881006977178], [-8665209730830], [-8985492116934], [3864768232356], [-7085642139284], [-4693802399998], [10664465643094], [8156633225088], [6647708078816], [7078208351366], [-2610519049604], [14184114055504], [844355459656], [9053045118046], [6977005641126], [-10723313306398], [13756818945546], [-12753860471228], [-12784465840222], [-6037456732090], [-2500427947548], [4210815764586], [208206170288], [9261063971812], [24276192341790], [12554573272280], [-13631954489106], [-17398726839362], [-64335460220], [-3321198114376], [1958320054710], [30225277196926], [-9300970845964], [-9271706394432], [1328676661212], [-2712970973312], [1321393710640], [-1161241765474], [34091413503594], [1602145704530], [33885021275004], [-21575739232562], [30624901989968], [-1923648167820], [18389317875142], [46327276438560], [2762515385192], [-17450239786674], [5061915827570], [-38758505827318], [48107017415316], [-46606260989282], [5096552773656], [-52684251399846], [-27829558926632], [-54244382262954], [22080604443780], [17093380725114], [-45313622362384], [61732522523470], [-46820641800520], [-78201383373076], [33149858284558], [39938422390958], [24242176769784], [-4114647201110], [-87710589649482], [61939792953172], [-64503908533462], [-10858138784], [97468633904626], [-89440078126748], [63907555566348], [-121160854212446], [90235311163932], [-58481024711218], [102612052631986], [103325362399638], [38160196641558], [35216595622256], [90438535123698], [-93776801567592], [137679386611854], [10359806172994], [-54830818682892], [93147505946130], [-18579054296776], [150832014485836], [-150742700259642], [-102348235006156], [-160661652791134], [-37073215479382], [143997760562160], [-174211144275548], [-17705900620056], [-52411059325942], [102476730682456], [-54626739883218], [133728028090256], [-17218275321726], [-33755884870826], [-229719175780912], [-110460895531890], [-30272206797752], [214849104214748], [191029693030550], [-182536691315874], [155271904696496], [-176418497327168], [-202925065377804], [200528142972390], [274627529319724], [-1023472601704], [105503484086662], [-68987858186692], [102600819327912], [-283822477003182], [1720885751786], [-124369481970684], [-47963922931368], [-206554097373348], [-76661578033836], [-410412502261856], [-419659437669378], [-178736864222154], [16045513711384], [-420346914585016], [389278279585420], [157472716958516], [-72460335313784], [314017679126950], [54668428849438], [-524197078729920], [-144498223843254], [196331954754146], [-103781543000868], [-168236891999018], [477668529923948], [-416417297588694], [-448357937550646], [248550634797736], [311059698333260], [-392896165418122], [6280709331798], [-101562507767418], [-76991306580068], [271680352723666], [293416962679622], [-11541569171860], [460041379931482], [22734224079374], [-223693209943868], [490149889453514], [517075265418888], [-377745023903838], [-586963840631056], [-820750830255564], [-609108722601810], [-152413796277174], [-51732406311540], [182581460201000], [179601598694704], [677483060978240], [-737274895480314], [-238287558043428], [-175111823066160], [731231643148594], [182741186096394], [-438377380165312], [433647292063230], [-576688387048846], [55552628423948], [659099929149486], [743317708996596], [276402054843494], [-93251584542750], [-1070243878525048], [-275921265326502], [-763266990458940], [692969560032836], [969149502790938], [-31548307699406], [-54202165087832], [502229707881372], [413040719553028], [-177614380914142], [-780670326532332], [-395434737547906], [248894527765176], [102141519936366], [-219241878715896], [892228955274666], [-860145339318690], [-964168545599596], [-189517279300192], [1145184842490634], [-510714761848308], [393969941043888], [-1619479351286190], [-1100614644281298], [-293933009612740], [-1674610506444310], [-188887739078366], [-284524373942264], [-1840693660525266], [1829903435951986], [-78962572248580], [1255915379164924], [-1871934911547336], [53218641999802], [310756633854942], [951805063360642], [-1243754698342120], [1726599849711308], [1397587112758868], [1033243556623364], [873282789733502], [1268479974630662], [-1274845638148342], [114940334777928], [1960923458331166], [143865317371550], [-438642308293926], [1330190237578512], [235967908650802], [-1318318280081460], [609781664174678], [-198097536097556], [-212240793461760], [-2400514165370854], [944828362295436], [261965446497834], [786350093160050], [79276219309912], [257016752996934], [1589042186724462], [966830904774656], [-164246897605644], [-1140590273706474], [-3050255691178448], [681290437883278], [-281333581643114], [-129905627622264], [-1768547321645756], [1519446802272932], [2595236519616010], [300384021342882], [-156347762085072], [149983164266426], [-1626692804546724], [602448455607444], [3120196522203160], [-1277875290513654], [785148764596944], [-2007288945740090], [346482178986076], [1150857811808592], [1077030787411202], [936986947872078], [-1177058342398598], [-1995062360759902], [-2233237200252546], [-501915185172656], [1831635969160742], [4235988496701948], [-1154129170455296], [2440445950967624], [-4705002676504258], [4296322410077676], [1901801004843768], [4280891633764866], [1839096218241562], [4351419608362372], [689857326504260], [3600857840289832], [975554034049274], [-3874428484704760], [-853139869914906], [4226540273791060], [-2391078658060374], [-2868554838846818], [2663629665208518], [-5888261836099640], [3334499662611470], [-5843541088741414], [209671909534480], [5705938046468918], [3642284207075054], [-3122759752763436], [4366992685680444], [-214772052206478], [96393747672618], [-5576087238192140], [1436279225423676], [1274145223106522], [4822994660482546], [-6421460794453504], [-1298672337249728], [-4249702450250250], [-5517654927106432], [5625421064543138], [2674405421409454], [3797653022882376], [6697326842598484], [-5617731793309318], [141544225055458], [-6567222615849460], [-3513912694742010], [-1938749265855004], [-4085680288788536]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_45_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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