
// Make newform 6864.2.a.bp 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_bp();".
// 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_bp();".
// 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 := [1, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, -1, 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, 0, -1], [1, -1, 1], [-1, 0, 0], [1, 0, 0], [3, -1, 2], [-3, 3, 1], [-3, 1, -1], [1, -1, -2], [2, 0, -1], [-4, 0, -2], [5, -3, -1], [-1, 1, -4], [0, -2, 2], [-2, 4, 6], [-4, 4, -2], [-2, 2, 2], [0, -2, -3], [-2, 4, 2], [-3, 5, 3], [-5, 1, -2], [2, -2, 0], [-6, 8, 3], [-4, 0, -2], [3, 3, 0], [10, -2, -2], [-4, -4, 2], [-5, -5, 5], [4, 2, -4], [-11, 13, 6], [-2, -6, 2], [2, -4, 7], [3, -9, -4], [3, -9, 1], [-7, -1, -3], [-1, -3, -3], [10, -2, 3], [-2, -6, -2], [13, 1, 2], [-5, -5, -5], [-19, 3, 3], [-6, 6, 4], [-9, -1, -11], [-5, 3, -9], [-2, 6, 6], [-15, -1, 4], [-6, 0, -7], [-9, 9, 1], [10, -10, -10], [5, -5, -4], [-7, 3, 7], [6, 0, 14], [-2, -2, 4], [2, 4, -4], [0, -8, -10], [-4, -2, 0], [-11, -5, -9], [0, 6, -10], [-9, -1, -9], [-13, -1, -2], [-13, -5, 3], [-5, 5, 3], [-17, 7, 1], [-17, 13, 3], [-10, 8, 11], [-4, -12, -3], [-18, 8, -2], [6, -4, 2], [-2, 8, 2], [-8, 0, 13], [15, 5, 5], [8, 0, 6], [-18, 0, -2], [2, -2, 1], [14, -6, 0], [-14, -8, 2], [4, -16, -2], [10, -2, -13], [9, 1, -13], [-9, 19, 3], [-20, -2, 2], [-2, 10, -10], [-10, -4, 4], [3, 1, 16], [-8, 12, 12], [-14, -10, 1], [-20, -6, -6], [9, 5, 7], [0, 0, 9], [-11, -3, 3], [3, 1, 1], [10, 10, -7], [-4, -10, -12], [6, 4, 3], [-8, 12, 2], [2, -12, 1], [6, -4, -8], [9, -17, -8], [10, -4, 16], [-7, -11, -12], [-5, -1, 9], [-22, -2, -14], [13, 9, -10], [3, -7, 14], [-28, -2, -2], [20, -8, -6], [-1, 15, -5], [-6, -18, 0], [2, -4, -12], [9, -15, 2], [-11, -7, -21], [18, -2, -11], [-8, 8, 11], [0, -4, 5], [-4, -2, -22], [-16, -2, 7], [2, -2, 4], [2, -16, -20], [0, -2, -6], [8, 18, 0], [-16, 24, 2], [-1, 13, 10], [-26, 32, 14], [-36, 8, 5], [7, 3, -16], [8, -8, 4], [20, -4, -12], [2, -14, -12], [1, 1, 15], [-9, -7, 15], [20, 4, -14], [4, -24, -6], [11, 13, 17], [-3, 17, 1], [10, 0, 0], [-10, -12, -5], [-21, -3, 3], [-20, 18, 6], [-3, -3, 18], [-17, 25, 15], [-21, 31, 15], [18, 6, 0], [43, 1, 9], [26, 4, 8], [18, 6, 6], [12, -22, 2], [17, -5, -6], [-26, -14, 12], [-6, -6, 0], [-2, 4, 2], [26, -8, 0], [6, -14, -2], [8, 10, 26], [-12, 24, 18], [18, -6, 12], [17, -3, -2], [4, 10, 9], [-10, -18, 8], [17, -27, -21], [-18, -12, -16], [-1, -7, 4], [21, 3, -17], [19, -25, -19], [-2, 12, 1], [22, 10, 26], [0, -12, 26], [-14, -8, -6], [21, 5, -9], [30, -8, -8], [-4, -8, -18], [12, 0, -10], [18, -20, -20], [6, 12, 18], [-38, -6, -6], [-12, 6, -14], [-27, 11, -7], [-8, -2, -11], [-3, 7, -8], [14, 8, -2], [2, 16, 3], [-20, 12, 8], [-1, 21, 13], [21, 5, 3], [6, -8, -4], [14, -28, -10], [-12, -8, -14], [-34, -6, -3], [14, 12, 10], [10, -6, -16], [7, -27, -3], [14, -14, -14], [6, -10, 18], [32, 6, 23], [18, 14, 18], [4, -2, -6], [-46, 12, 8], [6, 16, -10], [-19, -3, -31], [20, 26, -18], [-17, 7, -1], [1, 29, -10], [6, -16, -20], [28, -28, -16], [-26, -20, 4], [2, 12, 10], [-18, -2, -9], [-14, 18, 14], [31, -17, -5], [26, 10, -2], [18, -26, -8], [-50, -8, 4], [-4, 8, -26], [18, 6, -6], [31, -7, 5], [10, 22, -6], [-9, 1, 12], [-1, 9, 4], [30, 4, 10], [18, 14, 21], [-4, 18, -2], [35, -3, 1], [2, 6, 15], [2, 24, -7], [14, 24, 4], [24, -10, 4], [6, 28, 6], [38, -22, -8], [5, 11, -24], [-2, -18, -24], [14, -12, 4], [-39, -5, -14], [37, -9, -3], [31, -19, -18], [26, -10, -10], [16, -8, -20], [30, -12, -6], [37, 13, -3], [7, 27, 3], [21, -15, -17], [-6, -2, 12], [-1, 19, -2], [-6, -14, 26], [18, 24, -10], [11, -21, -1], [-8, -6, 14], [18, -2, 25], [-14, -4, 16], [-13, -11, 19], [12, 14, -22], [24, -34, -16], [-35, 25, 3], [22, -20, -10], [-13, 1, -25], [-43, 11, -4], [21, -17, -5], [-15, -5, 13], [7, -7, -21], [12, 6, -8], [4, -14, 4], [-31, 5, 8], [-38, -4, 8], [0, 6, 8], [30, -8, -18], [-8, -18, -15], [12, 0, -8], [20, 12, 1], [-10, 2, 9], [35, 1, -13], [-7, -9, 22], [-2, 20, 6], [30, -28, -11], [-6, -16, -38], [33, -15, -22], [-12, 2, 16], [24, -20, -7], [-2, -24, -6], [1, 13, 15], [-45, 15, -7], [-38, 4, 16], [-10, 36, 2], [-30, 18, 1], [26, 4, -4], [7, -9, -7], [23, -27, 5], [-8, 0, 4], [-6, 28, 24], [-17, -33, 11], [20, 16, -27], [9, 3, 8], [38, -8, 12], [31, -5, 9], [61, -7, -9], [-39, 11, 11], [52, -8, 4], [-27, 29, -10], [-50, 22, 8], [50, 0, -14], [-28, 18, -4], [5, 27, -11], [48, -14, 2], [59, -5, 1], [-9, 23, 10], [-23, 5, -29], [-4, 16, 16], [-2, 10, 40], [-19, -11, -19], [10, 8, -6], [30, -14, 18], [-20, -2, 0], [-42, -10, 12], [-34, -6, -7], [-23, -23, -4], [22, -6, -32], [14, -6, 24], [2, -16, 14], [-58, 14, 14], [3, 17, 1], [-28, 26, 16], [-1, 17, 10], [-9, -21, -10], [-10, -16, 4], [15, -31, -20], [32, -12, 5], [51, 7, -7], [-49, -15, -11], [-10, 4, -13], [-32, 24, 19], [-8, 0, 30], [23, -35, -16], [-39, 21, -13], [16, 6, 6], [-27, -7, 12], [31, 9, 17], [-23, 3, 3], [-28, 20, 10], [-8, 8, 26], [-15, -19, 29], [-28, 26, -12], [-19, 13, 28], [16, 0, 2], [34, -16, 18], [-9, 19, 13], [48, 0, 10], [38, 24, -19], [-66, 2, 0], [-10, -28, 4], [32, -24, -7], [19, -27, -15], [-56, 10, 6], [-35, -21, 9], [-32, -18, -4], [-40, 32, 19], [1, 31, 38], [8, 0, -12], [-27, 1, -38], [6, 12, -28], [33, -17, -1], [-19, -11, 30], [-4, -26, 22], [-4, 30, -22], [17, 31, 18], [10, -10, 8], [-19, -13, 27], [28, 4, 28], [-31, -1, -13], [-13, 23, 3], [9, 15, -17], [46, -42, -12], [-54, 18, 12], [-2, 34, -10], [15, 9, 21], [7, -33, -22], [-13, 33, 28], [-62, 0, 0], [-28, -22, -14], [-12, 8, 34], [27, -21, 5], [-29, 13, 10], [38, -6, 2], [-20, -4, 21], [42, 6, 11], [53, -9, 9], [7, 19, 21], [61, 11, 19], [44, -10, 8], [-16, -22, -25], [-34, 44, 10], [31, -23, -9], [-31, -3, -27], [-36, -8, -10], [58, -24, -13], [-8, 18, 16], [-20, 4, -40], [-8, 12, -10], [34, 2, -14], [-53, 9, -1], [-54, 16, 4], [-26, -22, -10], [-53, 23, 9], [64, -10, -6], [18, 8, -32], [43, -27, -5], [-24, 22, 9], [23, -33, -31], [-59, 1, 16], [12, 4, 16], [71, -5, -11], [44, 22, -21], [32, -30, -8], [-50, 16, 4], [51, 11, 16], [10, 2, -20], [-19, -29, 6], [-8, 18, 28], [38, -36, -12], [41, -33, -13], [-2, -18, 12], [-8, -20, -21], [-38, -4, -6], [4, 14, -14], [-38, 20, 14], [38, -4, -26], [-20, 8, -6], [-12, 38, 18], [-40, -16, -21], [40, 0, -16], [-1, 15, -11], [12, -32, -47], [-62, -8, 14]];
    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_bp();".
// 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_bp(: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_bp();".
// 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_bp( : 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, -4, 0, 1]>,<7,R![-4, -8, -2, 1]>,<17,R![26, -2, -8, 1]>,<19,R![-100, -16, 6, 1]>],Snew);
    return Vf;
end function;