
// Make newform 2070.2.a.e in Magma, downloaded from the LMFDB on 19 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_2_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_2_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 := 2;
    raw_aps := [[-1], [0], [1], [-2], [2], [-6], [4], [0], [-1], [-2], [0], [-8], [6], [-4], [0], [-6], [0], [-8], [-4], [-16], [6], [14], [-14], [8], [-6], [-6], [-2], [18], [-4], [-12], [0], [-12], [8], [-4], [-10], [12], [-16], [-4], [0], [-18], [20], [-12], [0], [-2], [-6], [-2], [-20], [-16], [18], [-20], [26], [-16], [-14], [-6], [-14], [-4], [18], [20], [-10], [-8], [-16], [10], [28], [32], [-34], [22], [20], [-34], [8], [-6], [-26], [-24], [10], [32], [16], [12], [-10], [-22], [24], [38], [14], [0], [36], [30], [32], [-4], [22], [18], [10], [-36], [30], [-8], [12], [12], [-28], [-4], [14], [4], [4], [26], [12], [22], [10], [-24], [12], [2], [-8], [-30], [24], [-22], [40], [-4], [-28], [0], [-22], [-16], [-28], [24], [-22], [-6], [0], [42], [-2], [-48], [28], [-30], [16], [-24], [38], [36], [12], [-4], [-50], [40], [10], [6], [18], [-4], [46], [18], [-44], [10], [-4], [22], [-38], [20], [26], [-30], [-12], [-24], [-2], [56], [-36], [-48], [-24], [-36], [-2], [-18], [42], [22], [-8], [-44], [52], [46], [-24], [12], [-32], [-2], [-14], [-30], [50], [-22], [-12], [22], [-52], [-60], [-52], [-26], [54], [-60], [52], [42], [38], [6], [28], [-18], [2], [-44], [-10], [-24], [-34], [-8], [12], [-50], [2], [16], [-54], [-44], [48], [48], [-10], [68], [22], [-58], [-22], [-42], [26], [36], [-26], [44], [-66], [-10], [34], [-50], [48], [54], [-72], [-14], [24], [-34], [-50], [30], [-54], [38], [28], [-10], [-12], [48], [-22], [-64], [-26], [0], [14], [34], [-8], [-12], [-14], [54], [4], [24], [66], [-12], [-36], [70], [10], [8], [-8], [-42], [16], [32], [72], [-12], [-12], [30], [78], [24], [52], [36], [26], [-42], [14], [-38], [-38], [-4], [58], [-16], [-66], [-4], [8], [-54], [50], [-52], [62], [-50], [-30], [52], [60], [-50], [-30], [-46], [-16], [-46], [-40], [32], [20], [-48], [-46], [-42], [-64], [82], [-42], [10], [70], [14], [14], [-2], [34], [-6], [-24], [-28], [70], [22], [-38], [-76], [-32], [-18], [12], [-60], [28], [2], [-80], [-6], [-52], [-44], [-36], [86], [-48], [0], [70], [70], [28], [78], [-42], [16], [60], [34], [36], [-36], [-24], [-42], [-30], [-6], [-32], [-48], [-32], [-8], [-12], [76], [-90], [70], [-14], [76], [-18], [-14], [50], [-24], [-66], [-20], [36], [-86], [-28], [-38], [66], [-46], [-16], [-2], [-12], [-78], [22], [32], [76], [-6], [-96], [-2], [-28], [-50], [62], [-94], [-34], [-68], [-52], [-24], [-30], [50], [-70], [-44], [28], [34], [-44], [-58], [-10], [-96], [-72], [2], [48], [-48], [60], [38], [-68], [-68], [14], [-70], [-72], [-20], [-12], [-78], [-10], [-36], [60], [54], [-82], [94], [42], [12], [46], [-76], [-72], [50], [24], [20], [34], [-42], [-14], [28], [46], [62], [-88], [4], [104], [-64], [70], [-56], [96], [56], [74], [-14], [74], [54], [28], [104]];
    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_2_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_2_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, 2));
    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_2_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_2_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2070_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![2, 1]>,<11,R![-2, 1]>,<13,R![6, 1]>,<17,R![-4, 1]>,<29,R![2, 1]>],Snew);
    return Vf;
end function;