
// Make newform 8550.2.a.ch in Magma, downloaded from the LMFDB on 25 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_ch();".
// 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_ch();".
// 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, -7, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, -2, 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], [1, -1, 0], [-1, -1, -1], [2, -1, -1], [-1, 1, 0], [-1, 0, 0], [0, 2, -1], [-2, -1, 2], [1, 2, 0], [0, 2, 2], [-3, 0, -1], [0, -1, 3], [-3, 2, 3], [-3, 1, 3], [-4, -1, 1], [-1, 1, 3], [4, 1, -4], [-7, 3, 2], [6, 0, -3], [-5, 4, 2], [0, 1, 2], [-2, 0, -3], [-3, 3, 0], [-10, 1, 1], [4, 2, 1], [2, -5, -1], [-8, -2, 0], [6, 0, -5], [-1, -2, 2], [-8, -3, 2], [-4, -2, -4], [-8, 5, 1], [-4, 6, 0], [5, -6, -1], [-7, -2, -1], [6, 0, 0], [-4, 0, 6], [2, -5, 2], [-2, -6, -2], [6, 1, -5], [-7, -2, -2], [5, 1, 6], [-2, -3, -1], [-6, -4, -8], [7, 5, -7], [8, 4, -5], [-12, 0, -2], [-2, -3, 4], [13, -7, -4], [-15, 10, 3], [5, -5, 0], [-9, 8, 1], [-10, 2, -1], [14, 2, 1], [2, -2, -2], [13, -3, 2], [-13, 7, 3], [-17, 2, 2], [6, -4, -2], [13, -7, -3], [-2, -5, -4], [-1, -4, -1], [-6, -8, 1], [-22, -1, 2], [8, -1, 4], [-4, 6, 0], [0, -6, -6], [10, 1, 6], [13, -1, -8], [-15, 2, 3], [-3, 3, 2], [10, -1, -5], [-12, -6, -2], [5, 3, 8], [-2, 2, 4], [-11, 9, 5], [7, -4, -2], [12, -2, -2], [-2, -2, -4], [8, 8, -2], [-20, 10, 4], [-15, 9, 0], [-1, -6, -8], [20, 1, 2], [-8, -6, 3], [1, -10, -7], [-22, 0, -2], [12, 6, -2], [-3, 7, -7], [22, -2, -5], [14, 2, 0], [10, -8, -6], [2, 11, 5], [16, 0, 0], [7, -9, -5], [-9, 10, 0], [-12, 2, 2], [14, -7, -6], [-1, -1, -3], [0, -9, 1], [4, -7, -9], [18, 2, -2], [6, 1, -1], [-9, -8, -2], [-22, 11, 2], [-4, -2, 12], [17, 3, -10], [-9, -5, -8], [18, -10, 1], [-20, 0, 6], [-6, -2, -10], [-12, -7, -1], [22, 0, -8], [-3, 2, -3], [12, 6, 10], [22, -4, 1], [2, 4, -4], [-2, -7, 1], [-12, -6, 4], [-15, 5, 2], [15, -17, -1], [4, -5, 1], [-20, 11, 9], [-12, -4, -6], [20, -3, -6], [-9, -6, 8], [-22, -2, -8], [-8, -9, -8], [-20, 6, 2], [-2, 8, -6], [-17, -8, 3], [-18, -3, -8], [3, 11, 6], [-4, -10, 7], [-12, 16, 6], [-16, 11, 4], [-15, 14, 7], [-19, 1, -10], [-1, 5, 3], [2, -3, 3], [4, -8, 0], [6, -11, 3], [8, -7, -13], [13, 3, 4], [-24, 2, -4], [-15, 18, 9], [-16, 4, -6], [14, -2, 2], [-4, -4, -12], [-6, -6, 2], [-8, 1, -9], [4, 10, 6], [-15, 0, 11], [2, -10, 6], [-1, 11, 12], [-16, 16, 2], [-18, 6, 2], [25, -7, 3], [2, 10, -12], [7, 2, -4], [4, -6, -2], [32, 3, -7], [13, -8, -5], [-17, -9, 10], [24, 0, 7], [-35, 15, 3], [-14, 4, 16], [14, 1, 1], [2, -8, 8], [10, 5, -5], [-11, -2, -17], [-15, -6, 4], [-30, -6, 5], [20, -2, -4], [-16, 18, 0], [8, 1, 11], [5, -2, -1], [11, -19, 3], [-25, 1, 0], [18, -15, -5], [-24, 11, 7], [43, 4, 6], [-33, 0, 6], [20, -7, 3], [-26, -10, 8], [-7, -11, -7], [18, -4, -12], [8, -10, -1], [-30, 2, -10], [17, -19, -13], [4, 3, 8], [18, 7, -14], [-9, -12, 9], [-31, -12, 15], [3, -2, -4], [-3, -7, 13], [20, -12, -6], [-21, -12, -6], [-20, -5, -4], [-11, 4, 9], [-18, -9, 11], [-3, 7, 2], [-42, -5, -6], [22, -4, 4], [-17, -3, 4], [2, 5, 1], [12, 10, -14], [3, 4, -15], [-45, 4, 6], [-8, 13, 19], [7, -1, 2], [10, -12, -4], [54, 2, 2], [-28, -6, 2], [32, 10, -12], [20, 6, 13], [-8, 0, -16], [-36, -8, 0], [12, 2, -20], [30, -16, -1], [29, -12, -13], [5, 13, 18], [20, -9, -5], [-35, 18, -1], [33, 10, -2], [-21, -11, -14], [-1, -4, 15], [25, 3, 3], [-14, 8, -4], [1, 3, -15], [13, 6, 12], [16, 6, -11], [20, -15, -3], [26, -14, -4], [19, 14, -9], [-12, 3, -5], [-28, 6, -10], [33, 1, -12], [4, -5, -11], [4, -18, -6], [14, 6, 6], [44, 1, 3], [-23, 10, 1], [-11, -8, 22], [-34, -8, -4], [4, -4, 14], [-17, -1, -7], [6, -2, -5], [1, 5, -7], [-29, -1, 4], [3, 18, 22], [-1, 9, 0], [-22, -6, 0], [19, -3, 15], [4, -14, -12], [20, 7, 0], [8, -4, -10], [-27, -10, -11], [29, -16, -6], [4, -19, -11], [-28, -11, 8], [-46, 1, 3], [6, -14, 4], [-24, -5, 16], [8, 12, 6], [21, 11, -2], [41, 9, 13], [10, 15, -5], [-10, -10, -2], [37, 1, -1], [-19, 0, -4], [-6, -6, 14], [48, -24, -6], [35, 1, -6], [46, 9, 4], [0, -15, -3], [-30, 16, -6], [12, 19, -6], [-25, 3, -8], [-19, -11, -4], [-5, -8, -5], [-36, 11, 11], [10, 18, -6], [-4, -16, -4], [0, 2, -1], [37, 1, -3], [-8, -2, -4], [45, 4, 10], [36, 9, -17], [3, -7, -13], [23, -10, 11], [-12, 9, 1], [-6, -10, 10], [-6, -3, 17], [29, -2, -13], [-22, 11, 19], [4, 14, 2], [-22, 10, 2], [33, -2, -8], [27, 15, -5], [-15, -9, 6], [16, -12, 8], [18, -18, 0], [-6, -2, 16], [8, 1, 3], [-18, 18, 8], [-5, -20, 16], [-32, 15, 10], [21, 12, -4], [-52, 1, 11], [13, 12, 16], [58, -1, -6], [9, 12, 13], [-3, 19, 20], [65, 7, -7], [22, -2, 16], [-25, 6, 3], [-41, -11, 4], [12, -16, -4], [-7, 2, -11], [-20, 6, 4], [28, -4, -12], [31, 5, 14], [-37, 7, 14], [-19, 24, 15], [45, 8, 3], [-35, 7, 2], [-4, 11, 11], [1, -17, 13], [56, -1, 2], [-10, -18, -18], [-44, 3, 4], [38, 2, -12], [-24, 5, -4], [-32, 2, -4], [-50, -4, -5], [0, -16, 3], [52, 2, -4], [-20, 23, 1], [31, -7, -2], [40, -25, 0], [8, -30, 5], [30, -21, -8], [-4, -10, -28], [54, 1, 2], [41, 1, -11], [-2, 14, 16], [24, -7, 7], [-21, 29, -1], [-17, 21, -4], [-32, -4, 2], [14, -4, 9], [-14, 16, 6], [16, -30, -1], [-44, 6, 1], [-1, -1, -15], [-49, -9, 12], [5, 11, 18], [-47, -7, 1], [31, 1, 10], [53, 9, -8], [70, -14, -2], [4, 10, 24], [-21, -13, -12], [20, -14, -6], [-19, 14, 11], [-4, -2, 26], [36, -1, -4], [26, -9, 12], [22, -14, -4], [-9, 3, 25], [20, -2, -6], [-40, -12, -6], [-54, 1, -9], [-24, 20, 7], [-19, -16, 12], [-22, 22, -4], [-2, -8, 6], [6, 16, 0], [-38, 8, 6], [28, -26, -12], [-19, -13, 2], [19, 1, 13], [23, -31, 2], [2, -8, 2], [6, -12, 20], [10, 14, 8], [-27, -13, -12], [51, -11, 2], [2, 3, -12], [-74, 5, -2], [-12, 12, -8], [15, -19, -8], [-19, 13, 8], [13, -22, -5], [14, -22, -23], [19, 1, 9], [-54, -9, 15], [28, 4, -24], [-36, 10, -12], [51, -10, 5], [7, -16, -2], [-25, -15, -7], [52, -4, -16], [-38, 3, 12], [15, -28, -4], [35, 9, 25], [53, 17, -19], [-40, 8, 10], [-34, 26, 16], [-68, 3, 11], [-14, 24, 12], [47, 10, 8], [-6, -2, 22], [-8, 30, 0], [27, 0, -18], [-24, 12, -2], [33, -3, -12], [18, 4, 28], [26, 18, -4], [57, 12, 14], [-52, 6, 16], [23, -9, -8], [10, 2, -26], [68, 8, 2], [-84, -2, -2], [-4, -23, -21], [11, -30, 2], [-37, 1, -10], [-22, -8, -18], [-18, -11, 15], [-37, 9, -6], [-17, 31, -1], [-58, -10, 8], [99, -6, -2], [-28, 26, -10], [-9, 7, 3], [-25, -13, -22], [-26, 16, -14], [18, -28, -10], [16, 9, 29], [2, -2, 10], [-2, -8, -27], [34, -20, 1], [-28, -17, 27], [-11, -13, -16], [22, 2, -18], [0, -19, 1], [-22, 5, -8], [-13, 9, 4], [-12, -13, 24], [-73, -3, -4], [87, -10, -2], [5, 3, -19], [60, 11, 7], [40, 16, -20], [-40, 34, 8], [-74, -2, 3], [63, 1, -1], [-2, -22, -7], [-64, -2, 6], [-22, 10, -6], [-14, 22, -8], [-14, 18, -5], [-22, 12, 1], [-33, -9, 9], [18, 0, -8], [-52, -15, 9], [79, -6, 0], [-6, 23, 17], [-4, 4, 6], [-31, 6, -15], [-2, 10, 28], [-54, -18, 0], [-22, 30, 14], [9, -3, 4], [-19, 10, -22], [-26, 17, 16], [45, -21, 0], [75, -6, 2], [32, 10, -16], [-13, 6, 21], [-48, -8, 14], [-51, 0, 23], [12, -1, 2], [-30, -6, 6], [20, 12, 8], [-38, -14, -12], [-4, -17, -37], [17, 23, -20], [1, -3, 24], [19, 3, 25], [-82, -3, -10], [0, 2, 32], [54, -26, -4], [-40, -8, -8], [-24, 38, 24], [-39, 9, 25], [-38, 13, -13], [-24, 34, 2], [13, 30, 8]];
    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_ch();".
// 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_ch(: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_ch();".
// 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_ch( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8550_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![10, -6, -2, 1]>,<11,R![-27, -5, 5, 1]>,<13,R![6, -8, -4, 1]>,<17,R![-10, -6, 2, 1]>,<23,R![81, -45, -1, 1]>,<53,R![117, -73, 5, 1]>],Snew);
    return Vf;
end function;