
// Make newform 238.4.a.a in Magma, downloaded from the LMFDB on 07 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_238_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_238_4_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_238_4_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
        poly := [-23, -1, 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_238_a();"
function MakeCharacter_238_a()
    N := 238;
    order := 1;
    char_gens := [171, 71];
    v := [1, 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_238_a_Hecke( : Kf := Kf)
    return MakeCharacter_238_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 := 4;
    raw_aps := [[-2, 0], [-2, -1], [5, -1], [-7, 0], [-6, 8], [-18, 8], [17, 0], [4, 4], [24, 2], [-90, -28], [81, 27], [-144, -32], [-232, 7], [0, -69], [-384, -6], [-373, 15], [148, 0], [-204, 69], [209, 49], [116, -16], [400, 21], [-24, 78], [-100, -158], [-440, -38], [-403, -109], [488, 144], [112, -10], [-914, -72], [1554, -136], [-468, 30], [287, -273], [-32, -220], [-610, -385], [37, 179], [-2398, -169], [2104, -249], [412, -160], [-256, 412], [-1118, 31], [-1668, 297], [820, 721], [318, 24], [-2423, -251], [-506, -240], [-2384, 632], [-138, -605], [4112, -246], [-484, -16], [-323, -1109], [-850, -392], [-4214, 400], [-264, -753], [1713, -349], [-912, -224], [2870, -1042], [-2508, 440], [6, 1512], [3580, -1022], [2988, 42], [-1483, 441], [5071, 733], [2686, -134], [2122, 870], [7411, -383], [-1863, 1767], [-310, 746], [-3953, 759], [-5348, 248], [1374, -1020], [-1078, -1134], [-9022, 624], [6875, -737], [-486, -633], [-606, 241], [-2870, 848], [-2046, 1248], [-9261, -405], [-635, 2411], [-4374, 696], [2872, 1742], [3559, -2511], [-9470, -647], [-6058, -1574], [482, -3030], [-7790, 513], [-316, 3084], [-2572, -984], [-1983, 2557], [13802, -1146], [-3184, 2931], [-3586, -338], [-5618, 1645], [-1678, -1134], [2045, 2181], [1654, 478], [-16679, 203], [328, 684], [6536, 2385], [-21480, 438], [4712, -206], [-324, 1924], [-5858, -1788], [3402, 1016], [-7110, 1895], [5624, -852], [-11808, 868], [1146, 1562], [-3492, 3324], [-4216, 3941], [3826, 1784], [7471, -2415], [-3069, -2321], [-526, -2396], [-4744, -1884], [21549, 1473], [12754, -2622], [6558, -3863], [7402, -1128], [19334, -1048], [1193, -3235], [9278, 1380], [2182, 2122], [-6658, 3716], [-3484, 3892], [702, 1251], [33810, 40], [30430, -1192], [-7082, -889], [-4834, 5574], [-9002, 1014], [-35632, 869], [22502, 2398], [6028, -5120], [8002, -5579], [9930, -922], [-12648, -4592], [-8524, -2030], [-7792, -3092], [7080, 5642], [-23008, -2932], [27694, -435], [11516, -3812], [6062, 2486], [-5662, 1966], [-36798, 2308], [4740, -2636], [-1266, -4616], [2871, 3025], [-36640, -1782], [-18813, 1195], [38128, 2456], [20511, 2161], [-28709, 2463], [2477, -1261], [-8474, 3780], [-5534, 8484], [10244, 3525], [-853, -3815], [-23920, 5320], [21088, 4689], [-14530, 8572], [-8381, 3595], [-33132, 255], [-254, -6472], [-13343, 1565], [35625, -2977], [-2570, 3652], [18164, 6301]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_238_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_238_4_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_238_4_a_a(:prec:=2)
    chi := MakeCharacter_238_a();
    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_238_4_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_238_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_238_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-17, 5, 1]>],Snew);
    return Vf;
end function;