
// Make newform 480.4.a.e in Magma, downloaded from the LMFDB on 28 January 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_e();".
// 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_e();".
// 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)
    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], [12], [24], [38], [-6], [-104], [-100], [230], [56], [190], [202], [148], [-124], [206], [128], [190], [204], [440], [1210], [-816], [1412], [-214], [1202], [1342], [-908], [876], [302], [-998], [-836], [1480], [1346], [-824], [-2450], [-2696], [-554], [1364], [2004], [-1546], [1072], [-3754], [-1224], [-1694], [3134], [-2560], [1856], [-1596], [3996], [-6090], [-894], [6336], [338], [4872], [-1878], [-2244], [-4314], [6392], [4398], [-7622], [-1020], [-3746], [-9700], [-4152], [6362], [10886], [-4128], [12002], [-6276], [-9362], [-838], [6896], [1132], [-12578], [-11752], [7372], [6654], [4278], [9074], [6682], [-4832], [3974], [-1112], [1106], [9280], [-7004], [-11502], [11578], [-6362], [-2892], [11036], [13664], [-4820], [-17464], [-13960], [-20388], [-12954], [-3542], [-1532], [-11826], [11260], [4374], [11604], [-7990], [26080], [13922], [-26340], [-9478], [-6528], [2090], [-8788], [-2626], [-29214], [-22984], [-4472], [-8798], [29428], [-4860], [-6570], [-26496], [-19642], [-19582], [-22914], [13764], [34688], [-17226], [-12970], [-10832], [-35588], [19238], [4072], [-31268], [28216], [-33874], [5466], [-8878], [-9538], [5404], [16326], [26202], [26208], [-1986], [5236], [26044], [21246], [17440], [33582], [-18942], [-25720], [-32436], [8646], [27442], [14116], [-4124], [-42100], [-34152], [-41984], [48434], [-25590], [-18906], [36316], [15890], [-116], [-4744], [-18374], [13036], [-15224], [-43794], [19298], [17518], [41936], [22942], [-39624], [45018], [48928], [54378], [58192], [6222], [-48940], [49246], [-28804], [23688], [9790], [-37870], [42780], [25182], [41686], [-4684], [45130], [48232], [-71342], [-26364], [-61392], [53478], [7324], [3282], [-64638], [27606], [-78102], [38460], [-18298], [62760], [-63074], [-66110], [-18816], [-21210], [-72800], [79236], [32762], [68192], [-62414], [-14002], [5508], [33356], [62416], [-24470], [-58436], [20850], [76708], [-47290], [-26426], [60400], [1554], [-53980], [-55908], [-27562], [-48862], [-32896], [61180], [19272], [19686], [-81368], [63160], [-22038], [1588], [8212], [-96174], [-80562], [22544], [-28440], [-34700], [46032], [87940], [60446], [99946], [34464], [-94948], [-22872], [34488], [42780], [-17274], [14658], [54132], [55578], [-50602], [6000], [-58346], [6380], [112350], [37402], [117332], [44732], [23126], [51462], [118842], [135448], [-111066], [55450], [114356], [-15138], [32622], [-34868], [-10870], [-28032], [56994], [75668], [-24820], [70734], [15738], [-127800], [-81076], [41224], [20276], [58518], [103308], [-101080], [-22366], [119758], [-55184], [125330], [70390], [-39300], [-26286], [149464], [-8042], [-114650], [-10376], [123182], [41424], [164556], [62314], [48630], [-137632], [-107148], [166448], [50578], [-141476], [44654], [-71904], [-53394], [-29956], [-144114], [-95390], [137492], [-40572], [-62518], [40352], [135816], [-10446], [12802], [-128960], [48538], [-126506], [-34764], [-126862], [-4846], [46856], [119780], [-148284], [-147746], [-205794], [-5562], [-91216], [-145788], [-189728], [-124308], [-63922], [-126982], [149626], [-117492], [-18370], [-82622], [-53490], [-24936], [23942], [123040], [-118490], [-18436], [57192], [63982], [-19296], [196986], [11622], [105268], [-121290], [41778], [-151440], [49704], [-77046], [-55668], [-210482], [-103062], [13780], [89760], [102012], [-3990], [127734], [-37788], [-100550], [15480], [-38952], [97740], [-102082], [-221416], [-36794], [-209440], [185144], [78658], [64226], [200650], [30966], [-76542], [-3028], [-86118], [197832], [172412], [-10040], [-30418], [-113436], [68340], [-36654], [-120802], [-172416], [-1604], [83208], [-110390], [-72736], [127642], [9680], [119246], [203918], [148026], [101644], [-178062], [38574], [-256312], [76918], [-246574], [171524], [219616], [-88238], [171278], [79972], [-47280], [46938], [-93258], [256000], [86876], [46026], [55596], [231078], [-90866], [-250396], [-122480], [290858], [-50698], [118036], [287562], [-192128], [-16400]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_480_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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