
// Make newform 6498.2.a.ca in Magma, downloaded from the LMFDB on 25 April 2024.
// 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_ca();".
// 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_ca();".
// 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 := [5, 0, -5, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-3, 0, 1, 0], [0, -3, 0, 1]];
    Rf_basisdens := [1, 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_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)
    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+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 := [[1, 0, 0, 0], [0, 0, 0, 0], [1, -1, 1, 1], [0, 1, 1, 0], [-2, 1, -3, 0], [-4, -1, 1, -1], [-1, 2, 1, 0], [0, 0, 0, 0], [1, -2, -3, -3], [-2, -1, -3, 1], [-7, 0, -1, -1], [-1, -2, 0, -1], [-2, 1, 2, 2], [-3, -2, -1, 1], [5, 1, 4, 1], [1, 0, -2, -3], [-1, -1, 2, -1], [-3, 1, -6, 2], [-1, 0, 3, -3], [-1, 3, -2, -3], [-4, 0, -1, -2], [-7, -2, -3, 3], [7, 3, 8, -3], [-6, 1, -4, 4], [-6, 6, 2, 1], [-1, 3, 3, -1], [-10, 5, -3, -2], [-3, -5, 0, -3], [9, 2, 4, -1], [-2, 4, 2, 5], [0, 0, 4, 4], [1, -3, 0, 7], [2, 2, -3, 6], [3, 3, 4, 9], [-5, -5, 4, -2], [0, 6, -6, 4], [3, -5, 6, 2], [4, -5, 5, 2], [1, -3, 6, -1], [3, 4, 12, -1], [-10, -4, -6, 2], [-4, -2, -2, 6], [13, -1, 14, 1], [-6, 4, 10, 0], [1, 3, -10, -2], [-2, 6, 0, -6], [0, -5, 11, 2], [-1, 4, 9, 5], [-4, -8, -4, 8], [3, 3, -5, 1], [1, -6, 5, -12], [9, -4, 15, 1], [-16, 4, -14, -4], [-6, -7, -7, 0], [10, -1, -4, -4], [-1, -1, -8, 3], [-4, 3, 9, 3], [5, -1, 2, -3], [11, -9, -3, -1], [0, -8, -4, -3], [8, -2, -6, 4], [18, -4, 4, 4], [-7, 2, -5, -13], [8, -5, -1, 4], [10, -2, -7, -6], [9, 4, 4, 1], [-4, -3, -15, -2], [2, -13, 0, 0], [12, -11, 11, 6], [1, 17, -4, -4], [-1, -2, 11, -4], [1, 7, -10, 1], [0, 2, 14, -4], [-10, -5, -7, -1], [-2, 6, 12, 2], [2, 5, -7, -2], [-19, 5, -16, -2], [-6, 6, 14, -2], [6, 8, 0, -8], [4, 5, 0, 10], [-10, -10, -8, 2], [-15, 0, -4, 13], [-10, 1, -3, 10], [-18, 1, 4, 6], [9, 0, 3, -17], [9, 2, -1, 13], [0, 2, 8, -1], [-14, -2, 5, -6], [-22, 6, -6, 2], [-5, -5, -4, 7], [2, -12, -10, -2], [9, 10, -7, 1], [2, -11, 13, 2], [16, 0, 8, -8], [-3, -7, -12, -5], [7, -4, 1, -5], [-6, -7, 7, -9], [-2, -2, 0, -7], [-24, 2, -10, -4], [-15, 7, -4, 6], [-3, -5, -8, -11], [4, -2, 2, 4], [-16, 1, -19, -2], [-16, -3, -14, -10], [18, -11, 5, 0], [-1, -6, 3, -8], [-10, -3, 9, 0], [-4, 0, -17, 6], [-7, 4, -17, 3], [4, 4, -14, -4], [-12, -8, -8, 0], [-3, 5, -7, 9], [-2, 2, -4, 2], [15, 3, 8, 5], [-3, -8, -1, -11], [-20, -2, -6, -11], [-4, -2, -22, -4], [10, 17, -1, 6], [17, 11, -1, 5], [-16, -3, -7, 10], [-8, -6, 4, -16], [-4, -9, 6, 6], [-18, 1, 3, 3], [0, -5, 27, -6], [-9, -11, -2, 5], [-1, -7, 3, 15], [-1, -17, -6, 6], [11, 8, -19, 7], [15, 3, 20, 3], [17, 7, 8, -12], [20, 5, 19, 6], [18, 8, -6, 2], [-5, 14, -1, 17], [-21, 3, 4, 0], [2, -6, -12, -16], [-6, -4, 13, 0], [-12, -13, -9, 5], [13, 1, 18, 5], [0, 9, -11, -7], [14, 16, 11, -18], [-1, -10, 9, 13], [13, -1, 0, -16], [1, -3, -4, -15], [5, -10, 15, -5], [13, 0, 8, 3], [25, 3, 16, 7], [13, -13, 4, -10], [-4, -18, 4, 3], [-9, -16, -1, -1], [-8, 18, 18, 4], [-2, 7, -5, -9], [0, 0, -7, -16], [1, 0, -15, 13], [19, 9, -4, 13], [-25, 14, 5, -3], [23, 10, -9, 1], [0, 10, -10, 12], [17, 8, 11, -18], [2, -10, 8, -10], [2, 12, 8, -8], [-12, -1, 9, 10], [-20, 10, -10, -9], [-31, 1, -24, 1], [24, 21, 9, -14], [10, -17, 20, -2], [-8, -11, -13, 4], [16, -17, -11, -4], [-29, -9, -5, 5], [-10, 6, -22, -13], [-19, -3, -14, 0], [21, -20, 13, 15], [-40, -10, -18, 18], [20, -5, -13, 8], [40, -4, 13, 6], [14, -12, -2, -10], [-23, 12, 1, 0], [-14, 17, -3, -4], [19, 5, 18, 18], [-5, -11, -16, 1], [-31, -3, -38, 0], [-4, 18, 2, -4], [18, 0, -14, -2], [-4, -3, 9, 7], [16, 5, 8, 8], [17, 8, 27, -11], [-21, -5, -31, -7], [13, -12, 6, -3], [-19, 13, 6, 13], [28, -2, 28, -9], [-7, 8, -1, -19], [12, 7, 22, 8], [-39, 1, -4, 7], [9, 12, -11, 3], [41, 0, 12, 9], [-4, -22, -18, 0], [26, 8, 24, 4], [-3, 4, 13, 14], [27, 1, 37, 13], [-19, 2, 9, -14], [11, -8, 5, -9], [26, -3, 19, -1], [19, 2, 27, 5], [-34, -7, -37, 15], [10, -4, -22, -11], [-7, 13, -8, 7], [-5, -13, -19, 5], [-23, -6, -7, 17], [-8, -20, -8, 20], [12, -6, 29, -10], [3, -6, -23, 5], [14, 4, 17, 4], [-7, 3, -5, -13], [-2, 16, -2, -22], [-24, -5, -13, 14], [15, 16, 17, 9], [0, -14, -4, -7], [-10, 11, -3, 14], [-18, -22, -10, 7], [-22, 15, 7, 22], [-23, -15, 13, 1], [6, 0, -22, 2], [27, 11, 34, -15], [10, 26, -2, 11], [3, -5, 16, -1], [-12, 22, 10, -8], [-7, -23, -15, -1], [26, 0, 12, 35], [-20, -3, -21, -8], [32, -7, 51, 4], [19, 7, 12, -7], [30, -16, 4, 12], [16, -1, -17, -6], [-11, 17, 6, 7], [-26, 8, -40, -8], [25, 12, 9, -7], [6, 3, 1, -18], [-19, -6, 3, 4], [10, -20, -8, -20], [-39, 14, -21, -19], [7, -18, -1, -3], [-9, 4, -5, -11], [3, 10, -7, -9], [-37, 15, -36, -13], [-1, 6, -32, -7], [-26, 16, -14, -25], [28, -3, 25, -12], [38, 2, 28, -6], [14, 14, 28, 10], [17, 16, 9, 11], [-7, 5, -16, -27], [3, -7, -3, -7], [-20, 20, -5, -16], [-12, 5, -19, 20], [32, -12, 34, 3], [14, -14, 6, 6], [-1, -4, 11, -1], [-17, -3, -9, -7], [36, -4, 8, 16], [-24, 6, -6, 10], [10, -2, -16, -14], [-13, -10, -33, -3], [-24, 3, -1, 22], [-26, 18, -22, 2], [2, -12, 6, -6], [-15, -2, -21, 16], [5, -3, 10, -7], [34, 8, 48, -8], [-7, 6, -3, -2], [16, -15, -7, -2], [-12, -10, -30, 4], [-15, 6, -36, 13], [1, 16, 37, 3], [-23, 6, -19, -20], [-15, 3, -18, -11], [-4, 17, -32, 20], [-29, 6, -29, 15], [-22, -9, 11, -24], [13, 2, -16, 13], [-12, 0, 2, -15], [-54, -6, -8, 6], [32, -16, 0, 16], [-16, 8, 0, -28], [3, 13, -2, -17], [28, 23, 3, 1], [-24, -12, -12, 8], [12, -5, 23, 4], [2, 8, -15, 14], [8, 25, 5, -11], [-35, -3, 8, -7], [20, -16, 14, -12], [-37, 7, -8, 12], [-5, -22, 21, -1], [24, 1, 26, 8], [4, 23, -29, 14], [-8, 15, -15, -1], [-41, -3, -59, 7], [16, -26, 18, 12], [-14, 4, -36, 8], [-27, 11, -16, 5], [26, -2, 40, 2], [22, -26, 23, 8], [-34, -3, -31, -21], [2, 18, -28, 6], [20, 0, 28, -28], [-22, -10, -4, -2], [-10, -34, -16, 11], [14, -10, 28, -10], [-31, 10, 8, 7], [37, 5, 20, 13], [3, -11, 45, -15], [21, 7, -10, 17], [22, 0, 36, -8], [-34, -25, 0, 6], [3, 13, -12, -5], [-2, 37, -9, -6], [-38, 8, -32, -5], [31, 15, -8, 25], [11, -9, 2, -3], [31, -20, 27, 18], [-28, -26, 9, -6], [-12, 12, -8, -24], [-19, 8, 11, 12], [-11, 10, -2, -7], [-12, 11, 29, 24], [42, 4, 41, 6], [-18, -10, 24, -15], [-14, 19, -23, 12], [-53, -17, -14, 3], [-28, -1, 9, -16], [-15, -13, 12, 4], [1, -21, 11, 21], [36, 14, 2, -2], [-14, -10, 12, -30], [27, 16, -13, -5], [2, -20, 14, 10], [-31, 2, -1, -11], [-20, -11, -3, 23], [-4, -13, -8, -4], [-5, 14, 19, 10], [2, 17, 11, -18], [-28, 2, -26, -6], [-30, 4, -12, 22], [12, 22, -18, 2], [13, -14, -27, -5], [-18, 23, -21, 13], [-15, 13, -50, 5], [-47, 7, -13, 13], [-58, -18, -28, 18], [19, 5, 8, 25], [-33, -17, -24, 12], [37, -5, 24, -7], [-36, 3, -6, 14], [-37, 11, 6, 8], [-2, -14, -4, 2], [24, -15, 39, -13], [-12, -19, -2, -24], [-14, -28, 2, 14], [7, -12, 11, -9], [-18, 10, 25, 18], [16, -6, -6, 16], [-3, -1, -10, -6], [-45, 22, -1, -6], [-29, 11, -14, 21], [50, -20, 10, 2], [47, 17, 30, -23], [24, 16, 10, 9], [-2, 20, -8, 24], [16, -15, -5, 4], [-4, 14, -14, -29], [-13, -19, -10, 29], [-3, 32, -31, -1], [2, -30, 4, -18], [8, -26, -38, -18], [-29, -7, -18, -33], [-5, -5, -6, -16], [-23, 1, -18, 1], [-28, -1, -33, -12], [7, 36, -37, 10], [-58, -6, -25, -10], [26, 18, 6, -5], [-6, 5, 13, 23], [-2, -12, 11, -18], [38, 4, 50, 10], [20, 12, 15, -28], [-3, -10, -1, 3], [-29, -13, 14, -15], [1, -6, 9, -31], [29, 17, 8, -14], [-17, -15, -22, -11], [52, 3, 1, 12], [-46, -12, -2, 13], [7, -36, 12, 9], [19, 36, 11, -17], [-14, 21, -15, 12], [12, 6, 22, -28], [34, 10, -2, -19], [4, -3, 35, 24], [30, 12, -2, -8], [37, -10, 35, 23], [1, -23, -28, 0], [25, -12, 30, 7], [30, 18, 39, -20], [-26, 9, 29, 2], [-20, -18, -22, 29], [-25, -4, 6, -13], [-10, -2, -32, 18], [-25, -5, 30, -14], [-66, 10, 12, -3], [-4, -26, -10, -28], [11, 27, 28, 5], [30, 8, 18, -25], [5, 15, 18, -2], [1, 38, 27, 3], [-56, 0, -8, 12], [28, 4, -13, 10], [-20, -34, 42, -16], [-32, 9, 11, 0], [-31, 37, -2, -9], [10, -52, 1, 10], [30, -22, 28, 34], [26, -15, 19, 7], [-23, -6, -18, -19], [27, -13, 4, -1], [1, -25, 12, -7], [-36, -21, -18, 26], [-33, -22, -22, 15], [-62, 11, -39, -32], [-40, 0, -45, -26], [16, -15, 3, -30], [27, 15, -24, -5]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6498_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6498_2_a_ca();".
// 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_ca(:prec:=4)
    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_ca();".
// 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_ca( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6498_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-19, 32, -11, -2, 1]>,<7,R![-4, -12, -6, 2, 1]>,<11,R![76, -12, -26, 2, 1]>,<13,R![61, 232, 109, 18, 1]>,<29,R![-19, -92, -31, 2, 1]>],Snew);
    return Vf;
end function;