
// Make newform 2800.2.a.bp in Magma, downloaded from the LMFDB on 19 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_bp();".
// 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_bp();".
// 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 := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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], [1, 1], [0, 0], [-1, 0], [-2, 1], [-1, 1], [-2, 2], [0, 2], [-4, -1], [5, 0], [3, -3], [3, 0], [7, -1], [-4, 1], [2, 0], [4, 2], [-5, -3], [-3, -3], [2, 1], [-2, -3], [-11, 1], [0, 5], [1, 3], [15, 1], [3, 1], [7, -1], [-4, -2], [-8, 0], [-5, 6], [-1, -6], [2, -7], [8, 4], [-2, -4], [5, -7], [-5, 4], [18, 1], [3, -1], [6, -2], [-3, -1], [-16, 2], [10, 6], [-3, 5], [-2, -2], [-1, 6], [3, -2], [-5, -1], [-12, 0], [-9, -5], [-8, -6], [0, -2], [-1, 4], [10, -2], [-8, 2], [-2, -2], [3, -7], [-14, -1], [-5, -3], [-17, -3], [-2, -8], [7, -10], [-4, -6], [-11, -9], [-18, 6], [-2, -10], [24, -2], [3, 10], [18, 3], [-12, -2], [-18, -1], [0, 2], [9, -5], [10, 9], [17, 9], [-11, -12], [0, 5], [31, 1], [-15, 8], [18, -4], [7, -2], [20, 2], [15, 5], [-13, 0], [-22, 2], [-6, -10], [15, -3], [6, 6], [25, -2], [-17, 2], [-3, -5], [-4, 8], [2, -4], [15, 5], [-8, 1], [8, -1], [-20, 4], [26, -8], [25, 7], [22, 0], [6, -10], [7, 4], [12, -1], [-27, 8], [-4, -6], [5, -4], [-12, -11], [-2, 0], [27, -1], [-6, -14], [0, 5], [-28, -4], [-13, 9], [-31, -6], [3, -4], [5, 3], [-12, -7], [17, 12], [-14, -2], [2, 8], [34, -4], [0, -8], [2, -20], [24, -2], [8, -10], [6, -9], [-7, 5], [-38, 4], [-30, 8], [-5, -5], [12, -4], [4, 0], [-10, -7], [6, 2], [-12, 4], [33, -6], [-8, 16], [-5, -17], [39, 5], [-43, 1], [-22, -6], [25, 2], [-2, 20], [2, 12], [16, 7], [-8, -15], [-30, 10], [15, 7], [14, 6], [-27, 5], [0, -10], [-34, 7], [8, 10], [17, -5], [26, -11], [37, -7], [-8, -12], [-12, 5], [30, -1], [45, -3], [33, 1], [-3, -1], [-8, -12], [-1, 2], [32, -8], [18, 0], [-7, -2], [1, 15], [-2, -5], [-32, -6], [-5, 4], [34, -6], [20, -19], [2, 16], [38, -5], [-6, 0], [-45, 7], [20, 0], [28, -11], [-8, -6], [11, 21], [5, -5], [12, 21], [8, 16], [-1, -4], [8, 22], [16, -1], [0, 6], [23, 6], [-14, 4], [-15, 12], [3, 15], [-26, -12], [-24, 11], [-12, -5], [2, -28], [-18, 19], [9, 9], [-3, 0], [-41, 8], [-12, -6], [-19, 11], [-10, -16], [28, 2], [23, 1], [-25, -13], [45, -11], [23, -9], [10, 0], [26, -10], [15, -12], [-7, 9], [3, -20], [2, 18], [-4, 1], [-8, 8], [-5, -1], [12, 20], [22, 19], [22, -4], [-18, -7], [29, 14], [-3, 4], [-20, 24], [-5, -4], [16, -9], [-3, -13], [30, -4], [19, 15], [30, 7], [32, 0], [58, 1], [29, 14], [-5, 1], [-32, -8], [7, -4], [-39, 15], [7, -19], [35, 11], [-1, -22], [10, 9], [28, -20], [6, 1], [23, -3], [-39, -13], [-15, -14], [-31, -5], [50, 6], [22, -8], [28, -6], [10, -10], [-24, 24], [-32, -14], [17, 25], [12, 20], [-10, 6], [44, 14], [-20, 0], [-3, -20], [42, -6], [-42, -12], [-2, 8], [26, -22], [-68, -3], [45, 3], [-31, -5], [13, 17], [0, 0], [25, -6], [57, 1], [56, 5], [-21, 8], [-8, -4], [-28, -8], [-26, -10], [-60, -3], [-22, 10], [6, -10], [32, 9], [10, -28], [-3, 6], [-12, 20], [51, 7], [-32, 4], [47, -3], [42, 10], [47, 7], [28, 15], [39, -10], [23, -14], [40, -12], [-20, 14], [-23, -22], [27, 9], [-21, 8], [-57, 7], [19, -10], [0, -24], [-7, 25], [29, -13], [-15, -19], [-28, 10], [-11, 13], [-2, -24], [0, 21], [-4, 1], [28, -7], [-12, 18], [52, -13], [35, 21], [-60, -11], [14, 4], [-29, -21], [20, -10], [-13, 26], [-4, 8], [12, -17], [-10, -22], [10, -8], [18, -2], [-41, 3], [5, 20], [-42, -6], [-2, -8], [-8, 18], [-14, 29], [-31, -16], [-43, -5], [50, 3], [16, 6], [12, 15], [49, 6], [52, 10], [-57, 4], [-40, 6], [76, 0], [48, -12], [-38, 4], [-15, -12], [29, 15], [-33, 9], [-3, 21], [54, -12], [33, -14], [35, -9], [-12, -19], [49, -2], [10, -15], [-13, -17], [42, 7], [-62, 12], [-47, 21], [23, 15], [3, -26], [2, 20], [66, 4], [5, 2], [-26, 12], [55, -3], [-27, -3], [18, -4], [-44, -12], [33, 24], [57, -5], [-8, -20], [-40, 3], [-28, 26], [-6, 4], [-12, 30], [26, -25], [-53, 4], [-42, -7], [5, 11], [56, -1], [-40, 10], [43, -7], [-7, 28], [-20, 20], [-42, -15], [4, 20], [-40, 18], [73, -7], [-13, 23], [29, -8], [12, 23], [33, 4], [25, -11], [36, -24], [-2, 13], [3, 37], [-4, -39], [17, 29], [5, -8], [9, 19], [-10, 5], [2, -28], [-32, -9], [29, 10], [60, 0], [-25, -35], [-82, -2], [-53, -10], [-5, 5], [-1, 30], [-48, -13], [63, -7], [-30, -4], [63, 13], [83, 2], [2, -40], [-29, -9], [-15, 39], [-31, -17], [-37, -4], [-24, -12], [-32, -11], [-97, 0], [12, 22], [-20, -24], [77, -7], [8, 12], [-9, 25], [0, -14], [-37, 19], [-48, 12], [30, -2], [49, 15], [3, -13], [16, 5], [0, -6], [38, 6], [-50, -4]];
    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_bp();".
// 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_bp(: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_bp();".
// 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_bp( : 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, -2, 1]>,<11,R![-1, 4, 1]>,<13,R![-4, 2, 1]>],Snew);
    return Vf;
end function;