
// Make newform 4.45.b.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_4_b_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_4_45_b_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_4_45_b_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_4_b();"
function MakeCharacter_4_b()
    N := 4;
    order := 2;
    char_gens := [3];
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_4_b_Hecke();"
function MakeCharacter_4_b_Hecke(Kf)
    N := 4;
    order := 2;
    char_gens := [3];
    char_values := [[-1]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 45;
    raw_aps := [[-4194304], [0], [94681488501586], [0], [0], [4746397497491127617277362], [-504652011666161847903676478], [0], [0], [-152160779312124788381478442879118], [0], [35088063909469944088702337296151762], [-94426535081528617629501241894433438], [0], [0], [163042973619137390933827733009903899282], [0], [2506573069383192859663671581243711923442], [0], [0], [-196251180328857016590296490866486306864158], [0], [0], [13096261849231128405538165979936005417300642], [92246626358267604714915915792541346844458882], [-79953924784130234814432839650077149989169198], [0], [0], [1287735347200833197980292033194437916295142962], [2876515648446155588939817493496807904513776962], [0], [0], [-190447853595219869644101045517390146869104567838], [0], [-216485016372469119562050352032174602127415797998], [0], [-4080716392051097388905405408434606118933604320398], [0], [0], [31326691315978725768016996624080140514230976027442], [0], [63118934817906494723073449054710248178517519295122], [0], [-122926963836402852859842838595163508708463258726398], [-601566141430892544790484107542650714781524462668718], [0], [0], [0], [0], [14848275761716970344780140353443455056789807418467282], [15755728837628226839069721369384588138796760377082722], [0], [23024442160096745489056072330332143985261436650692162], [0], [-192632210668051690241743346501957541053273405654655998], [0], [-477620194577119127509160369345743338186446255667430478], [0], [1085367502651589396881101866443004878483646479126701842], [1077893928587196864331609134505904149688274853136162722], [0], [1591587223950325776068983379835990948086138611715349202], [0], [0], [2986816472439124550936355819895475123800336636980656162], [-10894473260162083111319932784798788441372865907240747278], [0], [-68949027340416641937496780817257091849836890464032127038], [0], [139921798878090742317888109909288225793188420442244198002], [197025938274239075893329871878088244333028251042334462082], [0], [0], [-619256701913577469875903885113083316702451375658392309358], [0], [0], [-314960162301697393690031951789246673214994137123947997358], [1871200004178004765234835961735490784995860608448764956082], [-2182022232679972693189570521884311459353570110452816436798], [5535531499981884906030534781528188121586882242704445414562], [0], [-587042353674535271730935023887791019675388442442234262318], [0], [-6742820868355030780511508840879161832206874500070160447678], [0], [0], [-27995250689124419453532441625075544329704003296119943910398], [-27356767688179630000873800712702977552810437114810185447198], [-62408556184487318309990175220805929470051310469143284750158], [0], [0], [0], [0], [0], [0], [0], [-648019537776904874903110686777878202669403146694092534541838], [-1168293218897634335605404642924781222799269826263116223474718], [0], [2056573558073030416536881645609484328306167476228257339605362], [0], [-4844876836334550935409679915964100158920577980104650588923598], [0], [7982442786534990788108082605993911863884317042255900444505122], [0], [-2879860814843943701432970488510846140899956379867901660872958], [0], [-11334494701988518307464119943998683512439855084879389913358398], [0], [-25283270048336708126651247812005553126966551292422497384731998], [0], [-13029378127142222758940706053895678003969481562632844914325038], [39597202972708607359378057407109978008146879508606772195821922], [0], [0], [86364932572269118953283083575269967024760677373744984725423362], [0], [0], [-13338630135839561348294394162802465913812839476057120429335118], [0], [-130807507187027548490927437517143638910444515819968399537003758], [-221606231693522225018681911879630192923800181345206719960114558], [-45139097346902786086680148638967926892125334272450936323091758], [0], [0], [-390745412226690415177378094319489121228461723002400282366307598], [377534183390945966550332859805039785124065417491474010197332562], [0], [0], [-2140923969964657190676399654601421511193435398957982280836436878], [0], [0], [0], [-2195826349392872480301784183846387471008839420603619389576933998], [-2105955053648470552698104204444447143535144271006526237772673758], [4122823060518284804326650603798365574113705861846715162118705922], [-5423031780353053850126494167147121803548010699618223917601232558], [0], [4426171928917299760955127294356253985167214184463028383130970482], [1485696011471471524825462877400529575104322600232761211310276962], [0], [-23262669980096544078032513363394420532613089578560745450626635118], [0], [0], [-32137680619727249233102005472587170463782160557295829755208719118], [0], [-35513827179944152938581794048739281591051390753972769106446926318], [64958991484706290404121093584658818950795404630552523201357789602], [0], [0], [-100438565900635435201279142540748771798885216105927181311050807758], [122744982370650743836634897274584699881307246390370027594329011522], [0], [0], [0], [0], [0], [394542637060413566056785890845225555905261474052810322290009585282], [-177699231315948233486657600904294742791492707687229965174488513438], [-239291714655395111995052129690770287550879931699718792802323513038], [0], [667307794687046992903836869289853022692558680166432346779951861282], [0], [0], [963641363560965980393572384277632807227473148419001272301930933442], [0], [0], [-991460432805828043490741289048968969406036655060028792750217564718]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4_45_b_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_4_45_b_a(:prec:=1)
    chi := MakeCharacter_4_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 45));
    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_4_45_b_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_4_45_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,45,sign)));
    Vf := Kernel([<3,R![0, 1]>],Snew);
    return Vf;
end function;