
// Make newform 5550.2.a.g in Magma, downloaded from the LMFDB on 13 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5550_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_5550_2_a_g();".
// 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_5550_2_a_g();".
// 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_5550_a();"
function MakeCharacter_5550_a()
    N := 5550;
    order := 1;
    char_gens := [3701, 1777, 2851];
    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_5550_a_Hecke( : Kf := Kf)
    return MakeCharacter_5550_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]];
    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], [-1], [0], [1], [3], [-2], [-3], [2], [0], [-3], [-1], [-1], [9], [-11], [0], [9], [-6], [-1], [-8], [-12], [-8], [-4], [6], [-6], [13], [0], [4], [18], [-1], [-9], [-8], [-6], [18], [5], [-6], [2], [7], [-11], [0], [-15], [-12], [2], [15], [-2], [6], [-4], [11], [-5], [-3], [8], [12], [-9], [-10], [0], [6], [9], [-24], [-4], [-8], [6], [-20], [-21], [-2], [3], [-26], [33], [20], [-14], [12], [-28], [-3], [6], [-23], [10], [-16], [0], [-33], [-14], [-30], [-22], [36], [-10], [3], [-20], [17], [-6], [0], [-35], [39], [-26], [15], [0], [-2], [-12], [32], [-24], [-36], [27], [40], [-34], [-11], [-6], [-39], [-18], [-13], [-38], [-33], [6], [36], [-31], [22], [25], [-18], [5], [47], [9], [-23], [12], [-24], [0], [17], [28], [-6], [-27], [-25], [-30], [-13], [30], [-26], [1], [-7], [-39], [-40], [10], [-15], [26], [51], [-8], [0], [0], [20], [6], [16], [9], [-13], [18], [46], [-45], [14], [-9], [-41], [9], [43], [-3], [52], [0], [-16], [15], [16], [18], [-27], [-24], [16], [-51], [-15], [39], [29], [10], [-19], [6], [-6], [23], [27], [28], [14], [-6], [-22], [-42], [61], [8], [-8], [-12], [40], [27], [3], [-6], [-11], [-35], [14], [-24], [34], [36], [-34], [12], [18], [6], [44], [28], [6], [60], [-6], [2], [-5], [29], [45], [30], [-22], [30], [36], [-13], [-11], [45], [22], [54], [9], [23], [-38], [60], [-18], [-21], [32], [14], [57], [-56], [48], [-46], [-48], [-60], [37], [18], [-5], [68], [-10], [18], [-26], [-15], [-58], [-54], [-42], [0], [-9], [8], [-56], [-31], [-78], [39], [-32], [12], [23], [-6], [-68], [-66], [-33], [50], [78], [45], [26], [10], [21], [-5], [22], [24], [32], [-29], [-30], [47], [12], [-12], [52], [54], [14], [-29], [22], [59], [-2], [-29], [42], [50], [-79], [18], [-24], [77], [-63], [8], [52], [-42], [-59], [-15], [32], [0], [39], [-84], [6], [75], [55], [42], [-34], [66], [-60], [76], [-11], [-66], [-16], [72], [32], [-17], [-63], [50], [-30], [-8], [48], [-24], [-3], [58], [-42], [-16], [-39], [-60], [-38], [-24], [20], [-50], [-45], [-29], [36], [56], [-61], [55], [-18], [-9], [-70], [-66], [35], [-36], [2], [-54], [-10], [-66], [-10], [-56], [46], [-42], [-6], [-73], [42], [-78], [20], [34], [-21], [33], [59], [-32], [45], [64], [-34], [-18], [-63], [-6], [-42], [36], [-74], [54], [66], [-66], [94], [-89], [30], [-86], [2], [24], [-70], [45], [-54], [77], [31], [72], [36], [-32], [0], [88], [33], [-54], [16], [-60], [86], [-99], [98], [58], [-17], [-48], [-85], [48], [-78], [-53], [-12], [16], [56], [3], [47], [96], [50], [-9], [82], [42], [-66], [-64], [-32], [-57], [-44], [15], [-8], [-81], [51], [-106], [31], [24], [42], [-77], [-96], [-102], [-90], [-20], [12], [-9], [16], [-3], [-24], [-45], [20], [51]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5550_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5550_2_a_g();".
// 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_5550_2_a_g(:prec:=1)
    chi := MakeCharacter_5550_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(2999) - 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_5550_2_a_g();".
// 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_5550_2_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5550_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-1, 1]>,<11,R![-3, 1]>,<13,R![2, 1]>,<17,R![3, 1]>],Snew);
    return Vf;
end function;