
// Make newform 8550.2.a.bw 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_bw();".
// 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_bw();".
// 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;
    Rf_num := [[1, 0], [0, 2]];
    Rf_basisdens := [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], [-2, 0], [0, 1], [-2, -1], [0, -1], [1, 0], [0, 2], [0, -1], [2, -1], [-2, 1], [0, 0], [-2, -1], [0, 2], [-6, -2], [0, 1], [2, 0], [-8, -2], [0, 2], [-2, 2], [2, -1], [-6, 1], [0, -2], [-8, -3], [6, 0], [-2, 2], [0, 2], [-4, -3], [-6, 0], [-14, 0], [0, -1], [-12, -1], [-4, 4], [-6, 0], [2, -3], [-2, 5], [10, -1], [-12, -2], [-18, 0], [-12, 3], [8, 3], [6, -5], [4, -3], [-6, 2], [-4, 2], [-4, -4], [10, 4], [0, 0], [-22, -2], [-12, 1], [-6, 1], [14, -4], [0, 3], [-18, -2], [-12, -4], [-12, -3], [-4, 6], [10, -3], [24, -2], [10, 3], [6, 2], [4, 6], [6, 3], [-2, -6], [-6, -4], [8, 2], [16, -5], [6, 9], [2, -4], [-24, 3], [-30, -1], [-2, 8], [10, -3], [-16, 2], [12, 2], [6, 6], [-2, -5], [12, 0], [-10, -6], [-24, 3], [8, 9], [-12, -2], [4, 5], [14, -5], [6, -3], [-12, 4], [22, 0], [30, 2], [22, -2], [18, 1], [-18, 3], [-14, -6], [-24, -5], [-16, -2], [0, -2], [-12, -7], [-12, 0], [28, 0], [2, -12], [-20, -2], [6, 2], [12, -6], [-12, -4], [-28, 0], [-14, 6], [30, 3], [-12, 7], [12, -6], [26, -2], [10, -10], [-2, 3], [-12, -3], [8, 6], [-16, -2], [24, -4], [-14, -9], [24, -2], [-18, -8], [-12, -3], [32, 3], [-20, 5], [18, 0], [-12, -4], [20, 0], [-30, 2], [26, 6], [-18, 1], [-14, 4], [10, 9], [8, -6], [-24, 4], [2, -1], [10, 9], [12, 12], [14, 4], [-6, 4], [-20, 0], [6, 8], [12, 10], [44, 0], [6, -4], [22, 6], [-12, 2], [44, 1], [0, 4], [-2, -5], [-6, 6], [-28, -4], [36, 2], [34, -3], [0, -2], [-14, 3], [0, -12], [16, 0], [-24, 4], [32, 2], [-12, 0], [-2, -12], [-24, -7], [18, -5], [18, 0], [-14, 2], [-36, 5], [-18, 12], [12, 14], [2, -3], [-2, -3], [14, 12], [54, 2], [-24, -11], [-4, -5], [18, 3], [-2, 6], [14, -7], [24, -2], [20, -4], [-42, 6], [46, -4], [14, -4], [34, 0], [-48, 3], [34, -5], [-6, 0], [24, 10], [-6, 0], [-2, 3], [-44, -4], [26, -6], [-30, -7], [-32, 3], [18, -5], [20, -12], [0, 5], [-6, 5], [6, -2], [-46, 0], [-14, 11], [24, 5], [-24, -2], [36, -5], [38, -3], [-2, 7], [2, 2], [12, -5], [-30, -2], [-4, -12], [-12, -6], [0, -2], [-16, 10], [-14, -16], [-30, -4], [22, 4], [0, 8], [12, 8], [-22, 4], [-14, 6], [36, -4], [-36, 2], [6, -6], [20, 3], [-10, 11], [24, -4], [10, 0], [12, 4], [-10, 8], [18, -16], [36, -6], [22, 0], [36, 3], [-14, 15], [-4, 12], [-34, -9], [-24, 6], [22, -3], [48, -2], [2, 16], [-18, 4], [24, 5], [-12, 4], [0, -4], [-16, -6], [-2, 6], [-52, 5], [-6, -6], [-30, -3], [-14, -6], [-12, -17], [-28, 8], [36, 4], [34, 9], [48, -8], [-24, -2], [2, -12], [18, -4], [24, 7], [-22, -12], [-44, 0], [18, 14], [58, 0], [58, 0], [12, -10], [50, -2], [-2, -3], [12, -13], [-16, 6], [36, -9], [48, 0], [-20, 12], [-18, -8], [20, 15], [28, 6], [-62, 0], [-52, 0], [-8, -1], [-2, 0], [30, -7], [-4, 1], [14, -14], [0, -5], [-24, 12], [8, -12], [12, 12], [8, -19], [-26, 3], [-18, 15], [10, -14], [42, -4], [-16, -4], [36, -6], [54, -2], [-54, -3], [-18, -8], [48, 1], [22, -7], [18, -4], [26, 3], [-30, 8], [36, -1], [-2, -1], [-50, 6], [18, -16], [-64, 4], [24, 10], [8, -14], [-8, -11], [48, 6], [20, 3], [54, -5], [-2, 17], [12, -8], [-18, 20], [-12, -16], [4, 6], [-60, -4], [26, -6], [24, -7], [0, 26], [-26, 10], [-48, -8], [44, 8], [-38, -8], [0, 11], [46, -8], [24, 11], [-10, 16], [44, 4], [40, -4], [24, 16], [78, 2], [26, -2], [42, 6], [32, 6], [-6, -23], [-16, 18], [-30, -3], [8, -3], [-18, 4], [-22, 4], [-50, 0], [-38, -15], [60, 9], [-24, 3], [26, 9], [42, -2], [-36, -5], [-10, 12], [-44, 6], [60, 8], [66, -8], [20, -12], [-8, 17], [-54, -6], [-2, 6], [44, 9], [-18, -8], [-18, -7], [0, -23], [-72, 1], [0, 4], [-26, -3], [-24, 0], [0, 28], [-24, -11], [-38, -9], [-20, 3], [18, -4], [-50, -10], [14, -8], [-12, 11], [-16, 6], [-48, -14], [0, 27], [-4, -22], [10, -3], [-24, 1], [-42, 5], [-38, -6], [-12, -8], [64, 9], [-48, -7], [-12, 3], [22, 12], [-36, -11], [-40, -14], [24, -16], [-52, 4], [-86, -3], [-38, -3], [-12, -18], [-10, -4], [18, -6], [36, 19], [-14, 23], [36, 14], [-8, -3], [26, 1], [-24, 8], [20, -16], [6, -18], [8, 9], [36, 11], [-50, -6], [18, -12], [-36, -7], [-28, -12], [82, -3], [-60, 8], [-8, -18], [12, 17], [-80, 1], [30, 16], [-12, -4], [-16, -2], [10, -12], [-18, 12], [-36, -14], [-26, 18], [-12, -9], [-36, -2], [-72, 9], [-14, 5], [24, 10], [24, 3], [-8, 3], [30, -6], [0, 26], [0, -16], [44, -4], [54, 1], [2, 22], [-36, -13], [8, 18], [0, -12], [22, -9], [12, 18], [-10, 20], [-4, -3], [64, -6], [44, 4], [-6, 7], [24, -2], [20, -13], [0, -14], [-94, 0], [18, -18], [-50, 7], [-48, -4], [-22, -24], [32, -7], [4, 4], [12, -8], [42, -13], [-36, -16], [34, 8], [-96, 5], [68, 9], [-60, -3], [-62, -1], [-90, -2], [-16, 6], [-22, -1], [-48, -3], [-40, -3], [10, -15], [-62, -4], [2, 15], [-6, -13], [84, 6], [20, 20], [22, 22], [48, -4], [12, 18], [2, -16], [-84, 5], [58, 11], [-6, -8], [-52, 4], [-36, 8], [-6, 28], [-44, 3], [-12, 10], [40, 9], [-96, -1], [-2, -6], [-42, 1], [-10, 12], [72, -5], [-52, 16], [-22, 15], [-2, -15], [36, -14], [-10, -18], [30, -22], [-60, -11], [26, -24], [16, 18], [-54, 12], [32, 12], [8, 6], [-114, 0], [-14, -18], [-6, -26]];
    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_bw();".
// 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_bw(: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_bw();".
// 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_bw( : 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, 1]>,<11,R![-12, 0, 1]>,<13,R![-8, 4, 1]>,<17,R![-12, 0, 1]>,<23,R![-48, 0, 1]>,<53,R![-12, 12, 1]>],Snew);
    return Vf;
end function;