
// Make newform 6498.2.a.bg in Magma, downloaded from the LMFDB on 22 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_6498_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_6498_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_6498_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 := [-7, 0, 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_6498_a();"
function MakeCharacter_6498_a()
    N := 6498;
    order := 1;
    char_gens := [3611, 6139];
    v := [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_6498_a_Hecke( : Kf := Kf)
    return MakeCharacter_6498_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, 0], [0, 0], [-1, 1], [1, 1], [2, 1], [-2, 0], [0, 0], [0, 0], [-1, 1], [-1, 1], [3, 1], [-3, 1], [5, -2], [6, 2], [-7, 1], [-2, -4], [0, -3], [-7, 3], [2, -1], [-8, 2], [7, -2], [4, 0], [0, -3], [0, 0], [9, -2], [11, 1], [8, 2], [10, 2], [-4, -4], [-5, -4], [8, 2], [6, -3], [-5, -4], [16, 1], [-3, -3], [-5, -3], [0, -4], [-4, 3], [-12, 0], [-6, 0], [12, -3], [-9, -5], [4, -4], [-4, -4], [5, 1], [-4, -6], [8, 2], [-5, 9], [-10, 1], [20, 0], [-3, -6], [12, 0], [-3, 4], [-16, -5], [7, 2], [3, 3], [0, 0], [15, -1], [-9, -7], [-1, 10], [28, 1], [21, 3], [2, -1], [-11, -1], [-7, 6], [-6, 0], [4, -9], [15, -2], [10, 5], [0, 8], [3, -6], [-3, 3], [3, 5], [4, 0], [-16, 2], [-13, 7], [-12, 0], [29, -3], [17, 4], [-3, 4], [0, 12], [1, 9], [12, 6], [-2, -6], [13, -9], [-8, -1], [-19, -2], [17, 6], [2, -8], [-12, -10], [22, -1], [4, -4], [9, -5], [-34, -2], [-18, 5], [33, 3], [0, -12], [-17, 2], [-14, 6], [8, 0], [-6, -2], [16, -4], [18, -3], [-4, 4], [-16, 9], [11, 0], [30, -6], [-35, 2], [-9, -3], [-21, 4], [1, -3], [18, -4], [15, 6], [18, -10], [-1, -9], [-3, 6], [12, -7], [-4, 10], [-24, 0], [-8, -4], [-3, -5], [-2, 6], [-22, 4], [-16, 4], [-8, 4], [-13, 1], [1, 1], [-8, 2], [12, -4], [13, -11], [-10, -9], [-29, -7], [-8, 6], [6, -4], [-27, -6], [30, 2], [3, -3], [24, 7], [-21, -9], [9, 0], [26, 2], [6, 0], [-16, -6], [-50, -1], [-4, 8], [-23, -7], [-2, 4], [21, 0], [0, 5], [-39, 3], [39, 1], [21, 6], [6, -13], [-28, 4], [-32, -3], [9, 3], [-4, -6], [-1, 4], [23, -6], [38, -8], [-24, 12], [13, -10], [-8, -2], [-20, -13], [19, -10], [0, 12], [24, -8], [3, 5], [-6, 10], [-42, 0], [-30, -3], [37, -3], [-3, -21], [5, 0], [11, 17], [-9, -6], [-22, 9], [24, 12], [0, -20], [-13, -9], [36, 2], [14, -14], [36, 4], [-13, 10], [-12, -12], [3, -15], [16, 0], [-42, -2], [25, -12], [24, -6], [-21, 10], [8, -14], [-24, 13], [36, 12], [16, 5], [-18, 6], [5, -18], [-11, -5], [35, 4], [15, -15], [-30, 0], [12, 4], [6, -20], [-35, -6], [2, -5], [11, -5], [-7, -9], [36, -3], [15, -18], [10, 15], [-25, -12], [5, -23], [16, 4], [42, -3], [-24, -6], [14, -16], [4, -2], [18, -6], [59, 1], [-27, -15], [41, 5], [28, 6], [-11, 2], [-4, 12], [-2, 11], [34, 4], [13, 2], [-24, -12], [-29, 3], [-24, 12], [-23, -5], [-38, 3], [5, 11], [5, -2], [14, 3], [0, 6], [-29, -8], [-10, 16], [8, 19], [-33, -3], [-10, -17], [6, -1], [24, 8], [13, -3], [54, 6], [-27, 15], [-33, 11], [10, 17], [-32, 3], [36, 0], [9, 23], [20, 4], [-19, -17], [-23, -12], [-7, 1], [34, 14], [-2, 16], [10, -15], [54, 0], [0, -16], [-12, 22], [-36, 3], [7, 1], [23, -19], [-3, -12], [-6, -11], [72, 0], [-63, 6], [22, -6], [30, 0], [-55, -7], [-12, 16], [7, 16], [17, -3], [-2, 0], [1, -5], [-24, 9], [-39, -5], [-15, 4], [0, -12], [-45, -3], [-9, 17], [12, 12], [14, -16], [-48, 2], [-36, 0], [19, -14], [48, 12], [0, -28], [28, 20], [30, 12], [24, 12], [-27, -12], [-14, 14], [-41, 9], [-46, -8], [28, 18], [23, -11], [8, -2], [-14, 7], [15, -16], [31, -1], [-9, 11], [16, -7], [-32, -5], [-41, 6], [54, 3], [40, 12], [27, 3], [-4, 12], [64, -10], [-39, -15], [29, 16], [44, 11], [36, -18], [38, -10], [12, 3], [11, 1], [23, 0], [-44, -4], [42, -5], [1, -2], [51, 3], [-41, 15], [-54, 6], [20, 20], [48, -5], [-6, 25], [17, -17], [50, -8], [-39, -7], [-24, -24], [-16, 24], [-32, -4], [-2, 1], [-16, 4], [47, -7], [27, 6], [-28, 12], [-36, 2], [-33, 13], [-27, -12], [51, -9], [-44, 0], [-41, 11], [20, 13], [-32, 4], [20, -16], [19, 5], [57, -3], [0, -5], [31, -12], [-13, -5], [-88, 2], [-17, 21], [-7, -14], [20, -20], [-42, 15], [13, 2], [-15, -9], [-15, -19], [35, 22], [12, 24], [-32, 11], [14, 6], [4, -12], [0, -12], [17, 23], [57, -14], [72, -3], [8, -4], [32, 4], [-22, 4], [35, -15], [59, -15], [28, 8], [68, -8], [59, 6], [63, 0], [-19, -28], [39, 9], [-58, -14], [69, -1], [3, 12], [-28, -7], [7, 23], [-51, 5], [42, 20], [-6, -7], [-28, -14], [1, 12], [22, -16], [30, -3], [42, -7], [15, -21], [-47, -12], [84, 4], [49, 2], [-6, -17], [66, 0], [-14, -24], [-17, 20], [11, 23], [-34, -8], [24, -24], [29, 15], [12, -4], [37, -22], [-24, -2], [50, -11], [27, 28], [-36, 24], [2, -23], [-4, -9], [9, -28], [15, 3], [-48, 12], [-32, -12], [12, -12], [-49, 7], [39, -9], [28, 0], [-16, -26], [2, -17], [0, 16], [-3, -9], [-32, -7], [-20, -4], [32, 12], [-28, 22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6498_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6498_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_6498_2_a_bg(:prec:=2)
    chi := MakeCharacter_6498_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_6498_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_6498_2_a_bg( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6498_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-6, 2, 1]>,<7,R![-6, -2, 1]>,<11,R![-3, -4, 1]>,<13,R![2, 1]>,<29,R![-6, 2, 1]>],Snew);
    return Vf;
end function;