
// Make newform 6384.2.a.bs in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6384_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_6384_2_a_bs();".
// 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_6384_2_a_bs();".
// 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_6384_a();"
function MakeCharacter_6384_a()
    N := 6384;
    order := 1;
    char_gens := [799, 4789, 2129, 913, 1009];
    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_6384_a_Hecke(Kf)
    return MakeCharacter_6384_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], [-1, 0], [0, 0], [-2, -2], [-3, 1], [1, 0], [0, 0], [-1, -5], [-2, 0], [-10, 0], [-2, -4], [2, -4], [3, 5], [-5, -1], [-8, 0], [-2, 0], [10, 2], [-3, -1], [0, 6], [-4, 0], [-5, -3], [-2, 4], [2, 0], [3, -1], [-4, 4], [3, 1], [-8, 6], [-5, 3], [-10, -6], [1, -9], [6, 4], [-2, 10], [4, 6], [6, -2], [-14, 0], [14, -4], [6, -10], [-10, -4], [9, 3], [-2, 4], [8, 4], [-10, -8], [-18, 0], [2, 6], [-4, 0], [14, 4], [-6, -6], [4, 14], [8, -6], [-6, 6], [-6, -4], [-9, 5], [8, 2], [2, 10], [0, 18], [8, 12], [2, 6], [1, -3], [10, 6], [-6, 0], [2, -12], [-3, -9], [-2, 0], [7, 3], [2, -14], [20, 6], [6, 6], [-26, 4], [11, 3], [-24, -4], [-22, 2], [-6, 4], [-2, 10], [-6, 10], [-24, 2], [6, -16], [-5, 3], [-18, -6], [-19, -1], [-8, -14], [19, -11], [-2, -8], [-22, -8], [38, -2], [7, -1], [-10, -6], [23, -5], [-8, -8], [-19, 11], [-19, -5], [-12, -8], [-2, -10], [-4, 8], [-3, -1], [16, -14], [12, 14], [22, 0], [-22, 0], [-16, 16], [24, -2], [22, 2], [13, 9], [12, 8], [-10, 0], [7, -19], [33, -3], [9, -1], [34, 0], [20, -4], [6, -14], [10, -20], [-18, 18], [-34, -4], [-15, 5], [-10, -6], [-5, 5], [-22, -12], [-13, -11], [-10, 2], [-14, 4], [12, 10], [-3, -1], [-12, 12], [2, 0], [-10, 6], [-21, -15], [-12, -4], [-20, 14], [34, -8], [7, 1], [18, 18], [-2, -12], [25, 5], [14, -8], [-14, 0], [-14, -8], [10, -12], [10, -12], [-4, 0], [32, 2], [14, -20], [21, 19], [-10, -16], [8, 12], [-30, 8], [10, 4], [-32, -8], [17, 15], [-26, -16], [-1, -1], [-16, 4], [-18, -14], [20, -20], [11, 1], [16, 8], [21, -15], [14, 20], [-48, -2], [-16, 4], [35, 3], [2, 20], [-32, 16], [15, -25], [24, 0], [-8, 12], [-6, -8], [16, -6], [-9, 3], [3, -23], [-10, 18], [26, -10], [-6, 10], [-24, -16], [3, 11], [-18, -8], [-22, -24], [18, 4], [14, -16], [-40, 8], [8, 0], [-8, 14], [22, 16], [16, -16], [3, 15], [24, 18], [6, -12], [4, 2], [25, -17], [50, 2], [16, 28], [10, -14], [-28, -10], [28, -4], [-36, -14], [54, 6], [-50, -4], [27, 19], [33, 15], [19, -9], [-32, -16], [2, -12], [2, -30], [-19, -13], [-3, 5], [-14, -2], [13, -13], [40, -6], [-2, 20], [-2, 18], [9, -15], [26, 0], [-30, 10], [-8, -4], [-10, 14], [10, 28], [-20, -2], [35, -7], [0, 18], [-12, -2], [24, 0], [3, 3], [48, -8], [-48, -4], [10, -16], [12, 18], [-1, 21], [26, -16], [30, -22], [-10, -12], [-18, 0], [-24, 4], [-15, 21], [24, -4], [-37, 1], [-56, -2], [50, 4], [6, 18], [42, -6], [11, 5], [8, -16], [-10, -6], [-38, 20], [48, 14], [39, 5], [-22, -2], [22, 14], [-8, 16], [-4, -32], [22, -24], [27, -29], [42, 2], [-14, 26], [-45, -1], [-56, -4], [14, -16], [46, 4], [8, 10], [18, -8], [4, 36], [11, -23], [-4, -2], [-34, 6], [-63, -3], [2, 16], [-19, 29], [3, -21], [32, -4], [-60, -2], [14, -32], [4, -4], [4, -30], [4, -12], [-30, -8], [14, 10], [46, 14], [22, 28], [-2, -28], [-21, 9], [-18, -10], [26, -32], [-3, -1], [-22, 16], [-12, -8], [-18, 10], [6, -32], [-7, 17], [2, -30], [0, -22], [16, 22], [9, 35], [-3, -39], [76, 4], [62, -4], [-23, -31], [22, 28], [-7, 25], [-58, 2], [-42, -18], [-38, -24], [27, 15], [-16, 8], [41, 15], [26, -16], [32, 22], [-31, 15], [-2, -26], [34, 14], [-34, 2], [17, 27], [12, -6], [-35, 17], [2, 18], [-4, -40], [-6, 16], [-37, -7], [-1, -31], [-16, 6], [14, 12], [-44, -16], [22, -18], [56, 18], [26, 26], [-24, 14], [-46, 4], [24, 12], [16, 12], [63, 9], [30, -12], [-18, 16], [9, -39], [-14, 22], [-13, 21], [4, -32], [-35, 11], [38, -8], [-26, 32], [28, -14], [4, -8], [38, -32], [-18, 16], [-58, -4], [-16, -16], [19, 15], [-15, 11], [-8, 42], [16, 20], [36, 8], [-5, -9], [20, 0], [20, -10], [-42, 28], [-36, 4], [2, -40], [-4, -6], [15, 9], [-45, 13], [-64, -2], [73, -13], [62, 8], [-15, -27], [-31, -21], [-51, 11], [26, 6], [-34, -8], [-35, -27], [42, 22], [30, 40], [-60, -4], [-34, -24], [-46, 6], [-25, 11], [-32, -4], [34, -4], [0, -12], [-8, 36], [38, 28], [-95, -3], [-18, -20], [-20, 26], [22, 40], [-34, 20], [-18, -20], [50, -8], [-18, 22], [-14, -32], [16, -6], [18, 32], [-6, 10], [-28, -30], [30, -8], [12, 28], [-8, 4], [-41, -7], [4, 30], [-28, -20], [38, -4], [-22, -26], [48, -2], [30, -2], [66, 4], [-56, -20], [-60, 2], [-48, -2], [50, 22], [14, -36], [-15, -27], [-52, 16], [-79, 3], [-10, 32], [-48, -22], [21, 3], [-2, 44], [30, 8], [15, 19], [-39, 11], [-54, 12], [-21, 27], [8, 24], [53, -11], [14, 48], [18, -42], [8, -40], [-66, 2], [-26, -4], [25, 3], [48, -18], [22, -26], [-9, 41]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6384_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6384_2_a_bs();".
// 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_6384_2_a_bs(:prec:=2)
    chi := MakeCharacter_6384_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_6384_2_a_bs();".
// 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_6384_2_a_bs( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6384_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-2, -2, 1]>,<11,R![0, 1]>,<13,R![-8, 4, 1]>,<17,R![6, 6, 1]>,<23,R![0, 1]>],Snew);
    return Vf;
end function;