
// Make newform 5070.2.a.bj 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_bj();".
// 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_bj();".
// 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], [-1, 2, -3], [0, 0, 0], [2, -1, 2], [-1, -1, 1], [0, 3, 0], [-2, -3, 1], [-1, 0, 1], [0, 1, -1], [-3, -5, 3], [8, -4, 1], [-3, 4, 2], [3, 5, -5], [-4, -2, 5], [0, 4, 3], [4, -5, 6], [4, -3, 8], [0, 11, -4], [7, -3, 3], [-3, 4, 1], [-4, -3, -6], [0, 1, -3], [-12, 0, -2], [1, -4, -8], [12, -6, 3], [1, -1, 0], [-10, 4, -7], [9, -5, 5], [-4, 2, 3], [-1, 1, 7], [9, 4, 2], [-7, 1, -9], [-10, 10, 1], [15, -3, 6], [2, -2, 9], [-17, -2, -1], [16, -10, 15], [-7, 10, -12], [-10, -1, -7], [-5, -3, 3], [-1, 1, -14], [-6, -13, 8], [-6, 1, -14], [8, -6, 12], [9, -7, 2], [-11, 8, -6], [1, 1, 11], [-7, 6, -8], [-15, 10, -17], [-7, 9, 0], [-4, 9, 4], [-13, -5, 2], [14, -11, 15], [0, -22, 7], [-6, 9, -14], [-3, 5, 5], [4, -9, 12], [-6, 13, -2], [0, -20, 14], [-19, 5, -18], [-12, 8, -19], [5, -18, 7], [-24, 14, -15], [11, -5, 17], [-17, 6, -16], [11, 1, 2], [3, 0, 13], [-11, 7, 3], [-11, 9, -11], [-17, 10, 3], [-18, 14, -22], [-10, 1, -13], [0, -24, 9], [-10, 18, -1], [-5, -4, 1], [-5, 10, 13], [-33, 12, -20], [-2, 19, -17], [9, -11, 5], [6, -12, -3], [4, -6, 9], [1, 11, 15], [6, 1, -12], [1, -5, 10], [14, 5, -12], [-9, 9, -9], [2, 8, 17], [-13, 7, -26], [-17, 8, 10], [4, -19, 8], [-20, 0, -2], [20, -22, 28], [17, -9, -3], [-8, 20, -19], [-19, 8, 11], [-18, 24, -12], [6, 9, -19], [-4, 3, -5], [-21, 5, 7], [5, -10, 25], [3, -11, -18], [-9, -21, 8], [12, -12, 24], [-5, -15, 6], [18, -16, 28], [-3, -7, 14], [-19, -3, 7], [-24, -8, 7], [13, 6, 15], [-16, -7, 1], [-17, 5, -16], [6, 5, -18], [-28, 10, -12], [-3, -13, -3], [3, -27, 1], [4, -6, -18], [15, -23, 12], [-16, 2, -11], [-31, 20, -14], [-23, 24, -6], [4, -8, -17], [24, -29, 21], [-14, 4, -13], [14, 13, -4], [-2, -10, 5], [12, -11, 10], [-13, 19, 5], [16, 15, 4], [-2, 26, -17], [-19, -10, -2], [-19, 23, -27], [4, 10, -13], [-20, 17, 17], [15, -20, -15], [12, -7, -15], [4, 1, 19], [-11, 16, -3], [48, 0, -2], [14, -10, 15], [13, -34, 13], [-16, 12, -11], [22, -13, -18], [-11, 20, -6], [36, -8, 15], [-6, 26, 3], [-11, 5, -31], [3, 23, -10], [15, 1, 18], [-2, -11, -2], [34, 3, 10], [-14, 10, -14], [-7, -6, 9], [-5, 16, 22], [4, 19, 10], [33, -31, 33], [-49, 1, -10], [21, 14, -8], [6, -1, -9], [-1, -7, 21], [23, -2, 3], [12, -29, 11], [-24, -1, 5], [17, 1, -8], [-17, 7, 4], [-6, 17, -9], [18, -35, 12], [46, 8, -1], [5, -21, -1], [0, 22, 3], [-10, 27, -13], [40, -17, 8], [-18, -7, -3], [-4, -7, -16], [48, 9, -2], [-2, -1, -28], [8, 29, -14], [14, -12, -8], [-4, 11, -20], [19, -24, 31], [4, -10, -9], [-11, -8, -3], [29, 7, 10], [11, -34, 24], [-26, 4, 20], [-7, -17, 7], [3, -14, 19], [27, 25, -12], [-16, 23, -28], [37, -7, 17], [-29, 29, -13], [23, -32, 30], [-2, 14, -30], [8, 7, -5], [18, -16, -12], [30, -25, 34], [-34, 13, -12], [37, 2, 13], [24, 18, -13], [35, -10, -16], [-9, 10, 14], [-10, 8, 2], [-3, 17, -2], [-11, -18, -2], [10, -18, 3], [33, -23, 33], [-4, 4, 16], [-13, -3, -13], [14, -14, -24], [-21, 4, -9], [-10, 16, 31], [-9, -13, -3], [4, -34, 30], [-8, -4, -5], [-6, 18, -11], [31, -16, 4], [5, -8, 5], [33, -5, 22], [29, -30, 40], [-41, 8, 6], [28, -32, 43], [18, -31, 21], [13, 20, 1], [22, -7, 8], [43, 0, 15], [11, -26, 9], [-4, -27, -2], [-16, -31, 0], [-33, -1, -20], [5, -14, -25], [21, -23, -8], [-16, -21, 19], [13, -18, 6], [12, -28, 13], [-41, 29, -49], [7, -23, 10], [21, -7, -6], [15, 33, -10], [-46, 23, -32], [1, -9, -24], [-19, 2, -32], [-23, 32, 20], [-20, 18, -36], [15, -5, -4], [10, 6, -19], [-33, 22, 12], [-32, 22, -41], [43, 23, -13], [17, 13, -1], [-37, 1, 5], [-24, 7, 7], [25, 3, 2], [-8, 11, -43], [-20, -24, -11], [-4, -14, 0], [-41, 20, -3], [-5, 3, -6], [19, -41, 2], [-25, -8, 1], [31, -16, -17], [-24, -13, -17], [8, 34, 1], [-18, -32, 24], [-15, 36, 4], [-7, -3, 20], [-18, -1, -39], [0, -15, 30], [-10, 9, 2], [-27, 36, -36], [47, -11, 34], [-29, -1, -19], [0, 50, -11], [10, 33, -2], [-11, 46, -18], [-38, 40, -55], [26, -8, 10], [-32, 55, -43], [37, 11, 5], [1, 42, -22], [8, -20, 44], [22, 16, -29], [-31, -23, 1], [3, 8, 27], [30, -17, -22], [5, -32, 28], [-45, 6, -28], [7, -44, 10], [-25, -35, 21], [-6, -12, -28], [-8, 15, 5], [-39, 15, -16], [11, 9, -1], [-32, 27, -18], [5, -9, 28], [-14, -28, 8], [41, -17, 28], [-17, 3, -3], [-17, 4, 20], [1, -25, 21], [-47, 34, -32], [20, 18, 8], [12, -49, 6], [-10, -4, 36], [-4, 10, 44], [-10, -12, -29], [20, -6, -1], [-29, 39, -45], [-19, 46, -8], [40, 21, 0], [46, -7, 20], [-30, -4, -15], [-38, -4, -3], [-2, -43, 34], [-5, 24, 5], [-24, 7, -17], [5, -10, 39], [-22, 9, 23], [-17, -8, 1], [-58, 7, -19], [-40, -20, -10], [-1, -5, -25], [-2, 16, -14], [-14, 51, -12], [-6, -11, 44], [-44, -4, 21], [0, -17, 20], [33, -46, 34], [-11, -37, -2], [25, -31, 43], [36, -25, 37], [11, -49, 13], [31, -8, 10], [5, 21, -42], [-13, -16, 19], [34, -15, -30], [57, -20, 0], [-23, 35, -35], [34, -25, 36], [-45, 33, -30], [-21, 28, 2], [19, -45, -2], [-44, 41, -9], [-8, 62, -12], [-20, 12, -39], [-39, 17, -4], [4, 8, -44], [21, 20, -23], [27, -6, 11], [-39, 36, -14], [-17, 37, -23], [44, -29, -19], [-40, -8, 3], [32, -52, 57], [10, -32, -8], [38, -15, 14], [-26, 11, -12], [-43, -27, 16], [46, -27, 16], [-39, 43, -47], [-15, 45, 1], [0, 5, 23], [-18, -36, 33], [-3, 2, 9], [24, -39, 37], [-15, 20, -16], [-37, 1, 19], [32, -30, -2], [-11, 53, -33], [9, 4, 39], [15, -63, 19], [-25, 56, -24], [-24, 2, -34], [24, 24, -10], [-23, 35, 37], [45, 3, 8], [-39, -3, -13], [-68, 32, -35], [-44, 9, -22], [27, 24, 2], [84, -15, 13], [24, 38, -4], [29, -33, 16], [26, -43, -5], [-25, -18, 8], [-7, -15, 12], [-23, 37, -40], [57, -14, 6], [-32, 28, -20], [58, -30, 57], [-20, -9, 5], [-27, 34, 10], [-7, 16, 2], [-20, 17, -39], [-3, -5, 47], [-42, 3, -11], [29, -61, 14], [29, -10, 34], [32, -33, 29], [-1, 12, 8], [-6, 0, -11], [-37, 21, -11], [-26, 11, 23], [17, -14, 41], [-11, -21, -29], [30, -26, -12], [12, 25, 4], [-89, 17, -31], [-14, -38, -4], [-21, -9, -39], [33, -39, -8], [39, -7, -5], [-56, 47, -38], [-12, 22, -43], [66, -32, 5], [44, -19, 13], [35, -3, -7], [30, -41, -1], [-62, 13, -18], [-9, 2, 11], [13, -7, 13], [75, -22, 53], [-7, -23, 2], [14, -25, -21], [-36, 7, -50], [37, 3, -3], [41, 6, 12], [13, -38, -16], [8, -5, 53]];
    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_bj();".
// 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_bj(: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_bj();".
// 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_bj( : 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![-13, -15, -2, 1]>,<17,R![13, -4, -3, 1]>,<31,R![-1, 3, 4, 1]>],Snew);
    return Vf;
end function;