
// Make newform 420.4.a.d in Magma, downloaded from the LMFDB on 05 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_420_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_420_4_a_d();".
// 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_420_4_a_d();".
// 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_420_a();"
function MakeCharacter_420_a()
    N := 420;
    order := 1;
    char_gens := [211, 281, 337, 241];
    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_420_a_Hecke( : Kf := Kf)
    return MakeCharacter_420_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], [3], [5], [-7], [-44], [-42], [-94], [-36], [24], [54], [-112], [-322], [-22], [292], [272], [-578], [-44], [-26], [12], [-280], [410], [-320], [-1252], [-38], [1250], [-834], [-728], [-108], [534], [-1774], [2512], [1388], [-2406], [-860], [798], [3416], [70], [2444], [-648], [1526], [-84], [-1970], [720], [-1534], [3950], [3752], [5596], [-2672], [620], [4318], [-4902], [2176], [1330], [-972], [-1102], [-4600], [-3498], [8256], [-594], [-2326], [-5164], [-9602], [-836], [1512], [-9142], [22], [8932], [-3086], [-3356], [-9722], [-10254], [9800], [-7328], [9902], [-5292], [-6144], [-4402], [-7850], [11122], [-3030], [-13620], [-1282], [-13056], [-9550], [3640], [-10940], [13602], [15130], [-9770], [-1408], [-8644], [17184], [8744], [9012], [-18564], [552], [19558], [10346], [-3740], [-15450], [13260], [15238], [-11620], [25770], [-6828], [-25886], [-1180], [16386], [-1320], [1866], [28240], [1278], [-2662], [-15676], [23768], [-5758], [-7604], [-8072], [15302], [-4244], [-10706], [-10526], [-10146], [-10348], [-17252], [-35882], [21406], [-11184], [-2280], [18118], [30124], [-3768], [-18880], [-9266], [-4134], [-18110], [35358], [-31652], [-8442], [14298], [-44956], [-45090], [35128], [11204], [-2266], [-22408], [-21394], [-26022], [12756], [-2384], [-29482], [3266], [-4068], [-27544], [9092], [-22464], [1304], [-10094], [21338], [46934], [-9652], [-34998], [9160], [-6204], [-49614], [-25816], [48592], [-9634], [-28526], [-5618], [-7804], [-6490], [-10488], [56154], [-8512], [43834], [-39500], [8238], [62888], [-41738], [60272], [-53364], [1790], [554], [-36672], [60846], [3526], [-33172], [63610], [22080], [68418], [20404], [-61796], [-42490], [-2916], [34698], [59410], [48166], [47154], [-56488], [-27770], [46112], [-57810], [-14910], [70884], [67910], [-44944], [-48612], [-38310], [50660], [-24270], [-63666], [37912], [-45772], [-31656], [73274], [71776], [-9918], [68344], [-17226], [-7234], [86168], [41058], [-94176], [92636], [43310], [-98822], [53552], [-46232], [-33676], [-6410], [-82500], [-38768], [-43878], [-36860], [-27888], [8530], [-8770], [-56860], [104632], [-53492], [-63628], [-40824], [-2474], [91362], [20904], [47504], [26412], [-52060], [-14368], [-68762], [113010], [89352], [-42054], [-51978], [-980], [6926], [-106988], [34494], [-9078], [-89328], [-51428], [-56258], [-105274], [-77166], [54092], [42726], [-80038], [-69068], [42798], [-69354], [134940], [1802], [-45936], [-64174], [85784], [73124], [129254], [83034], [80956], [-37568], [101000], [21864], [129918], [-39004], [-28992], [-109838], [126], [-75880], [-21006], [88614], [13724], [50314], [18308], [-36618], [55686], [3280], [-37106], [63156], [-99220], [-50694], [157958], [98176], [-2004], [-137836], [81570], [-157228], [-85194], [166392], [107678], [-50448], [93918], [-92126], [32300], [138024], [102938], [-23748], [87696], [130050], [58322], [68092], [134218], [-61978], [53232], [44058], [143090], [-72532], [92148], [-69296], [63438], [25814], [-19434], [-51440], [120876], [-5308], [-109836], [87238], [-37422], [-53222], [26528], [-66962], [85162], [-62274], [-31480], [-57258], [5116], [-88674], [137860], [-156240], [177390], [131756], [-102], [-213018], [-132640], [177390], [104538], [-168096], [151492], [184818], [85368], [-50146], [133610], [-172000], [-1532], [-128468], [130042], [-102218], [-38744], [125770], [191004], [-38780], [-180032], [95262], [-9352], [230566], [-186628], [-121008], [-228478], [-83358], [172074], [-77402], [-157958], [97656], [-94494], [198828], [-86568], [44736], [5582], [101012], [193216], [122690], [139102], [17716], [104508], [129784], [-3062], [72016], [-127286], [-1020], [-60066], [-158682], [247842], [13312], [-26982], [-121826], [-202328], [-119242], [-106446], [72444], [-231444], [30482], [169374], [219876], [-225812], [133562], [141046], [101040], [132840], [-170718], [69032], [40918], [-265762], [198144], [123476], [177018], [23734], [178028], [-22422], [-63692], [-170296]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_420_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_420_4_a_d();".
// 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_420_4_a_d(:prec:=1)
    chi := MakeCharacter_420_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_420_4_a_d();".
// 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_420_4_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_420_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<11,R![44, 1]>,<17,R![94, 1]>],Snew);
    return Vf;
end function;