
// Make newform 5070.2.a.bk in Magma, downloaded from the LMFDB on 19 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_bk();".
// 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_bk();".
// 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], [0, -1, -1], [5, 0, 1], [0, 0, 0], [2, -1, 2], [5, -3, 5], [2, -7, 4], [4, -3, -3], [7, -4, 3], [-2, 3, 1], [1, 5, -5], [-2, 2, 1], [5, 2, -4], [-1, 3, -3], [2, 4, 3], [-10, 6, -7], [2, -1, 0], [8, -7, 4], [-2, -7, 0], [-1, -5, -1], [3, -2, -5], [2, -5, -2], [2, -3, 3], [0, -4, 6], [-9, 0, 0], [-6, -2, -1], [-3, 5, -4], [-6, 8, 9], [3, 1, 11], [-6, 0, -5], [1, 15, -7], [-1, 10, 2], [5, 1, 9], [-6, 8, -11], [7, 3, -4], [-20, 4, -9], [7, -14, 5], [2, 12, -3], [-1, 14, -6], [-2, 1, -3], [5, -13, -7], [-5, -3, -4], [12, 5, 2], [-16, 7, -14], [4, -10, -4], [5, 13, -6], [13, 2, 2], [11, -3, 3], [-3, 2, -12], [1, 10, 7], [-5, 3, -12], [10, 3, 10], [-13, 11, -10], [8, 1, -3], [10, -10, 13], [-16, 17, -22], [-9, 11, -15], [6, 1, -12], [8, -9, 16], [4, 0, 18], [11, -7, 10], [20, -4, -1], [-3, 14, -3], [14, -4, -3], [13, -15, 21], [-1, 0, 6], [-7, 9, 8], [7, 6, -5], [7, 13, -7], [-15, 17, -23], [13, -18, 17], [-10, 10, 6], [8, -3, -9], [-16, 2, -15], [0, 6, -3], [11, -2, 17], [-3, 2, 9], [9, 0, 0], [22, -13, 17], [3, 1, 13], [22, -12, 21], [4, 0, -15], [5, -15, -5], [-14, 15, 6], [5, -1, 0], [12, -17, 8], [-13, 21, -11], [-2, 16, 5], [5, 3, 4], [-17, 4, -26], [-24, 5, 0], [-20, 20, -30], [28, 2, -4], [5, -23, 9], [30, -16, 13], [17, 0, -7], [-6, 0, -28], [-30, 5, -5], [0, -5, -19], [-3, 5, -5], [-23, 4, 5], [25, 11, -8], [17, 15, -6], [-20, 12, -16], [7, 3, 4], [14, -8, 16], [-17, 11, -14], [9, 17, -5], [-4, 32, -19], [-7, 12, -13], [16, -1, -1], [-13, -13, 10], [-32, 5, -10], [16, 6, -8], [17, -19, -1], [11, -13, 9], [-12, -18, 6], [-13, -13, 8], [-14, 0, 13], [-7, 2, 16], [-3, 8, -16], [-2, -8, 13], [-18, -1, -11], [20, -4, 5], [-20, 11, -34], [-22, 6, 15], [24, -1, 14], [-17, -9, 7], [28, -13, 30], [-18, 8, -21], [15, -8, 28], [3, 13, -19], [24, 0, 5], [4, 7, 15], [-13, 34, -13], [4, 27, -7], [-4, -9, -5], [5, 32, -17], [-8, -8, -2], [-16, -6, 19], [3, 22, -5], [-14, 24, -17], [0, 27, -16], [-7, 8, 22], [30, -16, -1], [26, 2, -9], [-3, -11, 19], [-7, -11, 20], [-23, 9, -32], [0, 33, -6], [-16, 13, 12], [2, -14, 2], [33, -20, -5], [-23, 12, -2], [-42, 9, -6], [13, 7, -19], [-7, 27, -12], [-21, 24, -20], [4, 3, 11], [-37, 5, -3], [39, -10, 7], [-24, 7, -31], [36, -19, 11], [-25, -1, 2], [31, 7, -2], [-4, 5, 3], [-42, 3, 4], [-16, 14, -27], [-19, -7, -15], [6, -8, 15], [14, -31, 21], [-10, -11, 0], [-20, 1, -25], [22, -11, 0], [16, -19, 36], [10, -11, -22], [28, -25, -2], [-18, 44, -20], [-28, 7, 12], [15, -18, 1], [-34, 26, -15], [47, -4, 3], [-49, 29, -52], [-13, -16, 20], [18, -24, 16], [-59, 9, -19], [1, 18, 5], [3, 21, 20], [34, -37, 40], [-5, -1, 21], [7, -11, -7], [13, -22, 14], [18, -10, 18], [32, -21, -13], [6, -28, -8], [-26, 39, -20], [-10, 11, -20], [-21, 2, 17], [26, -14, 27], [-11, 0, -34], [9, 24, -2], [30, -36, 30], [-1, 25, -18], [17, 6, -4], [-22, 20, 11], [9, -23, 23], [-28, -16, 8], [7, 13, 5], [18, -42, 16], [5, -26, 33], [-14, -16, -3], [9, 1, -19], [8, -6, 2], [-8, 44, -15], [10, -2, 15], [-5, -14, -6], [13, -32, -17], [1, -3, 18], [-19, 18, 10], [55, -18, 20], [16, -30, 17], [30, -15, 1], [-11, 10, 5], [-32, 29, -22], [-21, 24, -21], [-7, 34, -37], [28, -9, 26], [-38, 25, -10], [7, -19, 34], [-27, 24, -17], [23, 7, 18], [34, 1, 19], [-37, 26, -24], [48, 10, -7], [1, 31, -7], [-13, -13, 18], [-15, -1, -6], [-7, 11, 6], [30, -21, 50], [-5, -17, -14], [23, -18, 20], [-13, -16, 6], [8, 6, -24], [21, -23, 12], [34, -18, 9], [31, -18, 34], [10, 6, 21], [-41, 29, -33], [21, -27, 9], [31, -5, 1], [18, -35, 43], [-27, 11, 22], [-8, -3, 13], [22, 14, -9], [44, -2, 24], [1, -6, 21], [-3, -5, -10], [39, 19, 0], [5, -20, 3], [-49, 6, -17], [28, -21, -11], [-10, 18, -1], [6, 28, -24], [3, -22, 16], [-49, 5, -10], [-8, 35, -25], [34, -23, -4], [-8, 1, -28], [9, -20, -18], [-15, 5, -6], [-9, -7, 9], [-24, -8, 3], [44, -27, 42], [33, -26, -2], [4, -8, -21], [-14, -32, -6], [-24, 45, -17], [-41, 11, 5], [-5, 8, -12], [-36, 28, -32], [22, -30, 25], [27, -7, 37], [-35, 10, -25], [-42, -3, 22], [69, -14, 26], [-11, -2, -10], [15, -2, -16], [37, 9, 3], [-30, -8, 24], [-54, 9, -1], [-37, 37, -36], [15, -21, -31], [-32, 3, 0], [33, -3, 46], [-10, 20, 4], [-41, 7, 4], [-11, -41, 13], [-49, 36, -26], [43, 23, -17], [11, -22, 6], [-4, -10, -20], [-28, 33, 8], [-6, 12, 4], [-12, 2, 12], [-32, 4, -9], [6, 12, -3], [23, 3, 47], [25, -40, 12], [-18, -21, 16], [-42, 31, -30], [30, -30, 49], [44, -2, 21], [-36, 21, -26], [-5, -40, 1], [28, -11, 3], [25, -38, 51], [-4, 25, -27], [7, -36, 19], [-4, -3, 11], [-16, -44, 18], [1, 17, 7], [22, -12, -22], [-2, -15, 36], [-18, -19, -20], [-26, -40, 23], [10, -29, 18], [7, 20, 4], [-13, -9, 26], [-1, 25, -25], [68, -7, 13], [-17, -43, 25], [27, -6, -30], [-47, -5, -16], [5, -10, 9], [-20, 31, 4], [15, 12, 4], [63, -11, 31], [38, 1, 16], [25, 13, 12], [-25, 24, -14], [-27, -21, 28], [-18, 5, 5], [-56, 34, -24], [6, 10, -31], [-5, 17, -44], [-12, 4, 0], [-27, 32, 13], [29, 32, -21], [25, 14, 14], [27, -29, 21], [-2, 5, 23], [24, 0, -11], [-46, 6, 7], [10, -12, 16], [-14, 9, -30], [-12, -37, 6], [17, 9, -12], [-12, 61, -20], [37, 7, 3], [-49, 5, 19], [-10, -47, 21], [-36, 42, -33], [-19, 48, -17], [42, -1, -23], [51, -8, 26], [31, -39, 47], [0, 26, -14], [11, 17, -25], [37, -14, 23], [13, -43, 1], [23, -58, 36], [8, -66, 26], [-12, 4, -10], [45, -31, 39], [3, 5, -24], [41, -25, -13], [20, -2, 25], [-66, 33, -34], [-7, 34, 2], [8, -37, -13], [-16, 22, 0], [47, -11, 20], [4, 1, -45], [15, 44, 2], [-25, -5, -42], [-19, -53, 14], [5, 10, -12], [20, 4, 24], [42, -14, 47], [28, 19, -9], [-23, -22, -20], [15, -60, 40], [48, 9, 17], [3, 23, 9], [-36, 53, -59], [7, -35, 20], [31, -52, 62], [-30, 33, 23], [-15, 52, -30], [-26, -12, 33], [59, -31, 29], [22, 5, 41], [-31, 20, 41], [21, 5, 19], [30, -14, 44], [18, -1, 0], [35, -9, -1], [-6, -6, 36], [-11, 55, -33], [-21, 21, -4], [35, 29, 1], [40, -7, 36], [-56, -16, 17], [-28, 12, -13], [20, -47, 37], [-7, 15, -25], [-26, 5, -35], [-24, -37, 18], [9, 24, -11], [29, 25, -13], [3, -14, -9], [1, 27, -30], [44, -17, 57], [54, -7, 24], [-59, 7, -33], [-65, 52, -58], [5, -52, 28], [-40, 49, -1]];
    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_bk();".
// 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_bk(: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_bk();".
// 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_bk( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5070_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![7, -7, 0, 1]>,<11,R![-91, 63, -14, 1]>,<17,R![13, -4, -3, 1]>,<31,R![7, 35, -14, 1]>],Snew);
    return Vf;
end function;