
// Make newform 6840.2.a.bj in Magma, downloaded from the LMFDB on 25 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_6840_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_6840_2_a_bj();".
// 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_6840_2_a_bj();".
// 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_6840_a();"
function MakeCharacter_6840_a()
    N := 6840;
    order := 1;
    char_gens := [1711, 3421, 5321, 2737, 6481];
    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_6840_a_Hecke( : Kf := Kf)
    return MakeCharacter_6840_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], [0, 0, 0], [1, 0, 0], [-2, 0, -1], [2, -2, 0], [2, 1, 2], [4, 0, 1], [-1, 0, 0], [2, 2, -1], [0, 0, 3], [-4, 0, 2], [4, 1, -1], [2, 2, -2], [-4, -2, -4], [0, -2, -2], [2, -1, -2], [2, 0, -1], [8, -4, 0], [0, 3, 4], [4, -4, 0], [-4, -4, -3], [4, -2, -4], [8, 0, -2], [-6, 2, 2], [-4, 7, 1], [0, 4, 0], [-2, -3, -1], [0, 3, 4], [-4, -6, -7], [8, 3, -1], [2, 1, 5], [4, 0, 0], [8, 0, 1], [-2, 6, 0], [0, 4, 0], [8, 2, 0], [10, -2, -2], [-8, 6, 0], [10, 1, 5], [8, -1, 1], [-4, 2, -2], [22, 0, 0], [6, -6, 1], [-4, 7, 1], [2, 0, 0], [2, -6, -5], [6, -4, 1], [6, 7, 7], [4, 7, 2], [16, -4, -2], [2, 0, -4], [14, 2, 5], [2, -10, -4], [4, 4, -4], [-8, 3, 1], [4, 4, 8], [2, 4, -4], [4, 8, 7], [-18, 6, 0], [14, -6, -2], [4, -4, 2], [14, -13, -4], [-10, 7, -3], [12, 0, -3], [-16, -2, -1], [-6, -5, 4], [2, -4, 3], [-12, -3, 3], [-16, -4, 2], [-6, 4, 4], [24, 0, -1], [0, -4, -1], [-16, -2, 6], [-6, 5, 0], [-10, 10, 3], [-10, -7, 3], [-2, -4, -6], [10, -6, 0], [10, 4, 8], [6, 0, -4], [16, 0, 6], [4, 4, -7], [16, 6, 2], [-8, 5, -3], [-8, -2, -4], [8, -4, -4], [2, -8, 0], [12, 2, -5], [2, 0, -8], [0, 12, 4], [-12, -12, -16], [-2, -6, -8], [26, -7, 1], [-24, 8, -2], [6, -14, -2], [-14, -2, -9], [10, -10, -2], [10, 4, -2], [8, -11, 0], [12, 4, 4], [-6, 9, 3], [-6, 14, 0], [10, 9, 3], [2, 0, 10], [2, 10, 10], [-12, -6, -3], [16, -12, 2], [-18, 0, -4], [-8, 10, 0], [-10, 2, -6], [-14, -7, -7], [6, -10, -12], [22, -14, -2], [6, 6, 12], [2, -2, -8], [-10, -6, -4], [0, 0, 2], [-6, 2, 3], [10, 6, 12], [-6, -4, -7], [8, 4, 3], [20, -1, 3], [-18, 3, 0], [-30, -3, -1], [2, -6, 10], [-12, 0, 12], [10, 12, 0], [24, 0, -3], [-2, 8, 3], [6, 8, 14], [-24, -4, 2], [6, 3, -1], [20, -6, -8], [-2, 12, -4], [-10, -2, 11], [-10, -10, -1], [-22, -9, -4], [0, 7, -12], [-14, -1, -14], [4, 6, -1], [10, 6, -7], [30, 0, 6], [-14, 0, 1], [12, 15, 10], [-12, 10, 1], [-8, 6, 6], [6, 8, -12], [4, -1, -9], [4, -12, -8], [2, 11, 1], [-6, -7, 4], [-12, 16, -2], [-4, -6, 12], [-10, -7, -9], [0, -19, -8], [-16, 2, -6], [-10, 2, 5], [-12, -10, 3], [-28, 4, -7], [8, 6, 1], [-16, 4, 8], [-20, 15, 11], [-36, 0, 8], [0, 12, 16], [32, 9, 3], [2, -3, 9], [-8, -6, 0], [30, 6, 6], [10, -6, 12], [-6, -6, -10], [-6, -14, 7], [-16, 2, 7], [-30, -2, 0], [-12, -10, 5], [-4, 0, 2], [-8, 12, 10], [-16, 4, 6], [20, 0, -6], [-38, 1, 1], [24, 0, 10], [-22, -6, 11], [26, -2, -5], [-12, 7, -11], [-4, -3, 13], [6, -6, -13], [2, -20, -4], [26, -17, -2], [-10, -5, -7], [6, -8, 10], [-10, -6, -7], [12, 9, 1], [-12, 0, -4], [16, 4, 8], [20, -4, -7], [-32, 14, 6], [20, -17, -3], [-20, 22, 5], [18, 8, 6], [20, -14, 3], [-6, 8, -1], [-6, 2, 2], [12, 6, 10], [-14, -11, -6], [-22, 10, -10], [2, 18, -6], [6, -2, 8], [-4, -8, -9], [20, -25, -6], [-20, -14, -5], [2, -2, -17], [-4, 6, 15], [24, 4, 0], [16, 0, 8], [-8, 3, -16], [-16, -8, 2], [-18, 2, -4], [-6, 20, 7], [18, -8, -8], [-26, 23, 7], [-18, 24, 4], [6, -14, 2], [20, -8, 6], [-18, -10, -16], [6, -6, 9], [-8, -5, -4], [18, -16, 4], [-40, -7, 11], [-32, 12, 4], [-6, -9, -23], [-16, -4, -2], [6, 20, 10], [10, 2, -13], [-8, 22, -6], [6, -18, -2], [-20, 0, -2], [-22, 0, 7], [16, -4, -14], [-22, 16, 4], [-14, 22, 10], [-52, 2, 0], [-2, 11, -15], [28, -16, -4], [-18, 0, -7], [-20, 8, 1], [4, 21, 15], [0, 4, -12], [-32, -2, 6], [12, -10, 10], [12, -4, 0], [22, -12, 5], [22, 0, -2], [-12, -14, -7], [-46, -10, -9], [-46, -4, -6], [-2, -8, -16], [-20, 24, 16], [18, -8, 16], [26, -7, 3], [-24, -3, 7], [26, 14, 6], [-22, 1, -11], [-14, 13, 15], [-44, -8, -6], [-42, -7, -6], [-18, 4, 0], [54, 4, 13], [-24, 0, -19], [-38, -10, -9], [8, 13, -4], [22, 0, -2], [-40, -2, -9], [0, -11, 24], [32, -20, 5], [-4, 0, 1], [-16, -1, 15], [6, 4, 17], [-20, 10, 14], [-4, 12, 5], [2, 6, 4], [62, 2, 4], [-30, 21, 9], [16, -4, -13], [50, 10, 15], [-12, -6, -17], [24, -4, 0], [26, 10, 24], [-32, -2, -13], [-12, 9, -13], [-10, 22, 9], [-26, 20, 8], [6, 16, 14], [4, -10, 10], [32, 5, 5], [52, -22, -6], [-8, -15, -25], [-8, -8, 18], [28, 16, 18], [-10, 8, -12], [-6, 2, 3], [-8, 14, -6], [-26, -14, -18], [30, 9, -14], [0, -8, -21], [-8, -3, -12], [0, -8, -22], [-4, -7, -5], [28, -5, -10], [4, -12, 19], [-48, 4, 4], [-30, -4, -6], [28, -18, 2], [-24, -20, -20], [-2, -16, 10], [-34, 11, 9], [20, 4, 4], [2, 2, -2], [10, -18, 14], [-8, -22, -14], [-32, 30, 13], [-30, 0, 16], [14, 10, -19], [-40, 12, -5], [8, -16, -1], [42, -9, 5], [-24, -8, 1], [-34, -14, 8], [-18, -4, 5], [-40, 9, 12], [38, -13, -9], [10, -2, -10], [64, 4, 12], [-26, 9, -18], [4, -4, -21], [40, 6, 20], [-38, 18, -6], [12, -6, -8], [4, -2, 1], [-20, 11, -5], [8, 22, 11], [-30, -22, -13], [-38, -9, -22], [8, 24, 21], [-60, 2, 1], [24, 16, -6], [26, -1, 14], [52, -26, -6], [-22, 16, -8], [8, 13, -4], [28, 4, -4], [-22, -10, 0], [-12, 8, -8], [-68, -1, -1], [16, 12, -16], [26, -1, 25], [-18, 30, 10], [20, -15, -23], [14, 2, 1], [20, -12, -8], [44, 8, 17], [30, -9, -1], [6, -10, 14], [-48, -4, -18], [-30, -1, 17], [14, 10, 13], [-36, -16, 4], [4, -19, 11], [2, 6, 18], [2, -9, -15], [-6, -14, 6], [-2, 22, 2], [-10, 4, 3], [42, 16, 1], [52, -14, 5], [-16, -12, 12], [-38, 2, 0], [-62, 18, 3], [-40, 4, 12], [6, 24, 4], [16, -10, 19], [4, -13, -3], [2, 16, -16], [26, 4, 12], [38, 4, -19], [34, -20, -16], [-2, 8, -3], [14, 3, 19], [60, 4, -3], [18, -6, -14], [20, 18, 12], [-14, -5, 21], [-34, -12, -20], [6, -31, -6], [8, -4, -2], [72, 4, -8], [-8, 14, 20], [-16, 3, -19], [-52, -2, -4], [-66, -14, -16], [20, -20, 12], [54, 8, 8], [-30, -8, 8], [-14, 0, 16], [46, -37, -5], [8, 5, 15], [38, 4, 24], [10, 26, -1], [50, 14, 0], [-22, -16, -6], [-16, 13, 4], [-24, 4, -26], [56, -15, -5], [-14, 4, -28], [28, -1, -2], [-18, 18, 0], [-12, -4, -3], [-58, -8, 12], [40, 6, -6], [-22, -11, -11], [16, 0, 17], [22, -15, -13], [-38, 0, -20], [-54, 41, 8], [26, -20, -13], [-26, -10, 7], [-8, 5, -11], [-34, 33, 6], [52, 7, 18], [26, -2, -5], [-4, 16, 12], [36, -4, 1]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6840_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6840_2_a_bj();".
// 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_6840_2_a_bj(:prec:=3)
    chi := MakeCharacter_6840_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_6840_2_a_bj();".
// 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_6840_2_a_bj( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6840_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-8, 0, 5, 1]>,<11,R![64, -20, -4, 1]>,<13,R![106, -22, -5, 1]>],Snew);
    return Vf;
end function;