
// Make newform 10.14.a.c in Magma, downloaded from the LMFDB on 25 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_14_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_14_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 := 14;
    raw_aps := [[64], [-2394], [-15625], [438122], [-1608288], [2653106], [108907962], [-63937300], [1123819326], [2080484790], [-6556003348], [18286017362], [39390632262], [-11907272674], [66374501922], [36595449546], [-318466174020], [343346468402], [564706251482], [-1454128449468], [-1708261304734], [-1923992449240], [175733708046], [3079262817690], [-3952362173758], [-2554831444458], [-5361418639834], [3294450017682], [-4625724763150], [37130973564666], [9669449467082], [24283845323232], [78465715401522], [53535746865260], [24178674218250], [-183309584161948], [-207767273867878], [424558361403326], [-306988298512518], [-186399704648214], [503730052303620], [359933114232902], [213686490202692], [794985857988506], [-1038214313210718], [745268736224360], [-1164952174755568], [-2953811650944754], [-3765558779967438], [-680472955444450], [-3841417530450534], [618757949062920], [2042201779533422], [2475751825909152], [-2302923577885638], [1527612150511686], [4645420699758210], [-10428082968683548], [5087833364132522], [-3859384601844858], [12295115870958806], [-2726165542089294], [-23407457740531558], [23037247894117692], [-12632312875412854], [12473569866872682], [-27414302274558328], [-35931715454794558], [32896171136339802], [-44369339974810330], [-49026263290092654], [9707905773518520], [69276102059164562], [-63840710835494614], [29068987022140340], [4555332932041566], [-52954688588075190], [89944570225076402], [-11851941724876638], [11129316174928670], [-88089243629326860], [-201113931033369238], [-96693313882543308], [222831187172504066], [101880132899373800], [-294426895409613714], [33377051651257830], [156125779824040442], [-84146156869874418], [-120342301432239994], [141666448801601082], [249669577699708680], [129638763229649762], [570241875455776032], [369516985776004460], [238733670377023686], [16527573968132790], [-44873803368380838], [-129923554727695594], [-137194979896917058], [-189660556946981038], [843882942101006802], [401435833137434646], [445244445125799390], [-1344477196236986488], [698209755555115562], [-1349341555909974318], [910221770973970386], [-63786229560500160], [1552451216534836982], [-65610083658259438], [-951443139975444334], [-2374331539400979558], [685001344358422820], [-122370900613678348], [610903138484670222], [390154869900476726], [2858689449420883122], [-31172769890290854], [-3923218329557081100], [-4058546565507818758], [2419136198267773586], [2214865057357528482], [-3197045218580994], [-5075715995989897528], [-32468597634817518], [-2854283735893403410], [-7331991722585170680], [1570263016879560122], [7820977676605647386], [-1934741153449430620], [4860419498158841406], [-3331522096392841108], [8051480513903888762], [7447471090447429962], [-1233634104024634750], [-8595718897204432014], [3051058590663389522], [-2186263298394894438], [-14548395821887171110], [-5203676200414599088], [-966965185148419878], [-15602492284188299554], [17234556567793831002], [-858684064227129550], [4830255723875050320], [21939501023030171906], [-14180529116224232718], [643743619054493420], [-2434457944322141154], [-2473477364202762358], [-8150427329548436658], [2823008472726997046], [-6461529564612682758], [26413416820646966282], [-3581645146350102468], [29836166954282954480], [12172877250382325430], [-15965723037238947958], [-25238956640282806818], [14602110603227678442], [-32629502145574029414], [-46927316087980871758], [-19442048389450318488], [-21146128834082848878], [29382460591990335366], [-1985960672961022228], [4136239982709436202]];
    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_14_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_14_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, 14));
    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_14_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_14_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_10_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,14,sign)));
    Vf := Kernel([<3,R![2394, 1]>],Snew);
    return Vf;
end function;