
// Make newform 8670.2.a.b in Magma, downloaded from the LMFDB on 27 June 2026.
// 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_b();".
// 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_b();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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 := 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], [-1], [-1], [-1], [2], [1], [0], [-1], [-4], [8], [7], [3], [2], [-9], [8], [-2], [-6], [5], [-11], [8], [-2], [0], [2], [4], [3], [2], [3], [0], [10], [0], [-1], [-10], [12], [-17], [10], [1], [-13], [16], [12], [-8], [0], [-25], [-26], [9], [10], [4], [13], [-8], [-20], [6], [-6], [24], [10], [20], [0], [-28], [24], [15], [17], [-20], [-29], [16], [8], [20], [1], [-8], [13], [-10], [32], [22], [26], [0], [13], [-22], [-25], [8], [30], [18], [18], [-11], [-18], [27], [-10], [-23], [-3], [18], [24], [-2], [20], [-5], [-18], [-4], [-25], [12], [13], [38], [-16], [0], [4], [18], [-1], [4], [18], [18], [-5], [-15], [32], [6], [6], [15], [-17], [-41], [48], [20], [-25], [6], [-23], [14], [-42], [32], [-43], [49], [-12], [42], [7], [0], [43], [-8], [-1], [33], [21], [10], [45], [53], [54], [50], [-36], [9], [46], [6], [-25], [30], [41], [50], [23], [-30], [-13], [-10], [55], [-10], [-22], [54], [-28], [6], [31], [-52], [16], [18], [29], [10], [-28], [-6], [8], [-14], [-6], [-4], [56], [7], [21], [6], [-6], [-31], [-6], [-53], [-33], [24], [17], [-18], [-40], [-51], [52], [44], [-15], [8], [6], [-30], [37], [-52], [-39], [30], [59], [-20], [-25], [44], [-52], [60], [-37], [62], [30], [-58], [-60], [12], [-19], [-11], [-26], [56], [-45], [-62], [24], [69], [-7], [0], [24], [-18], [-34], [-9], [-17], [24], [8], [-48], [-41], [-40], [62], [-43], [44], [49], [-14], [0], [63], [-70], [29], [-56], [43], [36], [27], [24], [-30], [-66], [4], [-48], [10], [41], [-40], [70], [12], [-72], [-25], [-48], [-65], [34], [-11], [20], [-52], [53], [48], [30], [-17], [-25], [-2], [53], [8], [-20], [-25], [55], [68], [20], [12], [-60], [17], [-78], [18], [-31], [19], [-19], [30], [-5], [0], [-31], [-25], [-38], [-10], [-56], [30], [1], [-12], [28], [-26], [4], [43], [38], [10], [18], [-66], [-38], [-50], [58], [-28], [16], [-48], [85], [66], [-56], [7], [-76], [-67], [2], [26], [-85], [-26], [-77], [-42], [-4], [44], [-32], [42], [-7], [30], [2], [31], [78], [-13], [-70], [-62], [-49], [-12], [62], [-52], [76], [46], [-78], [-5], [-26], [-88], [-14], [19], [-2], [-51], [6], [53], [24], [22], [68], [42], [48], [58], [48], [-26], [17], [64], [-8], [60], [83], [6], [55], [-11], [-32], [-18], [-12], [-10], [16], [-14], [-76], [82], [-42], [-16], [6], [-8], [24], [51], [-78], [65], [-50], [20], [0], [-67], [-74], [18], [61], [52], [7], [0], [-4], [-11], [54], [-37], [40], [37], [73], [-48], [-46], [-103], [-32], [-42], [64], [-12], [59], [85], [-56], [-77], [-30], [85], [-70], [96], [-4], [6], [-63], [49], [-10], [60], [60], [66], [-88], [-42], [-61], [-17], [34], [78], [43], [46], [36], [-20], [43], [-36], [60], [-87], [76], [-78], [-28], [39], [-26], [5], [-12], [21], [-22], [59], [64], [-14], [-75], [28], [36], [-42], [-36], [-75], [4], [65], [-72], [-5], [-36], [-89], [-77], [-112], [-30], [22], [-68], [3], [40], [-9], [-6], [113], [72], [-59], [71], [-68], [-55], [-61], [15], [17], [-98], [62], [-59], [4], [-8], [22], [46], [18], [33], [84], [-5], [-14], [34], [-42], [50], [7], [-100], [-16], [62], [26], [114], [-109], [-48], [82], [24], [-37], [-66], [16], [70], [-36], [-36], [84], [12], [-100], [-29], [60], [-100], [-85], [-104], [-86], [-88], [10], [-44], [-44], [42], [-62]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8670_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8670_2_a_b();".
// 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_b(:prec:=1)
    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_b();".
// 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_b( : 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, 1]>,<11,R![-2, 1]>,<13,R![-1, 1]>,<23,R![4, 1]>],Snew);
    return Vf;
end function;