
// Make newform 8550.2.a.k 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_k();".
// 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_k();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [4], [2], [6], [-1], [-6], [2], [-6], [-10], [0], [-6], [-6], [-10], [-2], [-6], [8], [12], [-16], [-14], [-12], [-4], [-10], [18], [8], [4], [4], [-2], [8], [8], [-6], [12], [6], [10], [-18], [-10], [0], [14], [18], [-4], [-24], [14], [-8], [-16], [-8], [-8], [12], [-10], [-14], [8], [-10], [-12], [-22], [2], [14], [32], [-26], [0], [22], [-2], [-12], [-24], [28], [-6], [-4], [6], [-20], [-26], [2], [8], [12], [6], [24], [-36], [-38], [-30], [-16], [26], [-8], [16], [24], [6], [-14], [0], [-4], [16], [18], [-8], [0], [16], [24], [0], [20], [14], [-6], [24], [36], [38], [-36], [-24], [12], [28], [-20], [-8], [28], [46], [0], [30], [-24], [-22], [18], [44], [-20], [-48], [-26], [-6], [-48], [-46], [-8], [26], [6], [36], [44], [22], [-2], [-48], [-28], [46], [20], [8], [-26], [-2], [-30], [-34], [50], [0], [54], [10], [-28], [-50], [-12], [-12], [-28], [-44], [-14], [18], [-28], [-36], [-46], [-18], [10], [12], [24], [36], [28], [-18], [-44], [-22], [8], [42], [28], [58], [26], [-56], [-6], [-2], [-50], [56], [62], [-44], [-16], [-4], [-38], [-14], [28], [54], [8], [-58], [52], [46], [34], [2], [26], [-6], [38], [-40], [-30], [0], [-14], [20], [-4], [-42], [-52], [26], [-18], [-22], [-42], [6], [30], [18], [-58], [42], [-24], [4], [36], [-44], [6], [-28], [20], [-42], [-28], [-12], [-28], [-70], [40], [72], [-28], [36], [-52], [-34], [16], [16], [52], [-2], [-26], [32], [32], [0], [-14], [-52], [-10], [-60], [26], [10], [46], [36], [12], [-16], [-4], [-28], [24], [4], [-58], [72], [-36], [70], [-40], [14], [22], [6], [42], [-74], [-32], [48], [58], [-44], [6], [-8], [56], [60], [10], [34], [-22], [-32], [6], [-42], [0], [12], [-36], [8], [-64], [-44], [-26], [56], [-16], [-20], [22], [12], [48], [28], [-30], [28], [-2], [-48], [16], [58], [-12], [0], [-46], [28], [-2], [70], [-10], [34], [-46], [-16], [-18], [46], [-72], [-66], [16], [52], [68], [86], [60], [36], [-40], [38], [-62], [-86], [64], [-80], [22], [34], [-44], [12], [-28], [42], [12], [32], [2], [-48], [-50], [6], [4], [44], [-8], [-48], [-54], [38], [-56], [24], [84], [28], [-40], [-62], [90], [20], [-10], [-58], [6], [-2], [14], [-90], [-70], [4], [-28], [20], [-56], [82], [-14], [96], [-64], [38], [-8], [80], [58], [-56], [-18], [-6], [-32], [-10], [74], [14], [-44], [32], [58], [-52], [24], [-14], [38], [20], [-2], [42], [88], [0], [30], [-74], [10], [-78], [-76], [-30], [76], [48], [-32], [-50], [-34], [-24], [54], [-66], [-48], [-26], [68], [-46], [70], [-20], [20], [-10], [-92], [26], [80], [-42], [38], [12], [46], [60], [-52], [68], [66], [20], [-36], [84], [64], [78], [24], [-80], [98], [-28], [-30], [38], [-78], [70], [94], [-50], [-108], [-10], [-52], [24], [-30], [-72], [-100], [44], [18], [-70], [78], [-76], [52], [-12], [-84], [54], [-60], [-40], [-82], [2], [-86], [52], [26], [100], [-108], [48], [36], [6], [20], [-90], [-16], [-18], [34], [66], [-40], [-50], [-6], [-8], [-90], [32], [98], [36], [-18], [60], [80], [-20], [0], [66], [70], [94], [-34], [-4], [-42], [-38], [-14], [72], [34], [-106], [8], [-104], [58], [-30], [-84], [-38], [2], [52], [-66], [102], [-52], [-18], [20], [36], [44], [8], [-30], [-72], [-62]];
    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_k();".
// 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_k(:prec:=1)
    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_k();".
// 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_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8550_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![0, 1]>,<11,R![-4, 1]>,<13,R![-2, 1]>,<17,R![-6, 1]>,<23,R![6, 1]>,<53,R![10, 1]>],Snew);
    return Vf;
end function;