
// Make newform 6384.2.a.bl in Magma, downloaded from the LMFDB on 24 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_bl();".
// 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_bl();".
// 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 := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_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], [-2, 0], [-1, -1], [-2, -2], [1, 0], [1, 3], [0, -2], [3, -1], [3, 1], [2, 0], [6, 2], [-3, -3], [4, 2], [0, 0], [-8, -2], [2, -4], [-2, 2], [-6, 4], [-5, -3], [-4, -4], [-10, 0], [-2, -6], [-3, 5], [1, -3], [-8, -4], [5, -5], [4, 6], [-3, -5], [8, 4], [8, 2], [0, 0], [-5, -3], [3, 5], [-12, -2], [-4, 4], [-8, 0], [-6, -4], [-10, -2], [-3, 1], [-7, -5], [4, 2], [3, -3], [10, 2], [8, -6], [-9, -1], [-8, 4], [-10, 4], [-26, 0], [-25, 1], [-18, -2], [-12, 0], [-2, 12], [-9, 5], [0, 2], [8, 8], [18, 4], [12, -2], [16, 0], [4, 6], [-18, 6], [-7, 5], [-6, 4], [-12, -10], [-2, 4], [18, -4], [2, 0], [0, -6], [4, -4], [5, 3], [-8, -8], [19, -3], [-10, 4], [-4, -4], [25, -1], [-2, 0], [-28, 2], [-30, -2], [-10, 2], [7, 1], [-2, -6], [14, -6], [-25, -5], [6, -8], [10, 8], [-2, -8], [7, 7], [-4, -4], [-8, 8], [-25, -5], [-13, 1], [-12, 2], [10, 14], [1, 5], [0, -6], [-18, 0], [6, 14], [2, 8], [-18, -8], [-17, 9], [-4, 12], [-30, -4], [18, -6], [18, 8], [2, 10], [-16, 12], [10, 6], [12, -16], [-3, 5], [4, 6], [18, 4], [0, 12], [-2, 10], [-18, -12], [-4, 4], [7, 3], [-21, 1], [-10, -18], [-13, 7], [-16, 10], [28, -6], [26, -2], [28, 0], [-23, 7], [20, 2], [-15, -3], [2, -14], [4, 6], [0, -20], [36, -4], [23, -3], [28, -10], [-38, 6], [-30, -4], [-16, -14], [12, 12], [-2, -16], [0, 6], [18, -6], [-23, -5], [36, 4], [2, 2], [5, 5], [-20, -12], [4, -6], [18, 12], [20, -8], [-4, 4], [23, -3], [-48, 0], [46, 2], [2, 2], [2, 0], [-2, 2], [0, 8], [30, -10], [-2, -12], [32, 2], [-48, -2], [-36, -10], [42, 6], [8, 12], [-12, 18], [-34, -2], [-7, -5], [8, 18], [0, -10], [-21, 11], [-30, -2], [17, 5], [3, -23], [24, -6], [5, 21], [20, -8], [28, -8], [27, 9], [-9, 15], [20, 2], [2, 14], [8, 16], [9, 23], [38, -8], [31, -3], [35, 11], [13, -1], [-24, 4], [0, 2], [-17, 7], [-16, 0], [-4, -14], [-22, 4], [32, 14], [-38, -8], [14, -20], [-8, 18], [44, 6], [48, 8], [11, -25], [20, -6], [-7, -15], [43, -1], [20, 12], [-10, -10], [13, -11], [-10, -18], [-14, 22], [-10, -20], [-32, -8], [18, -12], [-3, -19], [-24, 16], [-48, 0], [-20, 4], [-18, -10], [32, 8], [2, 0], [-38, -2], [29, 11], [37, 3], [35, 3], [-10, -8], [16, 16], [-28, -12], [30, 0], [-6, -24], [40, -8], [-63, -3], [-2, 12], [-6, -24], [0, -24], [43, -7], [-18, 8], [-4, -4], [27, 19], [-50, -8], [-51, -1], [0, -14], [-32, 0], [56, 0], [28, -8], [-4, 12], [-15, 3], [14, 12], [25, 21], [42, -6], [-32, 0], [-40, 14], [41, -1], [38, 4], [-48, -12], [47, -7], [-40, 8], [-1, 3], [-10, 24], [-8, 6], [2, -2], [8, -10], [-42, 4], [1, -17], [-28, 4], [-20, 6], [49, 1], [-22, 14], [-20, 0], [0, 6], [-8, 4], [-4, 6], [-51, 3], [-3, 25], [32, 14], [54, 0], [10, -18], [-32, 4], [-4, 12], [-28, 22], [5, -25], [-18, -12], [38, -10], [-34, -18], [-32, -16], [-3, 9], [-3, -19], [-28, -20], [13, 11], [14, 16], [18, -16], [-10, -18], [10, 20], [67, -3], [-8, 0], [-36, -2], [-32, -4], [9, -29], [-35, 1], [-7, 5], [19, 11], [0, 24], [12, 12], [54, 0], [48, -10], [10, 30], [16, 8], [18, 30], [28, 6], [-18, 18], [-35, -3], [-25, 25], [24, -26], [-9, -25], [35, -7], [-18, 20], [-44, -10], [-33, -7], [-20, -8], [0, -8], [18, -10], [-6, -12], [10, -4], [-42, -6], [-42, 16], [-18, 20], [-39, 19], [-36, -14], [-18, -2], [-50, -12], [16, 24], [42, -10], [-1, 21], [-18, 4], [-22, -4], [30, -18], [-34, 10], [28, 4], [-48, 0], [-65, -3], [-6, -8], [62, -12], [-18, 22], [59, -11], [28, -2], [0, -26], [13, 3], [54, 0], [30, -10], [-38, 12], [22, -8], [48, 0], [13, -3], [-2, 10], [8, -10], [27, 5], [-9, -1], [-25, 17], [14, -8], [25, 17], [48, 20], [-12, 2], [-14, 22], [58, -8], [32, 20], [22, 10], [-30, 14], [52, -8], [14, 16], [-27, 9], [1, -9], [-28, -22], [-32, -14], [40, 20], [21, 27], [-70, -4], [-32, 0], [-52, 10], [-20, 24], [-27, -9], [-6, 12], [-30, -2], [-22, 18], [-28, 2], [24, -18], [-38, 6], [-2, -4], [40, -4], [66, -6], [-62, 6], [-52, 10], [-34, -22], [-68, 4], [50, 12], [4, -38], [20, -6], [-28, -4], [8, 0], [4, -10], [35, -17], [10, -4], [38, 4], [-3, 3], [5, 5], [4, 10], [57, 19], [18, -24], [-20, -26], [-42, 6], [-62, 4], [-38, 20], [-24, -32], [40, -16], [64, 4], [13, -5], [-4, -8], [48, 0], [-2, -40], [-3, -15], [-40, 0], [-23, 9], [-22, -22], [6, -18], [30, 24], [3, 15], [-13, -15], [20, 24], [-6, -10], [-82, -8], [-24, 4], [70, 16], [-72, 8], [55, -9]];
    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_bl();".
// 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_bl(: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_bl();".
// 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_bl( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6384_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-4, -2, 1]>,<11,R![2, 1]>,<13,R![-4, 2, 1]>,<17,R![-16, 4, 1]>,<23,R![-44, -2, 1]>],Snew);
    return Vf;
end function;