
// Make newform 720.4.a.j in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_720_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_720_4_a_j();".
// 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_720_4_a_j();".
// 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_720_a();"
function MakeCharacter_720_a()
    N := 720;
    order := 1;
    char_gens := [271, 181, 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_720_a_Hecke(Kf)
    return MakeCharacter_720_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+1)]];
    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], [4], [12], [-58], [-66], [100], [132], [90], [-152], [-34], [438], [-32], [-204], [-222], [420], [902], [1024], [432], [362], [160], [72], [-810], [1106], [258], [988], [-24], [950], [1038], [124], [132], [1254], [2860], [-750], [448], [2246], [568], [-1524], [-3702], [3180], [-2098], [4392], [-2158], [1074], [-2840], [2668], [-1772], [-2784], [350], [-1962], [-4320], [-478], [2652], [2334], [-3948], [-1590], [-4952], [1646], [1158], [-6992], [258], [8944], [1392], [-5878], [-10326], [4228], [1106], [9336], [-11770], [-8322], [10680], [5884], [-2098], [-3860], [-9588], [13410], [-13114], [5838], [9530], [7260], [12062], [-13608], [-3838], [-7400], [8352], [-10770], [-6694], [3018], [-14492], [7776], [-13680], [-7916], [13932], [8260], [-11148], [9690], [16038], [-992], [7142], [-7616], [10314], [-7128], [-2010], [23188], [22466], [22776], [21198], [15960], [5882], [-8516], [8462], [11094], [-2180], [26848], [-26322], [10168], [-23604], [-16422], [-26100], [-3058], [10802], [10674], [-28608], [2428], [6618], [20510], [31680], [-13196], [8102], [12580], [29892], [40408], [32366], [17238], [10850], [-9102], [25504], [-14166], [-33210], [-39212], [-6222], [-31172], [-264], [-29050], [-21720], [-6658], [13974], [-23780], [-12228], [11606], [32958], [-8072], [15756], [-18776], [-20568], [6280], [20430], [8906], [17418], [-2544], [-15402], [49444], [-25188], [-2946], [15012], [5128], [-49714], [-16270], [21378], [1620], [-6298], [45792], [-27958], [-35600], [-50730], [6868], [-21342], [12748], [-12010], [-2996], [25092], [67502], [-52266], [56652], [-17550], [-51514], [-49832], [3050], [30552], [-10558], [-55728], [-15332], [-56742], [8496], [22518], [2882], [-55978], [-35586], [-14268], [64650], [-3512], [25886], [75170], [-81900], [1914], [-13760], [25992], [-2490], [33508], [76706], [5778], [49948], [20616], [19080], [-1078], [-58676], [-18162], [50556], [38058], [-31618], [23560], [55710], [10708], [31296], [29390], [36678], [103680], [58564], [-81828], [-57658], [-81020], [44248], [-96522], [9808], [-61164], [-6910], [15138], [-13740], [59232], [-22488], [-26012], [101788], [26390], [101358], [73320], [36604], [1332], [32140], [91932], [-68074], [-97602], [-117684], [-19510], [90378], [-99780], [97742], [-97976], [-66846], [-69334], [-21212], [59136], [-39490], [-13018], [-63186], [-9740], [-34230], [-42], [-44192], [-34302], [-85738], [132064], [-96838], [115360], [41426], [39148], [32136], [-33850], [28682], [34932], [58812], [-25472], [-86964], [76862], [46024], [-108888], [114242], [50274], [-44120], [111630], [-120822], [11136], [-93402], [-94548], [98102], [-45510], [-100952], [151698], [-151020], [-32816], [-152998], [128874], [-37760], [-26088], [48868], [-45454], [60216], [55190], [32520], [-142018], [41052], [-51630], [84318], [-80792], [-181044], [-13990], [97500], [62712], [85922], [-69570], [80188], [72266], [-55782], [-68012], [20838], [-93598], [-133580], [117088], [-82044], [55218], [-184138], [-179526], [-24560], [47832], [87028], [33336], [-95290], [-79842], [-66838], [-15716], [-15058], [-88746], [-93630], [16528], [102138], [-6900], [-38338], [-38696], [-143448], [-164766], [-170852], [170426], [-93942], [141748], [227630], [-17562], [-87120], [123132], [-155106], [-163308], [27566], [104358], [30276], [115140], [190384], [156362], [86394], [-181172], [162842], [148932], [30460], [86652], [172530], [-173792], [203606], [-238500], [-8328], [-235678], [-179490], [-108214], [60378], [-192762], [130804], [72414], [163060], [261012], [-85592], [-130354], [52288], [20676], [32210], [-257022], [-6540], [145504], [173472], [-70198], [-122480], [89670], [85108], [160338], [119270], [12558], [187804], [-23946], [151170], [-164432], [-217594], [84078], [201688], [10140], [188882], [-9966], [-201648], [87388], [132746], [157098], [179520], [-235916], [116574], [-155628], [37530], [165326], [89556], [-170940], [57242], [-7446], [255192], [-74490], [29428], [-100440]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_720_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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