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