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