
// Make newform 8550.2.a.c 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_c();".
// 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_c();".
// 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], [-4], [1], [0], [8], [1], [3], [1], [1], [-2], [10], [-8], [0], [-3], [-4], [5], [-5], [6], [-13], [-5], [-11], [-3], [10], [12], [1], [-14], [6], [1], [-17], [15], [-4], [6], [0], [0], [2], [10], [22], [11], [-20], [12], [-13], [-14], [0], [26], [25], [29], [30], [13], [4], [-24], [8], [-16], [27], [19], [26], [-14], [17], [15], [32], [-1], [-5], [16], [-21], [-9], [-1], [-16], [-12], [-25], [0], [-16], [-22], [32], [-32], [18], [22], [35], [5], [-18], [12], [22], [14], [-22], [7], [-3], [23], [-22], [12], [4], [3], [-21], [-32], [-4], [-4], [4], [-25], [1], [4], [27], [21], [-36], [-22], [-6], [6], [-21], [33], [20], [24], [-38], [27], [38], [-6], [-20], [44], [-6], [2], [-43], [24], [0], [-8], [16], [-3], [6], [10], [8], [-35], [-29], [-18], [23], [4], [24], [40], [23], [26], [-45], [-54], [1], [46], [16], [-49], [10], [-26], [28], [26], [48], [46], [18], [34], [-28], [42], [8], [-26], [48], [-48], [-18], [-2], [12], [42], [19], [52], [15], [38], [8], [-2], [-30], [-25], [-13], [-30], [46], [-44], [-40], [20], [21], [17], [30], [28], [-10], [-16], [-47], [-18], [18], [-18], [23], [-39], [36], [-44], [17], [52], [-7], [64], [-61], [-9], [9], [68], [22], [-39], [-29], [58], [33], [45], [8], [20], [-28], [-69], [52], [22], [-60], [-2], [28], [-29], [-26], [48], [42], [-20], [-26], [42], [45], [18], [18], [-18], [69], [42], [26], [2], [22], [-49], [42], [0], [39], [26], [29], [-75], [5], [34], [-24], [-58], [-18], [12], [42], [-52], [-16], [-14], [42], [46], [25], [-44], [50], [-49], [73], [-17], [-66], [-57], [-58], [-52], [55], [-58], [13], [78], [-38], [3], [20], [47], [-58], [46], [-13], [-10], [32], [13], [-64], [40], [23], [-65], [-10], [36], [-64], [-19], [-12], [20], [5], [-36], [28], [-48], [62], [-56], [36], [-31], [-61], [-64], [-17], [54], [1], [-54], [-70], [16], [-78], [-4], [76], [62], [26], [-39], [-11], [-10], [-16], [-14], [44], [36], [-32], [-31], [25], [-67], [-70], [5], [69], [16], [84], [9], [18], [82], [2], [48], [2], [34], [-80], [-24], [42], [68], [-92], [44], [58], [-65], [-79], [-36], [25], [-46], [-33], [62], [29], [1], [68], [4], [-2], [-15], [-25], [-7], [-54], [-53], [37], [-24], [48], [-45], [-32], [-88], [37], [8], [57], [19], [-33], [-58], [-44], [67], [0], [-78], [50], [-24], [-64], [78], [-64], [48], [-45], [-71], [56], [9], [-4], [-74], [50], [83], [47], [-52], [-14], [18], [-30], [40], [-96], [-35], [-12], [-28], [94], [24], [-46], [68], [57], [9], [10], [-26], [66], [64], [27], [73], [-48], [34], [26], [4], [-57], [-61], [-34], [97], [71], [47], [19], [64], [54], [-72], [32], [43], [-106], [-16], [53], [-84], [78], [38], [-58], [-25], [14], [68], [42], [-64], [12], [72], [101], [80], [-48], [36], [-8], [-3], [-102], [-21], [16], [51], [-58], [-36], [-26], [-78], [-80], [105], [-33], [14], [-78], [-6], [54], [21], [-72], [-75], [54], [53], [-13], [32], [0], [-98], [-73], [-29], [25], [-16], [-68], [-58], [3], [19], [69], [-64], [-10], [57], [-68], [-20], [-62], [90], [-92], [18], [18], [-3], [47], [26], [75], [-116], [2], [-116], [-60], [19], [-80], [-44], [-8], [8], [98], [-10], [-45], [9], [-54], [88], [18], [-50], [35], [-68], [16], [-51]];
    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_c();".
// 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_c(: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_c();".
// 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_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8550_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![4, 1]>,<11,R![-1, 1]>,<13,R![0, 1]>,<17,R![-8, 1]>,<23,R![-3, 1]>,<53,R![3, 1]>],Snew);
    return Vf;
end function;