
// Make newform 1472.4.a.b in Magma, downloaded from the LMFDB on 07 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1472_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_1472_4_a_b();".
// 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_1472_4_a_b();".
// 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_1472_a();"
function MakeCharacter_1472_a()
    N := 1472;
    order := 1;
    char_gens := [1151, 645, 833];
    v := [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_1472_a_Hecke( : Kf := Kf)
    return MakeCharacter_1472_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], [-8], [4], [-4], [-26], [-70], [94], [-54], [-23], [86], [-144], [172], [-42], [-386], [-80], [108], [-164], [400], [-398], [-320], [-810], [-204], [-102], [1018], [-1370], [1330], [-1160], [402], [-2040], [1362], [1664], [-2484], [1222], [1900], [3372], [56], [1116], [-160], [4176], [1214], [2216], [2592], [-1068], [-2918], [-1578], [3484], [4876], [5888], [-4498], [-352], [4362], [2936], [-7306], [3930], [-138], [3664], [-3354], [-7688], [7606], [4794], [-1898], [5380], [3112], [9504], [-1930], [-1866], [-6772], [8522], [-11584], [446], [-2046], [-2412], [9804], [3116], [-8558], [-10584], [-9560], [5770], [2862], [11378], [1754], [-12148], [4884], [2278], [-11480], [11840], [-2290], [-19370], [-18458], [-7496], [12074], [9912], [5272], [17936], [-1304], [-9364], [9798], [21510], [3498], [-10722], [5628], [4440], [7926], [-18706], [-16774], [2238], [23524], [-1274], [400], [-8746], [27056], [-328], [29778], [10646], [8056], [-25458], [3806], [2168], [-6462], [29354], [-17152], [766], [-3788], [412], [-28292], [-18648], [-18844], [31744], [3900], [-7948], [17368], [25704], [6672], [6648], [-3470], [9302], [4176], [-6090], [29824], [-29038], [-28012], [-4950], [2680], [-606], [-17642], [-24264], [-12998], [-44518], [-8000], [-1848], [902], [786], [8316], [8280], [4318], [-30732], [53692], [12014], [39514], [-35484], [21128], [-6962], [33616], [-31602], [-19482], [42716], [26328], [47614], [-10834], [6098], [-23014], [710], [-41880], [-14838], [-30040], [33946], [-8872], [49010], [-33856], [-41788], [-43904], [-13926], [-18282], [32874], [-6164], [-39664], [9330], [65478], [45686], [-36328], [69526], [-64156], [8342], [20202], [-60286], [-30862], [35626], [-812], [-52374], [-38512], [-73200], [-32136], [53462], [-16030], [-41730], [-55170], [89924], [72948], [-8674], [22688], [45006], [81690], [-25032], [-62034], [69464], [62814], [-46904], [55386], [17624], [13146], [42410], [-56080], [43914], [-12936], [17664], [95634], [-1382], [90984], [-45448], [10320], [-29450], [-94226], [-93656], [58326], [105726], [12500], [-25538], [-44272], [-77348], [93680], [79014], [1712], [56320], [-7270], [70578], [44600], [71824], [-32390], [54790], [-62888], [-102408], [46618], [26456], [12458], [-16422], [-64208], [-71912], [-43118], [-42306], [95906], [-59408], [-58958], [-121154], [99400], [-95934], [-9546], [-18896], [82642], [-6578], [88086], [17270], [-60514], [-73854], [63528], [-59070], [59688], [36956], [-14038], [111378], [99990], [27024], [-112568], [-68084], [108400], [18192], [-53472], [87838], [148968], [-22280], [41982], [141604], [12298], [62262], [-1226], [-31250], [-53092], [-156532], [-49734], [-88016], [-122196], [29238], [121848], [-140876], [-4764], [35930], [-145006], [-115392], [92888], [-164144], [64226], [31800], [-117004], [-113842], [33148], [-93988], [114042], [110064], [-4752], [-159998], [28646], [175606], [-100226], [57994], [132552], [-50346], [101214], [-161218], [-112396], [-51632], [71808], [78398], [107626], [117464], [41092], [-15946], [72544], [-192572], [-46766], [-181942], [58736], [10298], [-186650], [119130], [-18500], [36848], [149176], [36850], [129904], [67660], [164916], [109800], [-31402], [-198906], [186812], [93064], [-63142], [2336], [210010], [25498], [-34272], [-112520], [-125018], [-33440], [41502], [-106748], [108486], [73442], [-147908], [145646], [-232632], [135992], [-49712], [-46880], [1976], [106074], [-241452], [-83204], [86474], [98166], [-82278], [176568], [-108818], [5512], [7750], [-62582], [-162640], [-45880], [-12482], [-12182], [94084], [81962], [-220970], [183116], [87964], [112468], [174038], [119072], [-122562], [-121858], [-31918], [-207926], [174622], [-96716], [251814], [39538], [-122400], [114208], [-22242], [-136034], [10128], [-53482], [169674], [-251166], [99058], [139794], [187302], [-296520], [19960], [-152082], [-70260], [-248304], [179244], [32832], [-161916], [11954], [-257550], [81894], [-246], [-105420], [-123552]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1472_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1472_4_a_b();".
// 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_1472_4_a_b(:prec:=1)
    chi := MakeCharacter_1472_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_1472_4_a_b();".
// 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_1472_4_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1472_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![8, 1]>],Snew);
    return Vf;
end function;