
// Make newform 441.4.e.l in Magma, downloaded from the LMFDB on 21 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_441_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_441_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_441_4_e_l();".
// 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_441_4_e_l();".
// 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, -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_441_e();"
function MakeCharacter_441_e()
    N := 441;
    order := 3;
    char_gens := [344, 199];
    v := [3, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_441_e_Hecke();"
function MakeCharacter_441_e_Hecke( : Kf := false)
    N := 441;
    order := 3;
    char_gens := [344, 199];
    char_values := [[1, 0], [0, -1]];
    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, 4], [0, 0], [0, -18], [0, 0], [-50, 50], [36, 0], [-126, 126], [0, -72], [0, 14], [-158, 0], [-36, 36], [0, 162], [-270, 0], [-324, 0], [0, 72], [-22, 22], [-468, 468], [0, 792], [-232, 232], [734, 0], [180, -180], [0, -236], [36, 0], [0, -234], [-468, 0], [666, -666], [0, -252], [0, 670], [-162, 162], [1390, 0], [916, 0], [0, -2268], [806, -806], [-2628, 0], [0, -2390], [-3240, 3240], [3024, -3024], [0, 1784], [-3024, 0], [0, -1566], [3802, -3802], [468, 0], [0, 482], [810, -810], [2462, 0], [-4536, 4536], [2916, 0], [1080, 0], [1332, -1332], [0, 1620], [0, 6718], [3578, 0], [-756, 756], [-6516, 0], [0, 6030], [590, -590], [990, -990], [0, -3420], [2734, -2734], [-598, 0], [3600, -3600], [7902, 0], [10224, 0], [-3888, 3888], [0, 5112], [0, -10102], [0, -5508], [-9234, 0], [-6494, 6494], [-10080, 0], [738, -738], [0, 194], [-4752, 4752], [0, 2306], [-7452, 0], [0, 1152], [1894, -1894], [0, 9216], [0, -11650], [-7524, 7524], [-3852, 0], [10402, 0], [-10390, 10390], [-11232, 0], [0, 14616], [0, 11938], [-8186, 0], [0, -2106], [9486, 0], [-12652, 0], [0, 3708], [8064, -8064], [11664, -11664], [9814, 0], [0, 15228], [-11088, 0], [0, 5814], [11682, -11682], [0, -2988], [0, -7130], [-5488, 0], [5746, -5746], [-13068, 13068], [0, -1130], [-16864, 16864], [-2088, 2088], [10260, 0], [0, -3582], [7034, -7034], [18072, 0], [0, 28584], [10910, -10910], [5522, 0], [2412, -2412], [24676, 0], [-27482, 27482], [22752, 0], [-14832, 14832], [0, 2822], [15826, 0], [-23832, 23832], [13770, 0], [0, -8334], [-18598, 18598], [0, 8964], [-3542, 0], [0, 486], [0, 26928], [-20628, 0], [0, -9756], [-19064, 19064], [3766, 0], [0, 11664], [-34182, 0], [0, 4734], [30240, 0], [-27702, 27702], [-22644, 22644], [30150, 0], [-11318, 11318], [29628, 0], [0, 17770], [-7868, 7868], [-35726, 0], [27108, -27108], [23256, 0], [-35280, 0], [19710, -19710], [0, 3888], [0, -36634], [0, -1226], [-38538, 0], [-37260, 0], [0, -26640], [12636, -12636], [33638, 0], [0, -36936], [0, 22302], [-13824, 0], [-13554, 13554], [0, 44878], [-38362, 0], [26444, 0], [0, -17820], [34438, -34438], [-26064, 26064], [-33696, 33696], [36072, -36072]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_441_e_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_441_4_e_l();".
// 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_441_4_e_l(:prec:=2)
    chi := MakeCharacter_441_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_441_4_e_l();".
// 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_441_4_e_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![16, -4, 1]>,<5,R![324, 18, 1]>,<13,R![-36, 1]>],Snew);
    return Vf;
end function;