
// Make newform 10.16.a.d in Magma, downloaded from the LMFDB on 16 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_d();".
// 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_d();".
// 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 := [-59892, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-10, 20]];
    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_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, 0], [-922, -1], [78125, 0], [-492466, -423], [55776072, 12006], [144656798, 28548], [710869674, 13428], [3079703060, 134964], [-2165082942, -5204241], [-82147970970, 20046888], [-141355482508, 29450862], [395052579614, 59426568], [-187358632638, 224037468], [-461912216602, 10226907], [2398358606214, -577835703], [-1384460646042, 2557045548], [-10368616994940, -3981059784], [288943862582, 3129160464], [43276629038834, 4385860641], [36919453344732, 20725115814], [19986863510738, -15861716892], [210832652437400, -5107258116], [-360573330019482, 10814315895], [181856418311610, -74280619080], [144515049698474, -66757883220], [86723513723262, -158474044872], [-1414870712284102, -66598738245], [1816804614300114, 117502083981], [2189463725653430, 12179826072], [95158244850018, -121381326216], [-7464723991514746, -210464081919], [3117464315103912, 70218346698], [7570938378633594, -1373973517728], [-7317068659079020, -559916968824], [7432602701213550, -1197424621080], [-12968147712846148, 1295697371310], [-11825197598762266, -4599615759768], [-41879277744598162, -1834007887845], [31897949331497334, 92760205221], [54808226315233878, -13292043488280], [-31206016260703140, -14931587859408], [55823932786596542, -14172568653168], [119164038301954332, 8492911837434], [-79255532969933542, 29945981084580], [74168535628623894, 4182343416396], [81504094263674360, -12227017626432], [-211087944008648248, -34102245381390], [-214727737027928302, 58296784553811], [291461516673799794, 83398943526993], [374526239307262190, -60825016677024], [-146732637760778142, -113372379789588], [395504051592912840, -179313358291596], [-131631692847709798, 54963323998380], [-507447982446334248, -28142720948250], [-639525195437794446, -119035563368472], [811370728195321458, 156959482470111], [-2210404902573908730, 74854181990592], [-21426886982202388, -374464643645142], [460310382905388974, 372047804233992], [-1078497484106976798, -263844305847180], [1989654962094477638, 153572724930771], [2299722989228551758, -324766504116720], [-1605309823999768606, 1126956969545265], [-2350745171388192108, 1282365631049922], [674414174202301178, -1580089231242648], [331437637255318734, 1225929953669076], [-325155356102649328, 1352719606578066], [2495999299276321154, -1664250505040520], [1159224319610201154, -33688578607011], [-3131423335674028330, -2205276584475024], [3687697012735379058, 193198573788408], [7155410380884166200, 873593109471888], [-19592313786418747426, 122844945153933], [-19404377248993482322, 3434564882891160], [-21476369086095975220, -1120334904102492], [18198729741098509458, -3570764700251133], [31290029949980410830, -3159093002346144], [-8927559266401206946, -2154040120216476], [21373119262258139442, -2225433286561248], [-10092153806433718750, 2210486787213588], [2917216731347886300, 9413402821321176], [15096849980490481502, -3946884635522520], [40562999377696497852, -7957864072113390], [-65400751173844966342, 923011192725372], [2189848596509704520, 11433767680621728], [60420232372560277518, 9359242185733263], [-94033315493310232470, -4842404998153956], [79632216161087271194, 7364945343772080], [-102307110708516291498, 4460586282025560], [-13555259733852913102, -16224035442490197], [13279517501409849834, 95757869835981], [47951941423247466120, 3890594085836220], [89158892743212413414, -21909563643891987], [-123263218063681879608, 3087406376394102], [132376844596461582260, -12905896149265932], [39393165777660450138, 29880804144228867], [-55875456002838665130, -14522450777276256], [-174972468008961648198, 4366480483739520], [7222236466252441718, 87462439257925827], [115094092296487767782, -44040509730521496], [-356217231406176010366, -2451606226788087], [244991899681161786774, -32456432836594296], [-418970505185483778522, -8223121451497113], [-625448518126519696350, -18929254184076924], [-223436593095262019248, 86155022054321370], [78198409969120226594, 14877106492812048], [-562261470639231066726, 13072375431575721], [407963460470148182418, -55270920353656752], [95510911847971592640, -238824471674997468], [414838401985251275522, -110791238169601404], [-131596781861940920746, -47323774300470327], [899956816657377950918, 33342233078802564], [1130168180209212884514, -48234428004101940], [-385199985929882352820, -174646836001330740], [1397123099367384962492, -34385242237634178], [-418518458060499692598, -305975338018732980], [-62212818956631576802, -162188242058793933], [766103770568084399814, 235408316482213677], [-991274366128240566642, -38101401344661012], [721578829638595523580, -72788930375843088], [835267632314636102942, 336521376970174512], [-1405237221164331094822, -173100349332657900], [410793827385326187654, 122108734413963396], [-581392483879403992362, 151848009249160131], [-34347899208909262048, -411344357203987290], [150183766652658438822, -497345458898518344], [-813719188799806128130, 314154969337421064], [2381136797917617362280, -538172611404859980], [-2442869865808983783826, 48530991390765057], [-3841864451389201116202, 409770512679304944], [-709580957075384287300, -100079351925324408], [1209022732279859159658, -132199264205620605], [-838369225580670350188, -1148111631698664042], [123000383151444679454, -469201976132265792], [1453861197373817026122, 1008419921767619136], [-3610613793603764852590, -208987002724882536], [223791872370741097878, -582312203194796820], [-7399307940040930337206, -352995841675440963], [209757618389657683134, -1386289629113905332], [-4223667534236946400230, 1232706719313342144], [1857790709871953350472, 273323167617962646], [-10440865557224491993458, 297013877832461832], [575075888378343517298, 1072048175969808231], [6595582015828288526514, 1360670362534186389], [-6396399925355846587210, -980715400898689584], [-5682617459489919131760, 946872209706653124], [3388306817744838289478, 1234677599791840044], [10742936806431970355514, 319767772179647736], [-433241326428553444300, 3699742818461815728], [3958949373896187627978, 61899142485768327], [-2444248061471879615866, -159123105702750960], [-5120559829491659391798, -1994987591477760780], [3802406992095430031318, -2498560065400156785], [-8697856121187027238146, -1385229171799039095], [-18165851049716762132086, -776773505445184719], [1520086577376790185252, 3456377710809987870], [-11282156848593403419760, -345235537427203332], [1297722042712873496970, 4613694648906764700], [-22872230918803776900046, 1488298933307687940], [-9873080410530310719258, 1773944193132078912], [2732148853981276519074, -2982351167526931695], [8739136240026247044138, -3356084908707724368], [9951459903454612671614, 4023254536952643585], [12917998450160189041152, 5117786397302424570], [8262993705489061364874, -2041696851940148508], [15806125926313492731858, 2343199745943463527], [50273328592292134802852, -160222247133688170], [23024973400575532994054, -3383719007502845916]];
    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_d();".
// 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_d(:prec:=2)
    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_d();".
// 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_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_10_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,16,sign)));
    Vf := Kernel([<3,R![-23106816, 1844, 1]>],Snew);
    return Vf;
end function;