
// Make newform 6864.2.a.o in Magma, downloaded from the LMFDB on 17 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_o();".
// 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_o();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [-1], [3], [1], [-1], [1], [0], [-2], [-3], [-3], [-8], [2], [-9], [-5], [0], [-6], [3], [-1], [-11], [6], [-1], [-2], [-18], [0], [2], [-6], [-17], [15], [8], [-3], [10], [-3], [6], [16], [-12], [-8], [-22], [7], [9], [-9], [12], [2], [3], [14], [0], [1], [28], [28], [0], [5], [6], [15], [-10], [18], [15], [-24], [-24], [-8], [-1], [21], [-17], [6], [10], [24], [-13], [-15], [-11], [-10], [12], [20], [18], [-15], [16], [-25], [-8], [6], [30], [-7], [-36], [-7], [-36], [-7], [24], [29], [4], [24], [0], [29], [12], [-14], [-24], [-3], [-38], [-3], [-41], [-24], [-30], [3], [-20], [26], [-29], [-42], [0], [42], [-5], [-16], [-3], [-18], [9], [-28], [22], [8], [18], [13], [10], [3], [-44], [48], [6], [24], [-46], [-16], [-18], [-21], [16], [33], [-19], [3], [28], [-34], [-20], [-15], [-23], [38], [21], [23], [54], [-8], [12], [30], [-20], [-42], [13], [0], [-10], [-18], [20], [24], [-20], [12], [32], [-15], [-50], [-48], [-8], [0], [-20], [12], [20], [-60], [-12], [60], [-41], [-18], [24], [18], [-29], [41], [-19], [0], [-30], [-49], [60], [59], [-41], [51], [-26], [-21], [52], [35], [10], [24], [14], [-3], [42], [24], [2], [19], [-13], [63], [-46], [-6], [-44], [-3], [0], [54], [50], [14], [57], [-30], [30], [-56], [-55], [-22], [9], [66], [28], [33], [6], [-50], [-10], [-12], [37], [-60], [24], [-64], [4], [12], [66], [30], [65], [67], [-48], [16], [21], [-10], [-18], [-15], [70], [72], [38], [-47], [-5], [-66], [-44], [48], [-46], [-6], [-18], [0], [3], [-65], [49], [2], [51], [-6], [-38], [-63], [28], [36], [-34], [-54], [-18], [59], [27], [-30], [-52], [-26], [-60], [47], [-44], [15], [-16], [17], [0], [10], [33], [48], [58], [6], [-28], [4], [26], [40], [-40], [-38], [-3], [8], [-43], [-33], [6], [4], [-78], [68], [76], [45], [-58], [36], [40], [-24], [-78], [6], [-21], [-66], [-1], [-45], [55], [-12], [21], [-56], [-46], [-72], [-56], [-42], [82], [-22], [6], [-22], [-60], [-79], [-48], [57], [-72], [58], [12], [8], [-51], [-51], [-76], [48], [-20], [-52], [-27], [-38], [-27], [29], [43], [-44], [6], [-6], [80], [-72], [10], [-60], [-2], [12], [-19], [33], [86], [40], [-55], [93], [12], [-8], [75], [45], [62], [73], [15], [0], [-38], [-70], [54], [28], [5], [6], [-24], [-30], [-24], [-18], [-28], [78], [3], [-48], [10], [11], [78], [-11], [-52], [-66], [4], [3], [42], [-14], [-88], [-24], [-60], [-94], [84], [-28], [33], [30], [79], [-87], [10], [-54], [-44], [38], [88], [-84], [44], [39], [72], [10], [-66], [44], [79], [3], [-86], [-6], [8], [-27], [-17], [-78], [-84], [-32], [-61], [-63], [-11], [-75], [20], [-30], [12], [37], [-16], [78], [75], [16], [102], [-60], [30], [68], [-54], [-39], [2], [45], [-42], [78], [67], [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_o();".
// 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_o(:prec:=1)
    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_o();".
// 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_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6864_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-3, 1]>,<7,R![-1, 1]>,<17,R![0, 1]>,<19,R![2, 1]>],Snew);
    return Vf;
end function;