
// Make newform 2070.4.a.e in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2070_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_2070_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_2070_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_2070_a();"
function MakeCharacter_2070_a()
    N := 2070;
    order := 1;
    char_gens := [461, 1657, 1891];
    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_2070_a_Hecke(Kf)
    return MakeCharacter_2070_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 := [[-2], [0], [5], [-18], [32], [-47], [-20], [36], [23], [27], [-33], [56], [157], [18], [-65], [14], [744], [552], [-156], [-699], [-609], [-644], [-512], [102], [578], [6], [-160], [-380], [250], [390], [-769], [213], [-2836], [-1631], [1966], [35], [1702], [-2045], [-1016], [-598], [4607], [-1212], [1058], [1047], [-251], [-3508], [-3296], [-2720], [4134], [-4510], [5003], [6309], [3038], [1332], [-3301], [-2072], [-5721], [-5900], [6371], [-3190], [-4226], [-6048], [8628], [-8247], [2620], [-9906], [-8115], [-7586], [-1356], [6649], [-10691], [6420], [-524], [5566], [2240], [-8778], [-4056], [-9151], [-15930], [-5891], [-15282], [-10934], [2794], [-15062], [261], [7083], [10370], [-10496], [-18021], [-17188], [15246], [8556], [-1805], [-5245], [9027], [-3522], [-3949], [-3236], [12394], [-7159], [-19761], [-18010], [2648], [1566], [2864], [-929], [19499], [-6570], [-1880], [3701], [-3080], [24004], [-780], [21892], [8050], [25890], [4774], [-3349], [-24813], [-18180], [-29250], [-23027], [-20106], [18745], [24424], [27278], [12214], [-12932], [10046], [-5924], [829], [-7072], [16234], [9128], [-165], [-20834], [31782], [33104], [-4736], [7470], [19919], [22694], [-31907], [15236], [27286], [-23054], [-34506], [22263], [12851], [-15723], [-886], [37120], [-7524], [-9221], [29116], [-11440], [2958], [-20907], [9748], [-19624], [41859], [-29226], [-29849], [9390], [-33536], [-28994], [11272], [61186], [-23172], [5651], [29844], [32253], [51684], [14464], [-34455], [57722], [20165], [-13187], [-31952], [60652], [44435], [-9882], [3743], [31554], [-18086], [-20940], [54778], [-11288], [27905], [-55120], [-4343], [-58256], [33434], [-23850], [22954], [57546], [3632], [-62448], [58868], [14553], [1340], [-46480], [-37233], [-30772], [-18816], [-24307], [42140], [63019], [34881], [1673], [8237], [22989], [-69070], [85010], [-22332], [-79230], [-9803], [64395], [77126], [32827], [59715], [-25720], [17335], [-79042], [-6057], [3983], [-59252], [36175], [-25786], [76572], [-40326], [7630], [-42094], [-2026], [-81436], [104418], [102788], [-85128], [59597], [49271], [-87144], [71615], [-24479], [-38985], [-57866], [-82103], [-15083], [4254], [-24002], [-210], [-15856], [-77550], [61106], [33494], [-77670], [-62925], [-28560], [44290], [-29151], [-49969], [-14180], [48890], [61766], [29594], [-119586], [-83068], [-14120], [-14734], [-89028], [-22735], [26293], [-4930], [62314], [-125926], [40419], [143489], [53268], [95174], [-150298], [-37840], [-59175], [112682], [49028], [-47862], [146944], [70488], [130578], [-26996], [-1652], [98766], [-44962], [80752], [18774], [55608], [-134093], [32826], [6500], [-141], [129307], [27223], [-66706], [155468], [-104304], [97269], [-63692], [-86371], [-81484], [5272], [77154], [62114], [49343], [15328], [-117676], [-20765], [23116], [-116222], [106503], [-76531], [-109508], [-80719], [108082], [-134686], [147293], [113472], [-15606], [7448], [-67918], [-29957], [-52480], [-16480], [-108655], [138875], [-132851], [-146751], [138636], [28873], [-96298], [34842], [-8161], [-10310], [36557], [-49290], [88238], [175998], [171910], [38092], [-30265], [-14008], [182038], [65610], [-15373], [-65589], [-166702], [139362], [-192324], [180226], [-58372], [-51646], [-129351], [135384], [842], [-44769], [55073], [53870], [212799], [101111], [-96465], [116552], [241394], [-237881], [168596], [-11205], [-133340], [-85672], [30213], [-38265], [153372], [116298], [206380], [4849], [117782], [115968], [179536], [-150513], [-56782], [-129059], [-44911], [-155334], [23906], [43356], [-163924], [13502], [142825], [1916], [-218154], [144962], [148274], [90758], [-215984], [276806], [-10617], [113069], [-223302], [-268836], [31201], [-204281], [43980], [-281609], [24086], [-108772], [-211163], [185635], [-46436], [73534], [-45308], [65127], [-5440], [41480], [-121442], [-55878], [57634], [-156194], [-197744], [-15804], [290691], [-219961], [-146152], [-122766], [-267025], [-148359]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2070_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2070_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_2070_4_a_e(:prec:=1)
    chi := MakeCharacter_2070_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_2070_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_2070_4_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2070_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![18, 1]>,<11,R![-32, 1]>,<17,R![20, 1]>],Snew);
    return Vf;
end function;