
// Make newform 2550.2.a.p in Magma, downloaded from the LMFDB on 25 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2550_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_2550_2_a_p();".
// 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_2550_2_a_p();".
// 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_2550_a();"
function MakeCharacter_2550_a()
    N := 2550;
    order := 1;
    char_gens := [851, 1327, 751];
    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_2550_a_Hecke( : Kf := Kf)
    return MakeCharacter_2550_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], [4], [-2], [6], [1], [4], [-5], [0], [10], [-9], [11], [-10], [-8], [11], [-15], [-1], [14], [11], [-8], [-8], [5], [-6], [-8], [18], [-11], [-4], [-14], [3], [-8], [12], [12], [11], [-1], [-7], [18], [5], [-16], [-4], [23], [-7], [-14], [4], [-6], [10], [4], [7], [-18], [-2], [1], [6], [-14], [28], [0], [-8], [10], [19], [3], [14], [-3], [-15], [-22], [1], [-8], [18], [6], [-10], [-8], [-14], [0], [8], [34], [24], [29], [-16], [-33], [7], [23], [19], [-4], [8], [-20], [-30], [-28], [9], [6], [15], [-15], [-19], [-37], [-24], [-6], [33], [-27], [5], [-18], [-18], [6], [21], [-15], [-15], [-41], [10], [-19], [-31], [-23], [16], [-12], [26], [10], [42], [-22], [-36], [-15], [10], [-23], [-30], [-16], [-24], [-42], [-36], [48], [-34], [-35], [-5], [2], [-40], [28], [-26], [-20], [-37], [-24], [-40], [8], [-5], [17], [-1], [-15], [6], [-4], [-24], [40], [-18], [4], [15], [30], [-19], [28], [-28], [18], [-19], [34], [-27], [-13], [8], [1], [37], [-23], [42], [24], [18], [31], [-49], [42], [24], [-60], [10], [-32], [36], [37], [26], [-13], [26], [-25], [59], [-15], [6], [7], [28], [53], [8], [30], [-16], [6], [13], [-15], [22], [38], [20], [-56], [-18], [-20], [63], [16], [21], [60], [-50], [-63], [-46], [10], [-44], [48], [-19], [16], [46], [-7], [-36], [-30], [50], [34], [-10], [-14], [0], [45], [-14], [-24], [-30], [-4], [54], [38], [4], [28], [-56], [27], [30], [10], [24], [-45], [20], [10], [-11], [15], [-40], [0], [62], [-70], [60], [-60], [6], [-48], [18], [-24], [-26], [39], [-49], [16], [-58], [-14], [8], [-16], [-66], [26], [-34], [54], [-53], [-7], [-73], [-44], [38], [44], [12], [57], [29], [31], [6], [6], [-42], [35], [-77], [6], [74], [19], [5], [-17], [-59], [-8], [30], [-35], [-15], [36], [-14], [-51], [8], [-17], [2], [8], [-60], [51], [-66], [36], [40], [-24], [0], [26], [70], [-57], [51], [-78], [-8], [-25], [66], [-52], [36], [-40], [-44], [9], [77], [30], [-14], [-45], [40], [73], [-12], [48], [55], [5], [43], [-14], [-54], [55], [-22], [-15], [24], [-51], [-23], [5], [67], [0], [-50], [-21], [-2], [-50], [20], [-68], [-42], [40], [-25], [18], [-15], [24], [-50], [0], [53], [-14], [56], [-58], [80], [69], [0], [18], [-46], [-51], [46], [30], [60], [20], [26], [-78], [24], [6], [33], [18], [2], [-32], [89], [-12], [-1], [16], [-95], [-65], [97], [-94], [-56], [-25], [0], [-96], [-33], [6], [59], [-24], [-12], [46], [-26], [81], [-21], [72], [74], [67], [0], [-50], [6], [4], [4], [-42], [-22], [-8], [-24], [-5], [-23], [19], [-86], [5], [-3], [21], [94], [76], [-42], [20], [14], [-28], [95], [-12], [60], [58], [38], [11], [76], [-23], [-54], [-82], [33], [-43], [11], [-50], [86], [48], [105], [-42], [87]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2550_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2550_2_a_p();".
// 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_2550_2_a_p(:prec:=1)
    chi := MakeCharacter_2550_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_2550_2_a_p();".
// 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_2550_2_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2550_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-4, 1]>,<11,R![2, 1]>,<13,R![-6, 1]>],Snew);
    return Vf;
end function;