
// Make newform 14.8.a.a in Magma, downloaded from the LMFDB on 20 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_14_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_14_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_14_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_14_a();"
function MakeCharacter_14_a()
    N := 14;
    order := 1;
    char_gens := [3];
    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_14_a_Hecke( : Kf := Kf)
    return MakeCharacter_14_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]];
    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], [-82], [448], [-343], [2408], [7116], [2486], [36482], [-12880], [-88094], [282636], [-214534], [-140874], [36464], [716868], [-56946], [-2149862], [3084360], [-3034364], [-106624], [988930], [3415896], [-15142], [174810], [13506790], [-18764480], [-16208020], [6965796], [-14903894], [-26068442], [21313584], [10477330], [36198082], [-52765538], [73600278], [17428888], [-22215700], [62379560], [33123844], [-70579868], [-121176228], [23055012], [-20292696], [22608110], [-32717962], [72447236], [93800612], [1625672], [-246152526], [-106040756], [-202206262], [-36752328], [57641510], [-261332130], [347625330], [-176501472], [-407888924], [317618352], [293726654], [-54502678], [205409002], [-118886568], [163581346], [-432480248], [-427032890], [-347502114], [-815413360], [-555789906], [1077079728], [1441665652], [573266130], [-949334984], [-301770904], [-1361820362], [-1518386312], [454114100], [-1836997046], [1236677604], [1579477518], [-1925575330], [-2399956362], [1209400350], [-2162852136], [2257497038], [-745723896], [-1102152532], [3415999570], [427309894], [2181162748], [188134384], [854533882], [-682814068], [4151193632], [899538348], [-611109692], [5232407712], [233530548], [2230286934], [474795074], [-847969602], [-65569440], [612523582], [702101006], [243576822], [5289187656], [-3684552734], [-4235098042], [9709547994], [-4041764184], [-26257222], [-7264885632], [-11003712774], [850180694], [5792710618], [-6690516688], [4771944110], [4092950750], [-5399023548], [-4097865222], [-3774545344], [9819057400], [9987388346], [475559460], [276364524], [8824823186], [16161542170], [-8361016822], [-8188906500], [-14065743428], [-9536324520], [14513300520], [-1884342072], [-17194139016], [-10227517158], [2938064126], [-14971004258], [-15327071336], [-564462198], [20278613220], [3201389974], [-22221905246], [2573093774], [-5154900392], [20207870388], [-22692027176], [-11828343364], [11714085500], [16795479390], [-18623257954], [-19568254856], [-8760795086], [35910260874], [-34242022564], [13329936012], [-3956319708], [17786444976], [37930678744], [42341353398], [16514727458], [-31432941656], [-32711407376], [-26265539494], [25825270832], [22410243834], [-35458248006], [-14576737524], [12571289120], [-10403688856]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_14_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_14_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_14_8_a_a(:prec:=1)
    chi := MakeCharacter_14_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_14_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_14_8_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_14_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![82, 1]>],Snew);
    return Vf;
end function;