
// Make newform 1440.4.a.k in Magma, downloaded from the LMFDB on 08 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1440_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_1440_4_a_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_1440_4_a_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1440_a();"
function MakeCharacter_1440_a()
    N := 1440;
    order := 1;
    char_gens := [991, 901, 641, 577];
    v := [1, 1, 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_1440_a_Hecke( : Kf := Kf)
    return MakeCharacter_1440_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 := [[0], [0], [5], [-30], [50], [-88], [-74], [-140], [80], [234], [0], [116], [72], [-280], [120], [498], [-870], [650], [-420], [1020], [-322], [-160], [-980], [1124], [1114], [850], [1210], [1620], [-1054], [-462], [-1190], [2150], [-1334], [-220], [150], [-2420], [1744], [-2620], [-2160], [322], [1770], [1858], [740], [758], [4286], [740], [1340], [210], [6520], [2550], [-1218], [380], [-2650], [1830], [1794], [5200], [-350], [-7940], [5196], [308], [7180], [-3442], [2720], [4140], [2038], [4926], [540], [9734], [-9320], [3250], [-8602], [-3560], [3210], [-3928], [460], [9920], [4950], [-13764], [11500], [-15046], [-1650], [-11450], [-10480], [-1618], [-17860], [5200], [-10700], [-3694], [14350], [-610], [-11580], [700], [-1970], [6390], [220], [5560], [17146], [3900], [-5780], [-12678], [2120], [-12006], [15600], [12100], [21580], [-4846], [7140], [14442], [-7480], [-3050], [-15050], [-11612], [6726], [-14300], [13400], [7328], [-22500], [-19640], [-13802], [-6530], [-24950], [8022], [-12546], [6060], [1940], [35698], [-3050], [-5240], [-7810], [17668], [22580], [15360], [-25640], [-644], [21300], [-7250], [22], [11620], [12514], [-11104], [-40140], [24738], [-6010], [18120], [-22566], [-30000], [15348], [17894], [2060], [-400], [9304], [-19308], [-36500], [-19480], [41160], [51440], [25520], [10500], [-27366], [51550], [15160], [20898], [23450], [29150], [-39546], [-17120], [30620], [-47136], [23350], [-28662], [-15830], [44662], [-39480], [2718], [20800], [-17964], [-10260], [-49650], [40510], [9206], [42350], [-23290], [54508], [-42414], [-38040], [-14546], [9024], [12100], [-8234], [12300], [55502], [24280], [-45300], [158], [-13340], [48058], [34050], [71688], [-71574], [2440], [57766], [-1800], [-384], [-64850], [9090], [-10746], [34520], [71120], [26276], [70100], [-5186], [37302], [54290], [12840], [-28580], [-30350], [-23590], [-14100], [-50400], [-49078], [54350], [19660], [-78096], [63950], [54140], [58934], [79082], [42120], [-38650], [-62910], [29352], [76340], [26140], [62492], [-60940], [-10600], [61026], [-57458], [-27790], [63660], [25240], [87860], [83990], [108450], [53798], [-10580], [106090], [57970], [-52020], [98680], [-39036], [46400], [103920], [-114046], [-79062], [47310], [-3838], [-96620], [43266], [49294], [22090], [21360], [114350], [-69892], [11514], [104180], [69854], [75000], [34220], [31582], [-13578], [-37040], [-44098], [89400], [-115554], [-50990], [-9640], [54250], [-34950], [4830], [-83760], [-126260], [-38760], [64782], [153840], [40700], [-110678], [-40546], [-86500], [-83600], [129702], [-120260], [116838], [119290], [89732], [-17050], [-77720], [55778], [80490], [62160], [44142], [-30314], [-15500], [-153060], [106100], [-172526], [145820], [-27650], [100860], [-41352], [2320], [172794], [-152900], [113240], [57280], [-79850], [-110110], [-56940], [-65738], [52600], [-54340], [109766], [13722], [-154170], [77398], [-139450], [6620], [-53440], [133320], [-172038], [-148250], [154666], [97240], [-89300], [17900], [7340], [-5906], [135822], [46250], [-55910], [79408], [-41514], [92250], [106860], [36282], [-135830], [125750], [-53440], [24660], [164706], [-166860], [24946], [113242], [86930], [152250], [-114042], [-165520], [48570], [-74574], [-135440], [-70016], [-135200], [57160], [144130], [111900], [131178], [117354], [74250], [-66650], [-227190], [196220], [229360], [-106150], [-88380], [-94556], [-157590], [-208040], [143242], [-191900], [-101726], [-12850], [-119118], [128330], [175694], [-212580], [-64800], [160840], [156604], [-99960], [-247560], [-238674], [53058], [-78590], [269260], [24560], [-88262], [-160180], [238384], [-143540], [-58922], [77414], [-89502], [-69950], [21946], [133250], [-121880], [-52564], [217500], [188340], [14590], [-135918], [-156434], [2340], [17980], [199494], [-227750], [-182520], [136130], [-10614], [140680], [-7450], [78176], [-293720], [11790], [19198], [14694], [51900], [138000], [11260], [-245520]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1440_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1440_4_a_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_1440_4_a_k(:prec:=1)
    chi := MakeCharacter_1440_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_1440_4_a_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_1440_4_a_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1440_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![30, 1]>,<11,R![-50, 1]>,<17,R![74, 1]>],Snew);
    return Vf;
end function;