
// Make newform 8670.2.a.u in Magma, downloaded from the LMFDB on 28 April 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_u();".
// 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_u();".
// 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], [2], [1], [0], [-5], [0], [-4], [1], [-3], [-6], [-1], [0], [-10], [14], [-1], [13], [-12], [-6], [-8], [6], [-12], [-7], [2], [7], [-16], [-2], [8], [-21], [-10], [-8], [13], [6], [17], [3], [0], [-12], [-8], [-12], [5], [18], [3], [-18], [-20], [-9], [-24], [0], [6], [22], [16], [6], [0], [-16], [-12], [12], [-25], [7], [0], [5], [0], [8], [-28], [19], [-12], [-31], [18], [-4], [22], [34], [-24], [-17], [18], [-19], [4], [10], [-18], [-30], [13], [-18], [-33], [18], [-27], [-37], [30], [0], [38], [-12], [-33], [6], [16], [13], [4], [-1], [30], [-24], [36], [-4], [14], [41], [44], [34], [-6], [-7], [45], [-12], [-6], [2], [-23], [-11], [31], [-32], [-28], [7], [30], [-49], [-18], [10], [40], [-31], [19], [0], [14], [21], [36], [41], [24], [-13], [-7], [17], [18], [51], [-43], [18], [50], [20], [15], [-2], [30], [-35], [30], [11], [2], [-45], [-10], [37], [18], [-29], [54], [-2], [42], [52], [18], [-39], [16], [-40], [-42], [25], [-10], [-28], [22], [24], [10], [-10], [-36], [-16], [-23], [51], [22], [-46], [-51], [-6], [-9], [-57], [32], [11], [42], [-40], [41], [-36], [-20], [-1], [-44], [14], [26], [43], [36], [-25], [-18], [1], [32], [-45], [-32], [28], [-12], [-11], [34], [-58], [-42], [56], [68], [5], [-11], [10], [12], [35], [46], [44], [-31], [43], [-48], [-8], [-18], [-22], [-31], [-5], [-52], [28], [-52], [-13], [32], [66], [-57], [-32], [-43], [-66], [-16], [-13], [-10], [37], [-64], [-45], [12], [-45], [-48], [70], [-62], [0], [4], [54], [-3], [16], [-26], [56], [8], [29], [0], [19], [50], [13], [-20], [36], [19], [24], [6], [37], [33], [-30], [-47], [-72], [-24], [-59], [49], [-20], [20], [36], [8], [-9], [62], [-34], [-47], [23], [5], [30], [-49], [80], [-43], [-17], [-22], [18], [-56], [-74], [-11], [28], [-64], [26], [-48], [43], [-30], [2], [-2], [54], [38], [2], [34], [-28], [-76], [56], [61], [2], [24], [-7], [-64], [39], [-50], [42], [25], [-10], [3], [38], [84], [36], [32], [-66], [17], [38], [-50], [29], [-66], [-47], [-2], [-14], [-13], [72], [62], [20], [52], [78], [34], [-15], [-42], [0], [38], [57], [-14], [-15], [-6], [-93], [72], [-26], [-12], [-54], [-64], [78], [0], [-38], [25], [80], [-48], [20], [25], [-86], [-3], [-87], [-12], [50], [0], [6], [0], [30], [-76], [-18], [-74], [-32], [-74], [12], [-32], [21], [90], [-61], [-78], [-60], [-80], [-5], [26], [66], [-23], [-20], [19], [-68], [56], [-41], [58], [-47], [-36], [-59], [-7], [64], [-14], [-25], [4], [62], [-48], [-16], [33], [5], [84], [57], [42], [-81], [14], [-24], [80], [26], [-49], [25], [78], [-100], [-20], [-82], [28], [-70], [-39], [-85], [30], [-42], [-55], [62], [-16], [32], [-75], [72], [-20], [67], [92], [102], [36], [-29], [66], [21], [-36], [-33], [-78], [93], [-40], [-10], [-23], [52], [68], [22], [-104], [65], [40], [103], [12], [19], [-32], [-95], [-97], [-48], [42], [-78], [16], [55], [20], [35], [-42], [7], [-36], [23], [9], [-36], [-37], [-13], [-45], [97], [42], [-90], [-103], [-28], [36], [-90], [18], [-18], [-113], [-4], [35], [-10], [74], [-2], [-114], [-67], [-36], [-112], [58], [18], [-66], [-95], [-88], [2], [28], [5], [-42], [84], [2], [28], [-80], [76], [52], [-8], [79], [64], [44], [-21], [100], [-74], [56], [-54], [36], [-108], [102], [90]];
    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_u();".
// 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_u(: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_u();".
// 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_u( : 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![-2, 1]>,<13,R![-1, 1]>,<23,R![0, 1]>],Snew);
    return Vf;
end function;