
// Make newform 2800.2.a.bq in Magma, downloaded from the LMFDB on 25 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_bq();".
// 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_bq();".
// 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 := [-2, -6, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, -2, 1]];
    Rf_basisdens := [1, 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, 0], [0, -1, 0], [0, 0, 0], [1, 0, 0], [-2, 0, 1], [-2, -1, -2], [0, 2, 1], [-2, 1, -1], [-2, -2, -2], [0, 0, -3], [-4, 2, 0], [-6, 0, 0], [6, 2, 2], [0, 2, 2], [-2, 0, 3], [-2, -2, 2], [-2, 3, 3], [8, -1, -1], [-4, 4, 2], [-2, 2, 0], [2, 2, 2], [-4, -4, 1], [-6, 5, -1], [2, -4, 2], [4, -2, 1], [0, -1, 3], [2, 0, -1], [0, 0, 0], [4, -4, 3], [-6, -4, 0], [-2, 2, -6], [2, -3, 1], [0, -4, -4], [2, -3, 5], [-10, 4, 0], [-2, 2, 1], [-4, -1, -3], [4, 2, 0], [-14, 4, 3], [-14, -3, -2], [-4, -4, -4], [-8, -1, -3], [4, -4, -1], [10, -4, 2], [-14, 10, 2], [-12, -6, -8], [2, -6, 1], [-6, 2, 1], [-8, 3, 4], [16, -3, -1], [4, -4, 0], [14, -2, 1], [2, 2, 2], [10, -11, -3], [-6, 2, 2], [-8, -4, -4], [-8, -5, -3], [4, 0, -8], [10, -2, 2], [-16, -2, 3], [4, 7, -2], [-10, 7, 4], [-28, -1, 2], [12, 0, 4], [8, -10, -5], [-22, 2, 0], [8, 6, 2], [-2, 0, -4], [-8, -6, -12], [12, -1, 7], [12, 4, -5], [-8, 0, -4], [-2, 10, -3], [-6, 6, 4], [4, 2, 2], [0, -2, -2], [-20, 8, -1], [2, -3, -2], [-6, 2, 3], [2, -2, -4], [6, 3, -9], [8, 6, -7], [-6, 2, -9], [22, -4, -4], [12, -8, -2], [0, -4, 4], [0, 6, -1], [-6, -8, 8], [-4, -5, -9], [0, 8, 0], [0, 1, -4], [0, -14, -4], [18, 2, 6], [-18, 2, -7], [-14, 18, 7], [-10, -2, 3], [16, -3, -1], [10, 2, -4], [6, -5, 9], [8, -10, -5], [8, -2, 10], [-2, -6, -4], [-22, -3, -5], [-4, -8, 2], [-20, 6, -2], [12, 4, -3], [10, 5, 7], [0, 12, 5], [4, 8, 15], [2, -8, 2], [-2, -14, -5], [-6, 0, 6], [10, 8, 16], [-34, 3, -1], [4, -4, -1], [-4, -16, -10], [-8, -1, -8], [0, -10, -2], [-18, 8, -2], [-6, -4, 5], [8, 13, 5], [24, 4, -8], [-10, -11, 0], [-16, 0, 4], [-10, 9, 11], [8, -8, 5], [12, -8, 1], [12, -10, -8], [4, 2, -6], [18, -1, 10], [-14, -4, -15], [2, -2, 2], [-2, -10, -7], [-6, 8, 2], [26, -6, -2], [30, 6, -4], [-14, 1, -8], [-4, -3, 2], [-6, 7, 4], [6, -2, 11], [2, 1, -3], [0, 6, 5], [20, -4, -10], [16, -4, -6], [-12, -5, -3], [16, -6, -8], [4, -5, -11], [2, 8, 4], [-6, -17, -11], [-36, -8, -6], [2, 8, 6], [-10, 16, -2], [-16, -12, -20], [16, -6, -2], [4, 16, 2], [16, -16, -12], [-36, 0, 5], [10, -14, 6], [12, -4, 11], [24, -7, 9], [-24, 2, 0], [8, 8, 2], [18, 10, 12], [-10, 3, -5], [8, 4, -4], [-6, 16, 13], [-14, 2, 12], [-2, -3, 6], [22, -2, -9], [-28, -3, 3], [-4, 20, 4], [12, 13, 17], [32, 0, 7], [-24, 16, 2], [0, 6, 14], [10, 4, 6], [2, -10, -9], [8, 8, 3], [4, 4, 4], [40, 1, -3], [-26, -2, 8], [34, 3, -3], [22, 12, 6], [-14, -10, -22], [-18, 10, -8], [0, 7, 1], [-14, -10, -10], [24, -5, 0], [-12, 6, 13], [12, -6, -10], [38, 6, 2], [-28, 12, 8], [-30, -2, -15], [-40, 7, 5], [-12, -4, -12], [-24, -12, 1], [-30, -6, -3], [-6, 20, -8], [-20, 0, -9], [6, 6, -3], [-26, -12, -12], [-12, 2, 2], [40, 3, 1], [-26, 12, 10], [6, 5, 15], [-18, 3, 8], [36, 6, 4], [-8, 2, 14], [-36, -12, -10], [14, 13, 7], [2, -8, 12], [-12, 21, 7], [10, -10, 14], [-8, -13, 12], [-16, 12, -8], [2, -18, -8], [-4, -12, -10], [-10, 18, -6], [-16, -16, -16], [10, -8, -4], [-2, 18, 2], [8, 0, -8], [-8, -6, -15], [30, 14, 8], [16, 3, 20], [-6, 18, 10], [-24, 20, 3], [-30, 2, -5], [-30, 10, 1], [16, -6, 6], [-10, -16, -14], [6, 1, -13], [30, -2, 4], [-40, -6, 9], [8, -17, 0], [-22, -6, -3], [-14, 10, -6], [-10, -6, 12], [-2, -14, -15], [-48, -4, -6], [-40, 10, -2], [18, 11, 21], [22, -22, 1], [-18, 32, 8], [-12, -12, -7], [-8, 10, 14], [-12, -16, 12], [2, -25, -15], [18, 16, 15], [0, 16, 4], [30, 6, 0], [34, 4, -2], [-4, 16, 2], [-10, 8, 2], [0, 9, 19], [-14, -14, 7], [18, 6, 10], [10, -11, -13], [-46, 5, 0], [-12, 10, 11], [14, 14, 12], [-36, 6, -8], [28, -11, -9], [2, 13, 4], [2, 4, 8], [2, 5, 1], [24, 6, 9], [-10, -8, -14], [-4, 12, -14], [10, 0, -6], [8, 11, 21], [-16, 6, -4], [-8, -4, 23], [32, 8, 8], [-14, -10, 6], [-34, 10, -7], [4, 22, 14], [-10, -16, -8], [-22, -10, 3], [18, 19, -3], [18, 10, -3], [-4, 24, 1], [32, -10, -10], [-4, -9, -19], [12, -3, -6], [18, 14, 7], [-36, 4, 0], [-10, -10, -24], [20, -10, 0], [-18, -16, 0], [-12, -18, -3], [-8, 17, -4], [-18, 0, -16], [6, -25, -5], [46, 2, 8], [8, 3, 13], [20, 16, -14], [-2, -17, -2], [-46, 7, -7], [32, -9, -12], [28, 14, 5], [-2, -28, -8], [4, -16, -1], [4, -6, 18], [-46, 4, -5], [12, 0, 6], [44, -14, 6], [0, -11, 13], [24, -12, 4], [-2, -2, -6], [16, 8, 24], [28, 8, 17], [-18, -4, 0], [44, -2, -2], [16, -12, -8], [2, -16, 14], [22, -19, -13], [-56, -4, 7], [-36, 20, 11], [8, 10, -7], [-14, -9, -7], [12, -24, -6], [20, 3, -15], [-60, 8, 6], [26, 4, -2], [22, 14, -2], [6, 4, 11], [-6, -19, -1], [-34, 18, -2], [-34, 20, 8], [22, -16, -16], [10, -12, -4], [-16, -10, 12], [20, -9, 2], [64, -4, 0], [16, -25, -20], [-20, -16, -13], [-30, -14, -6], [6, 12, -10], [-10, -12, 19], [-22, -2, 14], [22, 0, -12], [16, -1, 9], [48, -16, -1], [38, -16, -16], [-4, 30, 2], [-8, 15, -19], [-8, -26, -6], [-28, 12, 6], [22, -3, 22], [-46, 17, 1], [-28, -4, -16], [4, 2, -3], [-14, 24, 3], [-20, -14, -3], [-22, -2, -22], [0, 10, -14], [18, 13, 5], [28, 4, 0], [-10, -18, -18], [58, 6, -4], [-2, -4, 12], [30, 18, 10], [6, 22, 7], [50, 9, 3], [-58, -4, -10], [-22, -1, -12], [30, -34, -8], [6, 14, 11], [62, -10, -5], [38, 9, 19], [4, -28, -14], [-32, -10, -9], [-20, -12, -24], [6, -2, 24], [-6, -9, -7], [-62, -6, -5], [-52, 4, -3], [-2, 18, 18], [-44, -2, 11], [-12, 9, 9], [-2, 16, 0], [4, -4, -18], [12, -20, 10], [22, -1, -13], [-38, 2, 1], [0, 16, 15], [34, 5, 16], [36, 0, 8], [26, -16, -15], [14, -10, 11], [-26, -7, -6], [-38, -18, -35], [-74, 15, 5], [74, 6, -1], [-48, 4, 12], [-12, -18, -10], [-30, -6, -10], [-18, 14, -9], [6, 2, -10], [-40, 15, -9], [56, -8, 10], [36, 4, 14], [52, -10, 9], [36, 9, 17], [-12, -26, 22], [-22, -10, -10], [-54, 34, 5], [18, 1, 11], [18, 11, 29], [4, -4, -21], [42, 12, 2], [4, 22, 8], [8, 4, 24], [16, -16, 2], [4, -3, -3], [8, -16, -25], [0, 2, -14], [18, -20, 8], [34, -10, 13], [12, 16, -5], [32, 5, -5], [0, 24, 4], [-2, -3, -5], [16, -6, -5], [-58, -1, -4], [-40, 14, 8], [-18, -8, 12], [2, -23, -19], [48, 6, 22]];
    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_bq();".
// 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_bq(:prec:=3)
    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_bq();".
// 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_bq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![2, -6, 1, 1]>,<11,R![-8, 8, 7, 1]>,<13,R![-106, -22, 5, 1]>],Snew);
    return Vf;
end function;