
// Make newform 245.4.e.k in Magma, downloaded from the LMFDB on 10 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_245_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_245_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_245_4_e_k();".
// 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_245_4_e_k();".
// 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 := [121, 0, 11, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 11, 11];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_245_e();"
function MakeCharacter_245_e()
    N := 245;
    order := 3;
    char_gens := [197, 101];
    v := [3, 2];
    // 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_245_e_Hecke();"
function MakeCharacter_245_e_Hecke( : Kf := false)
    N := 245;
    order := 3;
    char_gens := [197, 101];
    char_values := [[1, 0, 0, 0], [-1, 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 := [[-1, 1, -1, 0], [0, 0, -5, 0], [5, 0, 5, 0], [0, 0, 0, 0], [0, 4, 33, 4], [-5, 0, 0, -20], [0, -20, -35, -20], [70, -20, 70, 0], [8, -28, 8, 0], [-129, 0, 0, -48], [0, -60, 10, -60], [-164, 44, -164, 0], [-150, 0, 0, 100], [-58, 0, 0, 12], [-15, 40, -15, 0], [0, 120, 270, 120], [0, 40, -190, 40], [540, 60, 540, 0], [0, 96, 234, 96], [-528, 0, 0, 64], [0, -200, 430, -200], [-79, 348, -79, 0], [-20, 0, 0, 200], [-120, -380, -120, 0], [-815, 0, 0, -180], [0, 140, 1010, 140], [-15, -240, -15, 0], [90, -160, 90, 0], [0, -288, -951, -288], [1188, 0, 0, 68], [-1834, 0, 0, -64], [-120, -380, -120, 0], [0, -220, -1220, -220], [-2800, 0, 0, 0], [134, 392, 134, 0], [0, -444, -513, -444], [0, -160, 490, -160], [2760, 360, 2760, 0], [-1125, 0, 0, 680], [2875, 100, 2875, 0], [0, 400, 116, 400], [1970, 0, 0, 320], [-153, -700, -153, 0], [0, 308, 2512, 308], [714, 0, 0, 804], [0, 80, -4330, 80], [-4657, 0, 0, -100], [-1405, 0, 0, -720], [0, 840, -1125, 840], [-110, -140, -110, 0], [-2088, 1328, -2088, 0], [-2001, 0, 0, 500], [0, -20, -2380, -20], [-540, 0, 0, -1040], [1230, -320, 1230, 0], [0, -1448, 1558, -1448], [0, 280, 1920, 280], [-1060, -540, -1060, 0], [0, 880, -620, 880], [723, 0, 0, -1624], [0, -1200, -1875, -1200], [5865, 0, 0, 220], [285, 0, 0, 720], [0, 740, 3310, 740], [-2355, 300, -2355, 0], [-6386, 376, -6386, 0], [748, -776, 748, 0], [-1040, 0, 0, -360], [0, 276, 3444, 276], [-1490, 0, 0, 60], [0, -580, 5845, -580], [2576, 88, 2576, 0], [0, -120, -11105, -120], [-2128, -892, -2128, 0], [3104, 0, 0, 648], [-4080, 2160, -4080, 0], [0, 328, -7419, 328], [-4505, -2300, -4505, 0], [5763, -1656, 5763, 0], [0, -1800, 1950, -1800], [1410, 0, 0, 1160], [-1647, 0, 0, 936], [0, 3500, -3683, 3500], [5650, 0, 0, -1760], [-2780, -1920, -2780, 0], [-3390, 460, -3390, 0], [5791, 0, 0, 392], [4646, 2924, 4646, 0], [15620, 0, 0, 320], [6880, 0, 0, 2620], [4655, 400, 4655, 0], [0, -3940, 1540, -3940], [0, 2664, 6956, 2664], [8143, 0, 0, -1484], [5211, 4500, 5211, 0], [-1415, 0, 0, -200], [-3320, 4720, -3320, 0], [0, 2380, -9630, 2380], [8320, -2080, 8320, 0], [4893, -3216, 4893, 0], [-6316, 0, 0, -716], [0, 64, -7164, 64], [0, -1720, -18580, -1720], [16814, 1432, 16814, 0], [0, -4136, 10028, -4136], [0, 1860, 16015, 1860], [-10340, 0, 0, 80], [-555, 2060, -555, 0], [0, -1692, -4359, -1692], [13210, 0, 0, -3440], [6875, 1320, 6875, 0], [0, 672, -17522, 672], [-396, 0, 0, 5184], [0, 7540, -1540, 7540], [-323, 0, 0, 1724], [0, 3416, 13782, 3416], [-5085, 0, 0, -600], [0, -880, -6260, -880], [18750, -1300, 18750, 0], [-579, 0, 0, 700], [0, -3400, 1300, -3400], [5040, 0, 0, -4740], [-13175, 4940, -13175, 0], [0, -892, 7292, -892], [-11660, -840, -11660, 0], [-11473, 0, 0, -3200], [17929, -3000, 17929, 0], [-3920, -8980, -3920, 0], [560, 0, 0, -8960], [15185, 1260, 15185, 0], [0, 9372, -6131, 9372], [1530, 0, 0, 2920], [-1327, 1700, -1327, 0], [-7864, 0, 0, -3464], [26480, -1780, 26480, 0], [14210, 0, 0, 3360], [0, 6860, -3365, 6860], [0, -6880, -20545, -6880], [-10035, 0, 0, 2140], [0, 488, -2699, 488], [-10440, 0, 0, 2760], [-15737, 3200, -15737, 0], [0, -3468, -1682, -3468], [-2856, 0, 0, -8296], [0, -340, 29690, -340], [-3180, 0, 0, 8420], [16190, 0, 0, -1320], [0, -2560, 14950, -2560], [28580, 5920, 28580, 0], [6198, 7692, 6198, 0], [-6750, -5700, -6750, 0], [8960, 0, 0, 6160], [21652, 0, 0, -5268], [3120, -5640, 3120, 0], [0, 5420, 9620, 5420], [-9408, 0, 0, 1504], [14489, -7468, 14489, 0], [-3450, 3000, -3450, 0], [-8635, 0, 0, -5700], [0, -3020, -24380, -3020], [-10410, -5060, -10410, 0], [25462, 0, 0, -7388], [-28430, 0, 0, -3520], [-12610, -7540, -12610, 0], [0, -10956, 8646, -10956], [0, 2240, 15325, 2240], [0, -16584, -468, -16584], [0, 1380, 10605, 1380]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_245_e_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_245_4_e_k();".
// 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_245_4_e_k(:prec:=4)
    chi := MakeCharacter_245_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_245_4_e_k();".
// 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_245_4_e_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_245_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![100, -20, 14, 2, 1]>,<3,R![25, -5, 1]>],Snew);
    return Vf;
end function;