
// Make newform 3.43.b.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_3_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_3_43_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_3_43_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_3_b();"
function MakeCharacter_3_b()
    N := 3;
    order := 2;
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_3_b_Hecke();"
function MakeCharacter_3_b_Hecke(Kf)
    N := 3;
    order := 2;
    char_gens := [2];
    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 := 43;
    raw_aps := [[0], [-10460353203], [0], [146246101081752386], [0], [-357172201574584820855926], [0], [-165282232922573499748305862], [0], [0], [40071891552502334872877231380562], [1627039758795395209154445850600826], [0], [30195211903983689990258309024586314], [0], [0], [0], [55873936229113631301915176656255273322], [-397023094599476479692793424374906556134], [0], [-1167857467376379700865578403060403787246], [14082525970872707793274472783233500883058], [0], [0], [226617616347969910436414292537604801615106], [0], [2254114575726992571239133806751131034945794], [0], [7714056471168316230320562964062879749161418], [0], [87483096811945349138249647500934633434019346], [0], [0], [-2006631012355280708943132386029807497602378422], [0], [-9573780490379726133118819693123276942124642398], [-25273987538748659881037369056161171270000201814], [-39077161294279996365324741242708060243187745126], [0], [0], [0], [-29891501387903173415909630224870462119066795238], [0], [1971594643523445066282421726440381629011581482114], [0], [1667525822814516484840098819176139862428447420098], [-10386030815042116726572901591597808943454089657478], [-29285079431275447276224946454485585026188108467246], [0], [66954119721994255634953783971635563708817589870458], [0], [0], [-147097798951884005020593976088068308411216107298718], [0], [0], [0], [0], [-719126467517569734451046013281749547255048533842958], [-3913544130232206296472288184653864780430327336140454], [0], [4993563412449003920152567098181127868326833662641834], [0], [-16457729807904009070642377821667157335422426898131014], [0], [50766775353219363213042174495550431693218467836090674], [0], [-66725487722924117469826173267494647155143733501040438], [-205645647767402607823690659076363188075913499794562974], [0], [457360670287281181109563159984834113356302422063635498], [0], [0], [453139547708296245914305895947656287999537808336220466], [559645150124179504606056019728923141413111842448038554], [2105843273281299620438003055116678000960855751124879658], [0], [0], [-3710132002932225897349219067364325013730200736512578294], [0], [-7318285538888857027917454838430447285740857615590565582], [0], [-5179537857236400866955411827721787438549722471507223558], [0], [20149509052086366904925386673065397858099998478189017634], [-48182371820821271421573059598765996609519473328415192222], [0], [0], [127291113978531815533964396011491343372331555112776807186], [0], [-22729288926345343993145374210090576323587312437024301326], [0], [0], [-541598896943615760623156538486584699049775820095828402174], [0], [475732045770358257104912170420847794579842390993825053498], [0], [0], [0], [-1110314453811328135817954866847718644727881751327454230646], [4990774146703611456750890253378943488232161263648165104682], [-3920974234189308856478724266620962587278162491465335061094], [0], [0], [0], [3093045614988098629784089311308308104061098547560632283242], [18566296342671238912064260686409755415889524710652199646146], [0], [0], [0], [3938802862977419430933876300693511504152803293406410945202], [-15206639675368761825723342974606916168872642988172392816814], [43622984347408005119102460473349695995663746172581990030074], [0], [40982886408509412592104660850606591007476610014463347539338], [-84718625006757553334082529095262493323229678356699824423838], [0], [-167557499253157367019754648118742878324738932661777792603686], [0], [0], [0], [312492460566822842588767200862622314839769025721658744370522], [171754389248065815874394944854858045310670815126044170285954], [0], [0], [-843782294173792374695635560253328435371755135596710052019718], [0], [-834229107337328122150614850459732412539766045136953850362182], [0], [1795627514083757947185153462310605812261670579229866598698146], [-1965282657261412534809157785087280458681792040502607089924566], [-3487147990100661001620261272729232735057620493680846382051622], [0], [2893694448962915715526154656213859182899357723136767608449202], [1422399080314204979779992846502848529115868582103235307231386], [0], [-449510358994072300232350654664748257925118398306372905086462], [0], [-11169899088452686323063312864247713707418247999475377445944774], [0], [0], [3609599140214052614973667042872593738781342228138905731688522], [0], [28978488026894384365674092010149034473179256921883984896067554], [0], [-15381255792219569549355161275218128243800078147664938139992342], [0], [19670897860282019344269381602376334942082946645086190813979994], [0], [82160577388958886322086414774394558041180001148932185027891818], [0], [-108467844270018750377964597779213857764114598779290348731696054], [0], [-119984765767135306547186588630240941094972167543573159396504966], [0], [-157556440531448011201112192180421676588771276916935165928100214], [0], [-261130436771376498829846362698257309165697019663002808752285662], [0], [-464099521368651696169212633925353780577398732126917234375108974], [0], [0], [0], [-372658726443433478135100253759819384320699418010377358241567934], [0], [0], [0], [-774735961288733376622232264996544309586402763848929525123852718], [-1732616682836452572225506662681248802684824232512830760745151494]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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