
// Make newform 7800.2.a.bg in Magma, downloaded from the LMFDB on 19 October 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_7800_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_7800_2_a_bg();".
// 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_7800_2_a_bg();".
// 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 := [-3, -7, -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_7800_a();"
function MakeCharacter_7800_a()
    N := 7800;
    order := 1;
    char_gens := [1951, 3901, 5201, 7177, 4201];
    v := [1, 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_7800_a_Hecke( : Kf := Kf)
    return MakeCharacter_7800_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 := [[0, 0, 0], [-1, 0, 0], [0, 0, 0], [0, -1, 0], [-1, -1, 1], [1, 0, 0], [1, 0, 0], [-3, 2, 1], [-1, 2, 1], [1, -2, -2], [-1, -1, -3], [5, 0, -1], [1, 0, -3], [-1, 0, -1], [-2, 3, 2], [2, 2, -3], [-2, 1, -2], [-3, 2, 2], [1, -1, 1], [-3, -2, 1], [-5, 2, 3], [-5, 0, -1], [4, 1, -2], [-4, 2, 2], [8, 2, 0], [-8, 4, 3], [-7, -4, 3], [4, -2, -4], [-7, 2, 3], [2, -2, -2], [1, 2, -1], [-3, -2, 5], [10, -2, -4], [-2, 0, -4], [-8, 6, 4], [-8, 5, 2], [10, 2, 1], [-3, -2, -7], [3, 0, 1], [-4, 0, 3], [1, -4, 3], [8, -4, -5], [-10, -4, -4], [-13, -2, 1], [19, -4, -1], [-4, 0, 2], [-9, -2, 1], [-11, -6, 5], [7, -5, -5], [2, -8, -8], [-10, 2, 2], [4, -5, -2], [-3, 2, 7], [-1, 0, -7], [2, -6, 5], [-17, -4, 1], [5, 0, 4], [-14, 9, 0], [8, -10, 0], [-8, 4, 6], [-12, 8, 2], [-2, -4, 4], [-15, 4, -1], [-8, 8, 2], [-12, 6, -3], [15, 2, 3], [1, -2, -3], [-6, 4, 3], [-10, 8, 8], [-13, 4, 1], [11, -12, -1], [4, 9, 2], [-16, 0, 4], [0, 4, 9], [-1, 3, 11], [-3, 6, -3], [2, -6, 2], [2, 6, 2], [5, -4, -5], [-9, 4, -1], [1, 4, -1], [-14, -8, 6], [-13, 6, -1], [-16, -2, 4], [-13, -2, -7], [19, -4, -1], [6, 4, -2], [-1, -8, 3], [-20, -4, -2], [-5, 1, -7], [-16, -6, 2], [-1, 7, 3], [15, 5, -1], [-2, -4, 4], [14, -15, -8], [3, -10, -1], [-11, -2, -5], [6, -4, -4], [-28, 2, 4], [23, -14, -5], [-3, -4, -1], [11, 6, -3], [3, 10, 9], [-10, -12, 7], [21, -6, -5], [20, 6, -8], [-17, 15, 3], [-8, -4, -2], [3, 6, 3], [10, -2, -9], [2, -10, -10], [6, 4, -4], [6, 2, 6], [1, 4, -5], [-13, -4, -3], [-11, -8, 4], [-29, -2, 3], [-8, -2, -2], [-3, 4, 12], [29, -4, 1], [-1, 4, 15], [-26, -4, -1], [12, -4, -2], [13, 5, 1], [-10, -13, 6], [-13, 6, 6], [5, -4, 1], [31, -4, 1], [1, -8, -5], [6, 8, -10], [-7, 3, -1], [9, -7, 1], [-9, -6, 9], [-3, 0, 8], [1, -2, -3], [-2, 2, 0], [12, 2, 0], [-9, 7, 1], [21, 10, -8], [-36, 6, 4], [-2, 9, 4], [-11, 4, -5], [0, -10, -14], [-13, -7, -1], [-15, -10, -4], [27, 6, -5], [28, -12, -4], [-14, -8, -8], [1, -4, 9], [7, 7, -3], [-10, 10, 4], [-4, 2, 3], [-22, -10, 4], [9, -4, -7], [-20, 12, 4], [9, -2, -9], [-14, 10, 6], [-20, 0, 10], [7, -2, -10], [-33, -2, -9], [-29, 1, -5], [10, 12, -1], [-3, 1, 9], [-2, 14, 6], [26, 0, -2], [17, 5, 7], [-17, -10, 5], [-13, -10, 12], [0, -14, 6], [12, 4, -1], [23, -2, -5], [6, 10, -8], [49, 2, -3], [-27, -4, 11], [-10, 4, 0], [2, 16, -7], [9, -1, -13], [18, -2, -6], [-8, -6, -4], [-26, 2, 1], [-17, 6, 3], [39, -10, -3], [4, 10, 0], [36, -14, -2], [-8, 7, -8], [2, 6, -2], [-16, -10, -3], [2, -3, 12], [-37, -8, -3], [-25, 5, 13], [22, -8, -4], [6, -7, -4], [19, 10, 9], [-11, 6, 13], [-12, -8, -6], [-14, -2, -11], [-3, 8, -5], [8, 2, 9], [4, -8, -2], [20, -10, 0], [7, -6, -1], [-8, -4, 8], [8, -4, 6], [-2, 8, -3], [-5, 1, -17], [16, 4, -2], [-18, -11, 10], [53, 4, -1], [10, 0, 2], [31, 2, 11], [-29, -2, 8], [6, 6, 14], [-30, 18, 0], [-24, 21, 12], [-21, -13, 17], [36, -2, 6], [-12, 20, 2], [-2, -16, 1], [6, 13, -14], [30, -4, 6], [36, -6, 0], [-1, 10, 15], [-30, 16, 10], [2, -11, -14], [15, -8, -1], [1, 20, 2], [-34, 4, -8], [38, -4, 0], [-21, 14, -1], [6, -11, -6], [0, 0, 14], [-22, 22, 4], [-23, -13, -1], [8, 2, 0], [1, -14, -21], [-7, -14, -7], [-30, 0, -4], [-9, -4, 13], [0, -6, 6], [30, -4, -2], [7, 8, 17], [41, 4, 1], [35, 0, -3], [11, 14, 3], [-3, 4, 7], [5, -10, -7], [-23, 6, -3], [17, -8, -17], [9, 15, -15], [5, 16, 11], [-8, 0, -16], [1, -4, -1], [1, 2, 1], [-18, 8, -1], [4, -2, -4], [4, -3, 8], [4, 0, 6], [23, -15, -3], [-13, 16, 16], [-34, -6, -10], [-24, -12, 2], [-33, 8, 3], [20, -10, -6], [-18, -14, -18], [8, -14, -10], [1, 14, 3], [15, -16, 7], [-35, -10, 1], [26, -17, 0], [20, -18, -19], [24, -22, 0], [-8, 17, -6], [4, 10, -8], [15, 14, -17], [-30, 32, 5], [41, 11, -9], [27, -18, -5], [17, 0, 19], [28, 4, 4], [32, 12, 2], [6, -18, -18], [11, 10, 11], [-34, 10, 4], [-15, -10, 19], [-4, -17, 10], [33, 2, 11], [-37, -4, 12], [51, -8, -1], [-39, -1, -7], [16, 18, -1], [0, -14, -25], [-25, 6, 7], [32, 8, 2], [31, 5, 19], [68, -4, 1], [5, -6, -12], [34, 10, -12], [-22, 6, 10], [-37, 20, -1], [4, 5, 8], [-13, -8, -2], [-25, 8, -1], [-15, -6, -11], [40, -6, 10], [-29, -4, 5], [11, 6, -9], [-8, 14, -2], [46, -2, 2], [-25, -14, 3], [-8, 14, -11], [-17, 8, 19], [36, 0, -4], [-7, -16, -10], [-23, -8, -7], [47, -25, -1], [22, -28, 0], [-42, 15, 6], [11, 10, -9], [32, 4, -4], [21, -28, -12], [31, -6, -1], [9, 14, 11], [-34, 12, 8], [-38, -11, 0], [-9, -18, 3], [25, -2, 12], [18, -15, -10], [-32, 15, 0], [-11, -6, -11], [-29, 6, -8], [26, 0, -20], [12, -2, -8], [-39, -2, 17], [26, -15, -6], [-13, -15, -31], [-24, 11, -4], [46, 4, -12], [-48, -6, -10], [19, 12, -13], [6, -28, -4], [3, 0, 7], [10, -18, -2], [5, 0, -3], [31, 10, -3], [-1, 4, -15], [-24, -8, -12], [2, -20, -25], [14, 3, 0], [21, -15, 3], [31, 8, -12], [13, 9, -9], [-20, -6, 10], [-51, 0, -3], [41, -8, 9], [-20, 14, 12], [-35, 2, 4], [24, 3, 16], [2, -15, -20], [-32, 8, 1], [58, -5, 4], [-8, -14, 2], [-38, 12, 12], [-38, 8, 2], [-43, 34, 5], [-14, 4, -16], [-30, -10, 6], [9, -6, 19], [20, 19, 24], [-14, -6, 29], [-47, 14, 1], [-45, 20, 1], [11, 4, 5], [20, 8, 1], [-30, 0, 12], [-49, -2, 4], [23, 1, -19], [30, -18, 6], [-34, -12, 2], [22, 14, 7], [-22, -10, -22], [-21, -16, 7], [-4, -6, 26], [31, 13, -15], [-7, 14, -13], [-15, -22, -7], [-53, -10, -1], [-27, 7, 23], [-17, 20, -4], [27, -26, -5], [56, 0, 14], [30, -20, -14], [22, 20, -2], [-12, -13, 6], [-28, 20, -2], [-30, -5, -14], [45, -6, -8], [25, -11, -19], [-23, 8, 24], [44, -10, 0], [19, 18, -3], [11, -22, -9], [-65, 4, -2], [-27, -3, -9], [18, -6, -6], [46, -6, 2], [-28, -6, -24], [26, -14, 2], [11, -26, 9], [-18, -3, -10], [-11, -14, 1], [-49, 14, -4], [6, -6, -3], [43, 10, -5], [-54, -6, 10], [-50, 12, 8], [-54, -6, 1], [-15, -8, 7], [26, 10, -4], [-11, -22, -17], [24, -28, -2], [-20, 22, 25], [49, 12, -5], [-14, 9, 6], [-34, 24, 2], [-11, 12, 3], [-19, 2, 1], [-62, -2, -12], [9, 6, -13], [-40, -1, -6], [19, -8, -23], [23, -16, 11], [-15, -11, 1], [8, -18, -28], [-27, 3, 9], [-5, -6, 15], [-20, -4, -23], [-14, -6, 2], [14, 2, -20], [39, -8, -11], [-72, -7, 2], [52, 13, -18], [28, -14, -14], [64, -10, -8], [-2, 16, -6], [4, -4, -22], [58, 0, 8], [7, 0, 9], [-21, 15, 3], [-6, 20, -5], [-44, -8, 18], [26, -19, 8], [13, -21, 3], [47, 14, 3], [-41, 8, -11], [-17, -10, 11], [-41, -12, 16], [-13, 14, -19], [-60, -2, 18], [-22, 14, 25], [-51, -10, -7], [-4, -22, -6], [-22, -3, -8], [-22, -14, -32], [-5, 8, 0], [26, 5, 8], [-64, 20, 0], [-14, 30, 12], [7, 18, -13], [-68, 14, 1], [4, 8, -2], [12, -23, 4], [16, -19, -14], [57, 4, 15], [15, -20, -21]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7800_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7800_2_a_bg();".
// 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_7800_2_a_bg(:prec:=3)
    chi := MakeCharacter_7800_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(3361) - 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_7800_2_a_bg();".
// 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_7800_2_a_bg( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![3, -7, 1, 1]>,<11,R![-53, -17, 3, 1]>,<17,R![-1, 1]>,<19,R![-100, -20, 6, 1]>],Snew);
    return Vf;
end function;