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