
// Make newform 10.16.a.c in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_10_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_10_16_a_c();".
// 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_10_16_a_c();".
// 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_10_a();"
function MakeCharacter_10_a()
    N := 10;
    order := 1;
    char_gens := [7];
    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_10_a_Hecke(Kf)
    return MakeCharacter_10_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 := 16;
    raw_aps := [[128], [-1302], [-78125], [-90706], [-69411648], [-37057462], [-1372027686], [-5068760620], [-12342632022], [57825721470], [233727970052], [742247612954], [-772699832298], [-405994366942], [1623010601574], [-5365599400302], [9240158287140], [944308151402], [-70567580292586], [-82534723020948], [-178432352158222], [307261263603320], [43159732395618], [681677801811210], [-236520239800126], [-1396429070578098], [-1468859212504702], [1199603382462894], [263914047873290], [-4673323733737062], [5537118670793534], [7830954937849152], [-18887166932978046], [6088884175767860], [-29784749629234350], [34374967131376652], [32467413908713394], [24238595801270738], [3263837219918814], [-95420479353125022], [-108211352867778180], [22198360402892702], [-34238925181445748], [-227131053969543142], [26386999251416874], [199493129322630200], [64560376558673552], [-671969937040917622], [-540954921680692866], [752317364154118070], [-764780367482946582], [-674102787179393640], [316937965775237102], [-154964371528669248], [2252534013117811194], [1009254752726151138], [-929817760675671270], [-65137585952731348], [-87422786980631566], [1105845872880157302], [2151594567377420618], [5523318762868385658], [987586109146807094], [-3096441282551096748], [1193553150399594938], [-2701082085291869886], [-904957748172734248], [-684140355592076446], [-11842592705062588026], [-4678648687099162450], [-6215714654466025902], [8674222222716233640], [26007622458973434614], [3245218934116220978], [39727490900078827820], [-13905332730412608582], [-24051936675473061390], [468746867094969674], [-45928141838056884798], [-2870711596591117810], [-19518058272446816820], [78425834649619736402], [-52410623735926965348], [67208924054967050018], [-64193762404372288840], [80942005227457417458], [-56344091403260048250], [81266590541372411594], [112727119237264921302], [-179851796871059500462], [35079638720517022614], [13271555269715229720], [-227725805838981479146], [20651808167749129152], [208538402143232278100], [161974522155292732098], [184944740146608982590], [-119106069025828880598], [-207239792269746744022], [-426438025122158900698], [-146133561571525483426], [301056111880091266794], [543652698736255568538], [27760634038269510030], [786072601496087851352], [-93055157347502070166], [975603786574870582254], [111954452899599116658], [-749099457419308195200], [-159205145682001945498], [-811583080904468582506], [55593919711127987738], [-69794726309096977686], [-603520075345040534020], [-364877934644409150148], [206269224909288587502], [2118359494511004853658], [-2294853080924538090426], [-584612030919765438702], [1799219019758784400140], [1486199703250542480002], [-1015864550097875971822], [2646605084776629590634], [-1978074514717464267582], [2526339858154703817752], [-2185142960461702969398], [-26622793679734498810], [986146291182666569880], [-2402297205800824249666], [1878739979459143700018], [5379884942498634437660], [-2674344743878878482742], [4117968914864576438852], [-3832308556244406259006], [3197724650774619047802], [-5421960681718594966270], [-4690879869805774881222], [-9271309031952438278146], [8353138078733692719474], [-5868817890266547135510], [9207178267058313655952], [2780782507381965815202], [10862031152921757957578], [-4480333414689142020666], [-11556202985764443316630], [11640994345916081805360], [-8053370080181528681302], [3512784895752053620194], [4796197878475620532340], [6277721775362151279738], [-4699633779925755543166], [-18987638281277827675698], [-5437443026382752046982], [-14352937323755403031746], [-14440385549260847575306], [-6006608943891483299148], [22587481351147511064080], [32696209717995240520470], [2670831700811000392154], [-26116187056834021732698], [-10385905578372414400026], [116131100950671284298], [-35561915275404540078586], [-40888260093040088122248], [14705642838091141806834], [-20244301698302613440382], [19935632569542393173252], [-4001153991988860516526]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_10_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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