
// Make newform 16.10.a.c in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_16_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_16_10_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_16_10_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_16_a();"
function MakeCharacter_16_a()
    N := 16;
    order := 1;
    char_gens := [15, 5];
    v := [1, 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_16_a_Hecke(Kf)
    return MakeCharacter_16_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 := [[0], [60], [-2074], [4344], [-93644], [-12242], [-319598], [553516], [712936], [2075838], [6420448], [-18197754], [9033834], [-19594732], [18484176], [10255766], [-121666556], [-45948962], [-50535428], [-267044680], [-176213366], [269685680], [227032556], [72141594], [228776546], [-803255994], [-781725544], [1007558100], [-480691826], [-2897809422], [4243302272], [-2897275972], [-2356171830], [2715272628], [1674018550], [-5327085464], [-11583464642], [-948417636], [14471751768], [-13988594226], [4549239180], [15648401430], [-20205213888], [-7108270654], [22592354982], [-35550572488], [5584799084], [-47471286496], [33770236764], [7289894854], [67973875754], [31128335120], [14237169522], [57838873412], [-18717636350], [28043704312], [-44660013266], [103375407856], [181402536310], [-125487340070], [-133560982748], [-3506345466], [294356526348], [-24030478392], [-255229429254], [230255270622], [121212223732], [252248783826], [-299996354844], [-125625054210], [-431672436638], [-183614574696], [-377184699760], [269400214742], [204101558980], [41063054976], [-286341596314], [373016278958], [470676092178], [-860520026790], [-846564598116], [-227834561914], [647351247440], [569897580082], [-598042001592], [-310867196284], [747113578178], [-1542748002550], [1627664637422], [1115912327728], [530193690732], [2100193101344], [1053067241240], [-2105563975596], [-288806514612], [-517680916728], [601746738078], [-167285350070], [1579659728948], [-3087362040642], [-262135558628], [364237965134], [-3040524950516], [-735845268742], [-1446179281404], [-2269446467518], [-3419769190412], [-1324823990062], [4199355004584], [1056816176410], [-5970959278688], [2806501620038], [1483017996714], [-1534690184236], [4434983884424], [-4562565055102], [3328184469948], [-2313741117832], [7036972526766], [-2203195690068], [-7295701439242], [-4470794975582], [-3420953448058], [9187304863636], [1888109494156], [1619072302686], [-10637470151002], [-13276980190928], [-2600173095384], [-11481760443010], [7759843772764], [2581154752024], [8392078385424], [8158751330390], [-6274332345926], [6120270592514], [-6628748091162], [-11950278911188], [-11888669804098], [-16806313131158], [-19847266374892], [4839917601942], [-8416642196024], [21665755733252], [-3677342994722], [14694216924600], [-19984481397322], [21198869701914], [-25180929567516], [-21590511823712], [26318199578766], [4235125165810], [25655740252876], [31404421045640], [38700089580212], [-17343586363280], [1752315456872], [-19997698662494], [4621370155242], [16495866242766], [-19960617139572], [-8830867785606], [-20356173341384], [-7668880334220], [6230169370962], [-52279985380056], [37367157255200], [36623047460038]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_16_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_16_10_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_16_10_a_c(:prec:=1)
    chi := MakeCharacter_16_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_16_10_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_16_10_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_16_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![-60, 1]>],Snew);
    return Vf;
end function;