
// Make newform 10000.2.a.ba in Magma, downloaded from the LMFDB on 01 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_10000_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_10000_2_a_ba();".
// 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_10000_2_a_ba();".
// 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 := [16, 4, -9, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, -5, -1, 1], [-5, -1, 1, 0]];
    Rf_basisdens := [1, 1, 4, 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_10000_a();"
function MakeCharacter_10000_a()
    N := 10000;
    order := 1;
    char_gens := [8751, 2501, 9377];
    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_10000_a_Hecke(Kf)
    return MakeCharacter_10000_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, 0, 0, 0], [1, -1, 0, 0], [0, 0, 0, 0], [0, 0, 1, 0], [3, -1, 0, 0], [1, 0, 0, 0], [2, -1, 1, 0], [4, -1, 2, 0], [0, 2, 1, -1], [0, 0, 2, -1], [0, 2, -2, 3], [2, -3, 3, 0], [-2, -2, -2, -2], [3, -1, 1, -1], [4, 1, 0, 3], [4, 2, -2, 3], [-5, 0, -2, -2], [-2, 3, 2, 3], [1, 2, 0, 0], [5, -2, 7, -2], [1, -3, 2, -3], [-3, 0, 0, -4], [-5, 1, -9, 3], [2, -3, 8, 0], [9, 1, -2, 0], [-7, 2, -4, 4], [-8, -1, -4, -3], [4, -3, 8, 1], [7, -1, 8, 0], [2, 3, -1, 1], [-1, 4, -11, 3], [-2, 4, 6, 3], [3, -4, 6, -1], [-7, 0, 2, -3], [1, -6, 1, -3], [6, 1, -7, 1], [-4, 1, -1, -2], [10, 0, 3, -2], [3, 0, -2, 2], [-4, 4, -6, 1], [-4, -1, -11, -3], [-7, 6, -5, 0], [-8, -3, 5, 0], [-12, -2, -10, 3], [-6, 8, -12, 0], [17, 0, 1, -3], [10, 5, -5, 3], [10, -2, 7, -5], [17, 1, 5, -4], [-2, 3, -5, -3], [0, 7, 2, 1], [6, -2, 2, 2], [-15, -1, -6, -3], [-3, 4, 4, 2], [10, 2, 0, 1], [-1, 2, 5, -1], [-9, -1, -1, 2], [22, -3, 5, 3], [11, -2, 8, 4], [-9, 4, -8, -4], [-4, -3, -7, -3], [-8, -2, -15, -1], [5, -6, -1, 2], [13, 6, -1, 3], [15, 6, -1, 0], [12, 0, 13, 0], [-6, -7, -1, -1], [-9, 3, 9, 0], [1, -2, -6, -7], [-3, -10, 12, -7], [7, -5, 3, -9], [-6, 1, -13, 3], [-2, -4, -4, 3], [5, 8, -9, 8], [7, -3, 1, -1], [-2, -6, 3, -2], [4, 6, 13, 3], [16, 4, 8, -6], [-7, -4, 9, -7], [-8, -4, 2, -8], [1, 4, -4, 2], [-9, 8, -10, 5], [8, -8, 0, -1], [-8, 10, -3, 2], [12, 2, 7, 5], [0, 0, 6, -9], [8, 5, 1, 3], [-5, 4, -4, 8], [18, -4, 5, 0], [-2, 0, -1, 4], [26, -1, 8, 2], [5, -5, 3, -9], [19, 2, 20, 5], [-20, 10, -14, -4], [-6, 5, -15, 0], [6, -1, -13, 0], [-12, 12, -5, -1], [19, 0, 0, 8], [11, -5, 19, -2], [-16, 8, -2, 3], [-3, -10, -2, -6], [26, 1, 18, 1], [15, 2, -4, -1], [-1, 10, -12, 11], [12, 11, 5, -3], [6, -1, 3, -10], [-20, 7, -8, 3], [9, 2, -14, 1], [3, 7, 7, 5], [1, 1, -3, 2], [23, -3, 19, 8], [16, -4, -2, -3], [2, -4, -7, -2], [15, -2, 20, 7], [-9, 4, -34, 3], [2, 0, 6, -10], [-3, -2, -6, -7], [12, -3, 11, -5], [-3, 12, -19, 6], [0, 13, 10, 2], [3, 13, 5, 2], [16, -11, -5, -8], [8, -8, -3, -4], [12, 7, 16, -5], [-2, 7, -3, -8], [7, 10, 10, 0], [-17, 2, -12, 5], [-18, -7, -14, 4], [-9, -5, 12, -1], [-7, -2, 6, -4], [-11, 6, -12, 12], [-28, -1, -12, -2], [-13, 3, -26, 2], [-18, 3, -11, 8], [-14, 12, -11, -5], [9, 12, -10, 13], [31, -8, 16, 7], [1, 16, 2, 2], [-27, -1, -8, -10], [10, -6, -3, 4], [1, -14, 14, -6], [25, 3, 21, 4], [-29, 2, -10, -3], [6, 12, 6, 11], [-27, 5, -11, -8], [7, 7, 30, 3], [7, 8, 3, 1], [-14, 4, -2, 5], [42, -3, 19, 3], [13, -10, 16, 4], [-7, 2, -3, -12], [-12, -11, 8, -5], [19, 10, 0, -2], [-16, 8, -6, 7], [-8, 7, -22, -2], [18, -19, 1, -1], [-12, 5, -3, 11], [-28, 7, -21, 5], [6, -5, 3, -6], [9, 8, 14, 5], [-2, 1, -19, 3], [-14, 0, 5, -1], [-21, 14, 2, 3], [-4, 6, -1, 14], [-4, -1, -9, -13], [-17, 5, 3, 11], [7, 11, 3, 5], [2, 5, 30, 0], [-18, -5, -3, -1], [9, 4, 27, -4], [-9, -5, -14, -4], [-16, 10, -20, 3], [-3, 18, -12, -3], [-26, 6, -14, -5], [14, 8, 4, -4], [31, 1, 16, -9], [2, -3, -8, 12], [-5, 8, -36, 6], [-32, -3, 17, -3], [2, 12, -21, -2], [23, -3, 33, -5], [-36, 8, -22, -5], [-14, -5, 24, -3], [-23, -2, 11, -5], [-20, 2, -14, -2], [-25, 4, -12, -11], [-32, 4, 5, -5], [-24, -1, 6, 6], [13, -11, -18, -5], [10, 11, -5, 8], [-16, 3, -26, 7], [5, 13, -11, 3], [13, -9, -13, -10], [-21, 9, -12, 9], [-12, -3, -33, -4], [46, -11, 9, 1], [9, 12, 18, -4], [-25, 1, -28, -2], [-6, 7, -3, -1], [26, -12, -14, -10], [2, -3, 10, 4], [-29, -1, -18, -16], [-48, 7, -24, -12], [-18, 3, -12, 9], [16, -18, 13, 3], [4, 3, 1, -2], [0, -8, 37, -10], [34, -8, 22, 2], [11, 7, -10, -2], [18, -4, -19, -1], [32, -6, 6, 6], [18, -8, -8, 1], [10, 4, -24, 9], [13, -3, -31, -1], [-49, 5, -13, -10], [-4, -7, 7, -2], [-33, 7, -3, 12], [10, -8, -6, 2], [1, -5, 19, 5], [4, 8, -20, -3], [41, -1, 24, 8], [-7, 11, 6, 3], [4, -5, 1, -13], [-34, -10, 6, -12], [17, -17, 6, -9], [-6, -3, -5, -11], [3, 6, 25, 7], [19, -4, 18, -10], [2, 8, 0, 10], [6, -5, 12, 10], [-35, -8, -2, -14], [11, 12, -4, 2], [11, 12, -6, 14], [15, 20, -17, 13], [11, -4, -4, 2], [-24, -13, 1, -7], [-39, 1, -25, -15], [19, 4, 6, -6], [-5, -20, 16, -11], [-1, 9, 0, 14], [16, -7, 10, -3], [2, -1, -9, 8], [17, -5, 20, 7], [-56, 0, -10, 5], [20, 0, 5, -1], [-9, -12, 27, -13], [3, -26, 0, -6], [-6, -5, 12, -18], [9, -7, 34, -2], [11, 7, 40, 5], [-8, 17, 19, 15], [-4, 5, 7, 15], [11, -18, -2, -5], [-41, 7, 0, 3], [-17, 3, -4, 3], [13, 7, -3, 0], [-23, -6, -14, 0], [16, 6, 12, 3], [5, -12, -20, -8], [-31, -6, 2, -14], [-4, 4, 12, 15], [16, 21, -25, 6], [-1, -11, -11, -13], [11, -3, 43, -11], [-10, 8, -8, 13], [1, 0, -24, 0], [21, -23, 4, -1], [0, -8, 22, -11], [2, -1, 42, 1], [25, -2, 28, 14], [-15, -1, 2, -7], [-65, 7, -14, -6], [27, -12, 16, 1], [11, -22, 10, -16], [10, 17, -4, 19], [-21, -12, -1, 1], [-15, -8, -34, -11], [8, -11, -14, -8], [-20, 7, -20, 9], [6, 14, -35, 8], [-6, -1, -33, -2], [-8, 2, 0, 0], [9, 0, 5, 12], [-46, -4, -2, 5], [9, -13, 24, -20], [-20, 1, 19, 3], [-6, 5, -5, -8], [-14, -19, -6, 8], [21, 8, 26, 5], [26, 14, 16, -7], [17, -10, 5, -9], [12, -4, 25, -14], [3, -9, 26, 0], [20, -7, 39, 3], [28, 4, 20, 4], [33, 1, 14, 16], [8, 13, -5, -11], [-30, -6, -8, -6], [-58, -1, -21, -15], [16, 14, 17, -4], [-27, 11, -8, 19], [34, -11, 11, 7], [18, -20, -1, -15], [24, 7, 28, 1], [3, -12, -28, -6], [-2, -23, 24, -1], [8, 20, -23, 8], [24, -11, 14, 9], [10, 20, -31, 18], [3, 6, -6, 21], [-39, -3, -11, 11], [-63, 6, -9, -1], [-9, 5, -41, 0], [4, 15, -15, 19], [-43, 12, -42, -5], [-33, 16, 20, 9], [25, 2, 6, 23], [-34, 7, -18, -5], [-4, -13, -5, -22], [12, -18, 33, 0], [-6, 28, -2, 12], [-64, 0, -30, -7], [29, -8, -12, -11], [5, 25, -29, 8], [35, 6, 12, 15], [-16, 22, -5, 13], [2, 1, 28, -11], [12, -20, 36, -12], [-17, 22, -24, 11], [9, -15, 3, 13], [-35, -16, -16, 10], [0, -7, 7, -9], [12, 10, 8, -6], [54, -3, 29, 18], [-4, 10, 20, -5], [41, -14, 0, -13], [-15, 2, -20, 1], [-2, 0, -24, 12], [41, -1, 20, -1], [7, 15, -9, -2], [-32, -3, 15, -2], [-46, -1, -33, -12], [53, -16, 38, 14], [-4, 0, 10, -13], [10, 19, 2, 15], [-8, -2, -20, -8], [7, -5, 5, 3], [-58, 6, -10, 0], [8, -11, 29, -15], [22, -23, -8, -21], [23, -8, -6, 10], [21, -16, 33, 7], [-3, -16, -18, -26], [-25, 24, -23, -6], [-18, -2, -29, 14], [4, -6, -1, 15], [39, 6, 47, -8], [-3, -14, -16, -15], [73, -6, 43, 12], [31, 13, 24, 4], [13, -7, 3, 14], [12, 10, -18, 3], [-17, 12, 26, 3], [-27, -8, 24, -16], [-17, 22, 11, 8], [-44, 5, -10, 10], [-17, 10, -22, -14], [-19, 11, -28, -14], [-55, 19, -14, -4], [-24, 27, 20, 9], [-28, 11, -18, -5], [20, -24, 45, -9], [15, 16, -28, 18], [28, -1, -28, -3], [-8, -12, -17, 2], [0, 18, -16, 17], [37, 2, 36, 12], [-14, 5, -5, -7], [8, 25, -19, 16], [-34, -7, -18, -5], [16, -4, 18, 7], [-11, -35, 50, -17], [-9, -10, 38, -5], [19, 3, -7, -2], [3, 5, -18, -15], [20, 16, 14, 23], [39, 2, -12, 12], [-20, -23, 10, -4], [1, 9, -43, 0], [-31, 1, -42, -14], [-10, 30, -26, 6], [-24, 3, -5, -11], [8, -6, -6, -8], [2, 9, -28, 11], [28, 5, -5, -9], [-1, -12, -6, 7], [38, 11, 18, 12], [-29, -1, -25, 8], [-33, -20, -3, 0], [-31, 13, -6, -12], [-29, 7, 12, 14], [-7, 14, -28, 26], [-6, -25, -17, 6], [-14, 16, -1, 23], [-31, -11, -3, 1], [17, -4, 18, 13], [41, -19, 5, -4], [13, 8, 42, -5], [-30, -1, -41, 20], [-25, -4, -38, 3], [19, -9, 2, 9], [-15, 19, -34, -8], [40, 12, 15, -7], [50, -23, -2, -2], [5, 0, -8, 10], [-1, -3, -48, -3], [3, -11, -35, -4], [55, -6, 43, 4], [-26, -13, -6, -23], [-41, 6, 24, -4], [-18, 0, 16, -10], [23, 18, 0, 14], [-45, 0, -62, 11], [27, 10, 6, -1], [-26, 13, -14, -1], [28, 1, 10, -19], [7, -14, -2, -19], [-17, -15, 24, -4], [18, 24, -46, 15], [11, 6, 2, -6]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_10000_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_10000_2_a_ba();".
// 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_10000_2_a_ba(:prec:=4)
    chi := MakeCharacter_10000_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(2999) - 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_10000_2_a_ba();".
// 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_10000_2_a_ba( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_10000_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![11, 13, -6, -3, 1]>,<7,R![-1, 1, 1]>,<11,R![1, -31, 36, -11, 1]>],Snew);
    return Vf;
end function;