
// Make newform 338.4.e.c in Magma, downloaded from the LMFDB on 03 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_338_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_338_e_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_338_4_e_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_338_4_e_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
        poly := [1, 0, -1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_338_e();"
function MakeCharacter_338_e()
    N := 338;
    order := 6;
    char_gens := [171];
    v := [5];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_338_e_Hecke();"
function MakeCharacter_338_e_Hecke( : Kf := false)
    N := 338;
    order := 6;
    char_gens := [171];
    char_values := [[0, 0, 1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 4;
    raw_aps := [[0, 2, 0, 0], [1, 0, -1, 0], [0, 0, 0, -17], [0, -35, 0, 35], [0, -2, 0, 0], [0, 0, 0, 0], [0, 0, -19, 0], [0, -94, 0, 94], [-72, 0, 72, 0], [-246, 0, 246, 0], [0, 0, 0, 100], [0, 11, 0, 0], [0, -280, 0, 0], [0, 0, 241, 0], [0, 0, 0, 137], [-232, 0, 0, 0], [0, -386, 0, 386], [0, 0, -64, 0], [0, -670, 0, 0], [0, -55, 0, 55], [0, 0, 0, -838], [1016, 0, 0, 0], [0, 0, 0, -420], [0, 934, 0, 0], [0, 1154, 0, -1154], [292, 0, -292, 0], [-52, 0, 0, 0], [-12, 0, 12, 0], [0, 0, 0, -1213], [0, 0, 1158, 0], [-540, 0, 540, 0], [-1571, 0, 0, 0], [0, -568, 0, 568], [0, 0, -1845, 0], [0, -2850, 0, 2850], [0, 0, 0, 2763], [-466, 0, 0, 0], [0, 2552, 0, -2552], [0, 3768, 0, 0], [0, 0, 3296, 0], [45, 0, -45, 0], [364, 0, 0, 0], [0, 0, -2482, 0], [0, 1220, 0, 0], [0, -1593, 0, 0], [0, 0, 1606, 0], [-2469, 0, 2469, 0], [0, 1943, 0, 0], [0, -3032, 0, 3032], [0, 0, 0, 5311], [507, 0, 0, 0], [0, 0, 0, 6795], [0, -4442, 0, 4442], [0, 0, -5024, 0], [7065, 0, -7065, 0], [-1364, 0, 1364, 0], [0, 0, 4304, 0], [0, 1519, 0, 0], [0, 0, 1996, 0], [0, 0, 0, -2918], [812, 0, -812, 0], [0, -1855, 0, 1855], [0, 0, 0, 5350], [-2262, 0, 0, 0], [-1857, 0, 0, 0], [0, 0, 0, 3870], [0, -10520, 0, 10520], [-7839, 0, 0, 0], [0, 0, 1275, 0], [0, 375, 0, 0], [0, 1592, 0, 0], [0, 0, 0, -2424], [7970, 0, -7970, 0], [0, 0, -12492, 0], [0, -4284, 0, 0], [0, 2337, 0, -2337], [-3562, 0, 0, 0], [0, -5274, 0, 5274], [0, -4812, 0, 0], [0, 9448, 0, -9448], [521, 0, -521, 0], [0, 0, 0, -7141], [0, -6299, 0, 0], [0, 0, 3231, 0], [-410, 0, 410, 0], [-9397, 0, 0, 0], [0, 654, 0, -654], [0, 14982, 0, 0], [0, -10845, 0, 10845], [0, 0, 0, 13072], [15340, 0, 0, 0], [0, 19615, 0, 0], [0, 10904, 0, -10904], [-18519, 0, 18519, 0], [0, 0, 0, 14400], [0, 0, -20422, 0], [0, 15606, 0, 0], [1783, 0, 0, 0], [-11140, 0, 11140, 0], [0, 0, 0, 839], [17279, 0, 0, 0], [0, 20577, 0, 0], [0, 0, 11785, 0], [10887, 0, -10887, 0], [11453, 0, 0, 0], [0, 0, 0, -14382], [0, -10160, 0, 0], [0, 0, 0, 16842], [-13830, 0, 0, 0], [15835, 0, -15835, 0], [0, 0, 22894, 0], [0, 9886, 0, 0], [0, -8856, 0, 8856], [0, 0, 0, 3764], [0, 17775, 0, -17775], [0, 0, 13358, 0], [0, 26062, 0, -26062], [20598, 0, -20598, 0], [-27104, 0, 27104, 0], [0, 0, -7500, 0], [0, -10402, 0, 0], [-19715, 0, 19715, 0], [-1168, 0, 0, 0], [0, 3800, 0, -3800], [0, -17336, 0, 0], [10088, 0, 0, 0], [0, 11730, 0, -11730], [0, 0, -2190, 0], [2470, 0, 0, 0], [0, 0, 0, 8693], [0, 14636, 0, 0], [0, 27501, 0, 0], [11888, 0, -11888, 0], [-10776, 0, 10776, 0], [0, -21758, 0, 21758], [0, -8080, 0, 0], [0, -3981, 0, 3981], [0, -26048, 0, 26048], [0, 0, -12434, 0], [8113, 0, -8113, 0], [0, 0, 0, -732], [0, -32559, 0, 0], [0, 0, -43582, 0], [0, 0, 0, -23042], [-20690, 0, 20690, 0], [0, -43000, 0, 43000], [0, 0, 0, -33065], [28938, 0, 0, 0], [12508, 0, 0, 0], [0, 0, 0, 19535], [0, -18775, 0, 18775], [-43531, 0, 43531, 0], [-6955, 0, 0, 0], [-40728, 0, 40728, 0], [23653, 0, -23653, 0], [-206, 0, 0, 0], [0, 0, -28352, 0], [0, 17612, 0, -17612], [12014, 0, 0, 0], [0, 0, 0, 26737], [0, 35566, 0, 0], [0, 0, 12279, 0], [0, 0, 0, -51523], [0, 0, -41027, 0], [0, 23562, 0, 0], [0, 0, 0, -41307], [26586, 0, -26586, 0], [0, 0, -39298, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_338_e_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_338_4_e_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_338_4_e_c(:prec:=4)
    chi := MakeCharacter_338_e();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_338_4_e_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_338_4_e_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_338_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![1, -1, 1]>,<5,R![289, 0, 1]>],Snew);
    return Vf;
end function;