
// Make newform 5070.2.a.bi 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_bi();".
// 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_bi();".
// 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 := [-4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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], [1, 0], [1, 0], [1, 1], [1, -2], [0, 0], [0, 2], [-1, -1], [0, -3], [4, 1], [-2, 3], [-1, 2], [6, -4], [2, 1], [7, 0], [7, -1], [8, 1], [6, 0], [4, 4], [-10, 2], [0, -6], [10, -1], [-4, 2], [-11, 5], [-4, 2], [-12, -2], [3, -1], [2, 0], [-10, -4], [4, -3], [-7, 1], [1, 2], [4, -5], [11, -1], [-10, -5], [-6, 6], [17, 2], [-16, -1], [-5, -6], [3, -11], [-8, 3], [6, 2], [14, 2], [0, 0], [5, -5], [6, 2], [-11, 7], [7, -13], [-20, 0], [-18, 4], [-10, -3], [-2, 6], [-25, 2], [-5, 2], [-4, 1], [-13, 0], [12, -6], [4, 11], [-1, 0], [10, -4], [14, -1], [-7, -7], [10, -10], [12, -12], [22, -6], [-17, 5], [12, -12], [-6, 0], [4, 2], [-4, -8], [-4, 14], [10, -2], [0, -8], [-18, 5], [-13, 3], [8, 5], [-4, 9], [-17, 2], [5, 3], [-11, 5], [20, -8], [-20, 8], [-4, 12], [0, 12], [22, -2], [-10, 2], [-3, 11], [14, -4], [-16, 9], [8, 10], [4, 14], [-32, 4], [-1, -9], [-19, -1], [4, 0], [-29, 9], [14, -17], [-11, -3], [-22, 5], [-18, 6], [10, 10], [-7, 1], [-8, 16], [9, -11], [19, -3], [-22, 12], [-34, 4], [16, -11], [-14, 0], [5, -16], [9, -15], [23, 2], [-34, -3], [-19, 1], [-20, -4], [-13, -1], [28, 4], [21, -9], [-43, 1], [8, 9], [14, -10], [32, 4], [-34, 2], [14, -2], [-19, 1], [-16, 13], [28, -4], [20, -16], [15, -15], [31, 7], [-1, 17], [-4, -11], [-16, 5], [-5, 15], [-7, 7], [-38, -3], [7, -11], [36, 3], [10, -2], [-2, 8], [21, -17], [-10, -1], [-9, -9], [-22, 4], [28, 10], [18, -12], [-18, -13], [-14, -5], [7, -21], [4, 1], [10, 1], [-23, 1], [-2, 11], [-5, 18], [-18, 23], [-28, -6], [26, 6], [-22, 2], [22, -20], [-16, 6], [-22, 14], [34, -11], [11, -3], [-9, -3], [-28, 13], [29, -2], [26, -15], [-11, 17], [-25, 2], [-42, -4], [12, 8], [-30, 6], [6, 10], [10, 0], [2, 15], [-11, 3], [40, 2], [-20, 10], [0, -20], [-38, -8], [4, 4], [-21, -2], [-17, 4], [-12, 21], [19, 2], [10, -3], [33, 8], [44, -5], [21, -10], [-2, -18], [-22, 0], [8, -18], [-31, -1], [34, 1], [-14, -6], [38, -4], [22, -1], [37, -12], [-24, 9], [4, 13], [2, 0], [-6, 17], [30, 8], [9, -7], [-1, 9], [-34, -6], [-24, 8], [-52, 10], [-11, -15], [-27, 13], [-36, -8], [2, -3], [9, 21], [50, -10], [-14, 16], [7, -8], [-48, 6], [25, -3], [23, -23], [17, 9], [0, 20], [22, -14], [-1, -25], [60, -8], [-6, 12], [52, -2], [-14, -1], [30, -26], [-24, 6], [-13, 2], [-19, 24], [-7, -15], [-44, -4], [-55, 7], [-20, 7], [-5, -7], [50, -3], [-6, 20], [45, -13], [34, -2], [-26, -18], [-28, 18], [-47, -5], [2, 8], [14, 16], [36, 10], [-8, 8], [29, -13], [5, -29], [5, -26], [14, 5], [-13, 33], [-21, -22], [10, 19], [39, -15], [-25, 5], [30, 10], [18, -18], [19, -9], [26, -12], [11, -13], [12, -18], [-60, 4], [30, -16], [6, 1], [8, 18], [18, 8], [-5, 15], [28, -23], [-2, 14], [18, -2], [-20, 25], [-40, 16], [-36, -1], [-32, -8], [72, 0], [-6, 4], [-66, 8], [-66, -1], [-56, -7], [43, 1], [16, -17], [-16, -9], [-12, 32], [42, 13], [-18, -10], [2, 18], [17, -9], [42, 5], [23, -7], [-28, -13], [-24, 30], [20, 7], [-7, 10], [2, -20], [38, 3], [-46, 5], [77, -3], [16, 21], [-20, 5], [52, 2], [-34, -18], [-16, -7], [46, 2], [28, -20], [66, -10], [48, -22], [-50, 22], [-12, -8], [45, 1], [21, -20], [46, 15], [1, 1], [8, -21], [3, 9], [17, -39], [44, -17], [50, -8], [-30, -14], [-14, -16], [-4, 0], [-24, 12], [40, 1], [48, -12], [-18, 4], [34, 3], [60, -10], [34, -7], [-21, 8], [30, 22], [-12, 20], [13, -37], [-20, 17], [16, 24], [44, -8], [36, 14], [-48, -10], [-28, -9], [-11, -10], [5, -1], [73, 6], [28, -26], [-10, 17], [-12, -17], [7, -15], [23, -10], [12, 6], [22, -1], [-54, 24], [-19, 17], [77, -7], [-56, 0], [58, 4], [-1, 7], [24, 6], [42, 1], [-24, -8], [-5, 4], [-24, 7], [-7, -22], [37, 1], [19, -17], [44, -25], [51, 17], [74, -6], [68, 6], [-30, 2], [-25, 23], [-50, 1], [52, -16], [-37, -15], [40, -16], [-12, 26], [48, -29], [66, -16], [-49, 9], [6, -12], [-54, 10], [-31, 27], [48, 0], [-30, 19], [-12, -30], [47, -15], [36, -5], [25, -23], [-51, 23], [10, -33], [78, -3], [38, -1], [52, -4], [-21, 19], [5, -15], [19, -4], [-28, 27], [-20, 12], [-22, 40], [42, -11], [-2, -6], [-20, -10], [26, -11], [18, 6], [-4, 23], [24, 2], [-4, 10], [-22, -8], [14, 27], [34, 0], [33, 1], [6, -21], [-39, 7], [-38, 8], [-13, 29], [-4, -18], [41, -3], [26, 26], [18, 17], [42, -14], [13, 5], [-2, -19], [40, -32], [18, -44], [17, -34], [-35, 23], [17, 14], [92, -8], [-19, 9], [56, -16], [59, 1], [23, -21], [-18, -22]];
    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_bi();".
// 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_bi(:prec:=2)
    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_bi();".
// 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_bi( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5070_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-2, -3, 1]>,<11,R![-17, 0, 1]>,<17,R![-16, -2, 1]>,<31,R![-38, 1, 1]>],Snew);
    return Vf;
end function;