
// Make newform 8670.2.a.h in Magma, downloaded from the LMFDB on 24 February 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_h();".
// 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_h();".
// 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], [-3], [-6], [-7], [0], [-5], [-8], [0], [5], [-3], [10], [-5], [-12], [2], [-6], [-5], [-7], [-8], [-6], [8], [-14], [-4], [13], [-2], [-17], [4], [-2], [8], [3], [-18], [-16], [5], [-14], [-3], [3], [24], [12], [12], [0], [-7], [-6], [-9], [6], [4], [-9], [8], [-24], [6], [22], [-12], [-18], [24], [4], [-16], [4], [11], [-25], [12], [-31], [12], [32], [-12], [7], [-20], [25], [-6], [-24], [14], [-14], [-28], [23], [-14], [29], [-16], [10], [30], [-6], [29], [-22], [-37], [-26], [-15], [7], [-2], [-20], [-10], [-32], [-9], [6], [4], [-11], [8], [-1], [-22], [0], [24], [-44], [-26], [37], [-20], [30], [-26], [1], [-7], [-36], [-6], [10], [25], [-19], [-17], [-12], [-20], [-13], [18], [-29], [-38], [6], [-32], [-43], [-1], [0], [-18], [21], [-20], [-11], [36], [11], [41], [17], [-2], [39], [-11], [-30], [50], [-12], [-45], [14], [-6], [-11], [-30], [11], [-2], [7], [-42], [-51], [-26], [-13], [-10], [-10], [-10], [-36], [30], [37], [20], [40], [22], [-59], [-22], [12], [-2], [48], [6], [38], [-16], [-16], [-55], [3], [18], [-10], [9], [34], [27], [27], [16], [-5], [-38], [-32], [-35], [12], [24], [7], [8], [-54], [-22], [11], [-36], [-17], [-10], [29], [-8], [43], [-36], [40], [8], [5], [10], [18], [14], [-16], [-20], [-11], [-43], [42], [-12], [-1], [6], [36], [25], [47], [-12], [-40], [22], [-66], [41], [27], [-4], [-12], [-24], [-49], [-32], [-34], [39], [60], [-23], [18], [-4], [-61], [-50], [37], [16], [63], [-40], [39], [-32], [14], [62], [60], [-52], [-38], [69], [-16], [14], [-56], [76], [61], [-16], [19], [-22], [37], [-24], [48], [35], [64], [-34], [41], [-75], [18], [-3], [0], [-20], [17], [-55], [-32], [-20], [64], [12], [-69], [2], [-50], [-43], [-29], [41], [-42], [7], [60], [25], [-25], [-54], [6], [-8], [-54], [49], [-52], [32], [-14], [-56], [-1], [54], [-62], [70], [-30], [42], [50], [-54], [-36], [12], [-12], [1], [34], [-80], [-83], [0], [-81], [-50], [-70], [61], [50], [-21], [14], [56], [-4], [-72], [14], [-23], [-50], [22], [17], [-70], [-79], [-58], [-78], [-29], [-80], [-2], [4], [-52], [30], [-66], [69], [-58], [-72], [-66], [33], [82], [-11], [14], [27], [16], [-10], [-84], [-42], [8], [2], [-12], [-38], [-19], [36], [56], [-4], [-3], [50], [-27], [-27], [-72], [-30], [12], [74], [-92], [30], [24], [-10], [34], [40], [38], [-12], [56], [-83], [-10], [19], [-66], [-8], [-56], [-29], [98], [-18], [37], [64], [-65], [4], [24], [-25], [42], [73], [44], [1], [41], [-56], [66], [-41], [36], [58], [-24], [76], [21], [25], [60], [49], [-30], [-77], [74], [48], [60], [42], [35], [1], [2], [-92], [0], [62], [-12], [-54], [-55], [63], [94], [-66], [1], [6], [56], [-96], [-27], [-84], [32], [-41], [84], [66], [76], [11], [-14], [-27], [-20], [31], [42], [-51], [48], [-18], [-11], [76], [-68], [6], [72], [101], [-24], [55], [8], [47], [-12], [-71], [-61], [88], [-18], [78], [-76], [83], [-12], [7], [66], [71], [48], [79], [-75], [52], [-25], [-25], [63], [-11], [-6], [-50], [-95], [-44], [28], [-26], [18], [-2], [-49], [48], [7], [-82], [-78], [-58], [102], [-103], [-48], [-88], [-98], [-6], [-50], [89], [8], [-38], [24], [101], [-78], [-8], [2], [100], [68], [116], [-28], [12], [23], [84], [28], [99], [108], [54], [32], [42], [44], [76], [-62], [-78]];
    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_h();".
// 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_h(: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_h();".
// 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_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8670_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![3, 1]>,<11,R![6, 1]>,<13,R![7, 1]>,<23,R![8, 1]>],Snew);
    return Vf;
end function;