
// Make newform 10000.2.a.j in Magma, downloaded from the LMFDB on 18 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_j();".
// 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_j();".
// 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, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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, 1], [0, 0], [0, -1], [-2, -1], [3, 0], [-1, 4], [1, 1], [-2, 1], [4, -6], [2, 4], [5, -4], [4, 4], [-10, 0], [-7, 7], [-2, -4], [9, -2], [1, 7], [7, -10], [-3, 5], [6, -1], [-13, 0], [-8, 8], [7, -1], [14, 3], [-1, -6], [-5, 13], [1, -9], [-10, 9], [15, 2], [7, -5], [10, -10], [13, -2], [-9, 6], [-5, 13], [5, 10], [-1, -4], [2, 1], [11, -6], [20, 2], [-11, -4], [11, 3], [11, -18], [-6, 0], [14, -4], [11, -3], [1, 0], [12, -9], [2, 14], [-7, 2], [13, 1], [4, 0], [12, -1], [-5, 0], [16, -10], [21, -3], [6, 14], [-15, 10], [11, 6], [3, -4], [-7, 2], [-10, 15], [11, -13], [-23, 17], [11, -3], [28, 1], [-3, 0], [-18, -8], [23, 4], [11, -22], [-14, 22], [1, 20], [6, 4], [-1, -5], [8, -10], [0, -13], [-10, 13], [-20, -4], [33, -1], [12, -22], [23, -8], [-1, 14], [20, -12], [-26, 23], [30, -11], [4, 14], [-7, -14], [-7, -8], [6, 3], [22, 9], [-27, 9], [28, -18], [33, 6], [26, -12], [-27, 2], [21, -38], [-4, -15], [3, -8], [14, -10], [12, -26], [31, -20], [5, -25], [9, -34], [21, -2], [-7, 8], [11, -18], [-13, -11], [-15, 24], [-30, -10], [-6, 22], [-20, -4], [-16, -2], [26, -35], [19, -18], [-7, -10], [-6, -14], [-5, 28], [5, 24], [-21, 13], [-1, 15], [-32, 10], [-21, 4], [32, -15], [-29, -11], [31, -8], [5, -20], [17, -2], [-23, -1], [30, -7], [-11, 36], [-31, 2], [27, -7], [10, 13], [-5, 4], [10, -21], [-23, 10], [41, -12], [5, -18], [20, -9], [12, -31], [-7, 16], [4, 4], [9, -12], [-18, 26], [18, 18], [-2, 5], [25, -5], [14, 6], [9, -40], [19, -6], [-23, 19], [-35, 19], [17, 14], [-28, 2], [11, -9], [-27, -10], [-21, 34], [15, -34], [23, -22], [-15, 14], [-9, -6], [-6, 9], [13, -20], [-26, 25], [-23, -10], [-16, 16], [-22, -18], [13, -13], [-27, 24], [15, 19], [46, -19], [14, -10], [5, 26], [24, -12], [42, -12], [-28, 15], [21, -43], [15, -12], [1, -22], [-10, -27], [0, 26], [0, 14], [43, -17], [21, -27], [54, -12], [-37, 4], [-32, 41], [3, 27], [-10, -11], [-5, 26], [9, -39], [-50, -2], [36, -2], [-40, 15], [-43, 24], [41, -10], [21, -54], [8, -3], [11, 28], [-18, -14], [19, -31], [-2, 25], [29, -9], [5, -7], [54, -13], [-27, 16], [-32, 45], [-30, 10], [-38, -1], [-42, 17], [-10, 8], [-18, 20], [-38, -16], [-10, -22], [-36, -12], [29, -28], [46, -32], [50, -34], [48, -30], [16, -8], [-24, -15], [16, 9], [-29, 4], [-4, -20], [-28, 23], [31, -16], [11, 3], [17, 6], [-54, 24], [-21, 55], [-17, -34], [29, -24], [-31, 6], [-1, -15], [-13, 0], [-17, 44], [62, 0], [21, -6], [-23, 16], [-16, -3], [-15, 33], [-37, 2], [16, -7], [-44, 38], [16, -7], [-55, 27], [1, 18], [31, 7], [6, 11], [-2, -15], [7, -4], [-11, 28], [-11, 40], [-14, 41], [-6, 19], [36, -56], [-17, -12], [-14, -14], [19, 8], [5, 20], [28, 20], [-23, 0], [-32, -18], [-12, -16], [-26, 28], [-5, 32], [18, 31], [20, 14], [-23, 35], [53, -30], [-52, 43], [38, -57], [-3, 24], [-29, 20], [-15, 29], [67, -15], [-23, 22], [1, -7], [-49, 29], [-4, 39], [17, 22], [22, 34], [-23, 35], [42, -30], [-36, 45], [31, -20], [-23, 4], [-11, -33], [39, -18], [-36, 38], [63, -35], [32, 15], [-58, 5], [11, -48], [-40, 8], [-22, -15], [-17, 8], [-12, 50], [51, -22], [62, -11], [4, -13], [-55, 48], [-10, -49], [-9, -23], [37, -8], [-19, -31], [-4, 15], [-51, 17], [34, -51], [-73, 12], [-14, 46], [23, -61], [-44, 8], [-45, -24], [-3, 26], [-29, -24], [-43, 68], [23, 5], [9, 10], [-46, 33], [-6, -14], [-36, -2], [-35, 0], [38, -64], [-5, 30], [26, -5], [-43, 25], [0, 0], [25, 22], [-22, 12], [-7, -16], [-49, 64], [34, -38], [15, 26], [-18, -22], [-69, 26], [-45, 30], [-30, 0], [4, -51], [-26, 46], [47, -48], [-33, -38], [65, -38], [-16, 62], [-13, -15], [-30, 26], [14, -48], [52, -36], [39, -46], [65, -11], [21, 18], [23, -19], [-39, 42], [23, -17], [-28, -37], [46, -51], [-21, 13], [33, -42], [13, 45], [28, -33], [26, 0], [-70, 12], [7, -2], [-17, -24], [-55, 35], [-17, -9], [-5, -20], [56, -35], [52, -49], [-43, 75], [41, -43], [48, 15], [-29, -12], [-7, -29], [-76, 7], [-14, -26], [-7, -10], [-43, 8], [1, 30], [37, 7], [8, 38], [-14, -1], [17, 24], [-30, -16], [-20, 23], [-8, -42], [7, -58], [-41, 27], [-22, 30], [34, 21], [-12, 44], [21, 14], [-34, -20], [-69, 23], [27, -56], [-47, 26], [-65, 49], [18, 22], [-7, 5], [30, -23], [50, -75], [-7, -46], [9, -42], [50, 19], [-38, 6], [39, 2], [-14, -2], [-31, 18], [-27, -10], [37, 26], [-54, 65], [-44, 17], [24, 21], [-39, 39], [19, -16], [24, -65], [72, 14], [-7, 3], [-29, 13], [-75, 2], [46, -32], [27, -38], [55, -22], [3, 44], [17, 23], [-53, 55], [9, -44], [8, -13], [18, -10], [-9, 16]];
    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_j();".
// 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_j(:prec:=2)
    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_j();".
// 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_j( : 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, -1, 1]>,<7,R![-1, 1, 1]>,<11,R![5, 5, 1]>],Snew);
    return Vf;
end function;