
// Make newform 8670.2.a.bl in Magma, downloaded from the LMFDB on 12 March 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_8670_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_8670_2_a_bl();".
// 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_8670_2_a_bl();".
// 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, -3, 0, 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_8670_a();"
function MakeCharacter_8670_a()
    N := 8670;
    order := 1;
    char_gens := [2891, 6937, 6361];
    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_8670_a_Hecke(Kf)
    return MakeCharacter_8670_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]];
    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, 0], [0, 2, -3], [-4, 1, -1], [0, 0, 0], [1, -2, 0], [0, -1, 3], [0, -2, 2], [0, 0, 2], [1, 4, -4], [7, -2, 0], [-4, 2, -2], [-4, -1, 2], [-2, -2, -5], [0, 2, -7], [-4, 6, -6], [-2, 4, -2], [0, -8, 2], [0, -4, 4], [0, 6, -6], [2, -6, 0], [-4, 1, 2], [2, -6, 2], [10, 4, -6], [-11, 2, 0], [4, 0, -8], [-4, 4, 2], [-4, 6, 2], [-5, -2, 0], [12, 1, 5], [0, -2, 4], [9, -2, 0], [0, -4, 10], [-2, -12, 6], [-16, 3, 0], [2, -2, -4], [4, 6, 1], [2, -11, -1], [-4, 9, 5], [10, 8, -8], [8, -4, 12], [2, -6, 8], [-2, 2, -7], [2, 2, -6], [-8, -9, 0], [-14, -7, 5], [8, 4, -4], [-12, -2, -8], [-4, 8, -8], [10, 0, -2], [8, -5, 8], [-8, 10, -3], [0, 2, 2], [8, 3, -9], [-6, 12, 0], [8, 18, -10], [0, -17, 5], [22, -2, -5], [10, -6, 6], [-6, 14, 1], [2, -16, -4], [6, -16, 0], [12, -2, 6], [9, 6, -4], [-12, -1, 4], [6, 14, -6], [-6, -6, 10], [16, 16, -8], [8, 10, -8], [18, -4, -4], [-2, 12, -15], [4, -13, 16], [0, -20, 8], [5, 8, -16], [4, -14, 20], [8, -17, -3], [14, 6, -13], [8, 11, -15], [0, -1, -1], [-6, -16, 14], [10, 0, 8], [6, -2, 24], [14, 12, -4], [-10, 16, -18], [18, -4, -4], [4, 2, 8], [4, -4, 4], [-20, -9, 12], [14, 12, -4], [-16, -8, 10], [27, -2, 8], [8, -9, 2], [4, -15, 12], [-4, 9, -27], [22, -2, 6], [21, 6, -12], [-14, 2, 2], [4, -6, -2], [-10, 6, -12], [-4, 11, -6], [-14, -18, 10], [29, 6, -4], [-6, -19, 25], [10, 2, 0], [12, -20, 2], [10, -6, -14], [14, -18, 14], [20, -12, -1], [6, 3, 11], [8, -15, -8], [0, 24, -12], [-12, 9, 16], [-4, 16, -20], [32, -5, 18], [14, 2, -6], [16, 2, 13], [4, 11, -6], [23, 4, -8], [26, -6, 6], [30, 0, 2], [24, -9, 18], [10, -6, -20], [10, 25, -11], [-6, 24, -12], [-18, -14, 6], [-2, 10, -14], [14, 15, -9], [-19, -8, 0], [2, -4, 13], [-24, -6, 11], [-20, 6, 16], [8, 8, -1], [-8, 13, -22], [-4, -1, -16], [-11, 10, 20], [-4, 6, -16], [-4, -11, -10], [3, -2, -8], [20, -1, 8], [-4, -8, 12], [8, 12, -24], [-36, 12, 4], [12, -24, 10], [0, -12, 18], [40, 16, -9], [28, -6, -10], [17, -14, -4], [-24, 2, -9], [8, -5, 4], [42, -3, 3], [2, 16, -14], [-17, 8, 0], [10, 18, -6], [-18, 2, 0], [14, -10, 18], [14, -20, -12], [20, -6, 30], [0, -28, 16], [4, -10, 34], [-8, -4, -18], [15, -6, 16], [7, -8, -8], [30, 24, -18], [4, -8, 36], [-4, -28, 2], [24, 12, -19], [0, -9, 0], [37, 14, -12], [16, 11, -9], [8, 30, -6], [-22, 14, -20], [-8, -8, -8], [2, 22, -24], [10, 42, -17], [-6, 12, -17], [16, -16, 0], [-32, 15, -16], [12, 14, 8], [-13, -10, 12], [-20, -2, 9], [20, -15, 44], [22, -16, 10], [-28, 15, -13], [14, -6, 2], [32, 5, -9], [-8, 10, -24], [13, 20, -24], [-20, 18, 16], [0, -22, 0], [4, -2, -8], [34, 21, -19], [-30, -24, 10], [12, -26, 20], [-6, -14, 10], [16, -3, -16], [-28, 16, 1], [18, -24, 12], [-12, -42, 25], [12, 8, 8], [-22, -6, -4], [32, -8, 1], [12, -17, -15], [16, 23, -25], [-10, 3, -15], [22, -8, -4], [-14, 20, 20], [-30, 20, -4], [-6, 8, 11], [2, 28, -2], [16, -20, 20], [7, 14, 12], [16, 24, -14], [-24, 12, -14], [39, -8, 16], [-4, -5, -4], [-14, 10, 23], [8, 27, -33], [39, 2, -16], [2, -12, -14], [-8, -12, -16], [6, 6, -11], [16, 12, -28], [-6, -20, -16], [4, 20, 14], [14, 26, 0], [-4, 0, 8], [-12, 32, -16], [4, 7, -30], [-38, 16, -12], [-10, -36, 31], [16, -36, -6], [42, -2, -17], [-12, -12, 18], [-4, -2, -9], [0, 13, 4], [-27, -18, 24], [4, -32, -8], [12, -12, 24], [-6, -22, 22], [0, -21, 28], [-16, -40, 20], [-32, 26, -16], [-24, 12, -6], [-8, -32, 26], [-26, 12, 11], [-12, -5, -29], [8, 19, 8], [-28, -35, 17], [-24, 21, -40], [18, -1, -15], [20, -24, 12], [8, 5, 11], [30, -15, 27], [-16, -29, 15], [12, -30, -16], [22, -10, -8], [42, -2, 3], [-12, -36, 40], [-20, -11, -24], [-6, 34, 12], [-10, 8, -28], [4, -8, 7], [-2, 10, 6], [24, -31, -12], [8, -10, 40], [32, 7, 6], [-4, 32, 2], [2, -32, 36], [-50, -4, 12], [-14, -20, 24], [34, -20, 40], [-6, 6, 28], [6, -12, 42], [8, -4, -24], [-4, -22, 22], [22, 34, -30], [-11, 24, -40], [24, -30, -13], [-9, -28, 36], [-18, -2, 30], [-8, 29, -30], [6, 6, 8], [-48, 10, -32], [10, 4, 4], [-26, 18, 6], [2, 15, -35], [-16, 14, 0], [2, -25, 41], [-14, 18, 18], [-4, -10, 4], [6, -22, 14], [-4, 49, -22], [-7, 0, -44], [-60, 0, -4], [-12, 22, 2], [-14, -34, 5], [-24, -4, 20], [2, 38, -48], [-30, 28, -14], [4, -9, -6], [-38, -8, 22], [14, -26, 22], [-37, 10, -20], [20, 16, -38], [34, -10, 22], [4, -28, 16], [20, 34, -22], [-4, -31, -9], [-25, -12, -4], [-6, 14, -24], [-40, -15, -6], [-16, 20, 18], [5, -20, 36], [-4, 13, -20], [12, 9, 6], [-32, -2, 12], [-4, 8, 42], [14, 14, 1], [-2, 24, -7], [-36, -4, 24], [-12, 20, -14], [-10, 17, -19], [-14, -40, 30], [-8, 24, 5], [-46, 13, -23], [-14, -14, 4], [-37, -16, -12], [-30, -2, -29], [6, -8, 18], [8, 19, -10], [-8, -4, -8], [-22, 22, 8], [-35, 6, -36], [6, 8, 4], [-6, 0, -48], [-34, 30, -28], [-12, 32, 3], [22, -5, -13], [-17, 20, -28], [60, -14, -4], [-20, -2, -10], [4, 24, -32], [14, -15, -17], [20, -7, -11], [-8, -24, 42], [32, 12, -24], [-4, -20, 14], [14, 28, 8], [1, -10, 36], [22, -2, 0], [14, 18, 14], [16, -20, 4], [12, -8, -24], [16, -32, -8], [30, 46, -20], [-28, 17, -26], [42, 18, -26], [-32, 6, 9], [-46, -36, 16], [38, 18, -15], [-11, 16, -20], [28, -9, 19], [38, -12, 24], [-16, 42, 2], [41, 2, 0], [-44, 0, -8], [-17, -8, 20], [7, -12, 4], [-52, -8, 16], [-76, -3, 10], [0, -22, -12], [32, 24, -34], [14, -20, 52], [33, 16, 12], [-12, 8, 14], [-14, 2, 14], [-70, -2, -1], [20, 2, -18], [-10, 0, 8], [-28, 6, 12], [22, 27, -21], [4, -46, 36], [-30, 32, 3], [-8, -10, -1], [34, -2, 40], [32, -40, 15], [-24, -16, 8], [32, -21, 63], [11, 16, -44], [-30, 43, 9], [-17, 0, 4], [82, 2, -4], [-8, -14, -22], [-4, 46, -8], [-32, 8, 14], [34, -13, 29], [20, -25, 12], [0, -4, -28], [2, -38, 26], [-44, -2, 18], [6, -12, -21], [46, -18, -4], [-50, -12, -2], [14, -6, 32], [-6, 12, -4], [18, -19, 51], [8, -14, 0], [-8, 51, -38], [34, 4, 8], [13, 18, -28], [-36, 34, -38], [20, 8, -40], [26, -32, 68], [-22, -16, 6], [-46, 28, -12], [8, -11, -16], [58, -14, 4], [-48, 12, 0], [20, 28, -4], [-26, -4, -28], [32, -26, 21], [-12, 8, -64], [34, -14, -28], [-2, -6, 21], [-2, 22, -52], [-33, 10, -16], [84, 4, -8], [-10, -40, 36], [-4, 27, -15], [-44, 24, -8], [-11, 42, 16], [-19, -4, -16], [0, -36, 19], [-6, -5, 45], [-44, 3, 9], [-52, -8, 6], [12, 40, 6], [-6, -56, 46], [0, -18, 60], [10, 53, -21], [-2, 48, 4], [-6, -20, 0], [36, -29, 20], [66, -12, 24], [40, -46, -10], [0, 15, -18], [60, -3, 11], [10, 0, -24], [40, 48, -16], [32, 18, 2], [-2, 62, -40], [-3, 26, -56], [-32, -34, 18], [-20, -54, 30], [-32, -68, 44], [-40, -4, -8], [12, -29, -4], [34, 32, 12], [-2, -9, -33], [-66, -6, 16], [-60, -2, -15], [38, 32, 8], [0, 40, -22], [-30, 30, -60], [62, -8, 28], [24, -50, 18], [-22, 34, -35], [12, -20, 0], [18, -52, 13], [-4, 22, -16], [14, -4, -48], [-12, 19, -27], [-16, -31, 13], [52, 3, 1], [46, -2, 20], [34, 24, -30], [-16, 22, -1], [39, -10, 28], [40, 40, -16], [-58, -25, 29], [10, 22, -8], [0, -12, 52], [62, 32, -19], [-44, 18, 32], [-86, 10, 6], [7, -28, 60], [-7, -50, 16], [4, 20, -36], [0, 33, -40], [-8, 26, -9], [6, 20, -36], [-10, -6, 17], [-16, 25, 38], [-32, -56, 52], [-34, 16, -12], [90, 19, -11], [-34, -62, 30], [39, 26, -16], [44, -14, -8], [-2, 64, -35], [-26, -10, 0], [-68, -27, 20], [56, -27, 3], [-8, -32, 16], [-20, 8, -28], [12, 60, -14], [-16, -1, -3], [-4, 50, -42], [12, -55, 34], [-22, 42, 32], [12, -30, -4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8670_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8670_2_a_bl();".
// 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_8670_2_a_bl(:prec:=3)
    chi := MakeCharacter_8670_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(3673) - 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_8670_2_a_bl();".
// 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_8670_2_a_bl( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8670_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![1, -3, 0, 1]>,<11,R![-17, -21, 0, 1]>,<13,R![53, 45, 12, 1]>,<23,R![37, -21, 0, 1]>],Snew);
    return Vf;
end function;