
// Make newform 8700.2.a.s in Magma, downloaded from the LMFDB on 22 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_8700_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_8700_2_a_s();".
// 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_8700_2_a_s();".
// 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_8700_a();"
function MakeCharacter_8700_a()
    N := 8700;
    order := 1;
    char_gens := [4351, 5801, 4177, 901];
    v := [1, 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_8700_a_Hecke( : Kf := Kf)
    return MakeCharacter_8700_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 := [[0], [1], [0], [3], [-6], [1], [0], [3], [-4], [1], [-7], [-10], [8], [-11], [-6], [-6], [-4], [5], [3], [-6], [10], [-4], [-6], [4], [-5], [-10], [8], [-8], [-11], [14], [16], [-14], [-2], [-4], [0], [13], [-3], [11], [-14], [-4], [-18], [5], [-8], [5], [-12], [-7], [-5], [3], [-12], [-13], [-18], [-22], [21], [0], [6], [18], [22], [0], [5], [-14], [29], [24], [15], [16], [-17], [18], [28], [7], [-10], [-30], [4], [-10], [-13], [15], [-11], [-18], [36], [-13], [32], [31], [-14], [2], [16], [-35], [15], [14], [20], [-38], [-22], [-8], [-28], [12], [25], [-36], [21], [-26], [-30], [-28], [29], [11], [-12], [-24], [44], [-22], [-7], [13], [-2], [-40], [-36], [-43], [0], [26], [-6], [-25], [31], [40], [20], [-12], [-12], [32], [-14], [34], [-38], [36], [-28], [-38], [-39], [-6], [37], [46], [-20], [-36], [-32], [23], [-42], [-7], [42], [-11], [12], [-2], [-35], [2], [45], [0], [-46], [0], [-31], [28], [8], [22], [31], [14], [-29], [0], [24], [30], [-19], [46], [7], [-20], [-26], [26], [-48], [-22], [20], [-46], [35], [14], [-39], [10], [-2], [-57], [-60], [55], [-23], [24], [21], [18], [-47], [-17], [53], [58], [41], [-6], [10], [34], [3], [-5], [3], [42], [33], [6], [17], [40], [-44], [-6], [50], [-46], [40], [10], [60], [-44], [58], [-50], [26], [14], [11], [8], [6], [-31], [-23], [48], [-67], [14], [36], [14], [47], [48], [2], [-6], [59], [-35], [46], [-32], [0], [25], [-4], [20], [39], [-38], [47], [20], [-1], [4], [-12], [34], [62], [-6], [-68], [-32], [-2], [15], [37], [-75], [-18], [0], [-51], [-70], [-29], [4], [-50], [60], [32], [11], [-30], [-24], [-33], [-40], [-44], [22], [49], [28], [-6], [41], [24], [28], [12], [46], [-60], [66], [7], [-28], [-62], [-67], [-57], [77], [50], [27], [-11], [30], [20], [16], [-12], [-53], [-77], [-64], [15], [-36], [-80], [-22], [32], [32], [24], [-40], [13], [-84], [5], [-6], [30], [44], [82], [-8], [-35], [-20], [-84], [81], [50], [33], [48], [2], [-22], [-36], [22], [-49], [-2], [-7], [50], [24], [17], [56], [-12], [31], [-38], [1], [54], [2], [85], [-15], [-34], [32], [-65], [-44], [-9], [-74], [35], [36], [-49], [-36], [63], [-32], [17], [54], [-42], [-11], [6], [-60], [-13], [-53], [-68], [-8], [85], [34], [50], [-15], [53], [-78], [-48], [-66], [86], [54], [87], [76], [-6], [38], [-20], [-7], [42], [-40], [81], [30], [59], [78], [-32], [-32], [-27], [54], [92], [-35], [-78], [37], [-52], [-26], [-16], [-46], [68], [22], [69], [-58], [20], [2], [63], [-10], [60], [57], [-90], [21], [3], [-62], [-25], [-30], [-14], [54], [3], [-42], [0], [20], [-83], [102], [103], [82], [87], [22], [32], [-35], [-5], [28], [62], [-15], [-70], [54], [-40], [17], [-92], [-64], [-34], [4], [34], [-2], [103], [-78], [-45], [-28], [-55], [50], [94], [-36], [-54], [2], [57], [-5], [12], [-42], [-86], [-32], [-37], [-62], [41], [-48], [-71], [-11], [0], [-42], [60], [18], [-98], [62], [-70], [-90], [30], [90], [-67], [-75], [-70], [-25], [-29], [-79], [64], [-32], [-72], [-75], [-67], [-22], [-68], [35], [26], [-107], [-6], [25], [-94], [76], [-49], [102], [46], [-84], [67], [58], [-17], [36], [-39], [91], [-43], [-24], [43], [42], [46], [10], [43], [-90], [111], [-73], [-32], [28], [100]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8700_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8700_2_a_s();".
// 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_8700_2_a_s(:prec:=1)
    chi := MakeCharacter_8700_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(3593) - 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_8700_2_a_s();".
// 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_8700_2_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8700_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-3, 1]>,<11,R![6, 1]>,<13,R![-1, 1]>],Snew);
    return Vf;
end function;