
// Make newform 5070.2.a.bt in Magma, downloaded from the LMFDB on 24 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_bt();".
// 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_bt();".
// 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], [1, -2, 1], [-5, 1, 0], [0, 0, 0], [1, -1, -1], [-2, 2, 3], [-5, 3, -7], [1, 6, -3], [-3, -1, 4], [-1, 4, -3], [-6, 0, -5], [0, -3, 2], [-7, -2, -2], [2, 0, 3], [-6, 7, -4], [-4, 1, 6], [-1, -1, 1], [-1, -3, 7], [9, -7, 7], [-6, 6, -5], [-1, -7, 2], [3, -7, 5], [1, 0, 3], [-4, -2, -4], [-9, 0, 0], [-8, 3, -2], [-2, 1, -5], [2, -17, 8], [4, -12, 1], [-6, 5, 0], [-16, 8, -15], [9, -12, 10], [-6, 10, -1], [-2, -3, -8], [10, 1, 3], [16, -5, -4], [7, -9, 14], [14, -9, 12], [13, -8, 14], [-1, 2, 1], [-8, 20, -13], [8, -7, 3], [-17, 7, -5], [-9, 7, 7], [-6, 14, -10], [-18, 7, -13], [-15, 4, -2], [-8, 0, 3], [-1, 10, 2], [-11, 17, -10], [2, -9, -3], [13, -13, 3], [-2, -1, 11], [9, 2, 1], [0, -3, -10], [-1, -5, -17], [2, 4, 11], [-7, -11, -1], [-1, -7, -9], [-4, 18, 0], [-4, 3, 7], [16, 5, -4], [11, -11, 14], [-10, -7, 4], [2, 6, 15], [-1, -6, 0], [2, -17, 9], [-13, 1, -6], [-20, 6, -13], [-2, -6, -17], [-5, 1, -18], [0, -16, 10], [-5, -12, 3], [14, -13, -2], [6, -3, 6], [-9, 15, 2], [1, 11, -2], [-9, 0, 0], [9, -4, -13], [-4, 14, -1], [-10, 9, 12], [4, 15, 0], [-10, 20, -15], [1, -21, 15], [-4, -1, 1], [5, -9, 17], [-8, 10, -21], [-14, 21, -16], [8, -7, 3], [13, -22, -4], [19, 5, -5], [0, 10, 20], [-30, -2, -2], [-18, 14, -23], [-14, -3, 16], [17, 7, 0], [-6, 28, 0], [25, 0, -5], [-5, 24, -5], [-2, 0, -5], [-19, -9, 4], [36, -3, 11], [32, -9, 15], [8, -4, -12], [-10, 7, -3], [-6, 8, 8], [-6, 3, 11], [26, -12, 17], [28, -13, 32], [-5, -1, -12], [-15, -2, 1], [26, -3, 13], [27, -5, -5], [22, 2, 6], [2, -20, 19], [-2, 4, -13], [-30, 12, -18], [-26, 5, -13], [14, 13, 0], [-5, -18, 2], [5, 8, 8], [10, 5, 8], [19, -12, 1], [16, -1, -4], [9, -23, -11], [-16, -21, 6], [23, -13, -1], [26, -2, 9], [-15, 17, 13], [10, -13, -8], [7, -20, -8], [16, 6, 13], [-24, 5, 0], [-11, 22, -7], [-21, 21, -34], [-31, 20, -27], [-13, 14, -9], [37, -15, 32], [16, -10, 8], [22, 13, 6], [25, -17, 22], [-10, 7, -24], [27, -11, 27], [-1, 30, -8], [-14, -17, 16], [28, 7, 2], [-14, -8, -11], [18, 9, 11], [14, -23, -9], [33, -27, 33], [-3, -25, 13], [-12, 12, -14], [13, 25, -20], [-11, -10, 12], [-33, -3, 9], [-20, -12, -7], [20, -15, 27], [-3, 4, -24], [-7, 14, -3], [-32, -2, 5], [-29, -3, 10], [-17, 24, 7], [-17, -8, 19], [26, 1, 1], [38, -5, 7], [1, -8, 5], [39, 7, -3], [-2, 13, 14], [26, -22, 7], [2, 7, 8], [-17, 10, -31], [21, -11, 11], [-19, 24, 1], [11, 11, -11], [3, 17, 19], [1, -33, 11], [3, 27, -25], [26, -24, 44], [21, 19, -7], [-3, 17, -18], [-8, -11, 26], [-43, -1, 4], [20, -23, -29], [-29, -4, -16], [-6, 8, -24], [50, -10, -9], [-19, 23, -18], [-24, 41, -21], [-3, -3, -37], [6, 20, 1], [-4, 18, -11], [9, -8, 22], [8, -8, -10], [11, 34, -21], [22, -36, 28], [13, -19, 39], [-1, -9, -11], [-19, -19, 2], [-12, 13, 14], [-11, 34, 0], [-33, 22, -24], [-6, 6, -36], [-24, 7, -25], [23, -2, 6], [2, 31, -20], [-14, 0, -23], [44, -8, 16], [20, -18, 13], [-24, 26, -42], [-21, -7, -26], [-30, 19, -16], [-10, -18, -1], [-2, -4, 6], [-36, 29, -44], [8, -13, -2], [-19, 20, -14], [19, -49, 32], [2, 15, 3], [-1, -28, 18], [-37, 2, 18], [14, -13, 30], [-15, -14, 15], [-1, -15, 10], [-3, -7, 29], [3, -3, 24], [27, 3, 34], [19, -17, -9], [13, 15, -25], [-12, -15, -19], [-3, -7, 24], [-30, 25, -7], [35, -20, 1], [-11, -2, 26], [-58, 3, -10], [-32, 24, -31], [26, 5, 13], [-16, 7, -1], [4, -17, 11], [-9, 29, 21], [-22, 31, -17], [5, -2, -18], [29, -10, 16], [-14, -18, -6], [-2, 11, -23], [-16, -9, 18], [-13, 16, 18], [-16, 27, -6], [-12, 4, 29], [6, -18, 27], [-26, -4, 5], [17, 8, 35], [-16, -33, 11], [-11, -10, -3], [-36, 5, -14], [42, -22, -2], [5, 15, 6], [-8, 15, -5], [-58, 19, -19], [-15, 17, -20], [-43, 11, 6], [-7, -32, 21], [8, -17, 18], [-34, 4, -28], [-19, 6, -22], [44, -5, -5], [-27, 10, -35], [-11, -27, 23], [-7, 27, 1], [-11, 38, -20], [10, -1, -5], [16, 2, 7], [-32, 5, -8], [17, -15, -27], [-7, -28, 26], [4, -29, 8], [46, -38, 32], [-21, 28, -45], [-30, -16, 11], [3, 4, 8], [8, -4, -28], [-8, 5, -30], [-20, 30, 7], [25, -15, -10], [-45, -19, -3], [55, -12, -14], [13, -12, 2], [-13, -18, 2], [46, -12, 9], [-38, -16, -8], [-45, -8, 9], [0, 1, -37], [6, -52, 21], [-29, -3, 3], [30, -43, -3], [10, -24, 20], [-34, -11, 7], [-52, 28, -41], [13, 10, -36], [66, -6, 23], [11, -16, 22], [-14, 30, -10], [5, -41, 33], [6, -16, 12], [10, 14, -2], [-28, 5, 4], [18, -9, 12], [-26, 50, -3], [-15, 28, -40], [-39, 5, -21], [11, 1, -31], [0, -19, -30], [42, -19, -2], [15, -5, -21], [-45, 39, -40], [-17, -8, 11], [13, 13, 38], [-21, -2, -25], [-29, 17, -36], [-7, -8, -3], [60, -26, 44], [18, -24, 17], [-10, -34, 12], [17, 21, 15], [-37, 39, -19], [66, -17, 40], [19, -11, 29], [27, -24, 20], [-22, -17, -9], [-24, 0, -25], [61, -6, -7], [-60, 18, -43], [-21, -36, 6], [52, -21, 5], [5, -1, 10], [-11, 35, -31], [-27, 16, -12], [-52, 20, 11], [39, -17, 1], [-38, 25, -13], [-1, -10, 24], [48, 7, 21], [-13, -10, 5], [22, 10, -34], [16, 21, 10], [12, 27, 17], [8, 4, -4], [-5, 45, -32], [61, -11, 32], [-39, 28, -14], [2, -8, 29], [-3, 28, -5], [24, 11, 0], [-40, -13, 6], [-2, -4, -12], [5, -21, -9], [49, -31, 37], [26, 3, 9], [-49, 41, -61], [-44, 10, -7], [-44, -24, 5], [-57, 26, -47], [-6, 9, -42], [29, -31, 48], [41, 24, -1], [-43, 18, 8], [8, 8, 39], [26, -12, 26], [28, 8, 17], [23, -9, -14], [30, -42, 43], [-35, 22, -58], [-58, 40, -66], [-8, 6, 4], [-14, 8, 31], [8, 19, 5], [-16, -38, 25], [18, -23, -2], [-33, 1, 33], [-27, 36, -34], [29, -50, 37], [-6, 22, -22], [-36, 9, 11], [-5, -44, -1], [-59, 46, -44], [30, -47, 5], [-72, 39, -53], [-15, -2, -10], [24, -28, 4], [-28, 33, 14], [-47, 10, -19], [45, -42, 22], [-45, 20, -60], [-57, 26, -9], [26, -32, 23], [-17, -6, -53], [-28, 15, -35], [-21, -10, -52], [-3, 56, -33], [-37, 22, -52], [-38, -21, -12], [-28, -2, 31], [-27, 46, -5], [11, 61, -20], [26, -24, 5], [-16, 30, 14], [-17, -1, 1], [-26, -10, 9], [12, 30, 6], [44, -22, 55], [0, -17, 21], [64, -30, 29], [33, -29, -7], [-72, -1, -16], [-16, 1, 12], [27, -10, 47], [8, 10, 15], [21, -30, -5], [-61, 19, -37], [33, -13, 24], [-54, 12, -25], [11, -23, 14], [28, 3, 27], [-27, 40, 17], [-47, 17, 7], [-52, 26, 7], [13, -6, -52], [47, -24, 52], [9, -48, 49]];
    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_bt();".
// 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_bt(: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_bt();".
// 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_bt( : 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;