
// Make newform 10000.2.a.w in Magma, downloaded from the LMFDB on 17 April 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_w();".
// 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_w();".
// 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 := [1, 4, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, 0, 1, 0], [0, -3, 0, 1]];
    Rf_basisdens := [1, 1, 1, 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+1)]];
    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], [0, 0, -1, -1], [0, 0, 0, 0], [0, 0, -2, -2], [1, 0, -2, 0], [0, 0, 2, 4], [-3, -1, 0, -3], [-6, 2, -1, -4], [4, -4, 2, 4], [6, -4, 2, 6], [-2, 2, 2, 2], [-4, -2, 2, -2], [-1, 1, 4, -1], [-6, 2, -2, -5], [0, 2, 4, 2], [4, -4, 0, 4], [3, 0, 2, -3], [0, 2, 4, -6], [-6, -2, 3, 0], [2, -4, 0, 6], [0, 3, -4, 0], [-2, 2, 4, 4], [-3, 4, 2, 4], [4, 0, 5, 8], [-5, 0, 0, -9], [4, 2, 2, 6], [-4, 0, 0, 4], [-2, -1, -4, 0], [8, -6, -2, 2], [4, -5, -4, 4], [-8, 8, -2, -4], [2, -2, -2, 1], [-1, 0, -8, 0], [-2, 1, 0, 4], [-6, 8, 4, -6], [-2, 2, 6, 4], [2, 4, -6, -6], [-1, 1, -2, 7], [-4, -2, -2, -6], [0, 8, 4, -6], [-2, -3, 0, -8], [8, 0, 4, 14], [-4, 6, 0, -6], [4, 4, -3, 4], [4, 0, 6, 2], [8, 6, -6, 6], [-12, 8, -1, -9], [-8, 10, 6, 4], [6, 2, -2, -9], [-2, 2, -6, -6], [-15, -8, 4, 1], [10, 0, 8, 4], [0, 0, -15, 1], [16, -12, -1, 7], [-8, -4, -4, 11], [8, -4, -6, 8], [-8, 4, -12, -10], [8, 2, -10, -4], [-20, 0, 2, -8], [-1, -4, -12, -9], [2, 1, 4, -4], [-14, 6, -2, 2], [9, -1, 2, 5], [8, -14, 4, 10], [8, 4, 0, 1], [8, -6, 8, 8], [-9, -3, -6, -21], [11, -7, 4, -1], [10, 6, 9, 4], [6, -2, -8, -8], [-7, 0, -8, -15], [8, -2, 0, -10], [0, -6, 14, 8], [-2, -12, -6, 10], [16, -4, -1, 7], [-18, 6, 10, 4], [-8, 2, -6, -8], [0, 4, -4, -14], [-20, -8, 5, -3], [5, -4, -8, -16], [-5, 5, 2, 11], [20, -6, 2, 14], [0, -14, -2, 6], [-20, 8, 7, 3], [-20, 4, -2, -4], [2, 9, 0, 8], [12, 4, -11, -7], [0, 8, -1, 7], [16, 10, 0, -2], [-10, -12, 2, -8], [10, -2, -2, -3], [-14, 6, -2, -16], [8, -10, -8, 16], [-6, 10, -14, -15], [14, -10, 6, 21], [-24, 12, -12, -26], [2, -6, 4, 8], [4, -8, -9, -12], [-1, 4, 14, 4], [-12, 12, 14, 0], [7, -4, 10, -4], [-12, 14, 6, -8], [-1, 8, -14, -3], [16, 7, 4, 20], [-13, 0, -10, -7], [-7, -8, 4, 0], [-19, -8, 10, -8], [-12, -12, 1, -19], [-2, -2, 8, -6], [8, 8, -19, -16], [-18, -2, 6, 0], [-8, 6, 4, 12], [4, -12, 4, 15], [-18, 2, -14, -17], [-4, -12, 0, 10], [-11, 4, 12, -3], [-24, 4, -16, -12], [-38, 12, -6, -24], [32, -10, 2, 28], [-12, -8, 15, 7], [8, 4, -4, -8], [8, 8, 4, 5], [0, -10, -14, 4], [5, -9, 14, 17], [1, 0, 10, 16], [-12, -2, -4, -26], [12, -20, -8, 20], [4, 0, 0, -2], [2, -4, -4, -16], [0, 4, 18, 4], [2, -6, 6, 19], [-18, 0, 10, 16], [8, 16, 2, 4], [-22, 18, -8, -18], [12, 11, 0, 8], [8, -8, -7, 1], [-4, -2, -6, 16], [20, 4, 0, 16], [-8, 0, 8, 4], [-15, 12, 8, 5], [-19, 12, -6, -1], [-12, 8, -2, 0], [-20, 4, 8, 8], [-17, -11, -2, 11], [6, 0, -2, -4], [-10, -2, 2, 0], [14, 0, -14, -6], [-12, -4, -11, -8], [-25, -7, 10, -1], [-28, 12, -2, -34], [8, 6, 18, 4], [20, -20, 0, 21], [2, -2, 9, 12], [-10, -14, -12, 6], [-1, 4, -14, -3], [10, 4, 12, 2], [10, 10, 6, 18], [-24, 0, 0, 7], [-32, 0, -5, -8], [8, 2, -20, 8], [2, -10, -10, 3], [-4, 8, 17, 0], [14, 6, -12, 4], [7, -3, 6, -13], [-4, 12, -17, -17], [-18, 8, 6, 18], [2, 6, 8, -20], [-22, 6, 2, 6], [-4, -4, -13, -24], [-12, 0, 8, -22], [-14, -21, 8, 8], [26, 6, 14, 8], [0, -20, -20, 4], [20, -4, -3, 17], [-8, -2, -10, -22], [23, -12, -8, -4], [23, -16, -10, -8], [14, -10, -6, -4], [2, 0, -14, -26], [-2, 20, -4, -6], [-38, 10, -12, -18], [14, 2, 3, 12], [-16, 18, -4, -22], [0, 3, 32, 16], [-30, 12, 18, 12], [-2, 14, -2, -18], [10, 14, -4, -4], [11, -16, -14, 4], [-16, 0, -17, -8], [8, 4, -28, -12], [-16, 20, 1, -11], [-19, 0, 2, 20], [16, -20, 27, 27], [14, -24, 8, 16], [-2, 18, 17, -20], [-11, 24, 0, -7], [5, 11, -20, -11], [46, -24, 6, 36], [4, 12, 5, 5], [-32, -8, 0, 14], [2, -2, 2, -6], [-6, 14, -6, -14], [12, 2, -20, -14], [-32, 5, -8, -28], [-32, 16, -8, -20], [-12, -18, -10, 8], [-14, -24, 24, 12], [1, -8, 2, -9], [28, -12, -8, 21], [-25, -4, -10, -23], [0, 8, 24, 37], [-10, 14, 0, 18], [-28, 18, -4, -12], [26, -14, 5, 4], [6, 24, 12, 0], [-28, 3, -12, -32], [20, 6, 2, 38], [17, 0, -8, -24], [-50, 16, -12, -44], [30, -14, 6, 14], [-26, 10, 6, -8], [-24, 2, 22, 4], [-17, -15, 0, 11], [52, -6, 4, 0], [-25, -8, 14, -8], [-26, 18, -4, -10], [37, 0, 0, 12], [-4, 0, -2, 26], [-42, -6, 18, 6], [10, -2, -19, 16], [14, -12, 0, -10], [10, 23, 16, -8], [2, -18, 10, 14], [-1, 0, 32, 40], [34, -6, -2, 41], [20, -30, -14, 22], [5, 12, 4, 8], [20, -4, -8, -8], [48, -4, 7, 15], [-8, -16, 12, 26], [1, -5, -2, -27], [17, 15, 2, 29], [8, -18, 22, 10], [24, 14, 6, 18], [17, -36, -12, 8], [-32, 20, 12, -28], [-22, 24, 20, 22], [-26, 6, 10, -5], [1, -5, -34, -15], [-12, -8, -16, -4], [-28, 6, -16, -30], [32, -23, 16, 44], [32, 0, 2, 44], [4, 24, 17, -4], [-40, 26, 6, -6], [-4, -4, -1, -13], [18, -22, -14, 4], [-6, -14, 27, -4], [-10, -6, 14, 30], [-4, 4, -5, -25], [-2, -16, 16, 18], [8, 0, -39, -27], [44, -20, -12, -8], [16, 10, 28, 14], [35, 12, -20, 12], [-31, -20, 6, -4], [26, 14, -4, 32], [35, 0, 12, 7], [24, 4, -21, -21], [-26, 0, -24, -36], [14, -36, -2, 10], [10, 21, 4, -16], [47, -7, 4, 43], [-10, -8, -14, -26], [26, 20, -24, 16], [-28, 6, 2, -20], [12, 4, -17, 19], [-14, 30, 4, -6], [24, -32, -4, 21], [11, 21, -22, -17], [20, -14, -4, -12], [6, 14, 0, 28], [-40, 0, -4, 12], [-26, 16, 0, -38], [-10, 14, -9, -16], [-16, 28, -6, -12], [3, 16, -24, -25], [44, -30, 26, 52], [-38, 28, -6, -20], [-5, -8, -8, 7], [38, 20, -22, -4], [38, 10, 6, 13], [-20, -12, 13, 1], [-2, 23, 20, -36], [0, 26, -6, -2], [-32, 20, -4, -36], [28, 24, -8, 18], [-4, 2, -14, -36], [12, -12, -12, -8], [32, 4, -11, -23], [-8, 5, 12, -32], [2, 10, -24, -2], [-2, 14, 6, -24], [17, -13, -14, 5], [12, 32, 11, -13], [-5, -12, -4, -12], [65, -20, 2, 35], [16, -8, -12, 2], [-34, -20, 24, 4], [-14, 36, 22, 14], [-16, -12, 30, 4], [-6, -8, -14, -38], [40, 12, 17, -7], [44, -28, 12, 32], [-30, -6, 2, 12], [-41, 0, 0, -57], [-6, 10, 35, 48], [-22, 0, -12, -56], [0, 24, 15, -20], [-8, -31, -8, -8], [-33, 0, 2, 9], [1, 7, -16, 21], [36, 8, -22, 6], [8, -32, -20, 2], [12, -20, 0, 37], [-20, 44, 0, -17], [47, -24, 2, 48], [26, 2, 6, 53], [6, -2, 34, 22], [-30, 2, -14, -8], [-34, 36, 8, -40], [-6, 8, -10, -2], [48, 8, -6, 22], [-14, 22, -27, -36], [-19, 8, -14, -52], [31, -8, -18, 33], [58, -20, 8, 50], [-31, -28, 4, -11], [-52, 1, 16, -12], [-12, -8, -22, -30], [20, -14, 18, 40], [-41, 16, 20, 12], [-36, 4, -4, -62], [38, -18, -10, -4], [-36, -4, 16, -38], [12, -12, -20, -12], [-26, 14, 8, 0], [43, -7, 2, 15], [-24, -18, -4, -10], [-12, 2, -16, 10], [38, -10, 29, 12], [-8, 0, 16, 13], [-24, 30, 10, 8], [36, 20, -6, 6], [-42, -14, 0, 14], [-44, 32, 5, -39], [12, -42, -14, -14], [-50, 1, -12, -44], [-9, 16, -52, -25], [-16, 12, 28, 20], [-12, 38, 22, -38], [-4, 24, 25, 20], [-8, 14, -24, -12], [-6, 2, 26, 27], [-24, 8, 1, -27], [4, -13, 28, 16], [-22, 36, -2, -6], [0, -4, 6, -42], [-72, -13, 8, -8], [-53, -4, 2, -63], [27, 25, -38, -5], [20, -10, 48, 26], [52, -30, 12, 30], [-8, -4, -28, -58], [-4, -38, -14, 22], [23, -11, -26, -25], [34, 32, -4, -14], [-11, -24, 4, 16], [-44, 3, 4, -52], [23, 12, 0, -17], [68, -18, 10, 48], [16, 8, -3, 40], [2, 10, -12, -8], [47, -7, 8, 23], [-18, -10, -30, 9], [32, -6, -4, 16], [16, -6, -50, -42], [2, 18, 16, -28], [-9, -16, -6, -7], [22, 26, 22, -8], [-16, -4, -17, 35], [-2, 16, 24, 24], [-19, 15, -26, -11], [-10, -10, 3, -32], [38, 2, 10, 6], [-36, 28, 3, -21], [14, -14, 18, 30], [17, 8, -40, 8], [22, 14, -13, 16], [-26, 10, -44, -28], [-8, -22, -24, 26], [-12, -16, -7, -40], [28, 10, 8, 14], [-19, 7, 8, -27], [48, -4, -20, -26], [42, -12, 20, 32], [12, 16, -2, 22], [-35, -4, -4, -3], [12, -24, 8, -12], [-15, -1, -14, 5], [49, -32, -4, 28], [48, -14, -4, 28], [17, 8, 22, 16], [9, 0, -14, -25], [-8, 23, -4, -28], [-20, -14, 16, 2], [-48, 6, -2, -54], [10, 24, 4, -22], [-32, -4, 9, 12], [-10, -16, -20, 24], [16, -6, 20, 24], [0, -12, 0, 10], [4, -16, -28, -10], [44, -16, 7, 71], [-44, 45, 16, -32], [-22, -6, 44, 26], [1, 4, -30, -49], [25, -13, 12, -3], [-26, -26, 3, 8], [-40, -10, -26, 12]];
    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_w();".
// 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_w(: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_w();".
// 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_w( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_10000_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, 4, -4, -1, 1]>,<7,R![16, 32, -16, -2, 1]>,<11,R![31, 2, -16, -2, 1]>],Snew);
    return Vf;
end function;