
// Make newform 8550.2.a.cg in Magma, downloaded from the LMFDB on 24 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_cg();".
// 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_cg();".
// 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, -5, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, 0, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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], [0, 0, 0], [0, 1, -1], [-2, 1, 0], [1, -1, 2], [2, -1, -1], [1, 0, 0], [0, 0, 1], [-5, 1, 1], [1, -4, 0], [-2, 2, 0], [-3, 0, -3], [3, 1, 0], [-1, 2, -1], [0, -3, 2], [-1, -7, 2], [-2, 5, -2], [-1, 3, -1], [-8, 1, 1], [4, -4, -1], [1, 2, 0], [-3, -3, -1], [-8, 4, 3], [6, -5, -1], [-5, 1, 2], [8, 0, 1], [7, -5, 0], [6, -2, 2], [0, 0, 3], [1, -4, -2], [-1, -1, -3], [2, 2, 2], [11, -3, 4], [-10, 2, -2], [-1, -6, 3], [3, -2, 3], [2, 0, 4], [8, -4, 6], [-11, 7, -1], [-8, -2, -4], [-19, 3, 0], [-13, -4, 2], [0, 1, -1], [1, 7, 0], [2, 0, 8], [-8, 5, 0], [-2, 2, -3], [-4, 8, -2], [3, 1, 3], [-4, -1, -9], [-3, 6, 1], [2, -3, -7], [-15, 0, -3], [2, 2, -3], [-14, 4, -9], [-4, -10, 4], [-14, 5, 1], [0, 1, -4], [-13, 2, -4], [6, 4, 2], [-4, 5, -4], [-9, 1, 5], [-11, 4, -1], [-4, 0, 3], [17, -1, -1], [3, -5, 7], [-10, 6, 2], [6, -6, 0], [-9, 13, 1], [-14, 1, -7], [5, -10, 9], [-8, -7, 5], [-15, 7, -10], [26, -6, -4], [4, -5, 9], [-4, 2, -2], [-24, 7, 4], [-15, 0, -6], [6, 10, -4], [8, 2, -2], [0, 4, -10], [2, 2, -10], [-8, -7, 5], [7, -4, -4], [-15, 9, 3], [-8, 10, -9], [3, -2, -7], [10, -8, 10], [10, 2, 0], [8, 11, -6], [-6, 0, 3], [-12, -14, 2], [-10, 8, 2], [-9, -5, 6], [4, 4, -8], [0, 9, 8], [-9, -6, 6], [-2, 14, -8], [3, -11, 5], [-18, 13, -2], [-7, -7, 8], [-13, -7, -2], [4, -14, 4], [1, -7, -2], [-19, 0, -6], [21, 3, -3], [10, -14, 10], [-20, 1, -7], [0, 13, -3], [-10, -12, 1], [0, -8, 2], [-4, 2, 4], [7, -7, 10], [10, -4, -4], [3, -6, -7], [-10, -6, 0], [-8, 10, 1], [-6, 0, 8], [3, -9, 12], [-2, 2, 10], [-16, -3, 7], [24, -9, 12], [9, 3, -2], [-23, 11, -2], [-8, 16, -14], [5, -3, -3], [-19, -4, 8], [-12, 10, 10], [-23, 5, -5], [2, 6, 0], [-2, -8, -2], [-17, 8, -15], [-35, -1, 1], [-4, 11, 1], [-4, -6, -11], [16, 16, -2], [1, 5, 1], [-3, -6, -11], [0, -15, 7], [-12, 1, 2], [-21, 9, -4], [-4, 0, 0], [-31, 5, 2], [19, -1, 8], [4, 13, 3], [-34, -6, 2], [17, 14, -5], [-12, 4, -2], [28, -14, 0], [-8, -4, -8], [0, -6, 4], [13, -1, -2], [-22, 2, 4], [-1, 0, -9], [8, -10, -4], [22, -1, -3], [36, 0, 6], [-28, 6, -12], [4, -5, -2], [-8, 10, -2], [21, -6, 6], [14, -18, 4], [-13, 5, -6], [-29, -8, -1], [-10, -1, -1], [-14, 14, -5], [-18, 1, -4], [14, -12, 12], [25, -17, -6], [14, 8, -4], [9, 7, 0], [29, 2, 1], [5, -18, 6], [2, 12, -1], [-10, -10, -10], [-6, -14, 10], [-3, -15, 0], [-35, 2, -7], [-18, 13, -2], [24, 7, -7], [3, -9, 6], [3, -17, -2], [-1, -4, -2], [-19, 14, -12], [9, -15, 0], [-24, -2, -10], [26, 3, -8], [-18, 4, 8], [-8, 16, -5], [-16, -6, 0], [-10, 17, 6], [-21, -17, -1], [23, 5, -3], [-37, -4, -1], [3, 12, -1], [25, 14, -2], [-40, 3, -8], [44, -4, 14], [33, 6, -4], [13, 1, -9], [1, -4, -17], [1, -1, 18], [-26, -7, 3], [39, -3, -5], [-18, -24, 8], [36, -11, -1], [13, 13, 8], [6, -6, 4], [-25, -12, 7], [17, -24, -2], [25, 13, 4], [14, 9, 5], [-2, 4, 12], [-32, 10, 4], [2, -18, 4], [14, -6, 6], [8, 2, 9], [-8, -8, 0], [28, -8, 8], [30, 10, 2], [16, -10, -9], [-31, 20, -3], [-10, 3, -9], [-11, 7, -20], [-19, 6, -7], [3, -6, 16], [24, -9, -9], [-3, 28, -1], [-20, 13, -16], [6, 16, -4], [12, 19, -10], [-19, 12, 0], [4, 10, 17], [1, -1, 16], [16, -2, 10], [11, -6, 13], [17, -7, 6], [34, -14, 16], [-2, -5, -3], [25, -5, -6], [-6, -2, 8], [28, 14, 4], [23, -9, 8], [-39, 6, 3], [57, 6, 0], [6, 4, 8], [40, 4, 6], [-14, 23, -6], [10, 4, 13], [0, 7, 8], [28, 7, -9], [-5, 16, -2], [-30, 7, -25], [8, -10, -10], [-36, 3, 10], [-18, -2, 14], [-39, 13, -19], [-16, -4, 2], [23, 6, -3], [41, -6, 0], [55, -11, 0], [-7, -3, 19], [-9, 13, 8], [-40, 14, -10], [-33, -5, -13], [-24, -12, 6], [34, -5, -7], [30, -17, 8], [51, -15, -10], [-40, 6, 0], [-2, -25, 10], [7, 20, 4], [-4, 6, 0], [-4, 0, -2], [-12, 19, 11], [27, -3, -11], [-9, 19, -18], [6, -8, -6], [37, 13, 3], [46, 7, -7], [-38, 17, 7], [-13, 8, -23], [-7, 9, -10], [44, 6, 0], [32, -4, 4], [40, -10, -9], [4, -23, 0], [6, 10, -2], [-49, -4, -2], [29, -7, 8], [-32, 13, 2], [-41, 10, 1], [-3, 15, -8], [12, -14, -12], [-1, 5, 18], [-13, 6, -21], [15, -3, 10], [6, -6, -16], [28, -10, -16], [25, 2, -2], [-28, -1, 8], [-24, 19, -21], [60, 12, -4], [16, -10, 2], [0, -26, 10], [-21, 9, -18], [28, 14, -2], [-1, 2, 14], [-43, 9, -11], [-13, 14, 18], [25, 1, -8], [19, 4, -8], [27, 1, 11], [-35, 4, 3], [14, 21, -15], [20, -19, 6], [-8, 10, -14], [9, -2, 7], [26, 5, -7], [4, -16, 12], [55, 2, 9], [22, -2, 22], [28, 8, 0], [22, 19, -3], [40, -7, -13], [21, -8, -3], [27, -8, -9], [36, -21, -1], [29, 17, 2], [10, -1, -10], [-17, 31, -1], [36, -14, -4], [-41, -5, -5], [-16, -6, 18], [-3, -15, 9], [26, -6, -6], [20, -28, 15], [50, -12, 7], [-46, 18, 6], [-25, 15, 12], [14, -25, 13], [-51, 9, 3], [-28, 0, 3], [-11, -5, -23], [-58, 2, -10], [27, -23, -7], [6, -29, -4], [8, 2, 18], [55, -17, -8], [-32, 17, -2], [26, 21, 1], [12, -24, -6], [32, -6, 3], [-34, 0, 6], [36, -6, 5], [64, 4, 1], [26, -19, 14], [-4, 41, -3], [44, -1, -9], [44, -9, 0], [22, -23, 11], [-18, 21, -1], [8, -34, -4], [-14, 38, -2], [-24, -5, 11], [-10, 38, -16], [37, -22, 5], [-26, 26, 8], [-11, 13, 13], [17, 15, 3], [20, -10, 18], [8, -19, -2], [-2, -10, -12], [-32, 20, 10], [-1, 23, 14], [10, -14, 13], [39, -20, -4], [-32, -26, 6], [30, -8, 2], [-6, 0, -16], [6, -24, 6], [-2, -10, 10], [22, 13, -5], [-16, 33, -8], [40, 13, -3], [-6, -8, 6], [-26, -4, -8], [16, -22, 22], [-36, 3, -27], [6, -5, 13], [-55, 11, -11], [29, -1, 17], [32, -12, 28], [-12, 3, 5], [-12, 37, 5], [-17, 2, -25], [42, 6, -7], [0, -11, 16], [9, 15, -6], [-40, 12, -12], [-58, 14, -10], [-25, 18, 15], [-49, 8, -14], [-30, 27, -16], [0, 28, -4], [67, 17, -5], [-23, 4, 4], [8, 15, 12], [30, 3, 8], [12, -8, -26], [-12, -18, 14], [-19, 35, -4], [34, 8, 8], [35, -30, -6], [28, 10, -16], [-78, 6, -2], [-49, 6, -24], [-32, 4, 2], [-38, 25, -5], [2, -4, -8], [0, -14, -18], [35, 2, 12], [6, 18, -6], [-48, 7, -13], [40, -2, 8], [28, -32, -6], [34, -2, 28], [-9, 1, -2], [-19, 8, 14], [2, 15, -11], [-42, 24, -34], [9, 13, -10], [24, 21, 9], [-4, -39, 0], [-4, -10, 10], [-75, -2, 4], [14, 6, 12], [26, 9, 24], [-34, 27, -17], [-2, -32, 22], [-2, 28, 6], [43, -13, 18], [-40, -34, 8], [44, -12, 9], [-36, 12, -3], [67, -7, 12], [8, 11, -19], [-44, 14, 16], [7, 23, -6], [33, 7, -17], [-28, 23, -19], [-1, -37, 23], [42, -3, -7], [-1, 18, -8], [-54, 9, -10], [-31, -15, -6], [0, -24, 12], [22, -22, -10], [-2, -26, -11], [24, 13, 2], [18, -8, 19], [26, -22, 28], [16, 26, -8], [24, 10, -10], [-34, -18, -5], [-32, 26, 13], [-2, 7, 6], [-74, -8, 8], [19, -7, -24], [45, -8, 4], [-61, -1, -10], [68, -16, -2], [45, -14, 7], [-56, 22, -26], [-52, 6, -2], [-68, -14, 0], [-30, -23, 3], [13, 16, -18], [-45, -27, -1], [-6, -29, 11], [23, -22, -4], [-50, 26, -2], [-19, -10, -3], [-12, 28, 2], [13, 40, -11], [-17, 11, -17], [-4, 14, -28], [16, -28, 20], [8, -18, -6], [-1, 3, -6], [-12, 39, -7], [-32, 11, 19], [-28, 35, 2], [69, 15, 1], [-30, -26, 2], [24, 10, -10], [0, -24, -24], [6, -38, 26], [-22, -3, 0], [-9, -15, 0], [18, 22, -16], [27, -30, 14]];
    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_cg();".
// 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_cg(:prec:=3)
    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_cg();".
// 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_cg( : 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, -10, -2, 1]>,<11,R![-3, 3, 5, 1]>,<13,R![82, -36, 0, 1]>,<17,R![54, -6, -6, 1]>,<23,R![3, -9, 1, 1]>,<53,R![-183, -57, 5, 1]>],Snew);
    return Vf;
end function;