
// Make newform 10.14.a.b 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_b();".
// 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_b();".
// 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], [1224], [15625], [-65212], [7427652], [32243054], [-20088222], [77070740], [664071804], [1558250670], [-303290968], [-775029322], [43696205082], [-68680553536], [-138979393812], [-103656826986], [394887188940], [-488570895538], [368381730848], [325473704592], [-2262556998406], [2032917332000], [-854518199496], [8906829484890], [-9873550533742], [-12581335495338], [10415778230684], [-2334929045352], [-30423051962530], [15093336895314], [45495019817948], [102239948370252], [-10023730735062], [-60672787313380], [49366655600550], [-221679816178048], [-283127843232562], [136313648189624], [164992688986548], [-3252246796386], [-108842577432060], [-291068249554618], [-530742547788648], [-345160807421806], [-421479905479002], [271938456044840], [1128390108255932], [2190022725158324], [-2774926403436672], [2184149204243510], [-3917807994971526], [-2878972445051040], [3638509374376322], [4860289083166452], [2009822767550178], [-3495909617125716], [-1920330778742370], [2054457722736872], [-6843349539494362], [-4160591273481558], [772572158496464], [-13995847872430506], [12060286397949008], [25162538113422672], [2746459990975994], [8118322307227998], [-7057041228647788], [-3674101024896142], [24256611156669768], [-25374640294877170], [55045023719547714], [-67233849960718200], [16870390816451228], [52815299402969414], [-31661373568894180], [-68841296186784876], [-62727388581965130], [-127944370568846482], [44019146797401042], [-5156443918700950], [-19470331048037100], [39653785610345462], [-107744478731578008], [70670135650987874], [-149430184297284520], [118592365514879424], [223219689291572370], [-143446230326785942], [-222152698595595618], [-386188734084651196], [116420394589165248], [-181724169016239120], [267630004675113428], [466002161462467812], [119287456062388340], [258456277158024204], [211455738481592430], [-394874704938809238], [266612714411638784], [830449443512433902], [-90934543565728672], [-366722790039362082], [322592008753705944], [1393504569704363850], [688306980218322212], [-360332964874002622], [1482445307706523848], [874055630272193874], [385437556106832360], [501340936287716522], [-969295978369404772], [1409352766931861414], [140376844850715258], [1926245979132629420], [1390641834212880032], [-181432929895404078], [-1295581015228526536], [108535917007151988], [-64157495153950386], [340176769282008420], [2822381185548324422], [2827006805948278514], [-2516814536279080602], [-3878533903654650336], [4057591523160018572], [4361337870956499822], [-5170246571934144970], [-2954832713946358080], [2635108678055647988], [-5657225466028756306], [-5936511026732181100], [4957268611211362044], [7880518287884213912], [-736262235464948122], [-8321872164287392998], [466288450661352290], [-1842662472968508186], [-12185400552581115712], [1076890448189182878], [7496686443529233930], [-6332699636941686748], [10613042635896760902], [9257219440673704124], [6142761235393236168], [12760561382649208910], [2739598797258836760], [2864665858150704374], [14906525787137145498], [-17725825762912582900], [-81516400585084956], [-15605920951247738242], [-643110802854174558], [13501289427064736504], [-6454976169641854092], [3344070543892470248], [14531002584176356632], [24115441347603509960], [-17617292816116233870], [-6072074230781261542], [-20173254531319248738], [-30874664079445359792], [25350614194115964954], [-41193660607558376092], [-5436659147226283788], [40051196005908130338], [-11825313764699994276], [-28498492155585452728], [14450493217257602918]];
    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_b();".
// 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_b(: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_b();".
// 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_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_10_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,14,sign)));
    Vf := Kernel([<3,R![-1224, 1]>],Snew);
    return Vf;
end function;