
// Make newform 10000.2.a.k in Magma, downloaded from the LMFDB on 25 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_k();".
// 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_k();".
// 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], [1, 0], [0, 0], [0, -1], [3, 0], [1, -4], [-6, 3], [4, 2], [-3, 3], [-3, 6], [9, -2], [-2, 5], [0, -6], [-4, -5], [-3, 0], [-3, -6], [-3, 6], [-9, 2], [9, -4], [-9, 9], [0, -2], [9, -8], [0, -3], [-6, 12], [9, -2], [-3, 0], [-1, 4], [-9, 12], [-1, -8], [-3, 9], [0, -1], [-9, -6], [0, 6], [0, 10], [12, -9], [9, -17], [-14, 9], [-16, 9], [-15, -6], [-9, 6], [-9, 3], [5, -11], [0, -9], [13, -18], [-6, -12], [0, -5], [-17, 5], [-13, 13], [9, -9], [-7, -11], [3, -18], [12, 6], [8, -2], [3, 0], [-3, 12], [-12, -9], [9, -3], [7, -13], [-9, 4], [27, 0], [23, -9], [-15, 3], [-1, 1], [-18, -3], [-9, 1], [0, -9], [19, -7], [-9, 19], [-12, 18], [-16, -8], [-12, -3], [-21, -3], [-1, 16], [-23, 9], [0, -5], [0, -3], [-15, 15], [-26, 8], [-12, 3], [0, -10], [15, 0], [-18, -10], [-3, 12], [-18, 19], [-5, 5], [21, -30], [-15, 15], [-5, -4], [-18, 15], [-22, 1], [-24, 12], [-6, -3], [2, 0], [0, 6], [22, -9], [6, -15], [-27, 9], [27, 0], [9, -31], [-7, 18], [-37, -2], [21, -6], [36, 0], [0, 0], [-9, 19], [16, -31], [21, 12], [12, -6], [18, 9], [-1, -9], [-9, 17], [-9, -14], [-12, 15], [28, -16], [16, 14], [12, -30], [0, 2], [21, -3], [3, 27], [30, -30], [-27, 23], [-8, 9], [0, -9], [-3, -12], [18, -5], [15, -6], [-10, 0], [18, -6], [-36, -4], [13, -18], [1, 8], [6, 0], [1, 14], [18, -5], [-21, -9], [0, -10], [-12, 12], [23, 18], [15, -24], [6, 3], [7, -18], [9, -9], [-22, 46], [15, -6], [-31, 7], [48, -6], [-18, -11], [-15, 6], [-9, 13], [-39, 0], [-23, 27], [-3, 0], [29, 4], [-3, -30], [2, 10], [15, -9], [-27, 19], [-21, -3], [4, -7], [24, 6], [3, 3], [-9, -9], [-36, 26], [42, -3], [21, 9], [-24, 45], [-2, 5], [-14, 14], [27, 11], [33, -3], [27, 6], [-31, 36], [-12, 0], [-17, 2], [18, 4], [12, -24], [-50, -4], [-3, 0], [-9, -25], [8, 9], [0, -1], [45, 6], [9, -20], [18, -15], [-42, 6], [30, 0], [-11, 23], [18, -34], [-18, 26], [18, -15], [13, 2], [-6, 39], [-29, 9], [30, -36], [-60, 9], [9, 15], [-19, 22], [1, 36], [39, 3], [-12, 6], [30, -30], [43, -10], [36, 4], [9, -28], [-3, -9], [42, -33], [34, -13], [0, 42], [21, -42], [19, 23], [34, 18], [-27, 48], [-43, 28], [-42, 3], [-15, -15], [-10, -11], [11, 7], [-24, -18], [-24, -3], [3, 12], [41, -8], [-14, 18], [-3, -9], [26, 10], [30, -6], [-27, 29], [-24, 51], [21, -42], [56, -8], [-12, 0], [27, -26], [1, 8], [-11, 38], [6, -3], [9, -16], [-21, -9], [-36, 17], [-39, 6], [-6, 12], [33, -60], [-9, -30], [-18, -23], [14, -36], [47, -14], [9, 15], [0, -15], [-7, -32], [12, -48], [-29, 38], [-54, 0], [49, -27], [57, -15], [-36, 6], [-16, -8], [-24, 36], [57, -9], [41, -38], [9, -4], [-27, 0], [-9, -26], [65, -8], [30, 9], [-28, 31], [-18, 49], [21, -36], [-23, -4], [-6, 12], [-9, -18], [45, 2], [-21, 0], [36, -58], [45, 14], [-18, 4], [-5, -10], [43, 20], [14, -11], [48, -42], [0, 50], [-25, -36], [42, -33], [-36, 69], [0, 16], [45, -21], [9, 26], [53, -32], [-27, 45], [18, -23], [18, -30], [-44, 18], [-51, 12], [42, -45], [30, -21], [51, -54], [33, -15], [72, 4], [-15, -30], [-17, 45], [48, -48], [21, -27], [8, 43], [-50, 8], [3, 45], [37, -19], [3, -24], [49, 8], [27, -8], [60, -21], [59, -18], [-48, -9], [18, -38], [-30, 27], [-30, -15], [-9, -3], [9, -1], [30, -66], [-46, -8], [-18, 6], [15, -54], [-14, 41], [60, 15], [-26, 18], [-5, 26], [-60, 24], [53, 1], [-48, 24], [23, -47], [9, -8], [-72, -4], [24, 36], [12, 9], [27, 20], [-15, -39], [18, -56], [0, 27], [37, -28], [-54, 12], [20, 40], [-78, 24], [-18, 20], [9, -19], [-2, 17], [-18, -3], [-9, -42], [-27, 10], [15, 18], [-48, 36], [-36, 71], [-18, 50], [27, 27], [-9, -36], [45, -14], [-38, -13], [-33, 30], [-67, 31], [44, -23], [-15, -27], [-9, 33], [-24, -36], [21, -51], [51, -60], [19, -7], [21, -18], [24, -54], [21, -12], [-45, 29], [10, 38], [-51, 18], [11, 0], [29, -14], [3, 0], [-11, -18], [-39, 15], [-51, 72], [-5, 36], [-54, -11], [3, 24], [33, -60], [-11, 45], [0, 15], [63, 10], [21, -18], [-54, 6], [56, -18], [21, -21], [22, -54], [9, -66], [27, -68], [-72, 10], [5, 7], [63, -42], [32, -14], [-69, 21], [0, 30], [-45, -16], [-15, 21], [36, -14], [18, 34], [3, -51], [-45, -29], [-27, -42], [45, 20], [-9, 36], [68, -27], [39, -27], [24, -33], [-72, 10], [9, -17], [54, -54], [-22, 1], [24, -78], [54, -50], [81, -6], [15, -3], [-36, -2], [-53, 32], [54, -24], [39, -33], [-45, 29], [9, -42], [-69, 0], [48, 24], [1, 44], [12, -30], [-48, 6], [19, -10], [51, -6], [6, 30], [51, -12], [-9, -26], [-15, 30]];
    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_k();".
// 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_k(: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_k();".
// 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_k( : 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]>,<7,R![-1, 1, 1]>,<11,R![-3, 1]>],Snew);
    return Vf;
end function;