
// Make newform 9000.2.a.p in Magma, downloaded from the LMFDB on 16 November 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9000_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_9000_2_a_p();".
// 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_9000_2_a_p();".
// 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_9000_a();"
function MakeCharacter_9000_a()
    N := 9000;
    order := 1;
    char_gens := [6751, 4501, 1001, 2377];
    v := [1, 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_9000_a_Hecke(Kf)
    return MakeCharacter_9000_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], [0, 0], [0, 0], [3, -1], [1, 0], [-3, 2], [-1, 3], [-3, -2], [1, -6], [5, -2], [-7, 5], [-5, 2], [1, 5], [8, -3], [-1, 2], [4, 1], [7, 3], [-1, 3], [8, -4], [4, -9], [4, -3], [10, -6], [9, -5], [11, 0], [-1, 11], [12, -8], [8, 1], [-4, 7], [-11, 8], [-6, 6], [5, 4], [11, 1], [11, 0], [-1, -12], [-5, 12], [14, -10], [3, -15], [7, 0], [2, 8], [19, -5], [9, -12], [-14, 0], [-1, 2], [-9, -8], [17, -8], [-17, -4], [-8, 16], [-3, 0], [-4, 14], [6, 2], [12, -9], [-11, 9], [16, -6], [-12, -1], [3, 0], [11, -21], [-9, 23], [-18, 17], [0, 13], [14, -5], [13, 8], [24, -12], [9, 6], [-18, 9], [5, -17], [25, -2], [-22, -1], [4, 8], [-8, 15], [10, 15], [-5, 21], [-10, -12], [0, -1], [20, -5], [3, -1], [-3, 11], [10, -11], [24, -20], [-33, 6], [-2, 22], [12, 7], [26, -12], [-17, 20], [26, 0], [-12, 9], [-9, 3], [-10, 3], [-1, 13], [-33, 8], [-9, 29], [8, -9], [2, -22], [30, -4], [-8, 5], [23, -32], [4, -21], [2, -26], [32, -1], [-20, 8], [13, -17], [-3, -11], [16, 15], [16, -13], [7, 6], [2, 3], [-9, 22], [-31, 20], [19, -30], [19, -31], [27, -20], [8, -16], [-17, 0], [-39, 4], [8, -24], [-11, -16], [0, 18], [-14, -8], [-13, 35], [24, -30], [17, -28], [11, 13], [12, -36], [-10, 34], [19, 4], [43, -4], [-24, 26], [5, 10], [-33, 10], [-37, 20], [-16, 40], [35, -13], [-24, 14], [5, 3], [11, -36], [-17, -22], [16, 12], [1, -6], [12, 27], [-10, 1], [35, -17], [-18, 29], [3, -26], [42, -16], [15, -9], [-34, 38], [19, 10], [-21, 12], [10, -39], [7, 12], [-6, 31], [33, -2], [28, 14], [19, -36], [11, -28], [-11, -10], [-25, 3], [-8, -17], [-7, 9], [-24, 22], [25, 13], [29, -12], [20, 13], [33, -8], [-10, 18], [-32, 29], [22, -1], [-20, -15], [-3, -26], [28, -3], [1, 18], [-8, 9], [-45, -10], [-4, -17], [32, 11], [-53, 6], [5, -12], [7, 20], [8, -6], [-3, 3], [1, -24], [-23, 52], [-17, 3], [-14, 46], [-29, -14], [30, 9], [-29, 34], [-7, -1], [-19, -19], [-40, 10], [14, -43], [13, 25], [-11, -24], [-30, 25], [23, 0], [10, 2], [2, -35], [-10, 22], [-16, -16], [-32, 0], [16, -20], [-20, 29], [-34, -11], [-14, -6], [7, 14], [20, -20], [-34, -9], [-18, -27], [31, 9], [0, -1], [-17, -3], [54, 3], [-14, 14], [23, -20], [-18, -28], [-52, 8], [-27, 30], [-41, -3], [3, -2], [-52, -3], [-41, -6], [24, -3], [-11, 12], [-22, 38], [-17, -20], [5, 5], [16, -2], [-60, 22], [-5, 44], [36, -11], [2, 12], [23, 27], [18, -10], [-23, 21], [52, -9], [4, -8], [-25, 3], [6, -12], [-68, 6], [49, -28], [49, -33], [31, 0], [13, 13], [30, 3], [49, -26], [-56, 21], [-22, 29], [-39, 6], [-24, 43], [-10, -6], [-34, 40], [41, -51], [36, -27], [24, -34], [-46, -3], [45, -18], [15, 26], [11, -6], [-19, 36], [-20, 4], [28, -30], [-50, 34], [-54, 8], [-23, 40], [-50, -17], [-18, -16], [3, -24], [45, -56], [30, 8], [-17, 12], [9, 3], [-9, 23], [-45, -14], [2, -30], [40, -40], [46, -25], [44, 14], [-68, 0], [-55, -16], [-27, -6], [-5, 38], [6, -7], [-51, 9], [-32, 5], [-36, -4], [19, -54], [-31, 5], [2, -19], [-41, -17], [-29, -24], [51, -46], [-14, -10], [48, -40], [-49, 49], [-8, 50], [-2, 18], [64, -15], [-19, -12], [24, -31], [22, -30], [-47, 47], [-53, 44], [-14, -1], [-34, 43], [9, 42], [68, -18], [-32, 13], [23, -8], [21, -15], [-29, 16], [43, -47], [-64, -3], [42, -39], [-27, -14], [-43, 71], [8, 20], [15, -9], [19, -65], [-34, 52], [-7, 8], [-29, 54], [-28, 41], [0, -11], [-23, 47], [-74, -4], [-14, 42], [-41, -12], [47, -25], [35, -22], [47, -40], [-25, 30], [-39, 49], [7, 30], [30, 3], [-39, 30], [60, 1], [-12, -14], [-1, 8], [72, 9], [44, -47], [7, 10], [-69, -8], [-43, -1], [-8, 25], [-30, 4], [31, 5], [-20, 0], [24, -22], [10, -21], [54, -13], [-38, 29], [18, 6], [60, -29], [0, -24], [-87, 6], [70, 5], [49, -35], [26, -40], [27, 28], [16, -50], [-25, -17], [-19, 34], [-33, 52], [31, -58], [-38, 56], [-2, -2], [30, -56], [55, -51], [21, 14], [43, -32], [-57, 33], [-25, 17], [-19, -7], [-24, -18], [-6, -46], [4, -7], [29, 12], [-22, -34], [14, -10], [5, -37], [-6, 4], [-29, -3], [64, -28], [-15, 6], [50, -70], [31, 3], [-28, 18], [32, -61], [1, 17], [33, 17], [23, 0], [31, -26], [-47, 40], [-91, 11], [-12, -31], [25, -44], [14, 38], [-48, 79], [43, -14], [34, 31], [-17, 2], [-74, 27], [24, 41], [-52, -11], [53, 23], [18, -58], [3, 2], [10, 46], [53, -8], [25, 10], [-57, 0], [-9, -34], [-37, -8], [19, -36], [13, 16], [30, -36], [28, 5], [-59, 18], [-40, 4], [20, -40], [-25, 10], [22, 1], [-7, -22], [-23, 3], [61, 0], [-2, -41], [-21, 52], [32, 20], [34, -66], [39, -32], [39, -59], [-8, 0], [5, 5], [48, -12], [14, -6], [31, 37], [28, 37], [-9, -16], [-11, -8], [-11, 37], [-28, 56], [-29, -29], [-1, -18], [9, -33], [24, -78], [9, -61], [27, -4], [60, 24], [3, 27], [29, 35], [-96, 15], [-14, 39], [-25, 33], [59, 11], [-42, 41], [59, -64], [13, 15], [-77, -18], [5, 0], [-17, 50], [54, -28], [7, 21], [102, -13], [38, -46], [-100, -5], [56, -79], [-57, 51], [-17, 62], [-4, -40], [8, 49], [26, -30], [17, -26], [-23, -24], [-4, -7], [-68, 36], [10, -26], [-19, -24], [6, -26], [-16, -3], [-23, -11], [61, 0], [23, -4], [29, 16], [-83, 39], [-89, 15], [60, -42], [-18, 61], [38, -37], [-43, -39], [-54, 2], [-27, -16], [-82, 33], [-45, 66], [-33, -1], [36, 32], [23, -14], [-3, 38], [-25, 77], [-14, 18], [-78, 21], [38, 4], [63, 21], [-1, -45], [-11, 74]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9000_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9000_2_a_p();".
// 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_9000_2_a_p(:prec:=2)
    chi := MakeCharacter_9000_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(3593) - 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_9000_2_a_p();".
// 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_9000_2_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9000_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![5, -5, 1]>,<11,R![-1, 1]>,<13,R![-1, 4, 1]>,<17,R![-11, -1, 1]>],Snew);
    return Vf;
end function;