
// Make newform 5070.2.a.bx in Magma, downloaded from the LMFDB on 27 April 2024.
// 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_bx();".
// 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_bx();".
// 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
        poly := [1, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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)
    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+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, 0], [1, 0, 0], [1, 0, 0], [-3, -1, 0], [-2, -1, 1], [0, 0, 0], [-4, 4, -5], [-4, 3, 2], [-4, 2, -1], [3, -3, 6], [-6, 1, -1], [-1, -5, 2], [-2, 3, 2], [-1, -3, -3], [3, -8, 4], [-4, -3, 2], [-9, 7, -9], [3, 3, 1], [-8, 6, -3], [-4, -4, -3], [-4, 2, -11], [0, -3, 0], [-6, 3, -3], [2, 2, 9], [1, -5, -8], [2, -14, 6], [1, 2, 6], [7, -3, -5], [11, -10, 9], [-1, -3, 5], [6, -3, 4], [-5, -1, 3], [2, 5, -8], [-1, -6, -4], [0, -3, -10], [1, -7, 9], [3, -4, 11], [-13, 7, 5], [2, 1, -1], [-11, -1, -7], [15, -8, 12], [9, 3, 0], [0, -5, 4], [5, -2, 15], [0, 12, -5], [8, 10, -1], [4, 0, 2], [-15, 2, -7], [9, -4, 18], [12, -1, -6], [-3, 6, -8], [-22, 9, -7], [3, 16, -11], [-6, 6, 3], [-3, 10, -11], [7, -9, 14], [-7, 13, 5], [-16, 6, -7], [0, -19, 8], [12, -16, 5], [10, 2, -3], [-14, 6, -2], [-11, 16, -5], [-5, 17, -17], [-12, 15, -3], [-7, 15, -11], [0, -13, 10], [-3, 22, -8], [23, -12, 19], [-2, 11, 3], [24, 1, 2], [-20, -1, -10], [-14, 1, -9], [-4, 6, -4], [3, -7, 20], [5, 13, 1], [11, -3, 5], [-16, 7, -7], [10, -3, 5], [9, 0, 20], [27, -7, 10], [14, -15, -12], [19, -1, 13], [3, -21, 17], [-10, 1, -18], [-16, 0, -3], [-17, -10, -1], [-22, 22, -17], [2, 5, -10], [-7, 15, -5], [7, 0, -7], [-9, -10, 10], [-16, -6, -3], [18, -6, 2], [-20, 16, -22], [-2, 27, -4], [-19, 5, -25], [10, -7, 3], [-30, 4, 0], [3, 17, 6], [3, -5, 8], [8, -9, 10], [-2, -15, -3], [-13, 2, -9], [-15, 26, -7], [-28, 0, 0], [17, -8, -19], [6, 8, -4], [-9, 26, -23], [-18, 15, -28], [-13, 7, -9], [-8, -11, 9], [15, 13, -4], [3, -22, 9], [16, -18, 1], [-4, 24, -18], [16, 1, 14], [8, -29, 14], [-10, -6, 8], [39, -6, 17], [-13, 15, -13], [-27, -4, 8], [21, -8, 14], [-7, 7, 15], [3, -9, -4], [15, -11, -9], [-4, 2, 17], [-19, -7, -7], [2, -28, 1], [6, -25, -2], [-34, -2, 9], [-3, 15, -3], [-7, 6, -20], [0, -11, 2], [-3, -9, -13], [13, -25, -14], [12, -27, 7], [-17, -1, -8], [19, -9, -14], [0, -1, -19], [14, -18, 22], [13, 3, 15], [6, -13, 5], [7, -3, 21], [-22, 12, -21], [-31, 18, 2], [13, 23, -5], [33, -21, 37], [6, -35, 12], [-15, 2, -27], [-11, 24, 1], [-4, 34, -9], [-42, -2, 3], [-8, 26, -12], [-34, 11, -5], [33, -18, 18], [-26, -2, -7], [-8, -11, 10], [31, -6, 25], [35, -32, 32], [9, 3, -16], [-4, -27, 2], [22, 3, -11], [-15, 1, -30], [7, 1, 2], [45, -8, 5], [1, -16, 31], [23, -11, -6], [-2, -24, 5], [-25, -1, 15], [12, 3, 0], [25, -19, -15], [-13, 19, -34], [12, 10, 1], [-17, 11, 22], [-36, 12, 1], [8, 12, -23], [44, -10, 13], [-10, 0, 1], [-18, 8, 24], [-4, -30, 23], [32, -1, 19], [-25, 33, -17], [22, -7, 5], [35, -14, 37], [-17, -12, 12], [6, 20, 4], [-10, 51, -24], [-4, -19, 5], [21, -28, -3], [-36, 18, 11], [-8, 35, -4], [-2, -9, 10], [-5, -10, 20], [16, -14, 4], [-33, 21, -32], [30, 4, 0], [6, -2, 21], [6, 10, 1], [-26, 25, -25], [31, -17, -21], [17, -48, 30], [3, 8, 24], [24, 14, 10], [9, 8, 1], [-23, 16, -8], [-17, 35, -37], [-12, -19, 24], [-28, 16, -8], [-2, 27, -30], [26, -16, 6], [0, 9, 5], [-23, 23, -17], [22, -9, 42], [30, -6, -16], [-37, 1, -1], [-17, -3, 15], [25, -12, 36], [-18, -17, -1], [-47, 16, -3], [-45, 32, -44], [25, -14, 14], [25, -13, 25], [13, -27, 4], [-42, 25, -25], [-44, 2, -13], [2, -19, 5], [6, 13, 9], [-62, 12, -15], [-10, -26, 5], [-19, -6, -1], [10, -15, 19], [17, -24, 39], [-21, 21, -6], [-19, -8, 0], [-3, 25, 9], [-8, -11, 16], [-33, -12, 15], [-29, 44, -25], [5, -26, 21], [44, -4, -7], [-29, 6, 13], [17, -46, 36], [-7, 24, 22], [-4, -24, 34], [-29, 36, -31], [21, 27, -7], [23, 0, 12], [-9, 27, -1], [-14, 5, -18], [10, 17, 18], [-26, 25, -14], [-5, -27, -4], [7, -2, -1], [5, -7, -18], [43, -5, -7], [-32, -16, 2], [-64, 17, -37], [1, -28, 31], [25, -10, 9], [-12, -5, 11], [-38, 7, -15], [47, -13, -10], [-43, 19, -43], [2, -4, -8], [-3, 8, -18], [21, -10, -19], [-7, 17, 4], [40, -6, 35], [-10, -22, 17], [15, -36, 42], [-25, 32, -25], [-48, 25, -20], [-23, -9, 3], [16, -4, -25], [-23, -8, -22], [5, 33, -3], [52, -14, 22], [-7, -1, 32], [18, 7, -14], [21, 24, -10], [-48, 28, -36], [-1, 37, -35], [26, -27, 28], [42, -9, -11], [-4, -14, -25], [-61, 10, -30], [11, -26, -18], [-59, 10, -6], [66, -33, 54], [50, -8, -4], [23, -5, 10], [-65, -12, 1], [-34, 15, -46], [-28, 22, -39], [43, -22, 41], [-38, 8, -4], [53, -38, 45], [-20, -5, -10], [3, -10, -4], [-2, -25, -4], [53, -30, 50], [48, -4, -6], [-28, -14, 9], [-6, 28, -28], [20, -40, 30], [9, 5, 5], [7, -1, -13], [12, 13, 38], [-59, 18, -18], [28, 10, -15], [-12, 10, 15], [-13, -1, -19], [-39, 17, 13], [-12, -24, 9], [70, 5, 7], [11, -33, 34], [18, -15, -7], [-27, -11, 22], [34, 3, -7], [47, -11, 16], [-10, 38, -34], [6, -5, 32], [-40, 10, -2], [-30, 30, -17], [34, -32, 7], [-39, -15, -1], [30, -48, 43], [-31, 36, -22], [-5, 20, -33], [4, 35, -2], [57, -35, 42], [18, -9, 0], [-5, -16, 10], [31, -16, 39], [-14, -19, 31], [-30, 48, -41], [-49, 6, 2], [0, -29, -20], [-14, 58, -23], [-27, 0, 25], [1, 36, 20], [-3, 16, -23], [-9, 5, 20], [4, -32, 18], [-15, 17, -29], [33, -30, -11], [20, 36, -16], [-28, 11, -51], [-22, -3, -19], [21, 6, 44], [-16, 5, -6], [-13, -21, 4], [-1, -1, -1], [45, -31, 47], [42, -36, 20], [-16, 18, 27], [-24, 6, -41], [17, 20, 25], [-30, -18, 7], [12, 3, -34], [28, 23, -22], [5, -1, 18], [-19, -25, 13], [-2, -13, -37], [-25, 37, -16], [-63, 14, -20], [30, -11, -28], [26, -18, -32], [-8, -35, -18], [-46, -7, -3], [10, -5, 28], [-33, 36, -18], [-66, 18, -20], [18, -26, 34], [-38, 21, -14], [-23, 20, 41], [-4, -37, 8], [37, -29, 37], [54, 12, 7], [-33, -18, 4], [-45, 9, -36], [-4, 12, -46], [-5, 4, -15], [19, 1, 16], [-53, -2, -20], [-11, 4, -1], [15, -14, 5], [39, -24, 0], [-8, -28, -20], [27, -37, 55], [-9, 23, 22], [-37, 34, -10], [-71, 8, -2], [5, 35, 14], [-12, -31, 22], [-23, 41, 12], [-47, 14, -27], [3, -2, 2], [-1, 51, -20], [15, -12, -6], [31, -31, 41], [-44, 43, -46], [-13, 35, -20], [8, -3, 31], [-14, 13, -10], [46, -24, 42], [44, -40, 35], [14, -31, 48], [34, -40, 22], [32, -25, 28], [21, 22, -21], [-44, 11, -46], [12, -4, 33], [-49, 19, -55], [-7, -25, 1], [29, -37, 54], [-4, -11, 30], [19, 23, 8], [-12, -20, -17], [-24, -35, -13], [0, -57, 20], [-28, -33, 5], [-41, 44, -45], [9, -35, 20], [-84, 26, -35], [-12, 9, -6], [-3, 0, -46], [-65, 12, 8], [-17, -31, 24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5070_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5070_2_a_bx();".
// 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_bx(:prec:=3)
    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_bx();".
// 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_bx( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5070_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![29, 31, 10, 1]>,<11,R![13, 19, 8, 1]>,<17,R![-139, -46, 3, 1]>,<31,R![139, 83, 16, 1]>],Snew);
    return Vf;
end function;