
// Make newform 4.37.b.a in Magma, downloaded from the LMFDB on 24 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_37_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_37_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 := 37;
    raw_aps := [[-262144], [0], [-4228490555534], [0], [0], [-152935864759452674158], [-23125093646441048317118], [0], [0], [178879349123443365836288722], [0], [31870691915293393072612781042], [142745614735837791048783844642], [0], [0], [-18046568200945234989160879491278], [0], [271467758018404231546709127105362], [0], [0], [6512963410113083479146903535884962], [0], [0], [75073270510125487261136916910657762], [-918873327359871231451163027078417278], [-2157785698174447918962288946406025998], [0], [0], [-4548905491112756262656582795527595758], [13265562396333407802600311984183483842], [0], [0], [578063753621635483982848747988516923042], [0], [-2620458995041023953592247255774938110798], [0], [4315978749476478271553726275165167637202], [0], [0], [27182857049608756506488554942371316562962], [0], [27530971260816321833666019207196109759282], [0], [272520786033155285801805689036759899353602], [-335287588396157924144008150378148860155278], [0], [0], [0], [0], [356519053472004041253782171607726870420722], [4357308175510110527129965654004382309666082], [0], [-15029115244286962338218269332767404289367358], [0], [-29945317245912593998456729302590676834380798], [0], [4686947629138758842159044053642621069307282], [0], [-27148713947515956276698680582303332496879438], [-21857179013491432700979073659224877042341918], [0], [-241297934700509583343211774244367290187728398], [0], [0], [-218127388085565440892658271063091201036800158], [838644131459807519915313182096941041623788882], [0], [5781017048355227662229344758420057652792607042], [0], [-11166086373339044972464978848288440362358065198], [-14371355525736096431244340758085258352587377278], [0], [0], [27614423829549037307668019232960337120593318962], [0], [0], [79665818440068120826597143583875468978036322162], [1928072721458913951079362957337729760235768722], [-32452150994421290130644420506239330770526903998], [123763448565932063108749546820638895547732822242], [0], [-111839344483728652332531486819854654859483736078], [0], [-567205671863894046213641115559439235473732819518], [0], [0], [992524410609425008026828367353294270881524467202], [1332004954376795705369358307083542038534412983202], [286051031193162060647923417659594366578336316562], [0], [0], [0], [0], [0], [0], [0], [-1998640954276636136974684544510356673797381885358], [11737213405705729832118257593251086137484658242722], [0], [-30193279936097966534784759397554593152713484960558], [0], [-34352804726798516367257724229939252751771023663598], [0], [-25268617523347310477077124794738697099090868034718], [0], [7196490012463568606395830737723443254082441186562], [0], [143044796742382871192813502592074287095615763067202], [0], [92871274282188402987004696189987547956172266879202], [0], [-154243209174492849904469756555177088577282178726158], [335188777208832229625337457827622096448037186094882], [0], [0], [561423410782954720167718026292871216131803854608642], [0], [0], [871058811250595277917531508619761588124847762936722], [0], [-679622778599712320229110255973033847237641147170638], [53226811655527535995948388442925067738052716952962], [331603545249669198165517887108697410900958503077362], [0], [0], [2837570677387106537683737496186959955201242219582802], [-3694236202023388450720081777337718966166889309673358], [0], [0], [-6620194547554528348012682277159405565600312838825518], [0], [0], [0], [11223669648462906200335260043117394327055123492529202], [-8844088206027420556318218278104445811048702574721438], [-16273633815153060586080759146553408478050082286296318], [2364295735524143358910683467327076420976530298709362], [0], [-9030168272130813248957527835945951861788016901874478], [43930846741423688339874193919081868678692642219159842], [0], [51159274446614760815075937601403366400598932026799922], [0], [0], [66988159267234674193127620916457278870313539508663122], [0], [38523721279062970201587755113796524932376209771814322], [27381150339804687472275380644818858387971909592082402], [0], [0], [91850811976204744980780361693907838776579022365452562], [-15303930366748033609535555824227498843921904716857918], [0], [0], [0], [0], [0], [428014142102616734531159803162071322123203763949736322], [321413202454060183223003726044963218014376987896670242], [547762353582824799436015417359983654828901167143565842], [0], [-839313662607813370092097637457735053349844293618347678], [0], [0], [-121852994089263694374691316382704977195746678034056638], [0], [0], [1564354568324469143074648486571037232237641463212449522]];
    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_37_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_37_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, 37));
    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_37_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_37_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,37,sign)));
    Vf := Kernel([<3,R![0, 1]>],Snew);
    return Vf;
end function;