
// Make newform 10.8.a.a in Magma, downloaded from the LMFDB on 19 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_8_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_10_8_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_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 := 8;
    raw_aps := [[8], [28], [125], [104], [-5148], [-8602], [20274], [45500], [-72072], [231510], [-80128], [104654], [584922], [-795532], [425664], [1500798], [246420], [893942], [-2336836], [-203688], [-3805702], [5053040], [-45492], [980010], [-5247646], [-15380658], [3256808], [-14832876], [-7032250], [14607378], [-15166096], [-24598548], [35172474], [-44713660], [17334750], [59238152], [27394454], [-88538692], [-28530936], [-104350842], [100761180], [35684222], [52789152], [-32089342], [167463534], [161770040], [178418972], [126952688], [-157656036], [-338259250], [-35638182], [216044880], [384299282], [-236430348], [-23783166], [-79896312], [233546790], [-279281968], [163824734], [128061162], [-269378812], [-155781042], [-487125556], [288891432], [-409452982], [-269274186], [405515492], [-383012686], [1175743524], [288404630], [765131298], [-525903720], [893570624], [-813328642], [-1020946540], [-914342832], [223943790], [1807571174], [-1635687438], [2273809130], [404353260], [8372942], [-277412688], [878768018], [896006600], [-38306652], [755714370], [2224068794], [1195043622], [-3834314752], [-1645542036], [-780830880], [4798034504], [-1416435708], [-4181281060], [2852218968], [851998710], [2864773242], [2868162068], [271353302], [3765956444], [-1237886586], [-3721923732], [3891176010], [-7436845708], [-5382237886], [-4921340556], [-7302052302], [-256041240], [-3575071318], [6273242384], [-8708051122], [392214234], [-63917020], [5265471272], [-2370744318], [9352459868], [9025975464], [6742029798], [-5500263300], [-3208435618], [6248209058], [-8324687346], [9993225588], [1549019132], [12771150582], [-13441075090], [8537082480], [-10716519016], [-14446458922], [4705320620], [-17088288792], [20883551792], [-5699588866], [-3006097398], [-11166855550], [16721606958], [4201025324], [8804919894], [7270571610], [3533837252], [-27687484098], [11683062488], [2455259844], [4712943350], [-27705776520], [-9593177122], [20052412074], [-1403204620], [-35051758032], [18788111174], [7290399762], [38399432108], [-11725568136], [5311833524], [18458521872], [-2590353880], [1644374370], [-41285786086], [-22263123258], [5661379404], [4126399818], [16895090984], [-2006382108], [-3752330766], [-28279628232], [-14382818368], [-17453883826]];
    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_8_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_10_8_a_a(:prec:=1)
    chi := MakeCharacter_10_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_8_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_10_8_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_10_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;