
// Make newform 5070.2.a.q in Magma, downloaded from the LMFDB on 13 October 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5070_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_5070_2_a_q();".
// 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_5070_2_a_q();".
// 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_5070_a();"
function MakeCharacter_5070_a()
    N := 5070;
    order := 1;
    char_gens := [1691, 4057, 1861];
    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_5070_a_Hecke( : Kf := Kf)
    return MakeCharacter_5070_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 := 2;
    raw_aps := [[1], [-1], [1], [-3], [1], [0], [0], [-5], [-4], [0], [10], [-1], [6], [-2], [-9], [-13], [4], [-2], [-12], [-2], [-16], [-10], [12], [1], [12], [4], [-9], [-6], [-10], [16], [5], [-15], [16], [-9], [-6], [-6], [1], [-20], [-13], [-9], [12], [6], [-18], [16], [-15], [-2], [-15], [11], [-20], [-10], [10], [-2], [15], [11], [-24], [3], [-20], [-24], [23], [10], [2], [13], [18], [-12], [-34], [19], [28], [2], [-28], [36], [-36], [34], [0], [10], [-1], [-28], [-16], [-33], [25], [17], [-28], [20], [36], [16], [-10], [-18], [-15], [22], [-12], [-16], [-36], [-8], [35], [25], [20], [-1], [18], [33], [6], [-2], [34], [-3], [24], [-11], [7], [18], [-18], [28], [-30], [-27], [37], [23], [-6], [-31], [-4], [-9], [-44], [9], [41], [4], [14], [-32], [-26], [-26], [33], [4], [4], [36], [-37], [-5], [35], [24], [44], [39], [45], [-26], [-37], [16], [-14], [-18], [33], [18], [-5], [-30], [-44], [-54], [-14], [-18], [19], [-48], [38], [5], [42], [-13], [42], [12], [34], [34], [-10], [24], [-38], [22], [7], [27], [48], [53], [38], [-7], [31], [6], [28], [-22], [-10], [-22], [-10], [41], [-16], [60], [-48], [26], [-12], [59], [-9], [48], [27], [14], [-7], [48], [-51], [-50], [34], [-48], [29], [-58], [10], [-18], [-22], [29], [52], [0], [-30], [-2], [-2], [-11], [-13], [-58], [-24], [36], [33], [-23], [4], [54], [21], [-22], [-30], [7], [-8], [-11], [-45], [-27], [40], [-50], [-45], [60], [2], [44], [-18], [-34], [-64], [-45], [-59], [-35], [12], [-51], [16], [23], [46], [-22], [57], [-62], [-18], [28], [5], [-46], [38], [36], [-56], [-7], [33], [-3], [10], [-49], [-45], [30], [-69], [-53], [-2], [26], [-49], [34], [31], [-20], [-44], [-2], [-78], [-16], [-78], [-65], [-80], [-58], [18], [16], [32], [-40], [-16], [72], [-54], [22], [34], [-12], [39], [20], [68], [-44], [-2], [-66], [-38], [61], [38], [-45], [-16], [-8], [-56], [57], [-62], [-70], [-26], [-31], [-4], [32], [-20], [-26], [60], [62], [-20], [26], [8], [-18], [-36], [-63], [5], [42], [-3], [-36], [-1], [77], [-16], [18], [66], [-46], [12], [48], [-68], [64], [-10], [6], [-28], [-10], [43], [38], [-68], [73], [16], [-72], [44], [-12], [16], [64], [13], [-55], [73], [-12], [-54], [32], [-21], [-25], [-28], [26], [-30], [17], [17], [-48], [-70], [51], [8], [86], [80], [3], [12], [-31], [25], [-57], [48], [-41], [-46], [60], [90], [43], [58], [4], [-65], [-8], [36], [-60], [34], [35], [6], [34], [85], [-88], [-18], [12], [-37], [-24], [61], [-31], [-82], [-54], [-94], [-60], [-17], [-87], [-5], [-80], [-12], [-86], [-74], [-10], [36], [30], [-22], [104], [0], [-12], [-30], [26], [-62], [-67], [-14], [-59], [66], [-25], [12], [-67], [106], [-18], [18], [-7], [74], [56], [82], [65], [-15], [-63], [76], [33], [-48], [55], [-45], [22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5070_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5070_2_a_q();".
// 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_5070_2_a_q(:prec:=1)
    chi := MakeCharacter_5070_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_5070_2_a_q();".
// 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_5070_2_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5070_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![3, 1]>,<11,R![-1, 1]>,<17,R![0, 1]>,<31,R![-10, 1]>],Snew);
    return Vf;
end function;