
// Make newform 3.10.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3_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_3_10_a_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_10_a_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_a();"
function MakeCharacter_3_a()
    N := 3;
    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_3_a_Hecke(Kf)
    return MakeCharacter_3_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 := [[-36], [-81], [-1314], [-4480], [1476], [-151522], [108162], [593084], [-969480], [-6642522], [7070600], [-7472410], [-4350150], [-4358716], [28309248], [16111710], [-86075964], [32213918], [99531452], [-44170488], [-23560630], [-401754760], [-744528708], [769871034], [907130882], [-421901874], [579042704], [1397138868], [-2685304546], [454748562], [-83864968], [-3736010052], [6435977274], [1818327476], [-8301985938], [3840570992], [-2179121506], [-15414734644], [-5655058920], [76989222], [23224659660], [-12353220250], [-4204329984], [-4386113278], [-33669393714], [10273219472], [7966955180], [6965808248], [33569688780], [29319833846], [-82007862966], [62660930544], [77554759826], [-58190063148], [-7414851582], [-105270893064], [46723914774], [28686776456], [85067608646], [-787257126], [24896104868], [157073732046], [-245736910132], [-161050114584], [-244645611334], [112831999398], [287348225492], [-25263521134], [90480275892], [-15382241602], [-146875176702], [-442246437144], [148110431096], [76348923734], [-270191776300], [-661033396224], [-309860514594], [-650588507602], [27670067298], [208505488826], [450465300684], [860882644694], [-30240488160], [1036358270066], [-590669630080], [1270966072788], [-934644020238], [-452480726230], [-856467239418], [921379898504], [86538181788], [763706841840], [-525530965408], [2372647166388], [-133387409716], [-658632281832], [-1019653784154], [-557535075750], [2120502823364], [1927456296590], [-2327505923860], [494738823942], [1140831721692], [-16439841846], [-3676519620124], [-2290449830398], [4687504713108], [-2337699194766], [-4669954559208], [-3965170646374], [6247434786392], [-3731930293498], [-6051812008086], [4698489879956], [2168753028752], [3564458898930], [-5379166381876], [6018273074952], [-368383112154], [-5248098737460], [155038788182], [589588197410], [3329804700126], [2289277026756], [-9461285071684], [8222089125798], [7619574795734], [7948226626272], [-5757869609296], [10780820795054], [7377557150396], [-10289940041736], [-7565545234024], [-6887132816506], [4306411857834], [2162959476482], [-8154469122354], [-2251993797412], [-11612835766602], [2317683191130], [-9188154961468], [-19267891310466], [-10498955110288], [-8100525538908], [-15245202550930], [27225846806760], [5382337159766], [2131143312618], [10765000121780], [23669754699744], [-9918063001330], [12899192911794], [10095568951484], [-2224028165112], [-6355416996412], [-19143233557488], [28605258961040], [-11889861506766], [-34587125599894], [25974175144230], [24373876892364], [-23489074986102], [4686391456112], [-46393573340700], [25388951002722], [-8907802254360], [39084040742312], [-1940445389626]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3_10_a_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_10_a_a(:prec:=1)
    chi := MakeCharacter_3_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(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_10_a_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_10_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![36, 1]>],Snew);
    return Vf;
end function;