
// Make newform 2800.2.a.bo in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2800_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_2800_2_a_bo();".
// 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_2800_2_a_bo();".
// 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 := [-4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_2800_a();"
function MakeCharacter_2800_a()
    N := 2800;
    order := 1;
    char_gens := [351, 2101, 2577, 801];
    v := [1, 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_2800_a_Hecke(Kf)
    return MakeCharacter_2800_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 := [[0, 0], [0, 1], [0, 0], [1, 0], [3, -2], [-2, 0], [0, 1], [-2, 1], [3, 1], [5, 1], [6, -2], [-1, 5], [-4, -1], [5, -1], [-2, 4], [-2, -2], [-2, 6], [8, -2], [11, 2], [3, 3], [-8, -1], [1, -3], [-6, -3], [2, -5], [-6, 0], [0, 0], [2, 2], [0, -5], [9, -7], [-11, 4], [3, -5], [12, -4], [10, -3], [12, 3], [15, 1], [3, 1], [-4, -8], [4, -7], [6, -10], [6, -8], [16, -3], [-8, 2], [-16, 6], [5, -10], [1, 1], [8, 2], [-8, -1], [-16, 6], [2, -6], [-14, 0], [-1, -1], [4, 0], [2, 9], [20, -3], [-6, 4], [-3, -3], [22, -4], [-6, -4], [-10, 8], [9, 1], [-6, -3], [30, 0], [12, -3], [-8, 2], [-22, 0], [13, 3], [-27, 0], [-2, 3], [-3, 10], [-18, 2], [22, -4], [7, 3], [28, -4], [9, -9], [-11, 14], [-10, -4], [5, -1], [-18, -8], [-11, -8], [-18, 5], [6, 5], [23, -7], [24, -4], [-8, 17], [2, 2], [20, 1], [-5, 6], [9, -18], [-14, 8], [0, -8], [-30, 2], [10, 12], [33, 1], [-13, -3], [-4, 8], [30, -4], [26, 0], [-30, 1], [36, -3], [3, 15], [3, 12], [-7, -1], [-2, -2], [21, -16], [-35, 3], [2, 17], [-20, 11], [-20, 3], [9, -13], [-28, 9], [-22, -6], [-1, 3], [-5, -5], [-14, -6], [-11, -9], [-19, 1], [-28, 12], [-10, -6], [2, -14], [-16, -1], [-2, -8], [-26, -8], [-30, 6], [29, 2], [20, -1], [-2, 18], [22, 6], [-28, -4], [24, -10], [-12, -4], [11, -11], [12, -12], [-12, -6], [-21, 3], [-4, 15], [0, -13], [-14, 10], [16, 4], [-16, -10], [11, 15], [-18, -10], [10, 14], [15, -1], [1, -4], [8, -4], [-4, 2], [-16, 2], [-28, 9], [-6, -11], [-11, -5], [2, -10], [-10, -12], [19, -8], [-24, -10], [4, 0], [1, 15], [-31, 5], [0, 22], [12, -13], [14, -6], [-4, 8], [33, -2], [-32, 6], [10, -3], [23, 4], [-6, -22], [-19, 19], [-2, -4], [-13, -10], [-8, 22], [21, 2], [2, 8], [-3, 1], [-14, -5], [0, -4], [0, -11], [17, 18], [18, -14], [14, -12], [-30, 0], [49, -9], [-36, 3], [-13, 11], [-34, -11], [27, 11], [10, 6], [1, -15], [-26, -5], [-7, 8], [32, -14], [-2, -15], [7, 2], [35, -8], [30, -22], [33, -2], [-24, -10], [5, 22], [39, -9], [-10, 13], [-14, 20], [-6, 16], [38, -16], [30, 0], [24, -7], [-4, 0], [32, -4], [46, -4], [-28, 20], [-21, 7], [-36, -12], [7, 19], [48, 0], [-15, -13], [-28, 9], [24, -26], [52, -1], [21, 7], [-10, 29], [-21, -7], [15, 1], [-27, 3], [-12, -14], [27, 6], [-45, 5], [6, -13], [-26, 2], [56, -1], [5, 13], [-40, 8], [11, 4], [15, -1], [6, 15], [20, 14], [-5, 8], [-22, 2], [-22, 2], [-44, 7], [-55, -3], [-37, 24], [-8, -4], [-5, 4], [38, -13], [22, 0], [7, 7], [18, 21], [12, 2], [-22, 12], [-18, -10], [-32, 19], [0, 6], [-30, 24], [-36, 5], [-24, 10], [20, -7], [-10, -2], [16, -5], [13, -21], [20, 7], [34, 10], [18, 3], [-16, 22], [9, 20], [18, -36], [-58, 14], [32, -15], [12, 23], [39, -9], [40, -14], [1, -14], [-25, -3], [-52, -8], [-16, -3], [12, 3], [-23, -19], [16, -2], [-24, 24], [9, -10], [-30, 12], [-17, -21], [28, -13], [48, -14], [-24, 24], [2, -10], [-24, 22], [-8, -5], [23, 17], [9, 21], [5, 13], [-60, 0], [22, -24], [63, -1], [2, 26], [-33, 2], [-24, 5], [-59, -3], [8, -4], [60, 2], [18, 6], [-16, -28], [2, -27], [-12, 1], [-22, 24], [-51, -7], [9, -10], [9, -14], [2, -7], [-21, -3], [-10, 10], [29, 19], [38, -16], [-44, 14], [18, -22], [-63, 4], [4, -4], [51, 3], [12, 18], [42, 5], [44, 10], [-16, -17], [13, -26], [36, -12], [-38, 1], [70, 2], [-45, 25], [41, -15], [-38, 20], [-39, -6], [54, 6], [-29, -19], [-29, -11], [-18, 8], [-5, 15], [-26, 6], [-40, -15], [-16, 9], [-54, 10], [-35, 37], [30, -24], [-14, -17], [-20, -6], [-2, -26], [-33, 24], [-4, -12], [-27, 23], [43, 3], [-29, -19], [12, 28], [-23, 28], [2, -4], [-28, 14], [24, 1], [57, 1], [-6, 4], [-54, 20], [15, -15], [-2, 21], [10, -32], [-32, 7], [-62, -4], [-20, -6], [53, 7], [18, -25], [40, -18], [11, 9], [10, 5], [2, 19], [38, -10], [45, -25], [-29, 14], [-53, 5], [38, -7], [-41, 11], [-62, -12], [10, -20], [-39, -1], [44, 3], [-37, 11], [28, -13], [58, -19], [56, -10], [-12, -12], [53, -6], [-41, 25], [-43, 0], [-8, 12], [-68, 6], [35, -11], [-26, -2], [-39, 39], [56, 6], [49, -2], [14, -6], [67, -12], [-34, 5], [19, -29], [27, -8], [-52, 8], [-10, 1], [-28, 9], [1, 3], [-50, 8], [21, -22], [-29, 43], [2, 7], [-34, 42], [-22, 32], [-27, 35], [46, 16], [8, 12], [-42, 31], [-26, 21], [7, -31], [64, -3], [33, 3], [51, 2], [14, -16], [-32, 6], [-40, 6], [-32, -11], [14, -16], [-38, -26], [32, 10], [40, -12], [-12, -7], [46, -29], [-8, 44], [-55, 15], [22, 29], [-28, 31], [78, 10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2800_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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