
// Make newform 6864.2.a.br 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_br();".
// 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_br();".
// 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], [1, -1, 0], [-1, 0, 1], [-1, 0, 0], [-1, 0, 0], [0, -1, -1], [-3, 0, -1], [-1, -4, 1], [6, -1, 3], [-3, 1, 0], [-2, 0, 2], [3, 4, -1], [0, 1, -1], [0, -2, 0], [2, -2, -2], [2, 2, 0], [2, -2, 4], [3, -3, -2], [0, -4, -2], [-1, 2, 3], [2, 3, 3], [0, -2, 2], [5, -5, 2], [-2, 0, -2], [6, 1, 3], [4, -4, 4], [-2, -2, 4], [5, 6, -3], [-4, 2, -4], [4, 3, -1], [-6, 0, -6], [5, -5, 2], [2, -1, 1], [3, -8, 3], [1, 0, 3], [-11, -2, -1], [5, 3, 4], [2, -4, -6], [12, -3, -3], [11, 2, -1], [-1, 6, 5], [0, -2, -6], [1, 2, -3], [7, -2, -3], [4, 0, 0], [4, 7, -3], [7, -9, -4], [-3, 0, 5], [-2, -6, -4], [-16, 5, -1], [-13, 0, -1], [8, 2, 4], [8, 6, -2], [-4, 8, -2], [-6, 2, 4], [10, 6, -2], [21, -2, 1], [-4, 12, -2], [-3, 2, -5], [-4, 9, -7], [11, -6, 9], [19, 0, 5], [17, 4, 3], [-5, 4, 3], [5, -5, 10], [15, -1, 2], [-16, -6, 4], [12, 0, 2], [0, 14, 0], [27, -3, 4], [13, -4, 1], [16, 6, 2], [4, -6, -4], [23, -3, 0], [0, -6, -2], [-4, -2, -4], [2, -4, -6], [-7, -7, 2], [7, 2, 3], [7, -14, -1], [0, 0, -6], [-10, 4, -2], [2, -16, 4], [8, -15, 3], [4, 4, -4], [-5, 7, -2], [-8, 12, -2], [11, -4, -5], [3, 7, -2], [7, -16, 1], [13, -4, 5], [23, 9, -4], [22, 4, 4], [-7, 9, -12], [-22, 6, -4], [15, -7, -2], [-26, 4, 4], [4, -9, 1], [30, 0, 4], [-2, 5, -5], [-21, 4, -9], [6, 0, 10], [-8, -7, -3], [6, -1, -1], [0, -4, -10], [6, 2, 4], [7, 2, 13], [-4, 14, -10], [-6, 12, -4], [-32, 3, 3], [27, -2, -1], [19, -1, 2], [5, -3, -2], [-9, -9, 2], [4, 4, 14], [17, -5, 14], [16, 6, -6], [-20, 4, -2], [-28, -6, 0], [10, -14, -2], [34, 8, -2], [-6, 1, 5], [-8, 12, 10], [3, 7, -6], [-6, -15, -1], [0, 14, -10], [12, -8, 12], [-16, 6, -6], [15, 14, -5], [-7, 16, -1], [-34, -2, -4], [-8, 2, -2], [-19, 2, 7], [-15, 2, 3], [14, -8, 0], [-7, 7, -6], [17, -8, -1], [26, -8, 8], [-24, 5, 5], [-25, -4, -3], [21, -10, -9], [-8, -14, 6], [-11, 4, 5], [-2, -20, 0], [-14, 16, 2], [12, 0, 14], [-14, 11, -1], [4, 2, 2], [-36, 6, 2], [12, -10, 8], [10, -12, 8], [4, 0, 4], [8, 2, 12], [12, -6, -10], [-32, 6, -2], [-44, 3, -1], [35, -1, -4], [-8, 12, -8], [7, 16, -9], [-26, 2, -6], [-36, 3, 5], [-25, -2, -1], [21, -16, 7], [7, -7, -2], [-26, 12, -6], [2, -6, -8], [-4, 6, 0], [11, -18, -5], [16, 0, 2], [-6, 6, 4], [22, 0, 6], [-22, 2, 2], [-4, -10, 0], [-8, -12, 4], [-14, -8, 4], [3, -8, -7], [27, 3, -4], [-12, 23, -7], [4, -2, 0], [-3, -11, 4], [-4, -4, 12], [-35, -2, -1], [-5, 0, -1], [-2, 18, -6], [6, -6, -10], [-22, 16, -14], [-13, 13, 4], [8, -6, 0], [20, -10, 2], [17, -2, 3], [-38, 0, -2], [16, -4, 0], [-27, -15, 0], [-6, 16, -6], [6, 8, -12], [22, 0, 12], [20, -6, -12], [-9, 6, 9], [-16, 6, 0], [-11, 14, -1], [-24, 15, 3], [14, -16, 12], [0, -10, 10], [14, -2, -10], [-36, -2, 8], [-35, 3, 0], [42, -8, -6], [9, 18, -5], [8, 16, -4], [-4, 0, 0], [-14, 16, -20], [0, 2, 14], [-6, -4, -2], [1, -8, 13], [26, 6, -8], [40, -15, -9], [-20, 7, -11], [44, -8, 10], [-1, -13, -10], [0, -8, 2], [-23, 10, 5], [5, -3, -14], [31, 7, -4], [30, -10, 6], [-42, 2, 2], [-28, 18, 0], [-32, -2, -14], [-32, 19, 1], [-24, 6, -2], [-6, 4, 8], [26, -3, 21], [1, -4, 19], [-10, -19, 5], [-12, 20, 8], [12, 20, 0], [28, 14, 4], [-31, 6, 7], [-1, 14, -5], [19, -8, -7], [-12, -6, 10], [-20, -3, -3], [-10, 4, -10], [-44, 6, -12], [-17, 2, 13], [-24, -10, 0], [31, -7, 8], [30, 6, 6], [9, -4, 3], [-36, 6, 0], [-30, -2, -2], [19, -4, 11], [-16, 12, -6], [11, 24, -9], [16, -11, 15], [15, 12, -9], [5, 28, -3], [-1, -8, 1], [-14, -2, -22], [-30, 14, -10], [-38, 17, -5], [30, 26, -6], [-26, 10, -10], [-36, -2, -16], [-17, 7, 4], [-36, 12, -20], [-9, -3, -8], [-1, -1, -18], [-21, 28, 5], [-2, -25, -5], [20, -10, 0], [35, -17, 8], [-40, 14, 4], [-4, 7, -9], [10, 34, -10], [19, 19, -6], [16, 16, -2], [3, -14, 19], [45, -14, 5], [18, -10, 6], [0, 20, -18], [27, -15, 0], [-14, -14, 10], [-7, -6, -15], [41, 2, 13], [-16, 20, 12], [-14, -8, -8], [33, -22, 3], [-29, 19, -22], [16, -11, 3], [44, 8, 2], [-3, 8, -17], [-23, 0, 13], [43, 0, -5], [-32, 10, 6], [-8, -11, 1], [-24, 10, -10], [14, 2, 6], [-14, 12, 4], [-3, 32, -9], [28, 4, -6], [1, 4, 1], [12, -3, -3], [-17, -8, 5], [-14, 28, 10], [-32, 12, -12], [29, -22, 5], [-24, -2, 0], [6, -12, -6], [-22, 14, -18], [-12, 14, 18], [43, -1, 10], [14, -29, -3], [18, -22, -20], [-32, -2, -14], [12, -10, -8], [-30, -4, -6], [-11, -8, 13], [30, -2, -14], [42, -15, 17], [0, -39, 9], [-26, -4, 12], [16, -1, 9], [23, 23, -14], [-17, -20, -5], [69, -2, -5], [29, -7, -8], [-3, -23, 14], [18, -10, -12], [16, -17, 17], [-25, -10, 15], [0, -24, -10], [2, 21, 3], [-3, 0, -3], [-21, 22, -13], [-54, 6, -4], [26, -4, 10], [15, 6, -15], [-22, -2, -6], [-18, 5, 3], [-2, 8, 22], [28, -10, 0], [31, -16, -9], [2, -26, 12], [15, 9, -18], [-16, 10, 2], [-38, 24, 8], [-21, 31, -10], [1, 12, 9], [12, 8, -6], [-1, 24, -15], [10, -14, 2], [9, 39, -12], [-14, 1, 5], [12, 2, -2], [-8, -19, 1], [-30, 18, -6], [51, 8, 3], [-36, 9, 5], [-4, -14, 8], [0, 0, 14], [54, -1, 7], [-8, -2, 18], [-21, 24, 3], [24, -12, 4], [31, -2, 5], [-55, 10, -13], [-19, -26, 13], [24, 0, 4], [4, -14, 22], [-32, 32, 4], [1, -8, 5], [12, 11, -5], [-28, 13, 11], [-10, 0, -20], [0, -6, 20], [2, -2, 8], [9, 2, -3], [42, -27, -19], [10, -18, 8], [11, -19, 0], [1, 5, 10], [35, 24, -7], [25, 8, 13], [-27, 6, 1], [-34, 20, -16], [29, -1, 6], [-24, -6, -8], [-31, 16, 7], [49, 18, -3], [-26, -16, -14], [37, -5, 10], [-42, -12, 0], [4, 12, 0], [38, -22, -20], [-34, -2, 8], [39, -16, 13], [10, -24, 0], [-48, 8, -4], [19, 16, 7], [-16, 4, -26], [-32, -8, -6], [-7, -32, 11], [67, 7, 0], [-7, 32, -19], [-42, 1, 3], [-48, -6, 6], [3, 32, -21], [33, -17, -14], [-42, -16, 8], [-14, 20, -16], [-2, 45, -21], [-28, 10, -2], [34, 1, 9], [-10, 14, 22], [0, -4, 6], [-13, -4, 23], [40, 14, -2], [17, 15, -16], [-4, -20, 2], [38, -12, 32], [-24, -10, -16], [-12, 12, 6], [10, -2, -4], [-20, 4, -6], [9, -1, 20], [-80, -4, 4], [-33, 0, 3], [39, 11, -6], [8, -36, 22]];
    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_br();".
// 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_br(: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_br();".
// 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_br( : 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, -2, 1]>,<7,R![-4, -4, 4, 1]>,<17,R![26, -18, 0, 1]>,<19,R![-12, 12, 8, 1]>],Snew);
    return Vf;
end function;