
// Make newform 480.4.a.c in Magma, downloaded from the LMFDB on 03 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_480_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_480_4_a_c();".
// 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_480_4_a_c();".
// 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_480_a();"
function MakeCharacter_480_a()
    N := 480;
    order := 1;
    char_gens := [31, 421, 161, 97];
    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_480_a_Hecke( : Kf := Kf)
    return MakeCharacter_480_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], [-32], [-64], [-6], [38], [116], [120], [-122], [-164], [146], [-238], [148], [184], [470], [216], [806], [732], [-264], [-638], [-596], [884], [930], [322], [-946], [-424], [1668], [-1634], [1686], [-2640], [2536], [-634], [-2980], [-338], [428], [3010], [132], [-2176], [-2778], [3888], [1350], [4760], [1034], [-1354], [2324], [3220], [32], [3996], [-3010], [-2698], [2200], [-6174], [-4808], [3974], [-1408], [-3258], [-8612], [-4006], [6194], [-1724], [2502], [6404], [-896], [-4110], [6926], [2692], [11914], [6660], [3046], [-3522], [8656], [-936], [11578], [-9948], [-8336], [-6370], [10394], [-7470], [2810], [4320], [-15122], [12616], [15098], [2372], [36], [7330], [9642], [9654], [13960], [-9996], [8736], [-6712], [2512], [5708], [5440], [3942], [-2310], [2956], [2078], [-6164], [13526], [-276], [-774], [6676], [-11774], [12292], [7110], [-4416], [3850], [21880], [2786], [1014], [-10708], [6660], [90], [21684], [1344], [-9210], [-184], [-12866], [-26534], [30062], [-12724], [21972], [-15642], [36398], [36248], [4936], [-23838], [-31700], [13128], [15676], [-13238], [-5270], [-8526], [13606], [8836], [-29082], [26994], [9268], [6286], [-44088], [-30100], [18254], [-13008], [-16094], [-25938], [38564], [-10216], [-17006], [43898], [-29180], [14752], [12020], [18560], [10244], [1266], [47626], [31958], [-25196], [51574], [-48296], [27288], [14406], [-18952], [44308], [954], [-54094], [14702], [-15528], [38254], [-19032], [-10510], [-37620], [59922], [10892], [20830], [-21440], [67726], [-45744], [-56128], [-8294], [-62994], [-18864], [-1394], [-24006], [-372], [-21398], [-39240], [34522], [73340], [-52636], [-69018], [63996], [34126], [12098], [14890], [38454], [-11480], [-18474], [2260], [-29150], [-28798], [40496], [13726], [-10892], [-78548], [-79438], [-19236], [-42966], [26830], [35912], [34060], [10936], [-32918], [3032], [-60638], [21576], [-74922], [26638], [-34156], [67466], [-75144], [15636], [-10314], [65406], [3976], [-11904], [-46728], [51850], [-77892], [97084], [50386], [-3428], [-7584], [12418], [26094], [-44160], [18024], [-97796], [52148], [71528], [-100506], [36718], [-35144], [-94024], [-41088], [29956], [-37608], [91890], [55314], [103016], [-10422], [-22530], [-48824], [31414], [-42636], [-16746], [-10734], [-73232], [19300], [7198], [84506], [-76562], [7980], [-75690], [-17942], [-25828], [-8802], [55150], [-124364], [69298], [-131652], [131882], [-56728], [612], [4822], [32458], [-139592], [79392], [15924], [-92848], [46902], [-47436], [98680], [-43662], [109374], [74924], [66194], [26742], [63132], [-79482], [-152904], [-59302], [-40026], [26452], [71878], [138576], [4924], [-167806], [-72282], [-103708], [-79956], [-16724], [119218], [22908], [98246], [-1768], [-157718], [-169656], [121646], [-53326], [-69044], [59352], [67370], [19936], [-51008], [11818], [-60590], [-189988], [91218], [57062], [-113744], [-145122], [90898], [79196], [-30172], [115584], [-113426], [147526], [74518], [125748], [-16692], [131692], [-68868], [66142], [148238], [107210], [67440], [43802], [-135378], [-92562], [-161468], [108862], [108344], [-121042], [27676], [93888], [86422], [-60788], [103882], [-158922], [-48512], [-143202], [49302], [-153728], [-127880], [-204338], [-64512], [90346], [-182966], [-58512], [-56496], [47980], [149306], [194526], [103936], [49578], [29208], [-89420], [28704], [-40482], [16316], [-89374], [94776], [42672], [-54222], [-62142], [72170], [45222], [-28890], [126464], [-158850], [156076], [-15600], [156940], [-10310], [-53684], [7840], [62434], [192126], [141832], [247524], [-140664], [157306], [71100], [179650], [-14740], [30894], [-257730], [106974], [81536], [230566], [-182482], [-36444], [10258], [199058], [-277452], [126336], [157282], [-48546], [-139764], [-227724], [100706], [202246], [-123456], [63952], [28558], [154728], [131462], [33962], [250896], [-115880], [266130], [13278], [-90172], [-98758], [-305428], [271536]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_480_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_480_4_a_c();".
// 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_480_4_a_c(:prec:=1)
    chi := MakeCharacter_480_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_480_4_a_c();".
// 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_480_4_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_480_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![32, 1]>,<11,R![64, 1]>],Snew);
    return Vf;
end function;