
// Make newform 6864.2.a.bi in Magma, downloaded from the LMFDB on 23 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_bi();".
// 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_bi();".
// 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, 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_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], [1, 0], [-1, 1], [0, 0], [-1, 0], [-1, 0], [-1, -3], [2, 2], [-2, 0], [3, -3], [1, -3], [0, 6], [-8, 2], [1, 1], [0, -4], [2, -4], [-6, 2], [-4, -2], [9, 1], [2, -2], [-6, -2], [11, -1], [0, 4], [-11, 3], [-4, -6], [-7, 3], [2, -6], [-10, 2], [-2, -2], [-10, 4], [-1, -1], [0, 0], [-3, 3], [3, -1], [-2, 4], [6, 2], [-10, 2], [-15, 5], [-12, 4], [-7, 3], [-6, -8], [-10, -2], [0, 8], [6, 2], [6, 12], [18, -2], [-5, 11], [11, -1], [-14, 0], [-14, 0], [-19, -5], [14, -4], [2, -8], [-12, -8], [8, 6], [-18, -2], [-16, -2], [-14, 6], [14, -8], [4, 6], [-3, -15], [-6, 12], [10, -2], [-10, 12], [-2, 6], [9, 11], [5, -15], [20, -6], [0, 16], [-14, 4], [-3, -13], [-10, 4], [-16, -4], [4, 10], [3, 15], [-14, 2], [24, 6], [-16, -10], [9, -1], [-14, 6], [-6, 0], [2, 4], [8, -16], [14, 8], [-7, 13], [-12, 0], [-9, -11], [2, -12], [12, 10], [25, 1], [-6, -8], [-2, -16], [-13, -5], [-8, -8], [13, 5], [18, 10], [-17, -7], [2, -12], [-1, -9], [-6, 16], [17, 13], [22, -4], [4, 8], [-15, -17], [-1, -25], [-2, 4], [-14, -10], [2, -16], [-8, -16], [18, 12], [35, -5], [-30, -6], [-9, -11], [-41, 3], [-3, 13], [-10, 0], [3, 19], [0, 16], [36, -2], [22, 2], [16, -6], [14, 16], [-7, 19], [-2, -10], [21, -15], [-7, 11], [-6, 24], [24, -8], [-2, 2], [22, -6], [-12, 8], [28, 4], [-28, 12], [22, 10], [-34, 12], [-2, 0], [-23, 3], [-8, -20], [4, -10], [1, -25], [22, 10], [-8, -22], [2, -6], [26, 8], [18, -16], [16, -12], [-2, -4], [27, 1], [34, -10], [10, -14], [6, 8], [-30, 4], [-14, 18], [2, -10], [-28, 4], [-32, -8], [-17, -1], [21, 3], [14, 0], [-12, 14], [-40, 8], [-1, 29], [16, -4], [14, 8], [-9, -11], [-8, 20], [2, 18], [-4, -10], [-14, -2], [24, -22], [32, -4], [16, 2], [30, 14], [6, -20], [10, 2], [-24, 22], [-16, 0], [-23, -13], [-5, -9], [-28, 18], [-27, 9], [12, 4], [-10, -6], [-36, 10], [12, 12], [38, -8], [30, -4], [7, 3], [34, 0], [12, 20], [-2, -10], [20, 8], [-2, -10], [3, -27], [-4, -4], [-4, 6], [30, -16], [10, 16], [4, -10], [18, 10], [-32, -10], [35, 3], [-38, 8], [-16, -6], [4, 4], [-12, 26], [29, -3], [12, -24], [0, -18], [-38, 10], [10, 16], [-2, 8], [16, 8], [-32, -8], [-2, 12], [18, -8], [-11, 1], [15, -3], [-10, 6], [-5, 5], [38, -20], [16, 16], [5, -5], [31, 3], [-22, 10], [-20, 26], [32, 2], [0, 16], [19, -1], [-24, -20], [18, -8], [-11, -19], [42, 14], [25, -1], [-6, 2], [-12, 12], [32, 18], [-34, -12], [50, 8], [54, 8], [-38, -18], [-63, -3], [4, 0], [-24, -10], [-30, 0], [6, 10], [-21, 3], [-52, 0], [36, 16], [-6, -22], [22, -8], [-12, -10], [-54, -6], [6, -18], [53, -9], [-6, 12], [30, 22], [26, 22], [16, 10], [-22, 16], [-23, -15], [-18, 14], [-26, 0], [20, -14], [-15, -9], [8, -12], [37, -9], [-1, -11], [-14, 30], [15, -23], [22, 24], [-1, 23], [60, 2], [19, 27], [76, -2], [13, 13], [-42, 6], [-14, 2], [14, -6], [22, 18], [-52, -4], [-9, -25], [-22, -14], [-2, -22], [-4, 4], [-12, 20], [-14, -4], [20, -2], [-27, -19], [-55, -17], [36, 10], [26, 4], [62, -4], [30, 4], [28, 22], [-19, 15], [30, -14], [2, 28], [48, 8], [46, -2], [50, -8], [12, 6], [21, -35], [-2, 36], [22, 10], [-48, 14], [-34, -16], [-38, -24], [60, -8], [-8, -34], [18, 18], [27, 21], [-5, 1], [40, 0], [16, -32], [-20, 26], [0, 16], [42, -8], [-16, -26], [-51, 3], [17, -3], [10, 24], [-17, -15], [61, -11], [66, -4], [-34, -10], [-11, 37], [71, 3], [-22, -2], [-57, -7], [22, 26], [54, 16], [-15, -7], [-34, 4], [20, -32], [-22, 10], [-12, -34], [-8, 22], [-44, -18], [41, 9], [-64, -2], [0, 30], [-18, 28], [-22, -34], [27, 29], [-2, 22], [-34, -32], [-35, 1], [26, -40], [-18, -36], [12, 16], [-16, -18], [-1, 25], [61, -15], [-64, -6], [-43, -21], [-24, 24], [-6, 4], [-3, -13], [48, 0], [-46, -16], [-21, 9], [-24, 8], [-22, 20], [-24, 36], [-10, -14], [0, -34], [34, 18], [14, -32], [-28, 16], [10, -18], [38, 12], [39, -15], [5, 17], [-66, 0], [4, 20], [-6, -26], [-10, 18], [-55, 7], [0, 18], [-27, -9], [-19, 3], [20, -44], [36, 22], [-22, -14], [-34, 2], [-1, -21], [-18, -40], [0, -36], [-2, -12], [-56, -6], [5, -41], [-6, -14], [36, -24], [-38, 2], [80, 2], [6, -26], [-18, 4], [10, -18], [66, -12], [-30, 16], [-96, 2], [8, -36], [-63, -9], [-52, -10], [-67, 21], [-46, -12], [-22, 12], [59, 3], [-30, 30], [-54, 24], [49, -21], [16, -12], [-71, -7], [-4, -6], [12, 50], [10, 16], [-2, 30], [-21, -39], [48, 28], [28, 10], [82, 12], [-74, -10], [10, -18], [-38, 32], [11, 5], [48, -4], [90, 4], [-67, 9], [-12, -20]];
    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_bi();".
// 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_bi(:prec:=2)
    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_bi();".
// 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_bi( : 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, 2, 1]>,<7,R![0, 1]>,<17,R![-26, 2, 1]>,<19,R![-8, -4, 1]>],Snew);
    return Vf;
end function;