
// Make newform 8550.2.a.bt in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8550_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_8550_2_a_bt();".
// 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_8550_2_a_bt();".
// 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 := [-3, 0, 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_8550_a();"
function MakeCharacter_8550_a()
    N := 8550;
    order := 1;
    char_gens := [1901, 1027, 1351];
    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_8550_a_Hecke(Kf)
    return MakeCharacter_8550_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 := [[-1, 0], [0, 0], [0, 0], [1, 1], [0, -3], [3, 1], [1, 1], [1, 0], [-5, -2], [4, 3], [1, -4], [-2, -4], [0, 0], [7, 1], [0, 2], [-4, 5], [3, -3], [10, -1], [0, -3], [5, 3], [11, 2], [-1, 4], [-8, -5], [3, -4], [5, 7], [3, 5], [-1, -8], [1, -3], [0, -6], [-3, 10], [1, -6], [6, 3], [-6, -6], [-9, 3], [8, 8], [0, 6], [8, 8], [-10, 0], [-2, 0], [-14, -5], [-4, 8], [21, -1], [21, 2], [-5, -3], [-9, 5], [10, -4], [2, 3], [11, 4], [-2, 0], [0, 3], [9, 5], [14, -4], [13, -3], [0, -2], [9, 4], [-9, -2], [-12, -2], [-13, -7], [-2, -13], [11, 0], [-4, 0], [18, 5], [-4, 5], [12, 2], [9, -8], [-4, -11], [14, 3], [-2, 10], [-8, 4], [2, -9], [19, -9], [-6, -8], [7, 13], [19, 5], [2, -18], [15, -11], [-6, -4], [-22, -7], [9, -16], [0, 10], [-8, 8], [-2, 0], [12, -6], [11, -3], [-7, 6], [-2, 13], [3, -2], [-32, 0], [-12, 8], [22, -6], [-8, -5], [27, -6], [-20, 4], [28, 4], [1, 7], [-8, 12], [-2, 1], [-21, 10], [4, 8], [0, 5], [-12, 9], [23, 9], [27, 3], [14, -16], [-9, -1], [-3, -10], [20, -1], [6, 14], [-9, 15], [31, -3], [3, -22], [14, -4], [16, -10], [1, 15], [4, -4], [2, 6], [26, 4], [7, 4], [6, -18], [9, -1], [20, 4], [-31, 1], [36, -7], [33, -7], [7, 7], [-26, -10], [0, -17], [-1, 24], [0, -2], [-10, -1], [2, -14], [-4, 12], [28, 2], [-14, 15], [-1, 13], [45, 4], [32, 6], [16, 15], [12, -24], [7, 7], [4, -13], [-31, -3], [2, -16], [-11, -1], [-5, -1], [3, 19], [20, -18], [0, -8], [-10, -12], [34, -6], [48, 2], [-30, 6], [11, 19], [-2, 2], [24, -10], [28, -6], [-3, 23], [-28, -4], [26, -12], [6, 1], [16, 8], [-3, 6], [-4, -26], [39, -3], [6, -2], [3, 5], [-7, 12], [32, -5], [6, -16], [-39, 5], [38, -6], [17, -9], [0, 2], [-15, -20], [-41, 12], [32, 2], [-16, 12], [-45, -9], [-12, -2], [-28, 9], [-3, -9], [-13, -1], [-3, -3], [-33, 4], [-3, -12], [-9, 21], [-10, 2], [-26, -1], [-4, -32], [-11, 6], [-34, 2], [-42, -11], [24, 25], [18, 5], [-56, -2], [-6, -14], [1, 0], [40, -5], [14, -8], [-21, 2], [-10, -23], [-24, -6], [19, -3], [13, -3], [-36, 13], [-6, 10], [-41, 13], [35, 13], [44, -6], [-28, -2], [-49, 8], [31, 15], [-15, -3], [-6, 8], [38, -2], [44, 14], [36, -6], [-37, -4], [-6, -20], [4, 14], [-24, 14], [-39, -10], [-6, -22], [-23, 3], [-45, 3], [-8, -8], [15, -28], [-5, 9], [6, -24], [-16, -13], [4, -10], [10, 27], [45, -12], [1, 10], [17, 13], [-16, -8], [32, -20], [21, -23], [-18, -2], [-13, 13], [-11, 31], [-14, 34], [-28, 2], [27, 27], [4, 0], [15, 14], [8, -12], [-10, 36], [10, 13], [-45, -16], [8, -17], [-33, 25], [-29, -4], [-31, -5], [2, 10], [54, 9], [-46, 0], [62, 5], [8, 2], [-22, 10], [-29, 24], [-35, -5], [-20, -15], [11, 23], [12, 6], [40, 5], [-36, -10], [-63, 5], [-54, 15], [35, 5], [-4, 32], [40, 15], [-49, -16], [-52, -14], [24, 4], [35, -17], [-40, 7], [25, 15], [-36, 8], [18, 25], [-39, 1], [-7, -31], [10, -20], [15, 23], [-20, -24], [20, -24], [-77, 0], [18, -23], [-42, 10], [35, 8], [-1, -13], [20, -27], [42, -10], [19, -9], [28, 16], [15, 23], [-44, 6], [-45, 5], [-66, 8], [4, 34], [63, -10], [-20, 1], [-35, -29], [-20, 16], [18, -8], [2, 10], [11, 13], [38, 6], [-7, -44], [20, -33], [-41, 6], [-21, -21], [47, -14], [-36, 11], [24, -34], [-19, -39], [-48, -23], [-36, 26], [10, 30], [-27, 19], [30, -14], [32, -32], [-2, 0], [-16, -24], [-27, -15], [-65, 9], [8, -10], [-16, -30], [45, 21], [-51, -19], [-34, -11], [0, 19], [34, 6], [-36, -5], [-58, 16], [-18, -5], [28, 18], [51, -20], [1, 26], [-26, -22], [-37, 5], [-9, -31], [-32, -13], [-11, -20], [-16, 23], [4, 22], [-46, -5], [-24, -23], [62, 6], [-39, 19], [-40, 3], [-19, 25], [18, -14], [-47, -18], [-44, -8], [-13, -32], [-31, 12], [-20, 27], [-3, 3], [-75, 1], [-64, 11], [63, 3], [13, 7], [52, -26], [-12, -4], [23, 23], [26, -24], [32, 18], [-18, -34], [-8, 37], [-56, 11], [-44, 28], [24, -19], [-14, 30], [-52, -26], [-61, 7], [53, -12], [-55, -14], [6, 14], [-82, 8], [42, -32], [18, 8], [10, -22], [-5, -41], [70, 11], [-33, -21], [40, 16], [-8, -18], [-42, 26], [-9, -43], [-1, 31], [-38, 21], [-32, -13], [-20, 22], [-17, -27], [75, -15], [-44, -6], [-39, -4], [-44, 17], [-47, -25], [8, 26], [60, 2], [-92, 6], [-19, -22], [-26, 21], [-30, 36], [10, -3], [11, 12], [-20, 31], [46, -7], [4, 12], [34, 0], [-13, -51], [-14, 26], [35, 40], [8, 10], [-26, 10], [61, 8], [-44, 32], [-39, 3], [10, -20], [38, 28], [9, 10], [4, -26], [-25, 23], [-6, -8], [6, 10], [18, -46], [25, 3], [37, -24], [-77, 11], [30, 6], [-33, 13], [-65, 3], [42, 3], [16, 26], [15, -24], [34, 26], [0, -33], [-35, -13], [12, 44], [90, 8], [-51, 5], [34, -22], [25, 30], [-99, 0], [59, -21], [27, 45], [-12, -14], [9, -39], [-6, -43], [65, 1], [10, -15], [73, 11], [7, 38], [22, 33], [-13, 1], [56, -20], [4, -10], [-27, -28], [-2, -51], [7, 28], [18, 34], [-4, 52], [-10, 16], [-9, 58], [-59, 8], [18, -13], [44, -8], [-25, 19], [9, -4], [3, -47], [-24, -28], [-56, 12], [-66, 4], [-22, 30], [-24, -14], [-57, 21], [-59, 8], [72, -7], [-11, -9], [85, -18], [2, 18], [-52, -20], [72, 0], [-80, 10], [-46, 7], [52, 8], [20, -32], [80, 16], [45, 23], [27, 5], [-7, -13], [58, -3], [-42, -11], [72, 22], [2, 58], [-12, 34], [52, -26], [38, 1], [1, -5], [22, 42], [-23, 4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8550_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8550_2_a_bt();".
// 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_8550_2_a_bt(:prec:=2)
    chi := MakeCharacter_8550_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_8550_2_a_bt();".
// 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_8550_2_a_bt( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8550_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-2, -2, 1]>,<11,R![-27, 0, 1]>,<13,R![6, -6, 1]>,<17,R![-2, -2, 1]>,<23,R![13, 10, 1]>,<53,R![-59, 8, 1]>],Snew);
    return Vf;
end function;