
// Make newform 6864.2.a.bu in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6864_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_6864_2_a_bu();".
// 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_6864_2_a_bu();".
// 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, -5, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, 0, 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_6864_a();"
function MakeCharacter_6864_a()
    N := 6864;
    order := 1;
    char_gens := [2575, 1717, 4577, 4369, 2641];
    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_6864_a_Hecke(Kf)
    return MakeCharacter_6864_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], [1, 0, 0], [0, -1, 1], [-1, 0, -1], [-1, 0, 0], [-1, 0, 0], [-1, 1, 0], [-3, 0, 1], [3, 2, -1], [5, -1, 2], [-6, 1, -1], [-2, 4, -2], [-1, 4, 1], [5, -1, -2], [2, -2, 2], [-4, 2, 0], [-4, -2, 2], [2, 2, 0], [-8, -3, 1], [0, 0, -2], [3, -4, -3], [-7, 1, 0], [-8, -2, -2], [-8, 1, -3], [-2, -4, 2], [3, -5, -2], [-4, 4, 0], [4, -2, 2], [1, 0, 3], [-2, -2, 2], [-5, 3, 2], [-10, -4, 2], [-8, 5, 1], [-7, 3, -4], [-1, 0, 1], [-3, -4, -3], [7, -4, -1], [-4, 9, -1], [-10, -4, 2], [5, -1, 0], [-5, -8, 1], [5, -8, -3], [8, -2, 2], [-7, 4, -1], [-3, 2, -3], [-4, -4, -4], [7, 1, 6], [-10, 3, -3], [3, -6, 5], [-4, 2, -2], [-7, -7, 0], [-3, 6, 7], [4, -6, -4], [-4, 6, 2], [-8, 0, 2], [16, 6, -2], [8, -2, 0], [23, -2, 1], [-4, 4, 6], [11, -10, -5], [-19, -3, 2], [9, -6, 9], [-5, 12, 3], [-15, 6, 1], [1, 2, 3], [0, -7, -3], [-2, -7, 5], [-10, 6, 6], [6, -8, 0], [0, 6, -4], [-16, 5, -1], [3, 10, 1], [6, -14, 4], [10, -6, -6], [-8, -1, -11], [14, -2, 4], [-6, 6, -6], [18, -4, 10], [-22, 9, 5], [-1, -4, 1], [3, 8, -3], [-4, -8, 6], [-6, 12, -2], [-18, 8, 4], [-7, 3, -6], [4, -4, 4], [-6, -5, -9], [20, -4, 6], [-5, 4, 1], [-6, -11, 5], [-5, -2, 7], [-25, -2, 1], [-8, 3, -7], [20, 0, 10], [14, -11, 7], [0, -14, 6], [-16, -1, -5], [-2, 4, 8], [3, 17, -2], [14, -8, -4], [11, 1, 12], [-1, 4, -11], [-14, -4, -6], [21, -9, 0], [5, 1, 0], [12, -12, 2], [-8, 2, -6], [-3, -2, 1], [24, -2, 2], [26, 0, 8], [15, -13, -2], [7, -16, 1], [-6, 15, -9], [2, -5, 7], [18, 1, 9], [-20, 4, -10], [0, -1, 3], [-20, 6, -2], [-4, 4, -10], [-28, 6, -8], [4, 6, 0], [-16, 12, 0], [-21, 9, -2], [-28, 4, -14], [-6, 17, -3], [-13, 3, 6], [-10, -6, -4], [-4, 8, -4], [6, 6, -4], [15, 12, -7], [9, -4, -3], [-14, 14, 0], [2, -6, 12], [3, -8, -13], [-1, 14, 3], [18, 16, -4], [0, -15, 5], [5, -12, 1], [-22, 12, -8], [5, 11, -8], [-21, -8, -1], [-1, -2, -5], [34, -2, -4], [-21, 14, -11], [-10, 4, -4], [-2, -16, 6], [-20, 8, -6], [-15, 7, -6], [-22, 2, -8], [6, -6, -4], [28, -2, 4], [-26, -4, -8], [24, 4, -4], [20, -14, 12], [-30, 6, -8], [16, -2, 6], [11, 3, 10], [10, -11, 7], [-2, -16, 2], [11, -4, -7], [28, -2, -4], [31, -9, 8], [-3, -2, 11], [-27, 2, -11], [16, 7, -5], [42, 0, 2], [-12, 10, -2], [-34, 6, -6], [15, -8, 5], [16, -20, -2], [-10, -2, 0], [-42, -4, 2], [-14, -6, -2], [44, 6, -4], [0, 8, -4], [34, -4, 4], [-9, 8, -17], [-26, 17, 3], [3, -19, 2], [14, -14, 6], [-34, -11, -1], [-20, 0, -8], [23, -4, 15], [27, 12, -3], [28, 10, -8], [4, -2, -4], [-20, 16, -20], [4, 7, 9], [4, -22, 0], [-44, 6, -2], [15, 4, -1], [-38, 8, 2], [0, -12, 8], [6, -9, -15], [14, -16, 6], [-10, -4, 0], [10, 8, -8], [16, -6, 0], [-31, 14, -11], [-28, -2, 8], [19, -2, 3], [23, -1, 6], [-34, 8, 4], [-20, -6, 2], [-24, 2, -4], [26, 10, 2], [12, -27, 7], [6, 0, 6], [-25, 2, 11], [-8, 8, 12], [-10, -16, 10], [30, 0, 8], [2, -22, 4], [2, -12, -2], [31, -2, -3], [-20, 14, -2], [29, -5, 10], [11, 11, -4], [12, 0, -2], [34, -5, 15], [-20, -12, 2], [-17, -2, -3], [10, -11, -7], [14, -5, 13], [-2, 10, -10], [0, 10, -4], [30, 6, -2], [0, 6, 18], [19, 17, 6], [20, 6, -10], [2, -20, -4], [23, 3, -8], [9, 4, -3], [3, 1, 14], [12, -8, -12], [12, 4, 0], [-14, -14, 2], [7, 22, -1], [-5, -4, -7], [27, -2, 3], [-2, 14, 12], [-7, 1, 2], [34, -8, 6], [-18, 18, 6], [-11, 6, 1], [32, -10, -4], [16, 3, 13], [8, 10, 12], [-15, 24, -15], [0, 10, 12], [-2, 6, 18], [51, -8, -3], [12, -12, -6], [-19, 6, 11], [-7, 5, -12], [-31, -6, -1], [3, -10, 9], [19, 4, 11], [0, -18, 8], [6, 14, -14], [51, 1, -4], [-10, 2, -10], [10, 2, 18], [-2, -14, 14], [-42, 9, -21], [-4, 12, -12], [12, -15, -1], [6, -9, 19], [7, -12, 3], [21, -9, 18], [-32, 14, 0], [-6, 15, -11], [18, 14, -6], [27, -1, 2], [0, -14, -4], [-54, 5, 5], [4, -8, -2], [7, 12, -3], [21, -4, 7], [38, -10, -2], [14, 12, 0], [44, -5, 5], [38, -14, -6], [-55, 0, -5], [-21, -14, 1], [4, 4, -8], [38, -16, -8], [3, 6, -5], [-22, 21, -19], [5, 25, 0], [16, -4, 22], [37, -6, 5], [21, -12, 7], [-43, 2, -13], [28, -14, -6], [45, 7, -8], [22, 2, -8], [16, 6, -16], [-36, 0, -18], [-35, 0, 9], [4, 16, -10], [-31, -16, 11], [41, -3, 14], [31, -10, 15], [2, 28, -14], [-8, -12, 4], [21, 12, -5], [-20, -26, 12], [6, 24, 6], [-16, 2, -8], [2, 2, 20], [-62, 3, -5], [17, -19, -2], [-40, 10, -2], [-20, -2, -6], [6, 34, -10], [38, -20, 14], [23, -18, 17], [0, 2, 4], [-41, 5, -14], [-27, -11, -2], [18, 32, -4], [-1, 15, -20], [-22, 25, 1], [-37, 16, -19], [-9, -20, -5], [-30, -3, -13], [-46, -5, 3], [0, -6, -2], [-13, -17, 8], [7, -12, 21], [20, 32, -10], [-21, 29, -12], [-9, 10, 1], [-7, -22, 15], [44, 2, 6], [18, -4, 18], [33, -10, 17], [56, -2, 4], [59, -11, 0], [18, 4, 22], [-22, -22, 14], [23, 8, -7], [44, -14, -6], [-72, 7, 3], [-6, -14, 20], [10, 0, -16], [-22, -23, 1], [19, -14, 5], [-28, 20, -10], [-29, 12, 7], [4, -14, 8], [-40, 11, -15], [23, -13, 28], [-36, 14, -14], [-15, -21, 16], [8, 2, -16], [-15, -10, -9], [-27, -17, 12], [-66, 14, 6], [8, 0, 18], [-51, 3, -6], [-64, 14, 2], [29, -18, 3], [-8, -8, -8], [-27, -16, -11], [35, -10, -1], [-13, 10, -23], [22, 28, -10], [-8, -14, 2], [32, -4, 4], [-33, -2, -11], [-5, 9, -8], [-15, -17, -2], [-18, 8, 12], [26, -14, 22], [-28, 10, -10], [-3, 28, -5], [19, 25, 2], [70, -2, 4], [-32, 21, 19], [6, -15, 13], [-53, -12, 11], [-35, 8, -5], [-1, -6, 21], [-58, 8, 0], [-4, 11, 27], [36, 10, 0], [37, -12, 25], [-27, -4, -1], [-6, 28, 2], [8, -11, -15], [-2, 12, -20], [52, -16, 4], [20, 2, -2], [18, 2, 16], [-13, 28, -25], [-22, 32, 8], [-4, 36, -8], [-5, -4, -23], [-32, 20, -14], [4, 12, -2], [1, 28, 5], [-14, 25, 7], [-3, -28, -5], [51, 9, -8], [-18, -6, 16], [55, -12, 5], [8, -17, 3], [2, 4, -4], [50, 8, -4], [15, -1, 2], [-16, 18, 10], [27, -25, 8], [-24, -2, -8], [20, -28, 14], [-3, 2, -25], [-86, -2, 0], [0, -41, 9], [22, 28, -8], [-22, 12, 4], [12, -10, -16], [-52, 20, 10], [-24, 22, 2], [20, -8, 22], [16, 19, -7], [0, 12, 12], [-37, -8, -7], [-14, 29, 17], [6, 4, 24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6864_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6864_2_a_bu();".
// 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_6864_2_a_bu(:prec:=3)
    chi := MakeCharacter_6864_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_6864_2_a_bu();".
// 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_6864_2_a_bu( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6864_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-2, -10, 2, 1]>,<7,R![-12, -8, 2, 1]>,<17,R![-2, -4, 2, 1]>,<19,R![12, 24, 10, 1]>],Snew);
    return Vf;
end function;