
// Make newform 10000.2.a.c 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_c();".
// 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_c();".
// 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]];
    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], [4, -2], [0, -3], [-4, 2], [1, 3], [-5, -2], [-3, 1], [3, 0], [1, 2], [-2, -2], [3, -3], [0, 1], [-1, 4], [9, -3], [5, -6], [-6, -2], [6, -1], [-9, 0], [5, -5], [5, -2], [-4, 8], [-2, 3], [-1, -4], [-3, 9], [9, -12], [10, 0], [15, -3], [-10, 16], [0, 11], [-7, 8], [-5, 0], [1, 8], [-9, 9], [7, -10], [-11, 0], [-9, 9], [9, -16], [3, 4], [4, 6], [8, 10], [4, -6], [0, -6], [12, -9], [3, -10], [-6, -10], [-16, -2], [18, -6], [2, 8], [23, 4], [5, 4], [23, -10], [21, -3], [14, 5], [-14, -2], [8, 0], [-21, 6], [7, -5], [28, -3], [-22, -4], [-8, 2], [2, 17], [-18, -2], [-1, -14], [12, -18], [6, -3], [23, 5], [18, -6], [16, 5], [-2, 19], [20, -9], [-19, 15], [-1, 22], [-21, 20], [15, 0], [21, -13], [13, -22], [9, 12], [7, -4], [32, 0], [15, -24], [25, -3], [28, -21], [-25, 8], [9, 7], [-14, 12], [7, 10], [13, -18], [-12, 25], [9, -3], [29, -12], [21, -36], [-2, 9], [30, -12], [-16, 7], [17, -20], [15, 3], [16, -18], [25, 6], [6, 2], [-8, -1], [23, 4], [-3, -18], [-14, 32], [-9, -6], [-14, -5], [7, -4], [12, 15], [30, -9], [-2, 21], [13, -2], [-33, -4], [9, -2], [2, 5], [16, -24], [18, -30], [16, -5], [-18, -4], [3, -27], [6, -10], [10, -1], [11, -4], [-27, 15], [-20, 34], [-15, 30], [27, 6], [-19, 9], [-7, 21], [-3, 21], [-16, 20], [15, 16], [23, -12], [-3, 25], [6, -12], [-17, 31], [18, 10], [11, 2], [18, -21], [11, -6], [-24, 27], [-44, 6], [9, 13], [-34, 3], [-9, 3], [2, 28], [3, -27], [9, 12], [27, 9], [-18, 30], [-28, 20], [28, 12], [-20, 16], [11, -36], [39, -2], [39, -23], [20, -35], [27, 15], [-39, 12], [6, 14], [4, 19], [-14, -16], [-5, 1], [-11, -14], [-9, 1], [3, -20], [15, -16], [-15, -20], [36, -35], [1, 28], [15, -31], [3, 25], [-21, -6], [7, 6], [-3, -34], [-10, 6], [45, -6], [15, -42], [-32, 29], [7, 32], [-12, -20], [5, -3], [22, 20], [19, -20], [23, -26], [33, -12], [12, -21], [-40, 10], [33, 15], [-26, -21], [-12, -8], [26, -21], [-14, 32], [22, -53], [2, -7], [-12, 8], [-3, -17], [18, 28], [57, -6], [14, -28], [-43, 42], [44, -24], [-39, 43], [18, -6], [25, -11], [6, -27], [12, -51], [3, -6], [-20, 36], [-37, 3], [31, -8], [27, -36], [-6, 3], [28, -41], [9, -24], [12, 7], [-22, -7], [-60, 6], [39, -36], [-19, -18], [20, 0], [-13, 26], [-31, 55], [-12, 40], [11, 33], [-33, 18], [5, -10], [-26, 3], [-38, 17], [-3, -37], [-24, 28], [-26, 18], [58, -2], [0, -12], [16, 14], [-13, -9], [-7, -19], [-40, 5], [13, -20], [21, -9], [24, -22], [-43, 19], [-36, -3], [16, -35], [48, -41], [15, -24], [-11, 38], [-23, 6], [-32, 22], [15, -36], [-13, 20], [-9, 49], [23, 9], [-18, 18], [-39, 38], [-32, 23], [-12, -30], [24, -34], [-51, 26], [4, 30], [35, -19], [-26, -3], [3, 46], [10, 34], [18, -16], [16, -47], [-42, 48], [37, -6], [5, -38], [1, 2], [-38, 47], [65, -3], [-11, -18], [-24, 7], [-49, 16], [29, -32], [12, -34], [-65, 24], [-35, 11], [2, -1], [-20, 51], [12, 27], [27, -30], [52, -3], [-22, 20], [-11, 44], [11, 2], [35, -30], [13, -61], [-22, 8], [-4, -46], [-41, -26], [-45, 6], [16, -15], [27, -54], [23, 25], [13, 11], [33, -21], [-59, 14], [12, -17], [33, 18], [-31, 42], [-15, -12], [-59, 9], [-5, 14], [-9, -1], [-46, -3], [25, -40], [-15, -23], [48, -28], [2, 26], [-74, 2], [-40, -2], [-34, 19], [-39, 38], [31, -62], [-20, 41], [-23, 8], [13, 4], [-10, -29], [-10, -21], [-31, 26], [-65, 38], [-25, 2], [-24, 42], [-63, 21], [-65, 18], [-13, 17], [38, -4], [37, -15], [16, 7], [-45, -30], [-4, -4], [-36, -7], [17, 47], [43, -36], [-13, -47], [23, 18], [68, 0], [9, -46], [-47, -2], [42, 16], [-9, -1], [16, -25], [-6, 2], [0, -36], [15, -24], [-40, 76], [-21, 31], [27, -43], [9, -54], [-3, 30], [4, -60], [-25, -15], [-24, 35], [22, 1], [42, -3], [19, -64], [-36, 15], [58, -27], [-20, 4], [1, 19], [-48, 26], [-23, 47], [21, 45], [66, -3], [67, 9], [2, 15], [6, 54], [-48, 51], [5, 8], [-44, 13], [42, -13], [48, -12], [-30, 0], [-32, 50], [33, 26], [31, -62], [-34, 22], [-8, 40], [18, 21], [-42, -30], [51, -33], [60, -10], [67, -41], [-19, -21], [73, -12], [-6, 35], [20, -34], [-30, 45], [-33, 23], [8, 19], [60, -9], [17, 22], [-71, 44], [-18, 6], [-56, 2], [-21, -42], [-3, -35], [-21, -18], [-60, 22], [-60, 41], [50, 29], [-35, 35], [-15, -24], [-27, 43], [-16, 56], [-30, -2], [43, -46], [7, -12], [-8, -25], [8, 37], [-12, 0], [-71, 51], [-36, -34], [-1, -13], [-5, 11], [45, -46], [-3, -16], [-34, 13], [-49, 57], [61, -41], [42, 11], [-34, 60], [42, -45], [-36, 5], [57, -34], [-36, -22], [58, -26]];
    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_c();".
// 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_c(: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_c();".
// 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_c( : 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![4, -6, 1]>],Snew);
    return Vf;
end function;