
// Make newform 6864.2.a.by 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_by();".
// 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_by();".
// 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, -6, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-3, 0, 1, 0], [1, -4, 0, 1], [1, -6, 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_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, 0], [1, 0, 0, 0], [-1, 1, 0, 0], [-1, 0, 0, -1], [1, 0, 0, 0], [-1, 0, 0, 0], [0, -1, 0, -1], [0, 0, -1, 1], [-1, 0, 2, 1], [-5, -1, 1, 1], [-2, 1, -1, 2], [2, -2, -2, 0], [-3, -2, 0, 1], [1, -1, -1, -1], [0, 0, -2, 2], [-2, 0, 0, 0], [1, 0, -1, 2], [-3, 0, 3, 0], [1, -1, 2, 0], [-6, 2, 2, -2], [-7, 2, 0, 1], [-2, -1, 0, -1], [2, 0, 2, -4], [-6, 3, 1, 0], [2, -2, -2, 0], [-6, 1, 2, -3], [-5, 0, 1, -2], [5, 0, 1, 0], [2, 0, -3, -1], [-3, 6, -1, 2], [-2, 1, 0, 1], [3, 2, -3, 0], [-4, 3, 1, 2], [0, -3, 0, -1], [-2, -2, -3, -3], [-2, 0, 1, 1], [0, 0, -1, 3], [3, 1, 2, 4], [1, -2, -3, 2], [-15, -1, -1, -3], [6, -6, 1, -1], [0, 0, 5, -3], [-1, 2, 3, -2], [0, 0, 3, -5], [-10, -2, -1, 3], [5, -4, 3, 2], [4, -1, 0, -3], [14, -1, -1, 4], [-6, 2, 1, -1], [-9, 2, 3, -8], [2, -5, 0, 1], [5, 8, 0, -3], [2, 4, -2, 2], [10, 0, 4, 2], [-17, 4, 5, 0], [0, -2, 0, 2], [-4, 6, -2, 2], [-6, 0, -1, -1], [5, -2, -5, 6], [-5, -6, -2, 5], [13, -3, -1, 1], [-12, -2, -3, 3], [-8, 4, 1, -5], [-2, -2, 1, -1], [5, -2, -2, 3], [-15, 1, 6, 0], [-3, 1, 0, 0], [-2, 6, 0, -2], [-8, 4, 2, -2], [0, 0, -8, -2], [-4, 1, -3, -4], [-13, 0, 0, -5], [0, -4, -4, 0], [17, 0, -3, 6], [-2, -3, -3, 4], [-10, 6, -2, -2], [-2, -6, -2, 0], [-1, 12, 1, 0], [2, -3, 5, -2], [19, -2, 2, -3], [6, 2, 1, 7], [-1, -6, 5, 2], [-12, 0, 2, -6], [-3, 6, 5, 4], [-16, 1, -2, 1], [12, 4, 0, -4], [-14, 11, 5, 0], [13, -6, -5, 6], [6, 4, 7, 5], [4, -5, -5, -2], [-10, 2, -5, -3], [-1, -4, 0, 3], [0, 5, 3, 0], [-1, 6, -5, -2], [-9, -1, 0, -8], [8, 2, -8, -2], [-16, -7, 3, 6], [7, 6, -5, 0], [16, 7, 2, -1], [2, 8, 4, -4], [9, -7, 7, -7], [-20, -2, 3, -3], [20, -4, -2, 2], [-6, -3, -8, -5], [-11, -7, 1, -1], [4, 0, -6, 0], [-5, -4, 7, 0], [-20, 6, -3, -1], [-3, 2, 5, -6], [-4, 4, 0, -2], [-6, -11, 0, 1], [6, 0, 3, 5], [12, 11, 1, -2], [17, -1, -2, 0], [-20, -5, 5, 4], [-5, 2, 1, -6], [-6, -1, -3, 10], [-4, -8, -2, -2], [-6, -6, 6, 4], [-8, -2, -4, 10], [6, 6, 4, 2], [0, 0, 4, -10], [2, -1, 4, -7], [13, -8, -7, 8], [2, 3, -1, 0], [-13, -1, 7, -1], [15, -2, 7, -8], [3, 6, -7, 0], [-4, -6, -8, 2], [-28, 4, 1, 1], [-6, -6, -1, -7], [17, -2, -7, -2], [5, -10, -5, 0], [12, 0, -5, 3], [15, -4, -8, 5], [-13, -2, 7, -4], [0, -5, -3, 10], [-10, 2, -9, 5], [12, -6, -10, 6], [-10, 5, 8, -9], [2, 16, 3, -1], [4, -16, 1, -3], [17, 12, -1, -6], [-34, 10, 5, -1], [-2, 8, -4, -4], [-22, 4, 2, -8], [0, 4, -8, 2], [-8, 5, -6, -5], [-8, 10, 8, 2], [20, -6, -4, 10], [8, 4, 4, -2], [-3, 2, -7, 12], [-10, 6, -2, 6], [4, -10, 8, 2], [-8, 0, 4, -8], [-20, 4, -6, -2], [-20, 1, 4, 3], [18, -1, -5, -6], [-16, 16, 4, -2], [-14, -4, -1, 9], [4, 12, -4, -4], [-16, -7, -2, -13], [9, 12, -4, 1], [20, -6, 3, -5], [6, 1, -3, 2], [6, -8, -10, -4], [-5, 12, 3, 0], [-5, 0, 13, -8], [-9, -10, 6, 5], [8, 6, -4, 8], [-10, 4, 0, 6], [5, 0, -11, 14], [12, 6, 2, 8], [3, -6, 5, 10], [-13, -16, -3, -6], [-9, -8, 7, 2], [20, 2, 7, -5], [3, 1, 2, -2], [0, 3, 2, -5], [-3, -12, 1, 2], [8, -7, 9, -6], [8, 8, -8, 0], [24, 0, 7, 3], [-29, 6, 2, -3], [14, -12, 6, -4], [-8, 4, 2, -12], [22, 4, 4, -8], [35, 11, 0, -4], [11, 6, -7, 2], [-37, -2, -3, -4], [4, 8, -1, -13], [-6, 8, 4, 2], [16, -2, -12, 10], [-7, 3, -12, 8], [16, -4, 8, -12], [6, 10, 8, 2], [-6, -4, 0, 0], [10, -12, 0, 0], [3, -2, 0, 7], [-6, -2, 4, -12], [-4, 0, -11, 1], [-20, 1, 2, -3], [11, 6, 3, 12], [-30, 14, 6, 0], [-29, 6, -7, 0], [18, 2, -6, 0], [50, 3, 1, -2], [11, 14, 7, 10], [20, 4, 5, -7], [14, 6, -2, -2], [-22, -8, -4, 8], [-8, 16, 2, 0], [9, 2, 7, 12], [-8, 0, 2, 2], [-10, -10, -7, 3], [-4, 0, -6, -4], [12, -3, -2, 17], [0, -3, 0, 5], [14, -10, -8, 8], [8, 3, 5, 6], [-1, 2, -5, -4], [-23, 0, -6, -1], [2, 1, 9, 6], [-14, 3, -9, 4], [-1, 4, -1, -4], [2, 2, -4, 2], [-22, -2, -2, -4], [-35, -6, 1, -2], [34, -5, 2, -3], [12, 4, -12, 0], [-10, -8, 0, 0], [-1, 11, -13, -3], [-7, -10, 6, 13], [-10, 11, -2, -1], [40, -2, 0, -2], [-8, 8, 0, 0], [-6, 2, -4, 2], [-16, 18, -1, 1], [8, 6, 11, 11], [-22, -2, 3, -7], [5, -12, 5, -4], [37, 1, -1, -3], [25, -10, 5, -6], [18, 18, 2, 4], [41, 4, -4, 3], [22, -10, 2, -6], [-28, -3, 3, 4], [15, 2, -17, -6], [-6, 2, -1, 1], [0, 6, -10, 0], [6, 12, 4, 4], [8, -4, -7, -7], [-10, -14, 4, -8], [-11, -10, 6, 11], [-11, -19, -5, 3], [-20, -10, 5, 9], [42, -8, 7, -3], [24, -16, -11, 11], [20, -10, 2, -2], [-37, 2, -1, 0], [24, 3, 6, -5], [21, 0, 9, -4], [12, 8, -6, 0], [-25, -8, -5, -10], [6, -1, 1, -16], [-10, 12, 6, 0], [1, 3, -2, -6], [-10, -1, 11, 2], [4, 8, 9, 11], [-2, -15, 2, 5], [16, -8, 6, 4], [18, 3, 5, 6], [26, 6, 6, 4], [-12, 13, -12, -1], [8, 18, 0, 4], [0, -5, 1, 4], [-5, -4, 15, -12], [-18, 8, -5, 13], [-21, -2, -12, -5], [17, 4, 11, 2], [30, 12, 0, -2], [22, 5, -15, 0], [14, 14, -4, 0], [2, -4, -3, 11], [6, 2, -7, -13], [13, 10, -5, 4], [-2, 12, -12, 4], [2, 4, 7, -15], [-18, 15, 11, 4], [-8, -5, -2, 1], [-2, -10, 2, -8], [-8, -2, -1, 7], [-47, -12, 0, 7], [8, -10, -3, 5], [5, -4, -13, -4], [17, -1, 1, -13], [11, -12, 5, -2], [-52, 12, 14, -4], [-49, 6, 11, -10], [30, 4, 1, 9], [-2, 4, -8, 8], [-2, -8, 5, -5], [-12, -5, -8, -11], [12, -6, 9, -3], [30, 18, -4, -12], [-22, 6, -2, 8], [-32, 2, 1, -15], [18, -12, 4, -4], [0, -8, -4, 0], [-1, -12, -1, -2], [8, -6, -8, 6], [17, -7, 6, -4], [16, -1, 10, 5], [-42, -8, -4, 6], [-44, 12, 4, -4], [-20, -14, 2, 14], [-61, -2, -1, -10], [-9, -12, -12, -9], [-28, -14, -4, 12], [4, -13, -4, -1], [16, 3, 2, 15], [-16, -8, 10, 4], [23, 7, -5, -5], [8, -5, -7, 20], [39, -16, -12, 5], [31, -2, 0, 3], [-13, -9, -12, 0], [38, -3, -5, -2], [-26, 10, -8, 12], [26, 1, -14, -7], [-14, -24, 3, 1], [-24, 4, -4, -14], [2, 11, -14, 1], [-18, -10, -3, -13], [24, 2, 9, -19], [28, -18, -12, 6], [-25, 4, 7, -14], [27, -6, -4, 15], [6, 2, 8, 10], [12, -17, 8, -15], [47, -16, -7, 4], [-11, -4, -1, -4], [-30, -6, -3, 13], [4, -2, -14, 4], [15, 11, -12, -10], [11, 8, 5, 2], [10, 0, -12, 8], [17, -7, 8, 12], [-23, 0, 6, -21], [-28, -12, 12, 6], [28, -6, 7, -5], [2, -14, -6, 12], [-16, 7, -3, 2], [-12, 1, 20, -1], [-9, 0, -3, -16], [-18, 25, 8, -5], [0, -4, 4, 0], [-40, 14, 9, 1], [-4, -3, 14, -1], [6, 12, 6, -12], [-4, -8, 4, -10], [14, -11, 2, -15], [23, -18, -9, 6], [38, -6, -1, 5], [-30, 12, 22, -12], [-39, 2, 12, -11], [-8, 4, 1, -11], [-25, 14, -2, 3], [-20, 0, 0, -10], [34, 12, 8, 18], [28, 2, 4, -6], [-19, 20, 6, 3], [14, -1, 20, -7], [-14, -7, -4, 21], [32, 4, 2, 12], [40, -4, 12, -8], [4, 6, -2, -16], [-4, -16, -1, -13], [-12, 15, 4, 3], [-56, -10, -4, -8], [21, -9, 0, 0], [4, -15, 5, 4], [21, 0, -18, 7], [43, -18, -4, 3], [-48, -4, -7, 11], [-10, 14, 14, 2], [-18, -1, 1, 2], [10, 12, 0, 0], [42, -2, 3, 9], [-10, 6, 15, 1], [56, -6, -14, 6], [39, -3, -2, 10], [-52, -6, 2, -16], [2, -12, -14, 8], [-34, 2, -6, 6], [4, 18, 0, -4], [-71, 10, -8, 7], [-25, 22, 3, 0], [-14, -14, -10, 6], [-16, 26, 7, 1], [44, -8, -16, 10], [-51, 0, 15, 0], [-23, 8, 8, 9], [48, 11, 7, 8], [10, -4, -11, 19], [-12, -5, 0, 13], [-35, 2, -13, 6], [11, 4, 12, -3], [-11, 9, 4, 8], [7, -8, -19, 14], [20, 0, -2, -4], [-10, 5, 0, -17], [-16, 8, -6, -14], [23, 19, 5, 19], [-32, -10, 2, -2], [6, 2, 10, -12], [-7, 28, 0, 13], [-8, 22, 8, -6], [-4, 11, 3, -12], [24, -16, -4, -8], [10, 2, -24, -6], [-44, 8, -4, -2], [-10, -2, 16, 0], [3, -16, -9, -8], [34, -12, -12, 16], [-23, 13, 16, -2], [30, -8, 2, -8], [56, -2, -5, 21], [15, -27, 6, -8], [-36, -8, 2, -2]];
    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_by();".
// 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_by(:prec:=4)
    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_by();".
// 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_by( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6864_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![20, -12, -8, 3, 1]>,<7,R![-16, -40, -12, 3, 1]>,<17,R![16, -36, -28, 0, 1]>,<19,R![32, -48, -24, 2, 1]>],Snew);
    return Vf;
end function;