
// Make newform 441.4.a.a in Magma, downloaded from the LMFDB on 04 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_441_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_441_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_441_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_441_a();"
function MakeCharacter_441_a()
    N := 441;
    order := 1;
    char_gens := [344, 199];
    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_441_a_Hecke( : Kf := Kf)
    return MakeCharacter_441_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 := [[-4], [0], [-18], [0], [50], [-36], [-126], [-72], [-14], [-158], [-36], [-162], [270], [-324], [72], [22], [-468], [792], [232], [734], [180], [236], [-36], [-234], [468], [666], [-252], [-670], [162], [1390], [916], [-2268], [-806], [2628], [2390], [3240], [3024], [-1784], [3024], [-1566], [-3802], [-468], [-482], [-810], [2462], [-4536], [2916], [-1080], [1332], [1620], [-6718], [3578], [-756], [6516], [6030], [-590], [990], [-3420], [-2734], [-598], [3600], [-7902], [-10224], [-3888], [5112], [10102], [5508], [-9234], [6494], [10080], [738], [-194], [-4752], [-2306], [-7452], [1152], [-1894], [9216], [11650], [-7524], [3852], [10402], [10390], [11232], [14616], [-11938], [-8186], [2106], [-9486], [-12652], [3708], [8064], [-11664], [9814], [-15228], [11088], [5814], [11682], [-2988], [7130], [-5488], [-5746], [-13068], [1130], [16864], [-2088], [-10260], [-3582], [-7034], [-18072], [28584], [-10910], [5522], [2412], [24676], [27482], [-22752], [-14832], [-2822], [15826], [-23832], [13770], [-8334], [18598], [8964], [-3542], [-486], [26928], [20628], [-9756], [19064], [3766], [-11664], [-34182], [4734], [-30240], [-27702], [-22644], [-30150], [11318], [-29628], [-17770], [7868], [-35726], [27108], [-23256], [35280], [19710], [3888], [36634], [1226], [38538], [-37260], [-26640], [-12636], [33638], [36936], [22302], [13824], [-13554], [-44878], [-38362], [26444], [-17820], [-34438], [-26064], [33696], [36072], [27326], [56106], [2650], [-34128], [230], [14762], [-30024], [36090], [58880], [-49054], [40212], [-23400], [-14276], [58212], [-23906], [-39438], [-1310], [-49446], [-50706], [26388], [-28550], [-66456], [65268], [-40342], [-19764], [41130], [-18814], [-18702], [-5670], [58246], [60534], [-2160], [-69538], [41760], [-3636], [2268], [-81540], [78354], [63792], [5306], [26510], [4608], [46334], [-63738], [-22032], [23724], [49176], [36792], [82944], [6570], [-50134], [20722], [-47142], [-17316], [44294], [79056], [-3492], [7614], [46926], [-47822], [75492], [-89042], [-67230], [23112], [-54432], [8734], [66528], [19872], [88452], [85406], [44510], [-5328], [-14306], [-76572], [37368], [-71766], [-22986], [-41256], [-79452], [106740], [-74288], [112018], [64638], [6714], [1094], [80820], [29250], [-62510], [81326], [28368], [-42246], [-82152], [15748], [104062], [-2628], [83592], [-7182], [16308], [-8618], [19602], [106720], [138578], [-54792], [113076], [104292], [53784], [14508], [-19476], [-52718], [9882], [67230], [83988], [138600], [-20860], [20736], [-104040], [106164], [-33178], [155682], [-140090], [109548], [41094], [16574], [-87804], [102722], [139500], [74486], [-51462], [-90000], [-122850], [109692], [34308], [-30960], [-60566], [62692], [-5278], [15968], [-132354], [66902], [100044], [30334], [156978], [-143064], [120442], [-37742], [-137700], [-39334], [-32508], [65052], [117842], [-15228], [156154], [63720], [-16686], [63882], [-10368], [25214], [-85068], [-167776], [101016], [23918], [134762], [41310], [56362], [-121572], [-127332], [-69712], [-182124], [156170], [39366], [-48708], [56412], [-86434], [66586], [-96930], [-65448], [-214438], [-43654], [156420], [-14580], [-87552], [16002], [51984], [-76138], [-104882], [-31248], [-27794], [187434], [119088], [-67356], [43294], [-30722], [-37442], [105102], [168566], [99634], [38196], [80514], [6462], [111724], [-206226], [-6538], [-206136], [-33602], [130846], [198756], [7994], [-99036], [-201550], [-13752], [55386], [61452], [-111798], [-106474], [-158760], [40126], [150300], [14112], [-38232], [-164124], [-24352], [-82656], [237458], [-63018], [18490], [-22968], [189590], [-29322], [-28440], [-72990], [-246224], [-46454], [-105840], [151934], [10924], [119646], [239958], [-132552], [275434], [109894], [-187164], [174060], [-136296], [28346], [-5962], [260172], [56090], [120006], [41882], [-181404], [-115614], [-281592], [-77702], [143568], [-179546], [-106020], [-52560], [154170], [17230], [-27886], [-284292], [-107136]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_441_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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