
// Make newform 5.10.a.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5_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_5_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_5_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
        poly := [-252, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_5_a();"
function MakeCharacter_5_a()
    N := 5;
    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_5_a_Hecke(Kf)
    return MakeCharacter_5_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 := [[-5, -1], [130, 2], [625, 0], [850, 214], [11992, -1900], [57510, 1352], [206410, -12856], [-148260, 2840], [-524610, -19398], [-1833490, 106960], [806572, -154700], [-10560970, -205296], [-13478638, 155800], [26444850, -25798], [29206090, 523334], [-19517570, -1137448], [-27497780, 1544720], [-137289858, 692000], [-159290, -2416706], [-3565468, 6278500], [60429090, 8830952], [3438760, -18775640], [701174370, 2748402], [415044330, 13381680], [319197290, -2622216], [-976995498, 10201200], [354029030, 18863202], [-162986250, -36853386], [1350842270, 18348720], [-36160190, -29533648], [-10639830, 39729974], [1359826872, 27413100], [-1434897270, -77983296], [1541880380, 3181680], [-520250650, -183095600], [4640560452, 32719700], [-609149650, -114185136], [-228757990, 276824202], [1678047210, 132204894], [1926905790, 405724752], [6210451060, -8038240], [5062684022, 163956000], [-7979350588, 317280700], [8431290650, -879397848], [-16104185010, 708101784], [6746065800, 203619200], [12881245592, -340539300], [-25863718210, 311819202], [21350968070, 858809374], [-29628471290, -1063519040], [47279101170, -716232648], [-79707693320, 47193080], [-5730071238, 2256059000], [5991679752, 388492500], [49431889650, 463250064], [-26337148690, 1524558202], [78646100590, -23800960], [-100741400268, 222710300], [-111198496730, 1152407824], [-16830909678, -2957374200], [46041187570, 3087770602], [-26427269850, -3545108448], [129315122550, -4926579586], [94633517292, 114180300], [-146432755990, -1132190448], [-146927234890, -176181656], [302722753072, 3315643900], [-110595320670, -4341842896], [327740797990, 536074934], [196401016350, 7190444000], [-116956709070, 8515912752], [-100501085880, -6557554080], [92303932210, -6889607906], [149149221990, -3788740048], [111412986660, 12925053560], [-252781164930, 7399492002], [-15584297370, -157504320], [-581594714010, -8369505016], [-288670199598, 233505600], [40557647570, -22985732280], [-592845389260, 3650985040], [414305454582, 21013662800], [-347318902428, 349673100], [918852886170, 10921440152], [690222193080, -14917299520], [-790665170550, 14304454002], [502371543850, 28356051800], [502122359850, 24123517664], [595121601342, -29998414800], [513085379710, -27888077198], [-1222755871090, -2650742906], [12270738360, 801230760], [248443108730, 51773943054], [-585657925288, -5419993100], [1524252119100, -35707613800], [606898425830, -29962963598], [-891598573730, -13867238080], [-1895557838518, 18325676800], [499688809890, 34849266602], [-49147358738, -36911572400], [-435613918410, 18914572334], [2044346893950, 44259544464], [-391567244190, 26145672402], [-1530438889710, -15748259160], [1805967445232, -17328086100], [-1039896164830, -13098324576], [-1798748134770, 32968782654], [-2334492681550, 12015096352], [-1153367838400, -118819961000], [-3705529803598, -20760423000], [-1903117352550, 12727695014], [-37979740290, -99312185848], [2615159282610, -132122030856], [1026816711140, 47567206440], [-923046624828, -180654772300], [-121540402038, -192069049800], [3188524038250, -114709210598], [-4080486924710, 49695568334], [1263959199830, 71810009752], [1106186840020, 152128025120], [-3220493030058, -109122167200], [4079918372890, 137086434952], [9369336481470, 3512367624], [-4200732261630, -182709810198], [1976679522912, 113798323700], [-3402924345298, -94943517200], [1323557560470, 20760315920], [-7526269205160, -63339348360], [-6559924642030, 186678243174], [2113582005470, 21316169952], [10442753344980, -99958754320], [-4600318843850, -144504428398], [4263843944652, -150641340700], [7704992505750, 119857979264], [2221219914042, 381883843200], [2053143251090, -298328130960], [-1923902124210, 244032904152], [10909819942830, -320789049946], [7696370660390, 42139092184], [-15680814897430, -240546942080], [9904451685592, 54526174900], [4097505101382, -560075074800], [114251846990, 252497677002], [10934050095670, -44252520826], [6569380461310, 537915724960], [-12834240453520, 358923715480], [16086545075230, 132888315352], [-11740232048150, 330848230064], [-14648799414180, -73834883680], [6424707504710, -323862118598], [3856773988270, -229808996576], [8628413327722, 474763257800], [-20700276223630, -316772326398], [3537720939330, -550547810346], [188913401950, 288743952814], [-8548555347908, 463500046100], [-4256999817360, 259730708840], [13103130515210, 168187529560], [-19499654750270, 333640798504], [-31872115705138, 486011113600], [18722461643190, 751830431934], [-12693295616870, 510480611552], [-4995308032990, -897017819706], [-8420057165568, -922158402900], [-793415651030, -1234956559576], [35693460996270, -81345054198], [-24977396400388, 846333713700], [1664516457790, -723043205816]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5_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_5_10_a_b(:prec:=2)
    chi := MakeCharacter_5_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_5_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_5_10_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![-984, 10, 1]>],Snew);
    return Vf;
end function;