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