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