diff --git a/doc/source/fq_default_poly.rst b/doc/source/fq_default_poly.rst new file mode 100644 index 00000000..13da4d3b --- /dev/null +++ b/doc/source/fq_default_poly.rst @@ -0,0 +1,13 @@ +**fq_default_poly** -- polynomials over finite fields +=============================================================================== + +.. autoclass :: flint.fq_default_poly_ctx + :members: + :inherited-members: + :undoc-members: + +.. autoclass :: flint.fq_default_poly + :members: + :inherited-members: + :undoc-members: + diff --git a/doc/source/index.rst b/doc/source/index.rst index 71e50360..03d62af7 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -74,6 +74,7 @@ Polynomial types fmpq_poly.rst nmod_poly.rst fmpz_mod_poly.rst + fq_default_poly.rst arb_poly.rst acb_poly.rst diff --git a/setup.py b/setup.py index d129b1a5..2b4a1ace 100644 --- a/setup.py +++ b/setup.py @@ -105,6 +105,7 @@ ("flint.types.fmpq_mpoly", ["src/flint/types/fmpq_mpoly.pyx"]), ("flint.types.fq_default", ["src/flint/types/fq_default.pyx"]), + ("flint.types.fq_default_poly", ["src/flint/types/fq_default_poly.pyx"]), ("flint.types.arf", ["src/flint/types/arf.pyx"]), ("flint.types.arb", ["src/flint/types/arb.pyx"]), diff --git a/src/flint/__init__.py b/src/flint/__init__.py index 4db5de5f..4786804b 100644 --- a/src/flint/__init__.py +++ b/src/flint/__init__.py @@ -25,6 +25,7 @@ from .types.fmpq_mpoly import fmpq_mpoly_ctx, fmpq_mpoly, fmpq_mpoly_vec from .types.fq_default import * +from .types.fq_default_poly import * from .types.arf import * from .types.arb import * diff --git a/src/flint/flintlib/fq.pxd b/src/flint/flintlib/fq.pxd index b98daa44..7dee6ddf 100644 --- a/src/flint/flintlib/fq.pxd +++ b/src/flint/flintlib/fq.pxd @@ -6,7 +6,7 @@ from flint.flintlib.fmpz_poly cimport fmpz_poly_t, fmpz_poly_struct from flint.flintlib.fmpz_mod_poly cimport fmpz_mod_poly_t, fmpz_mod_poly_struct cdef extern from "flint/fq.h": - + # Type definitions **********************************************/ ctypedef fmpz_poly_t fq_t ctypedef fmpz_poly_struct fq_struct @@ -24,9 +24,22 @@ cdef extern from "flint/fq.h": fmpz_mod_poly_t inv char * var - ctypedef fq_ctx_struct fq_ctx_t[1] + ctypedef struct fq_poly_struct: + fq_struct * coeffs + slong alloc + slong length + ctypedef fq_poly_struct fq_poly_t[1] + + ctypedef struct fq_mat_struct: + fq_struct * entries + slong r + slong s + fq_struct ** rows + ctypedef fq_mat_struct fq_mat_t[1] + + # Parsed from here **********************************************/ void fq_ctx_init(fq_ctx_t ctx, const fmpz_t p, slong d, const char *var) int _fq_ctx_init_conway(fq_ctx_t ctx, const fmpz_t p, slong d, const char *var) void fq_ctx_init_conway(fq_ctx_t ctx, const fmpz_t p, slong d, const char *var) diff --git a/src/flint/flintlib/fq_default_mat.pxd b/src/flint/flintlib/fq_default_mat.pxd new file mode 100644 index 00000000..ea3c3e4b --- /dev/null +++ b/src/flint/flintlib/fq_default_mat.pxd @@ -0,0 +1,78 @@ +from flint.flintlib.flint cimport flint_rand_t, slong +from flint.flintlib.fq cimport fq_ctx_t, fq_struct +from flint.flintlib.nmod_mat cimport nmod_mat_t +from flint.flintlib.fmpz_mat cimport fmpz_mat_t +from flint.flintlib.fmpz_mod_mat cimport fmpz_mod_mat_t +from flint.flintlib.fmpz cimport fmpz_t +from flint.flintlib.fq_default cimport fq_default_t, fq_default_ctx_t +from flint.flintlib.fq_default_poly cimport fq_default_poly_t +from flint.flintlib.fq_mat cimport fq_mat_t +from flint.flintlib.fq_nmod_mat cimport fq_nmod_mat_t +from flint.flintlib.fq_zech_mat cimport fq_zech_mat_t +from flintlib.nmod_mat cimport nmod_mat_t +from flintlib.fmpz_mod_mat cimport fmpz_mod_mat_t + +cdef extern from "flint/fq_default_mat.h": + # Type definitions **********************************************/ + ctypedef union fq_default_mat_struct: + fq_mat_t fq + fq_nmod_mat_t fq_nmod + fq_zech_mat_t fq_zech + nmod_mat_t nmod + fmpz_mod_mat_t fmpz_mod + ctypedef fq_default_mat_struct fq_default_mat_t[1] + + # Parsed from here **********************************************/ + void fq_default_mat_init(fq_default_mat_t mat, slong rows, slong cols, const fq_default_ctx_t ctx) + void fq_default_mat_init_set(fq_default_mat_t mat, const fq_default_mat_t src, const fq_default_ctx_t ctx) + void fq_default_mat_clear(fq_default_mat_t mat, const fq_default_ctx_t ctx) + void fq_default_mat_set(fq_default_mat_t mat, const fq_default_mat_t src, const fq_default_ctx_t ctx) + void fq_default_mat_entry(fq_default_t val, const fq_default_mat_t mat, slong i, slong j, const fq_default_ctx_t ctx) + void fq_default_mat_entry_set(fq_default_mat_t mat, slong i, slong j, const fq_default_t x, const fq_default_ctx_t ctx) + void fq_default_mat_entry_set_fmpz(fq_default_mat_t mat, slong i, slong j, const fmpz_t x, const fq_default_ctx_t ctx) + slong fq_default_mat_nrows(const fq_default_mat_t mat, const fq_default_ctx_t ctx) + slong fq_default_mat_ncols(const fq_default_mat_t mat, const fq_default_ctx_t ctx) + void fq_default_mat_swap(fq_default_mat_t mat1, fq_default_mat_t mat2, const fq_default_ctx_t ctx) + void fq_default_mat_zero(fq_default_mat_t mat, const fq_default_ctx_t ctx) + void fq_default_mat_one(fq_default_mat_t mat, const fq_default_ctx_t ctx) + void fq_default_mat_swap_rows(fq_default_mat_t mat, slong * perm, slong r, slong s, const fq_default_ctx_t ctx) + void fq_default_mat_swap_cols(fq_default_mat_t mat, slong * perm, slong r, slong s, const fq_default_ctx_t ctx) + void fq_default_mat_invert_rows(fq_default_mat_t mat, slong * perm, const fq_default_ctx_t ctx) + void fq_default_mat_invert_cols(fq_default_mat_t mat, slong * perm, const fq_default_ctx_t ctx) + void fq_default_mat_set_nmod_mat(fq_default_mat_t mat1, const nmod_mat_t mat2, const fq_default_ctx_t ctx) + void fq_default_mat_set_fmpz_mod_mat(fq_default_mat_t mat1, const fmpz_mod_mat_t mat2, const fq_default_ctx_t ctx) + void fq_default_mat_set_fmpz_mat(fq_default_mat_t mat1, const fmpz_mat_t mat2, const fq_default_ctx_t ctx) + void fq_default_mat_concat_vertical(fq_default_mat_t res, const fq_default_mat_t mat1, const fq_default_mat_t mat2, const fq_default_ctx_t ctx) + void fq_default_mat_concat_horizontal(fq_default_mat_t res, const fq_default_mat_t mat1, const fq_default_mat_t mat2, const fq_default_ctx_t ctx) + int fq_default_mat_print_pretty(const fq_default_mat_t mat, const fq_default_ctx_t ctx) + # int fq_default_mat_fprint_pretty(FILE * file, const fq_default_mat_t mat, const fq_default_ctx_t ctx) + int fq_default_mat_print(const fq_default_mat_t mat, const fq_default_ctx_t ctx) + # int fq_default_mat_fprint(FILE * file, const fq_default_mat_t mat, const fq_default_ctx_t ctx) + void fq_default_mat_window_init(fq_default_mat_t window, const fq_default_mat_t mat, slong r1, slong c1, slong r2, slong c2, const fq_default_ctx_t ctx) + void fq_default_mat_window_clear(fq_default_mat_t window, const fq_default_ctx_t ctx) + void fq_default_mat_randtest(fq_default_mat_t mat, flint_rand_t state, const fq_default_ctx_t ctx) + int fq_default_mat_randpermdiag(fq_mat_t mat, flint_rand_t state, fq_struct * diag, slong n, const fq_ctx_t ctx) + void fq_default_mat_randrank(fq_default_mat_t mat, flint_rand_t state, slong rank, const fq_default_ctx_t ctx) + void fq_default_mat_randops(fq_default_mat_t mat, flint_rand_t state, slong count, const fq_default_ctx_t ctx) + void fq_default_mat_randtril(fq_default_mat_t mat, flint_rand_t state, int unit, const fq_default_ctx_t ctx) + void fq_default_mat_randtriu(fq_default_mat_t mat, flint_rand_t state, int unit, const fq_default_ctx_t ctx) + int fq_default_mat_equal(const fq_default_mat_t mat1, const fq_default_mat_t mat2, const fq_default_ctx_t ctx) + int fq_default_mat_is_zero(const fq_default_mat_t mat, const fq_default_ctx_t ctx) + int fq_default_mat_is_one(const fq_default_mat_t mat, const fq_default_ctx_t ctx) + int fq_default_mat_is_empty(const fq_default_mat_t mat, const fq_default_ctx_t ctx) + int fq_default_mat_is_square(const fq_default_mat_t mat, const fq_default_ctx_t ctx) + void fq_default_mat_add(fq_default_mat_t C, const fq_default_mat_t A, const fq_default_mat_t B, const fq_default_ctx_t ctx) + void fq_default_mat_sub(fq_default_mat_t C, const fq_default_mat_t A, const fq_default_mat_t B, const fq_default_ctx_t ctx) + void fq_default_mat_neg(fq_default_mat_t A, const fq_default_mat_t B, const fq_default_ctx_t ctx) + void fq_default_mat_mul(fq_default_mat_t C, const fq_default_mat_t A, const fq_default_mat_t B, const fq_default_ctx_t ctx) + void fq_default_mat_submul(fq_default_mat_t D, const fq_default_mat_t C, const fq_default_mat_t A, const fq_default_mat_t B, const fq_default_ctx_t ctx) + int fq_default_mat_inv(fq_default_mat_t B, fq_default_mat_t A, const fq_default_ctx_t ctx) + slong fq_default_mat_lu(slong * P, fq_default_mat_t A, int rank_check, const fq_default_ctx_t ctx) + slong fq_default_mat_rref(fq_default_mat_t B, const fq_default_mat_t A, const fq_default_ctx_t ctx) + void fq_default_mat_solve_tril(fq_default_mat_t X, const fq_default_mat_t L, const fq_default_mat_t B, int unit, const fq_default_ctx_t ctx) + void fq_default_mat_solve_triu(fq_default_mat_t X, const fq_default_mat_t U, const fq_default_mat_t B, int unit, const fq_default_ctx_t ctx) + int fq_default_mat_solve(fq_default_mat_t X, const fq_default_mat_t A, const fq_default_mat_t B, const fq_default_ctx_t ctx) + int fq_default_mat_can_solve(fq_default_mat_t X, const fq_default_mat_t A, const fq_default_mat_t B, const fq_default_ctx_t ctx) + void fq_default_mat_similarity(fq_default_mat_t M, slong r, fq_default_t d, const fq_default_ctx_t ctx) + void fq_default_mat_charpoly(fq_default_poly_t p, const fq_default_mat_t M, const fq_default_ctx_t ctx) + void fq_default_mat_minpoly(fq_default_poly_t p, const fq_default_mat_t M, const fq_default_ctx_t ctx) diff --git a/src/flint/flintlib/fq_default_poly.pxd b/src/flint/flintlib/fq_default_poly.pxd new file mode 100644 index 00000000..00b3fea3 --- /dev/null +++ b/src/flint/flintlib/fq_default_poly.pxd @@ -0,0 +1,102 @@ +from flint.flintlib.fq_default cimport fq_default_ctx_t, fq_default_t +from flint.flintlib.nmod_poly cimport nmod_poly_t +from flint.flintlib.flint cimport slong, ulong, flint_rand_t +from flint.flintlib.fmpz_poly cimport fmpz_poly_t +from flint.flintlib.fmpz cimport fmpz_t +from flint.flintlib.fmpz_mod_poly cimport fmpz_mod_poly_t +from flint.flintlib.fq_poly cimport fq_poly_t +from flint.flintlib.fq_nmod_poly cimport fq_nmod_poly_t +from flint.flintlib.fq_zech_poly cimport fq_zech_poly_t + + +cdef extern from "flint/fq_default_poly.h": + # Type definitions **********************************************/ + ctypedef union fq_default_poly_struct: + fq_poly_t fq + fq_nmod_poly_t fq_nmod + fq_zech_poly_t fq_zech + nmod_poly_t nmod + fmpz_mod_poly_t fmpz_mod + ctypedef fq_default_poly_struct fq_default_poly_t[1] + + # Parsed from here **********************************************/ + void fq_default_poly_init(fq_default_poly_t poly, const fq_default_ctx_t ctx) + void fq_default_poly_init2(fq_default_poly_t poly, slong alloc, const fq_default_ctx_t ctx) + void fq_default_poly_realloc(fq_default_poly_t poly, slong alloc, const fq_default_ctx_t ctx) + void fq_default_poly_fit_length(fq_default_poly_t poly, slong len, const fq_default_ctx_t ctx) + void fq_default_poly_clear(fq_default_poly_t poly, const fq_default_ctx_t ctx) + void _fq_default_poly_set_length(fq_default_poly_t poly, slong len, const fq_default_ctx_t ctx) + void fq_default_poly_truncate(fq_default_poly_t poly, slong newlen, const fq_default_ctx_t ctx) + void fq_default_poly_set_trunc(fq_default_poly_t poly1, fq_default_poly_t poly2, slong newlen, const fq_default_ctx_t ctx) + void fq_default_poly_reverse(fq_default_poly_t output, const fq_default_poly_t input, slong m, const fq_default_ctx_t ctx) + slong fq_default_poly_degree(const fq_default_poly_t poly, const fq_default_ctx_t ctx) + slong fq_default_poly_length(const fq_default_poly_t poly, const fq_default_ctx_t ctx) + void fq_default_poly_randtest(fq_default_poly_t f, flint_rand_t state, slong len, const fq_default_ctx_t ctx) + void fq_default_poly_randtest_not_zero(fq_default_poly_t f, flint_rand_t state, slong len, const fq_default_ctx_t ctx) + void fq_default_poly_randtest_monic(fq_default_poly_t f, flint_rand_t state, slong len, const fq_default_ctx_t ctx) + void fq_default_poly_randtest_irreducible(fq_default_poly_t f, flint_rand_t state, slong len, const fq_default_ctx_t ctx) + void fq_default_poly_set(fq_default_poly_t poly1, const fq_default_poly_t poly2, const fq_default_ctx_t ctx) + void fq_default_poly_set_fq_default(fq_default_poly_t poly, const fq_default_t c, const fq_default_ctx_t ctx) + void fq_default_poly_swap(fq_default_poly_t op1, fq_default_poly_t op2, const fq_default_ctx_t ctx) + void fq_default_poly_zero(fq_default_poly_t poly, const fq_default_ctx_t ctx) + void fq_default_poly_one(fq_default_poly_t poly, const fq_default_ctx_t ctx) + void fq_default_poly_gen(fq_default_poly_t poly, const fq_default_ctx_t ctx) + void fq_default_poly_make_monic(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_ctx_t ctx) + void fq_default_poly_set_nmod_poly(fq_default_poly_t rop, const nmod_poly_t op, const fq_default_ctx_t ctx) + void fq_default_poly_set_fmpz_mod_poly(fq_default_poly_t rop, const fmpz_mod_poly_t op, const fq_default_ctx_t ctx) + void fq_default_poly_set_fmpz_poly(fq_default_poly_t rop, const fmpz_poly_t op, const fq_default_ctx_t ctx) + void fq_default_poly_get_coeff(fq_default_t x, const fq_default_poly_t poly, slong n, const fq_default_ctx_t ctx) + void fq_default_poly_set_coeff(fq_default_poly_t poly, slong n, const fq_default_t x, const fq_default_ctx_t ctx) + void fq_default_poly_set_coeff_fmpz(fq_default_poly_t poly, slong n, const fmpz_t x, const fq_default_ctx_t ctx) + int fq_default_poly_equal(const fq_default_poly_t poly1, const fq_default_poly_t poly2, const fq_default_ctx_t ctx) + int fq_default_poly_equal_trunc(const fq_default_poly_t poly1, const fq_default_poly_t poly2, slong n, const fq_default_ctx_t ctx) + int fq_default_poly_is_zero(const fq_default_poly_t poly, const fq_default_ctx_t ctx) + int fq_default_poly_is_one(const fq_default_poly_t op, const fq_default_ctx_t ctx) + int fq_default_poly_is_gen(const fq_default_poly_t op, const fq_default_ctx_t ctx) + int fq_default_poly_is_unit(const fq_default_poly_t op, const fq_default_ctx_t ctx) + int fq_default_poly_equal_fq_default(const fq_default_poly_t poly, const fq_default_t c, const fq_default_ctx_t ctx) + void fq_default_poly_add(fq_default_poly_t res, const fq_default_poly_t poly1, const fq_default_poly_t poly2, const fq_default_ctx_t ctx) + void fq_default_poly_add_si(fq_default_poly_t res, const fq_default_poly_t poly1, slong c, const fq_default_ctx_t ctx) + void fq_default_poly_add_series(fq_default_poly_t res, const fq_default_poly_t poly1, const fq_default_poly_t poly2, slong n, const fq_default_ctx_t ctx) + void fq_default_poly_sub(fq_default_poly_t res, const fq_default_poly_t poly1, const fq_default_poly_t poly2, const fq_default_ctx_t ctx) + void fq_default_poly_sub_series(fq_default_poly_t res, const fq_default_poly_t poly1, const fq_default_poly_t poly2, slong n, const fq_default_ctx_t ctx) + void fq_default_poly_neg(fq_default_poly_t res, const fq_default_poly_t poly, const fq_default_ctx_t ctx) + void fq_default_poly_scalar_mul_fq_default(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_t x, const fq_default_ctx_t ctx) + void fq_default_poly_scalar_addmul_fq_default(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_t x, const fq_default_ctx_t ctx) + void fq_default_poly_scalar_submul_fq_default(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_t x, const fq_default_ctx_t ctx) + void fq_default_poly_scalar_div_fq_default(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_t x, const fq_default_ctx_t ctx) + void fq_default_poly_mul(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, const fq_default_ctx_t ctx) + void fq_default_poly_mullow(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, slong n, const fq_default_ctx_t ctx) + void fq_default_poly_mulhigh(fq_default_poly_t res, const fq_default_poly_t poly1, const fq_default_poly_t poly2, slong start, const fq_default_ctx_t ctx) + void fq_default_poly_mulmod(fq_default_poly_t res, const fq_default_poly_t poly1, const fq_default_poly_t poly2, const fq_default_poly_t f, const fq_default_ctx_t ctx) + void fq_default_poly_sqr(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_ctx_t ctx) + void fq_default_poly_pow(fq_default_poly_t rop, const fq_default_poly_t op, ulong e, const fq_default_ctx_t ctx) + void fq_default_poly_powmod_ui_binexp(fq_default_poly_t res, const fq_default_poly_t poly, ulong e, const fq_default_poly_t f, const fq_default_ctx_t ctx) + void fq_default_poly_powmod_fmpz_binexp(fq_default_poly_t res, const fq_default_poly_t poly, const fmpz_t e, const fq_default_poly_t f, const fq_default_ctx_t ctx) + void fq_default_poly_pow_trunc(fq_default_poly_t res, const fq_default_poly_t poly, ulong e, slong trunc, const fq_default_ctx_t ctx) + void fq_default_poly_shift_left(fq_default_poly_t rop, const fq_default_poly_t op, slong n, const fq_default_ctx_t ctx) + void fq_default_poly_shift_right(fq_default_poly_t rop, const fq_default_poly_t op, slong n, const fq_default_ctx_t ctx) + slong fq_default_poly_hamming_weight(const fq_default_poly_t op, const fq_default_ctx_t ctx) + void fq_default_poly_divrem(fq_default_poly_t Q, fq_default_poly_t R, const fq_default_poly_t A, const fq_default_poly_t B, const fq_default_ctx_t ctx) + void fq_default_poly_rem(fq_default_poly_t R, const fq_default_poly_t A, const fq_default_poly_t B, const fq_default_ctx_t ctx) + void fq_default_poly_inv_series(fq_default_poly_t Qinv, const fq_default_poly_t Q, slong n, const fq_default_ctx_t ctx) + void fq_default_poly_div_series(fq_default_poly_t Q, const fq_default_poly_t A, const fq_default_poly_t B, slong n, const fq_default_ctx_t ctx) + void fq_default_poly_gcd(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, const fq_default_ctx_t ctx) + void fq_default_poly_xgcd(fq_default_poly_t G, fq_default_poly_t S, fq_default_poly_t T, const fq_default_poly_t A, const fq_default_poly_t B, const fq_default_ctx_t ctx) + int fq_default_poly_divides(fq_default_poly_t Q, const fq_default_poly_t A, const fq_default_poly_t B, const fq_default_ctx_t ctx) + void fq_default_poly_derivative(fq_default_poly_t rop, const fq_default_poly_t op, const fq_default_ctx_t ctx) + void fq_default_poly_invsqrt_series(fq_default_poly_t g, const fq_default_poly_t h, slong n, fq_default_ctx_t ctx) + void fq_default_poly_sqrt_series(fq_default_poly_t g, const fq_default_poly_t h, slong n, fq_default_ctx_t ctx) + int fq_default_poly_sqrt(fq_default_poly_t s, const fq_default_poly_t p, fq_default_ctx_t mod) + void fq_default_poly_evaluate_fq_default(fq_default_t rop, const fq_default_poly_t f, const fq_default_t a, const fq_default_ctx_t ctx) + void fq_default_poly_compose(fq_default_poly_t rop, const fq_default_poly_t op1, const fq_default_poly_t op2, const fq_default_ctx_t ctx) + void fq_default_poly_compose_mod(fq_default_poly_t res, const fq_default_poly_t f, const fq_default_poly_t g, const fq_default_poly_t h, const fq_default_ctx_t ctx) + # int fq_default_poly_fprint_pretty(FILE * file, const fq_default_poly_t poly, const char * x, const fq_default_ctx_t ctx) + int fq_default_poly_print_pretty(const fq_default_poly_t poly, const char * x, const fq_default_ctx_t ctx) + # int fq_default_poly_fprint(FILE * file, const fq_default_poly_t poly, const fq_default_ctx_t ctx) + int fq_default_poly_print(const fq_default_poly_t poly, const fq_default_ctx_t ctx) + char * fq_default_poly_get_str(const fq_default_poly_t poly, const fq_default_ctx_t ctx) + char * fq_default_poly_get_str_pretty(const fq_default_poly_t poly, const char * x, const fq_default_ctx_t ctx) + void fq_default_poly_inflate(fq_default_poly_t result, const fq_default_poly_t input, ulong inflation, const fq_default_ctx_t ctx) + void fq_default_poly_deflate(fq_default_poly_t result, const fq_default_poly_t input, ulong deflation, const fq_default_ctx_t ctx) + ulong fq_default_poly_deflation(const fq_default_poly_t input, const fq_default_ctx_t ctx) diff --git a/src/flint/flintlib/fq_default_poly_factor.pxd b/src/flint/flintlib/fq_default_poly_factor.pxd new file mode 100644 index 00000000..e1d9e33c --- /dev/null +++ b/src/flint/flintlib/fq_default_poly_factor.pxd @@ -0,0 +1,42 @@ +from flint.flintlib.fq_default cimport fq_default_t, fq_default_ctx_t +from flint.flintlib.flint cimport ulong, slong +from flint.flintlib.fq_default_poly cimport fq_default_poly_t +from flint.flintlib.fq_poly_factor cimport fq_poly_factor_t +from flint.flintlib.fq_nmod_poly_factor cimport fq_nmod_poly_factor_t +from flint.flintlib.fq_zech_poly_factor cimport fq_zech_poly_factor_t +from flint.flintlib.nmod_poly_factor cimport nmod_poly_factor_t +from flint.flintlib.fmpz_mod_poly_factor cimport fmpz_mod_poly_factor_t + +cdef extern from "flint/fq_default_poly_factor.h": + # Type definitions **********************************************/ + ctypedef union fq_default_poly_factor_struct: + fq_poly_factor_t fq + fq_nmod_poly_factor_t fq_nmod + fq_zech_poly_factor_t fq_zech + nmod_poly_factor_t nmod + fmpz_mod_poly_factor_t fmpz_mod + ctypedef fq_default_poly_factor_struct fq_default_poly_factor_t[1] + + # Parsed from here **********************************************/ + void fq_default_poly_factor_init(fq_default_poly_factor_t fac, const fq_default_ctx_t ctx) + void fq_default_poly_factor_clear(fq_default_poly_factor_t fac, const fq_default_ctx_t ctx) + void fq_default_poly_factor_realloc(fq_default_poly_factor_t fac, slong alloc, const fq_default_ctx_t ctx) + void fq_default_poly_factor_fit_length(fq_default_poly_factor_t fac, slong len, const fq_default_ctx_t ctx) + void fq_default_poly_factor_set(fq_default_poly_factor_t res, const fq_default_poly_factor_t fac, const fq_default_ctx_t ctx) + void fq_default_poly_factor_print_pretty(const fq_default_poly_factor_t fac, const char * var, const fq_default_ctx_t ctx) + void fq_default_poly_factor_print(const fq_default_poly_factor_t fac, const fq_default_ctx_t ctx) + void fq_default_poly_factor_insert(fq_default_poly_factor_t fac, const fq_default_poly_t poly, slong exp, const fq_default_ctx_t ctx) + void fq_default_poly_factor_concat(fq_default_poly_factor_t res, const fq_default_poly_factor_t fac, const fq_default_ctx_t ctx) + void fq_default_poly_factor_pow(fq_default_poly_factor_t fac, slong exp, const fq_default_ctx_t ctx) + ulong fq_default_poly_remove(fq_default_poly_t f, const fq_default_poly_t p, const fq_default_ctx_t ctx) + slong fq_default_poly_factor_length(fq_default_poly_factor_t fac, const fq_default_ctx_t ctx) + void fq_default_poly_factor_get_poly(fq_default_poly_t poly, const fq_default_poly_factor_t fac, slong i, const fq_default_ctx_t ctx) + slong fq_default_poly_factor_exp(fq_default_poly_factor_t fac, slong i, const fq_default_ctx_t ctx) + int fq_default_poly_is_irreducible(const fq_default_poly_t f, const fq_default_ctx_t ctx) + int fq_default_poly_is_squarefree(const fq_default_poly_t f, const fq_default_ctx_t ctx) + void fq_default_poly_factor_equal_deg(fq_default_poly_factor_t factors, const fq_default_poly_t pol, slong d, const fq_default_ctx_t ctx) + void fq_default_poly_factor_split_single(fq_default_poly_t linfactor, const fq_default_poly_t input, const fq_default_ctx_t ctx) + void fq_default_poly_factor_distinct_deg(fq_default_poly_factor_t res, const fq_default_poly_t poly, slong * const * degs, const fq_default_ctx_t ctx) + void fq_default_poly_factor_squarefree(fq_default_poly_factor_t res, const fq_default_poly_t f, const fq_default_ctx_t ctx) + void fq_default_poly_factor(fq_default_poly_factor_t res, fq_default_t lead, const fq_default_poly_t f, const fq_default_ctx_t ctx) + void fq_default_poly_roots(fq_default_poly_factor_t r, const fq_default_poly_t f, int with_multiplicity, const fq_default_ctx_t ctx) diff --git a/src/flint/flintlib/fq_mat.pxd b/src/flint/flintlib/fq_mat.pxd new file mode 100644 index 00000000..f51d2ab1 --- /dev/null +++ b/src/flint/flintlib/fq_mat.pxd @@ -0,0 +1,74 @@ +from flint.flintlib.fq cimport fq_t, fq_struct, fq_ctx_t, fq_mat_t, fq_poly_t +from flint.flintlib.fq_poly cimport fq_poly_t +from flint.flintlib.flint cimport flint_rand_t, slong +from flint.flintlib.nmod_mat cimport nmod_mat_t +from flint.flintlib.fmpz_mod_mat cimport fmpz_mod_mat_t + +cdef extern from "flint/fq_mat.h": + # Parsed from here **********************************************/ + void fq_mat_init(fq_mat_t mat, slong rows, slong cols, const fq_ctx_t ctx) + void fq_mat_init_set(fq_mat_t mat, const fq_mat_t src, const fq_ctx_t ctx) + void fq_mat_clear(fq_mat_t mat, const fq_ctx_t ctx) + void fq_mat_set(fq_mat_t mat, const fq_mat_t src, const fq_ctx_t ctx) + fq_struct * fq_mat_entry(const fq_mat_t mat, slong i, slong j) + void fq_mat_entry_set(fq_mat_t mat, slong i, slong j, const fq_t x, const fq_ctx_t ctx) + slong fq_mat_nrows(const fq_mat_t mat, const fq_ctx_t ctx) + slong fq_mat_ncols(const fq_mat_t mat, const fq_ctx_t ctx) + void fq_mat_swap(fq_mat_t mat1, fq_mat_t mat2, const fq_ctx_t ctx) + void fq_mat_swap_entrywise(fq_mat_t mat1, fq_mat_t mat2, const fq_ctx_t ctx) + void fq_mat_zero(fq_mat_t mat, const fq_ctx_t ctx) + void fq_mat_one(fq_mat_t mat, const fq_ctx_t ctx) + void fq_mat_swap_rows(fq_mat_t mat, slong * perm, slong r, slong s, const fq_ctx_t ctx) + void fq_mat_swap_cols(fq_mat_t mat, slong * perm, slong r, slong s, const fq_ctx_t ctx) + void fq_mat_invert_rows(fq_mat_t mat, slong * perm, const fq_ctx_t ctx) + void fq_mat_invert_cols(fq_mat_t mat, slong * perm, const fq_ctx_t ctx) + void fq_mat_set_nmod_mat(fq_mat_t mat1, const nmod_mat_t mat2, const fq_ctx_t ctx) + void fq_mat_set_fmpz_mod_mat(fq_mat_t mat1, const fmpz_mod_mat_t mat2, const fq_ctx_t ctx) + void fq_mat_concat_vertical(fq_mat_t res, const fq_mat_t mat1, const fq_mat_t mat2, const fq_ctx_t ctx) + void fq_mat_concat_horizontal(fq_mat_t res, const fq_mat_t mat1, const fq_mat_t mat2, const fq_ctx_t ctx) + int fq_mat_print_pretty(const fq_mat_t mat, const fq_ctx_t ctx) + # int fq_mat_fprint_pretty(FILE * file, const fq_mat_t mat, const fq_ctx_t ctx) + int fq_mat_print(const fq_mat_t mat, const fq_ctx_t ctx) + # int fq_mat_fprint(FILE * file, const fq_mat_t mat, const fq_ctx_t ctx) + void fq_mat_window_init(fq_mat_t window, const fq_mat_t mat, slong r1, slong c1, slong r2, slong c2, const fq_ctx_t ctx) + void fq_mat_window_clear(fq_mat_t window, const fq_ctx_t ctx) + void fq_mat_randtest(fq_mat_t mat, flint_rand_t state, const fq_ctx_t ctx) + int fq_mat_randpermdiag(fq_mat_t mat, flint_rand_t state, fq_struct * diag, slong n, const fq_ctx_t ctx) + void fq_mat_randrank(fq_mat_t mat, flint_rand_t state, slong rank, const fq_ctx_t ctx) + void fq_mat_randops(fq_mat_t mat, flint_rand_t state, slong count, const fq_ctx_t ctx) + void fq_mat_randtril(fq_mat_t mat, flint_rand_t state, int unit, const fq_ctx_t ctx) + void fq_mat_randtriu(fq_mat_t mat, flint_rand_t state, int unit, const fq_ctx_t ctx) + int fq_mat_equal(const fq_mat_t mat1, const fq_mat_t mat2, const fq_ctx_t ctx) + int fq_mat_is_zero(const fq_mat_t mat, const fq_ctx_t ctx) + int fq_mat_is_one(const fq_mat_t mat, const fq_ctx_t ctx) + int fq_mat_is_empty(const fq_mat_t mat, const fq_ctx_t ctx) + int fq_mat_is_square(const fq_mat_t mat, const fq_ctx_t ctx) + void fq_mat_add(fq_mat_t C, const fq_mat_t A, const fq_mat_t B, const fq_ctx_t ctx) + void fq_mat_sub(fq_mat_t C, const fq_mat_t A, const fq_mat_t B, const fq_ctx_t ctx) + void fq_mat_neg(fq_mat_t A, const fq_mat_t B, const fq_ctx_t ctx) + void fq_mat_mul(fq_mat_t C, const fq_mat_t A, const fq_mat_t B, const fq_ctx_t ctx) + void fq_mat_mul_classical(fq_mat_t C, const fq_mat_t A, const fq_mat_t B, const fq_ctx_t ctx) + void fq_mat_mul_KS(fq_mat_t C, const fq_mat_t A, const fq_mat_t B, const fq_ctx_t ctx) + void fq_mat_submul(fq_mat_t D, const fq_mat_t C, const fq_mat_t A, const fq_mat_t B, const fq_ctx_t ctx) + void fq_mat_mul_vec(fq_struct * c, const fq_mat_t A, const fq_struct * b, slong blen, const fq_ctx_t ctx) + void fq_mat_mul_vec_ptr(fq_struct * const * c, const fq_mat_t A, const fq_struct * const * b, slong blen, const fq_ctx_t ctx) + void fq_mat_vec_mul(fq_struct * c, const fq_struct * a, slong alen, const fq_mat_t B, const fq_ctx_t ctx) + void fq_mat_vec_mul_ptr(fq_struct * const * c, const fq_struct * const * a, slong alen, const fq_mat_t B, const fq_ctx_t ctx) + int fq_mat_inv(fq_mat_t B, fq_mat_t A, const fq_ctx_t ctx) + slong fq_mat_lu(slong * P, fq_mat_t A, int rank_check, const fq_ctx_t ctx) + slong fq_mat_lu_classical(slong * P, fq_mat_t A, int rank_check, const fq_ctx_t ctx) + slong fq_mat_lu_recursive(slong * P, fq_mat_t A, int rank_check, const fq_ctx_t ctx) + slong fq_mat_rref(fq_mat_t B, const fq_mat_t A, const fq_ctx_t ctx) + slong fq_mat_reduce_row(fq_mat_t A, slong * P, slong * L, slong n, const fq_ctx_t ctx) + void fq_mat_solve_tril(fq_mat_t X, const fq_mat_t L, const fq_mat_t B, int unit, const fq_ctx_t ctx) + void fq_mat_solve_tril_classical(fq_mat_t X, const fq_mat_t L, const fq_mat_t B, int unit, const fq_ctx_t ctx) + void fq_mat_solve_tril_recursive(fq_mat_t X, const fq_mat_t L, const fq_mat_t B, int unit, const fq_ctx_t ctx) + void fq_mat_solve_triu(fq_mat_t X, const fq_mat_t U, const fq_mat_t B, int unit, const fq_ctx_t ctx) + void fq_mat_solve_triu_classical(fq_mat_t X, const fq_mat_t U, const fq_mat_t B, int unit, const fq_ctx_t ctx) + void fq_mat_solve_triu_recursive(fq_mat_t X, const fq_mat_t U, const fq_mat_t B, int unit, const fq_ctx_t ctx) + int fq_mat_solve(fq_mat_t X, const fq_mat_t A, const fq_mat_t B, const fq_ctx_t ctx) + int fq_mat_can_solve(fq_mat_t X, const fq_mat_t A, const fq_mat_t B, const fq_ctx_t ctx) + void fq_mat_similarity(fq_mat_t M, slong r, fq_t d, const fq_ctx_t ctx) + void fq_mat_charpoly_danilevsky(fq_poly_t p, const fq_mat_t M, const fq_ctx_t ctx) + void fq_mat_charpoly(fq_poly_t p, const fq_mat_t M, const fq_ctx_t ctx) + void fq_mat_minpoly(fq_poly_t p, const fq_mat_t M, const fq_ctx_t ctx) diff --git a/src/flint/flintlib/fq_nmod.pxd b/src/flint/flintlib/fq_nmod.pxd index c273be9d..da598834 100644 --- a/src/flint/flintlib/fq_nmod.pxd +++ b/src/flint/flintlib/fq_nmod.pxd @@ -7,7 +7,7 @@ from flint.flintlib.nmod_mat cimport nmod_mat_t from flint.flintlib.nmod_poly cimport nmod_poly_struct, nmod_poly_t cdef extern from "flint/fq_nmod.h": - + # Type definitions **********************************************/ ctypedef nmod_poly_t fq_nmod_t ctypedef nmod_poly_struct fq_nmod_struct @@ -28,7 +28,20 @@ cdef extern from "flint/fq_nmod.h": char *var ctypedef fq_nmod_ctx_struct fq_nmod_ctx_t[1] + ctypedef struct fq_nmod_poly_struct: + fq_nmod_struct * coeffs + slong alloc + slong length + ctypedef fq_nmod_poly_struct fq_nmod_poly_t[1] + + ctypedef struct fq_nmod_mat_struct: + fq_nmod_struct * entries + slong r + slong s + fq_nmod_struct ** rows + ctypedef fq_nmod_mat_struct fq_nmod_mat_t[1] + # Parsed from here **********************************************/ void fq_nmod_ctx_init(fq_nmod_ctx_t ctx, const fmpz_t p, slong d, const char *var) int _fq_nmod_ctx_init_conway(fq_nmod_ctx_t ctx, const fmpz_t p, slong d, const char *var) void fq_nmod_ctx_init_conway(fq_nmod_ctx_t ctx, const fmpz_t p, slong d, const char *var) diff --git a/src/flint/flintlib/fq_nmod_mat.pxd b/src/flint/flintlib/fq_nmod_mat.pxd new file mode 100644 index 00000000..790e1f99 --- /dev/null +++ b/src/flint/flintlib/fq_nmod_mat.pxd @@ -0,0 +1,73 @@ +from flint.flintlib.fq_nmod cimport fq_nmod_struct, fq_nmod_ctx_t, fq_nmod_t, fq_nmod_poly_t +from flint.flintlib.flint cimport slong, flint_rand_t +from flint.flintlib.fmpz_mod_mat cimport fmpz_mod_mat_t +from flint.flintlib.nmod_mat cimport nmod_mat_t + +cdef extern from "flint/fq_nmod_mat.h": + # Parsed from here **********************************************/ + void fq_nmod_mat_init(fq_nmod_mat_t mat, slong rows, slong cols, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_init_set(fq_nmod_mat_t mat, const fq_nmod_mat_t src, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_clear(fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_set(fq_nmod_mat_t mat, const fq_nmod_mat_t src, const fq_nmod_ctx_t ctx) + fq_nmod_struct * fq_nmod_mat_entry(const fq_nmod_mat_t mat, slong i, slong j) + void fq_nmod_mat_entry_set(fq_nmod_mat_t mat, slong i, slong j, const fq_nmod_t x, const fq_nmod_ctx_t ctx) + slong fq_nmod_mat_nrows(const fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + slong fq_nmod_mat_ncols(const fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_swap(fq_nmod_mat_t mat1, fq_nmod_mat_t mat2, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_swap_entrywise(fq_nmod_mat_t mat1, fq_nmod_mat_t mat2, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_zero(fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_one(fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_swap_rows(fq_nmod_mat_t mat, slong * perm, slong r, slong s, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_swap_cols(fq_nmod_mat_t mat, slong * perm, slong r, slong s, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_invert_rows(fq_nmod_mat_t mat, slong * perm, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_invert_cols(fq_nmod_mat_t mat, slong * perm, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_set_nmod_mat(fq_nmod_mat_t mat1, const nmod_mat_t mat2, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_set_fmpz_mod_mat(fq_nmod_mat_t mat1, const fmpz_mod_mat_t mat2, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_concat_vertical(fq_nmod_mat_t res, const fq_nmod_mat_t mat1, const fq_nmod_mat_t mat2, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_concat_horizontal(fq_nmod_mat_t res, const fq_nmod_mat_t mat1, const fq_nmod_mat_t mat2, const fq_nmod_ctx_t ctx) + int fq_nmod_mat_print_pretty(const fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + # int fq_nmod_mat_fprint_pretty(FILE * file, const fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + int fq_nmod_mat_print(const fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + # int fq_nmod_mat_fprint(FILE * file, const fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_window_init(fq_nmod_mat_t window, const fq_nmod_mat_t mat, slong r1, slong c1, slong r2, slong c2, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_window_clear(fq_nmod_mat_t window, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_randtest(fq_nmod_mat_t mat, flint_rand_t state, const fq_nmod_ctx_t ctx) + int fq_nmod_mat_randpermdiag(fq_nmod_mat_t mat, flint_rand_t state, fq_nmod_struct * diag, slong n, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_randrank(fq_nmod_mat_t mat, flint_rand_t state, slong rank, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_randops(fq_nmod_mat_t mat, flint_rand_t state, slong count, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_randtril(fq_nmod_mat_t mat, flint_rand_t state, int unit, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_randtriu(fq_nmod_mat_t mat, flint_rand_t state, int unit, const fq_nmod_ctx_t ctx) + int fq_nmod_mat_equal(const fq_nmod_mat_t mat1, const fq_nmod_mat_t mat2, const fq_nmod_ctx_t ctx) + int fq_nmod_mat_is_zero(const fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + int fq_nmod_mat_is_one(const fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + int fq_nmod_mat_is_empty(const fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + int fq_nmod_mat_is_square(const fq_nmod_mat_t mat, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_add(fq_nmod_mat_t C, const fq_nmod_mat_t A, const fq_nmod_mat_t B, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_sub(fq_nmod_mat_t C, const fq_nmod_mat_t A, const fq_nmod_mat_t B, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_neg(fq_nmod_mat_t A, const fq_nmod_mat_t B, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_mul(fq_nmod_mat_t C, const fq_nmod_mat_t A, const fq_nmod_mat_t B, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_mul_classical(fq_nmod_mat_t C, const fq_nmod_mat_t A, const fq_nmod_mat_t B, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_mul_KS(fq_nmod_mat_t C, const fq_nmod_mat_t A, const fq_nmod_mat_t B, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_submul(fq_nmod_mat_t D, const fq_nmod_mat_t C, const fq_nmod_mat_t A, const fq_nmod_mat_t B, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_mul_vec(fq_nmod_struct * c, const fq_nmod_mat_t A, const fq_nmod_struct * b, slong blen, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_mul_vec_ptr(fq_nmod_struct * const * c, const fq_nmod_mat_t A, const fq_nmod_struct * const * b, slong blen, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_vec_mul(fq_nmod_struct * c, const fq_nmod_struct * a, slong alen, const fq_nmod_mat_t B, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_vec_mul_ptr(fq_nmod_struct * const * c, const fq_nmod_struct * const * a, slong alen, const fq_nmod_mat_t B, const fq_nmod_ctx_t ctx) + int fq_nmod_mat_inv(fq_nmod_mat_t B, fq_nmod_mat_t A, const fq_nmod_ctx_t ctx) + slong fq_nmod_mat_lu(slong * P, fq_nmod_mat_t A, int rank_check, const fq_nmod_ctx_t ctx) + slong fq_nmod_mat_lu_classical(slong * P, fq_nmod_mat_t A, int rank_check, const fq_nmod_ctx_t ctx) + slong fq_nmod_mat_lu_recursive(slong * P, fq_nmod_mat_t A, int rank_check, const fq_nmod_ctx_t ctx) + slong fq_nmod_mat_rref(fq_nmod_mat_t B, const fq_nmod_mat_t A, const fq_nmod_ctx_t ctx) + slong fq_nmod_mat_reduce_row(fq_nmod_mat_t A, slong * P, slong * L, slong n, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_solve_tril(fq_nmod_mat_t X, const fq_nmod_mat_t L, const fq_nmod_mat_t B, int unit, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_solve_tril_classical(fq_nmod_mat_t X, const fq_nmod_mat_t L, const fq_nmod_mat_t B, int unit, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_solve_tril_recursive(fq_nmod_mat_t X, const fq_nmod_mat_t L, const fq_nmod_mat_t B, int unit, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_solve_triu(fq_nmod_mat_t X, const fq_nmod_mat_t U, const fq_nmod_mat_t B, int unit, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_solve_triu_classical(fq_nmod_mat_t X, const fq_nmod_mat_t U, const fq_nmod_mat_t B, int unit, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_solve_triu_recursive(fq_nmod_mat_t X, const fq_nmod_mat_t U, const fq_nmod_mat_t B, int unit, const fq_nmod_ctx_t ctx) + int fq_nmod_mat_solve(fq_nmod_mat_t X, const fq_nmod_mat_t A, const fq_nmod_mat_t B, const fq_nmod_ctx_t ctx) + int fq_nmod_mat_can_solve(fq_nmod_mat_t X, const fq_nmod_mat_t A, const fq_nmod_mat_t B, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_similarity(fq_nmod_mat_t M, slong r, fq_nmod_t d, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_charpoly_danilevsky(fq_nmod_poly_t p, const fq_nmod_mat_t M, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_charpoly(fq_nmod_poly_t p, const fq_nmod_mat_t M, const fq_nmod_ctx_t ctx) + void fq_nmod_mat_minpoly(fq_nmod_poly_t p, const fq_nmod_mat_t M, const fq_nmod_ctx_t ctx) diff --git a/src/flint/flintlib/fq_nmod_poly.pxd b/src/flint/flintlib/fq_nmod_poly.pxd new file mode 100644 index 00000000..29003791 --- /dev/null +++ b/src/flint/flintlib/fq_nmod_poly.pxd @@ -0,0 +1,193 @@ +from flint.flintlib.fq_nmod cimport fq_nmod_struct, fq_nmod_ctx_t, fq_nmod_t, fq_nmod_poly_t, fq_nmod_mat_t +from flint.flintlib.flint cimport ulong, slong, flint_rand_t +from flint.flintlib.fmpz_mod_poly cimport fmpz_mod_poly_t +from flint.flintlib.nmod_poly cimport nmod_poly_t +from flint.flintlib.fmpz cimport fmpz_t + +cdef extern from "flint/fq_nmod_poly.h": + # Parsed from here **********************************************/ + void fq_nmod_poly_init(fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_init2(fq_nmod_poly_t poly, slong alloc, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_realloc(fq_nmod_poly_t poly, slong alloc, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_fit_length(fq_nmod_poly_t poly, slong len, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_set_length(fq_nmod_poly_t poly, slong newlen, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_clear(fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_normalise(fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_normalise2(const fq_nmod_struct * poly, slong * length, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_truncate(fq_nmod_poly_t poly, slong newlen, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_set_trunc(fq_nmod_poly_t poly1, fq_nmod_poly_t poly2, slong newlen, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_reverse(fq_nmod_struct * output, const fq_nmod_struct * input, slong len, slong m, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_reverse(fq_nmod_poly_t output, const fq_nmod_poly_t input, slong m, const fq_nmod_ctx_t ctx) + slong fq_nmod_poly_degree(const fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + slong fq_nmod_poly_length(const fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + fq_nmod_struct * fq_nmod_poly_lead(const fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_randtest(fq_nmod_poly_t f, flint_rand_t state, slong len, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_randtest_not_zero(fq_nmod_poly_t f, flint_rand_t state, slong len, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_randtest_monic(fq_nmod_poly_t f, flint_rand_t state, slong len, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_randtest_irreducible(fq_nmod_poly_t f, flint_rand_t state, slong len, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_set(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_set(fq_nmod_poly_t poly1, const fq_nmod_poly_t poly2, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_set_fq_nmod(fq_nmod_poly_t poly, const fq_nmod_t c, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_set_fmpz_mod_poly(fq_nmod_poly_t rop, const fmpz_mod_poly_t op, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_set_nmod_poly(fq_nmod_poly_t rop, const nmod_poly_t op, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_swap(fq_nmod_poly_t op1, fq_nmod_poly_t op2, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_zero(fq_nmod_struct * rop, slong len, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_zero(fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_one(fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_gen(fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_make_monic(fq_nmod_poly_t rop, const fq_nmod_poly_t op, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_make_monic(fq_nmod_struct * rop, const fq_nmod_struct * op, slong length, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_get_coeff(fq_nmod_t x, const fq_nmod_poly_t poly, slong n, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_set_coeff(fq_nmod_poly_t poly, slong n, const fq_nmod_t x, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_set_coeff_fmpz(fq_nmod_poly_t poly, slong n, const fmpz_t x, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_equal(const fq_nmod_poly_t poly1, const fq_nmod_poly_t poly2, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_equal_trunc(const fq_nmod_poly_t poly1, const fq_nmod_poly_t poly2, slong n, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_is_zero(const fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_is_one(const fq_nmod_poly_t op, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_is_gen(const fq_nmod_poly_t op, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_is_unit(const fq_nmod_poly_t op, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_equal_fq_nmod(const fq_nmod_poly_t poly, const fq_nmod_t c, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_add(fq_nmod_struct * res, const fq_nmod_struct * poly1, slong len1, const fq_nmod_struct * poly2, slong len2, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_add(fq_nmod_poly_t res, const fq_nmod_poly_t poly1, const fq_nmod_poly_t poly2, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_add_si(fq_nmod_poly_t res, const fq_nmod_poly_t poly1, slong c, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_add_series(fq_nmod_poly_t res, const fq_nmod_poly_t poly1, const fq_nmod_poly_t poly2, slong n, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_sub(fq_nmod_struct * res, const fq_nmod_struct * poly1, slong len1, const fq_nmod_struct * poly2, slong len2, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_sub(fq_nmod_poly_t res, const fq_nmod_poly_t poly1, const fq_nmod_poly_t poly2, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_sub_series(fq_nmod_poly_t res, const fq_nmod_poly_t poly1, const fq_nmod_poly_t poly2, slong n, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_neg(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_neg(fq_nmod_poly_t res, const fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_scalar_mul_fq_nmod(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, const fq_nmod_t x, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_scalar_mul_fq_nmod(fq_nmod_poly_t rop, const fq_nmod_poly_t op, const fq_nmod_t x, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_scalar_addmul_fq_nmod(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, const fq_nmod_t x, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_scalar_addmul_fq_nmod(fq_nmod_poly_t rop, const fq_nmod_poly_t op, const fq_nmod_t x, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_scalar_submul_fq_nmod(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, const fq_nmod_t x, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_scalar_submul_fq_nmod(fq_nmod_poly_t rop, const fq_nmod_poly_t op, const fq_nmod_t x, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_scalar_div_fq(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, const fq_nmod_t x, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_scalar_div_fq(fq_nmod_poly_t rop, const fq_nmod_poly_t op, const fq_nmod_t x, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mul_classical(fq_nmod_struct * rop, const fq_nmod_struct * op1, slong len1, const fq_nmod_struct * op2, slong len2, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mul_classical(fq_nmod_poly_t rop, const fq_nmod_poly_t op1, const fq_nmod_poly_t op2, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mul_reorder(fq_nmod_struct * rop, const fq_nmod_struct * op1, slong len1, const fq_nmod_struct * op2, slong len2, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mul_reorder(fq_nmod_poly_t rop, const fq_nmod_poly_t op1, const fq_nmod_poly_t op2, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mul_univariate(fq_nmod_struct * rop, const fq_nmod_struct * op1, slong len1, const fq_nmod_struct * op2, slong len2, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mul_univariate(fq_nmod_poly_t rop, const fq_nmod_poly_t op1, const fq_nmod_poly_t op2, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mul_KS(fq_nmod_struct * rop, const fq_nmod_struct * op1, slong len1, const fq_nmod_struct * op2, slong len2, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mul_KS(fq_nmod_poly_t rop, const fq_nmod_poly_t op1, const fq_nmod_poly_t op2, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mul(fq_nmod_struct * rop, const fq_nmod_struct * op1, slong len1, const fq_nmod_struct * op2, slong len2, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mul(fq_nmod_poly_t rop, const fq_nmod_poly_t op1, const fq_nmod_poly_t op2, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mullow_classical(fq_nmod_struct * rop, const fq_nmod_struct * op1, slong len1, const fq_nmod_struct * op2, slong len2, slong n, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mullow_classical(fq_nmod_poly_t rop, const fq_nmod_poly_t op1, const fq_nmod_poly_t op2, slong n, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mullow_univariate(fq_nmod_struct * rop, const fq_nmod_struct * op1, slong len1, const fq_nmod_struct * op2, slong len2, slong n, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mullow_univariate(fq_nmod_poly_t rop, const fq_nmod_poly_t op1, const fq_nmod_poly_t op2, slong n, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mullow_KS(fq_nmod_struct * rop, const fq_nmod_struct * op1, slong len1, const fq_nmod_struct * op2, slong len2, slong n, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mullow_KS(fq_nmod_poly_t rop, const fq_nmod_poly_t op1, const fq_nmod_poly_t op2, slong n, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mullow(fq_nmod_struct * rop, const fq_nmod_struct * op1, slong len1, const fq_nmod_struct * op2, slong len2, slong n, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mullow(fq_nmod_poly_t rop, const fq_nmod_poly_t op1, const fq_nmod_poly_t op2, slong n, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mulhigh_classical(fq_nmod_struct * res, const fq_nmod_struct * poly1, slong len1, const fq_nmod_struct * poly2, slong len2, slong start, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mulhigh_classical(fq_nmod_poly_t res, const fq_nmod_poly_t poly1, const fq_nmod_poly_t poly2, slong start, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mulhigh(fq_nmod_struct * res, const fq_nmod_struct * poly1, slong len1, const fq_nmod_struct * poly2, slong len2, slong start, fq_nmod_ctx_t ctx) + void fq_nmod_poly_mulhigh(fq_nmod_poly_t res, const fq_nmod_poly_t poly1, const fq_nmod_poly_t poly2, slong start, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mulmod(fq_nmod_struct * res, const fq_nmod_struct * poly1, slong len1, const fq_nmod_struct * poly2, slong len2, const fq_nmod_struct * f, slong lenf, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mulmod(fq_nmod_poly_t res, const fq_nmod_poly_t poly1, const fq_nmod_poly_t poly2, const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_mulmod_preinv(fq_nmod_struct * res, const fq_nmod_struct * poly1, slong len1, const fq_nmod_struct * poly2, slong len2, const fq_nmod_struct * f, slong lenf, const fq_nmod_struct * finv, slong lenfinv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_mulmod_preinv(fq_nmod_poly_t res, const fq_nmod_poly_t poly1, const fq_nmod_poly_t poly2, const fq_nmod_poly_t f, const fq_nmod_poly_t finv, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_sqr_classical(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_sqr_classical(fq_nmod_poly_t rop, const fq_nmod_poly_t op, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_sqr_KS(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_sqr_KS(fq_nmod_poly_t rop, const fq_nmod_poly_t op, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_sqr(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_sqr(fq_nmod_poly_t rop, const fq_nmod_poly_t op, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_pow(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, ulong e, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_pow(fq_nmod_poly_t rop, const fq_nmod_poly_t op, ulong e, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_powmod_ui_binexp(fq_nmod_struct * res, const fq_nmod_struct * poly, ulong e, const fq_nmod_struct * f, slong lenf, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_powmod_ui_binexp(fq_nmod_poly_t res, const fq_nmod_poly_t poly, ulong e, const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_powmod_ui_binexp_preinv(fq_nmod_struct * res, const fq_nmod_struct * poly, ulong e, const fq_nmod_struct * f, slong lenf, const fq_nmod_struct * finv, slong lenfinv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_powmod_ui_binexp_preinv(fq_nmod_poly_t res, const fq_nmod_poly_t poly, ulong e, const fq_nmod_poly_t f, const fq_nmod_poly_t finv, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_powmod_fmpz_binexp(fq_nmod_struct * res, const fq_nmod_struct * poly, const fmpz_t e, const fq_nmod_struct * f, slong lenf, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_powmod_fmpz_binexp(fq_nmod_poly_t res, const fq_nmod_poly_t poly, const fmpz_t e, const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_powmod_fmpz_binexp_preinv(fq_nmod_struct * res, const fq_nmod_struct * poly, const fmpz_t e, const fq_nmod_struct * f, slong lenf, const fq_nmod_struct * finv, slong lenfinv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_powmod_fmpz_binexp_preinv(fq_nmod_poly_t res, const fq_nmod_poly_t poly, const fmpz_t e, const fq_nmod_poly_t f, const fq_nmod_poly_t finv, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_powmod_fmpz_sliding_preinv(fq_nmod_struct * res, const fq_nmod_struct * poly, const fmpz_t e, ulong k, const fq_nmod_struct * f, slong lenf, const fq_nmod_struct * finv, slong lenfinv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_powmod_fmpz_sliding_preinv(fq_nmod_poly_t res, const fq_nmod_poly_t poly, const fmpz_t e, ulong k, const fq_nmod_poly_t f, const fq_nmod_poly_t finv, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_powmod_x_fmpz_preinv(fq_nmod_struct * res, const fmpz_t e, const fq_nmod_struct * f, slong lenf, const fq_nmod_struct * finv, slong lenfinv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_powmod_x_fmpz_preinv(fq_nmod_poly_t res, const fmpz_t e, const fq_nmod_poly_t f, const fq_nmod_poly_t finv, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_pow_trunc_binexp(fq_nmod_struct * res, const fq_nmod_struct * poly, ulong e, slong trunc, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_pow_trunc_binexp(fq_nmod_poly_t res, const fq_nmod_poly_t poly, ulong e, slong trunc, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_pow_trunc(fq_nmod_struct * res, const fq_nmod_struct * poly, ulong e, slong trunc, const fq_nmod_ctx_t mod) + void fq_nmod_poly_pow_trunc(fq_nmod_poly_t res, const fq_nmod_poly_t poly, ulong e, slong trunc, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_shift_left(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, slong n, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_shift_left(fq_nmod_poly_t rop, const fq_nmod_poly_t op, slong n, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_shift_right(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, slong n, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_shift_right(fq_nmod_poly_t rop, const fq_nmod_poly_t op, slong n, const fq_nmod_ctx_t ctx) + slong _fq_nmod_poly_hamming_weight(const fq_nmod_struct * op, slong len, const fq_nmod_ctx_t ctx) + slong fq_nmod_poly_hamming_weight(const fq_nmod_poly_t op, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_divrem(fq_nmod_struct * Q, fq_nmod_struct * R, const fq_nmod_struct * A, slong lenA, const fq_nmod_struct * B, slong lenB, const fq_nmod_t invB, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_divrem(fq_nmod_poly_t Q, fq_nmod_poly_t R, const fq_nmod_poly_t A, const fq_nmod_poly_t B, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_divrem_f(fq_nmod_t f, fq_nmod_poly_t Q, fq_nmod_poly_t R, const fq_nmod_poly_t A, const fq_nmod_poly_t B, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_rem(fq_nmod_struct * R, const fq_nmod_struct * A, slong lenA, const fq_nmod_struct * B, slong lenB, const fq_nmod_t invB, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_rem(fq_nmod_poly_t R, const fq_nmod_poly_t A, const fq_nmod_poly_t B, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_div(fq_nmod_struct * Q, const fq_nmod_struct * A, slong lenA, const fq_nmod_struct * B, slong lenB, const fq_nmod_t invB, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_div(fq_nmod_poly_t Q, const fq_nmod_poly_t A, const fq_nmod_poly_t B, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_div_newton_n_preinv(fq_nmod_struct * Q, const fq_nmod_struct * A, slong lenA, const fq_nmod_struct * B, slong lenB, const fq_nmod_struct * Binv, slong lenBinv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_div_newton_n_preinv(fq_nmod_poly_t Q, const fq_nmod_poly_t A, const fq_nmod_poly_t B, const fq_nmod_poly_t Binv, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_divrem_newton_n_preinv(fq_nmod_struct * Q, fq_nmod_struct * R, const fq_nmod_struct * A, slong lenA, const fq_nmod_struct * B, slong lenB, const fq_nmod_struct * Binv, slong lenBinv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_divrem_newton_n_preinv(fq_nmod_poly_t Q, fq_nmod_poly_t R, const fq_nmod_poly_t A, const fq_nmod_poly_t B, const fq_nmod_poly_t Binv, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_inv_series_newton(fq_nmod_struct * Qinv, const fq_nmod_struct * Q, slong n, const fq_nmod_t cinv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_inv_series_newton(fq_nmod_poly_t Qinv, const fq_nmod_poly_t Q, slong n, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_inv_series(fq_nmod_struct * Qinv, const fq_nmod_struct * Q, slong n, const fq_nmod_t cinv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_inv_series(fq_nmod_poly_t Qinv, const fq_nmod_poly_t Q, slong n, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_div_series(fq_nmod_struct * Q, const fq_nmod_struct * A, slong Alen, const fq_nmod_struct * B, slong Blen, slong n, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_div_series(fq_nmod_poly_t Q, const fq_nmod_poly_t A, const fq_nmod_poly_t B, slong n, fq_nmod_ctx_t ctx) + void fq_nmod_poly_gcd(fq_nmod_poly_t rop, const fq_nmod_poly_t op1, const fq_nmod_poly_t op2, const fq_nmod_ctx_t ctx) + slong _fq_nmod_poly_gcd(fq_nmod_struct * G, const fq_nmod_struct * A, slong lenA, const fq_nmod_struct * B, slong lenB, const fq_nmod_ctx_t ctx) + slong _fq_nmod_poly_gcd_euclidean_f(fq_nmod_t f, fq_nmod_struct * G, const fq_nmod_struct * A, slong lenA, const fq_nmod_struct * B, slong lenB, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_gcd_euclidean_f(fq_nmod_t f, fq_nmod_poly_t G, const fq_nmod_poly_t A, const fq_nmod_poly_t B, const fq_nmod_ctx_t ctx) + slong _fq_nmod_poly_xgcd(fq_nmod_struct * G, fq_nmod_struct * S, fq_nmod_struct * T, const fq_nmod_struct * A, slong lenA, const fq_nmod_struct * B, slong lenB, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_xgcd(fq_nmod_poly_t G, fq_nmod_poly_t S, fq_nmod_poly_t T, const fq_nmod_poly_t A, const fq_nmod_poly_t B, const fq_nmod_ctx_t ctx) + slong _fq_nmod_poly_xgcd_euclidean_f(fq_nmod_t f, fq_nmod_struct * G, fq_nmod_struct * S, fq_nmod_struct * T, const fq_nmod_struct * A, slong lenA, const fq_nmod_struct * B, slong lenB, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_xgcd_euclidean_f(fq_nmod_t f, fq_nmod_poly_t G, fq_nmod_poly_t S, fq_nmod_poly_t T, const fq_nmod_poly_t A, const fq_nmod_poly_t B, const fq_nmod_ctx_t ctx) + int _fq_nmod_poly_divides(fq_nmod_struct * Q, const fq_nmod_struct * A, slong lenA, const fq_nmod_struct * B, slong lenB, const fq_nmod_t invB, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_divides(fq_nmod_poly_t Q, const fq_nmod_poly_t A, const fq_nmod_poly_t B, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_derivative(fq_nmod_struct * rop, const fq_nmod_struct * op, slong len, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_derivative(fq_nmod_poly_t rop, const fq_nmod_poly_t op, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_invsqrt_series(fq_nmod_struct * g, const fq_nmod_struct * h, slong n, fq_nmod_ctx_t mod) + void fq_nmod_poly_invsqrt_series(fq_nmod_poly_t g, const fq_nmod_poly_t h, slong n, fq_nmod_ctx_t ctx) + void _fq_nmod_poly_sqrt_series(fq_nmod_struct * g, const fq_nmod_struct * h, slong n, fq_nmod_ctx_t ctx) + void fq_nmod_poly_sqrt_series(fq_nmod_poly_t g, const fq_nmod_poly_t h, slong n, fq_nmod_ctx_t ctx) + int _fq_nmod_poly_sqrt(fq_nmod_struct * s, const fq_nmod_struct * p, slong n, fq_nmod_ctx_t mod) + int fq_nmod_poly_sqrt(fq_nmod_poly_t s, const fq_nmod_poly_t p, fq_nmod_ctx_t mod) + void _fq_nmod_poly_evaluate_fq_nmod(fq_nmod_t rop, const fq_nmod_struct * op, slong len, const fq_nmod_t a, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_evaluate_fq_nmod(fq_nmod_t rop, const fq_nmod_poly_t f, const fq_nmod_t a, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_compose(fq_nmod_struct * rop, const fq_nmod_struct * op1, slong len1, const fq_nmod_struct * op2, slong len2, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_compose(fq_nmod_poly_t rop, const fq_nmod_poly_t op1, const fq_nmod_poly_t op2, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_compose_mod_horner(fq_nmod_struct * res, const fq_nmod_struct * f, slong lenf, const fq_nmod_struct * g, const fq_nmod_struct * h, slong lenh, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_compose_mod_horner(fq_nmod_poly_t res, const fq_nmod_poly_t f, const fq_nmod_poly_t g, const fq_nmod_poly_t h, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_compose_mod_horner_preinv(fq_nmod_struct * res, const fq_nmod_struct * f, slong lenf, const fq_nmod_struct * g, const fq_nmod_struct * h, slong lenh, const fq_nmod_struct * hinv, slong lenhiv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_compose_mod_horner_preinv(fq_nmod_poly_t res, const fq_nmod_poly_t f, const fq_nmod_poly_t g, const fq_nmod_poly_t h, const fq_nmod_poly_t hinv, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_compose_mod_brent_kung(fq_nmod_struct * res, const fq_nmod_struct * f, slong lenf, const fq_nmod_struct * g, const fq_nmod_struct * h, slong lenh, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_compose_mod_brent_kung(fq_nmod_poly_t res, const fq_nmod_poly_t f, const fq_nmod_poly_t g, const fq_nmod_poly_t h, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_compose_mod_brent_kung_preinv(fq_nmod_struct * res, const fq_nmod_struct * f, slong lenf, const fq_nmod_struct * g, const fq_nmod_struct * h, slong lenh, const fq_nmod_struct * hinv, slong lenhiv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_compose_mod_brent_kung_preinv(fq_nmod_poly_t res, const fq_nmod_poly_t f, const fq_nmod_poly_t g, const fq_nmod_poly_t h, const fq_nmod_poly_t hinv, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_compose_mod(fq_nmod_struct * res, const fq_nmod_struct * f, slong lenf, const fq_nmod_struct * g, const fq_nmod_struct * h, slong lenh, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_compose_mod(fq_nmod_poly_t res, const fq_nmod_poly_t f, const fq_nmod_poly_t g, const fq_nmod_poly_t h, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_compose_mod_preinv(fq_nmod_struct * res, const fq_nmod_struct * f, slong lenf, const fq_nmod_struct * g, const fq_nmod_struct * h, slong lenh, const fq_nmod_struct * hinv, slong lenhiv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_compose_mod_preinv(fq_nmod_poly_t res, const fq_nmod_poly_t f, const fq_nmod_poly_t g, const fq_nmod_poly_t h, const fq_nmod_poly_t hinv, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_reduce_matrix_mod_poly (fq_nmod_mat_t A, const fq_nmod_mat_t B, const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_precompute_matrix (fq_nmod_mat_t A, const fq_nmod_struct * f, const fq_nmod_struct * g, slong leng, const fq_nmod_struct * ginv, slong lenginv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_precompute_matrix (fq_nmod_mat_t A, const fq_nmod_poly_t f, const fq_nmod_poly_t g, const fq_nmod_poly_t ginv, const fq_nmod_ctx_t ctx) + void _fq_nmod_poly_compose_mod_brent_kung_precomp_preinv(fq_nmod_struct * res, const fq_nmod_struct * f, slong lenf, const fq_nmod_mat_t A, const fq_nmod_struct * h, slong lenh, const fq_nmod_struct * hinv, slong lenhinv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_compose_mod_brent_kung_precomp_preinv(fq_nmod_poly_t res, const fq_nmod_poly_t f, const fq_nmod_mat_t A, const fq_nmod_poly_t h, const fq_nmod_poly_t hinv, const fq_nmod_ctx_t ctx) + # int _fq_nmod_poly_fprint_pretty(FILE * file, const fq_nmod_struct * poly, slong len, const char * x, const fq_nmod_ctx_t ctx) + # int fq_nmod_poly_fprint_pretty(FILE * file, const fq_nmod_poly_t poly, const char * x, const fq_nmod_ctx_t ctx) + int _fq_nmod_poly_print_pretty(const fq_nmod_struct * poly, slong len, const char * x, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_print_pretty(const fq_nmod_poly_t poly, const char * x, const fq_nmod_ctx_t ctx) + # int _fq_nmod_poly_fprint(FILE * file, const fq_nmod_struct * poly, slong len, const fq_nmod_ctx_t ctx) + # int fq_nmod_poly_fprint(FILE * file, const fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + int _fq_nmod_poly_print(const fq_nmod_struct * poly, slong len, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_print(const fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + char * _fq_nmod_poly_get_str(const fq_nmod_struct * poly, slong len, const fq_nmod_ctx_t ctx) + char * fq_nmod_poly_get_str(const fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + char * _fq_nmod_poly_get_str_pretty(const fq_nmod_struct * poly, slong len, const char * x, const fq_nmod_ctx_t ctx) + char * fq_nmod_poly_get_str_pretty(const fq_nmod_poly_t poly, const char * x, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_inflate(fq_nmod_poly_t result, const fq_nmod_poly_t input, ulong inflation, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_deflate(fq_nmod_poly_t result, const fq_nmod_poly_t input, ulong deflation, const fq_nmod_ctx_t ctx) + ulong fq_nmod_poly_deflation(const fq_nmod_poly_t input, const fq_nmod_ctx_t ctx) diff --git a/src/flint/flintlib/fq_nmod_poly_factor.pxd b/src/flint/flintlib/fq_nmod_poly_factor.pxd new file mode 100644 index 00000000..83234f7a --- /dev/null +++ b/src/flint/flintlib/fq_nmod_poly_factor.pxd @@ -0,0 +1,44 @@ +from flint.flintlib.flint cimport ulong, slong, flint_rand_t +from flint.flintlib.fq_nmod cimport fq_nmod_ctx_t, fq_nmod_t, fq_nmod_struct +from flint.flintlib.fq_nmod cimport fq_nmod_poly_struct, fq_nmod_poly_t + +cdef extern from "flint/fq_nmod_poly_factor.h": + # Type definitions **********************************************/ + ctypedef struct fq_nmod_poly_factor_struct: + fq_nmod_poly_struct * poly + slong * exp + slong num + slong alloc + ctypedef fq_nmod_poly_factor_struct fq_nmod_poly_factor_t[1] + + # Parsed from here **********************************************/ + void fq_nmod_poly_factor_init(fq_nmod_poly_factor_t fac, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_clear(fq_nmod_poly_factor_t fac, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_realloc(fq_nmod_poly_factor_t fac, slong alloc, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_fit_length(fq_nmod_poly_factor_t fac, slong len, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_set(fq_nmod_poly_factor_t res, const fq_nmod_poly_factor_t fac, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_print_pretty(const fq_nmod_poly_factor_t fac, const char * var, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_print(const fq_nmod_poly_factor_t fac, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_insert(fq_nmod_poly_factor_t fac, const fq_nmod_poly_t poly, slong exp, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_concat(fq_nmod_poly_factor_t res, const fq_nmod_poly_factor_t fac, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_pow(fq_nmod_poly_factor_t fac, slong exp, const fq_nmod_ctx_t ctx) + ulong fq_nmod_poly_remove(fq_nmod_poly_t f, const fq_nmod_poly_t p, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_is_irreducible(const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_is_irreducible_ddf(const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_is_irreducible_ben_or(const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + int _fq_nmod_poly_is_squarefree(const fq_nmod_struct * f, slong len, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_is_squarefree(const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + int fq_nmod_poly_factor_equal_deg_prob(fq_nmod_poly_t factor, flint_rand_t state, const fq_nmod_poly_t pol, slong d, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_equal_deg(fq_nmod_poly_factor_t factors, const fq_nmod_poly_t pol, slong d, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_split_single(fq_nmod_poly_t linfactor, const fq_nmod_poly_t input, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_distinct_deg(fq_nmod_poly_factor_t res, const fq_nmod_poly_t poly, slong * const * degs, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_squarefree(fq_nmod_poly_factor_t res, const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor(fq_nmod_poly_factor_t res, fq_nmod_t lead, const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_cantor_zassenhaus(fq_nmod_poly_factor_t res, const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_kaltofen_shoup(fq_nmod_poly_factor_t res, const fq_nmod_poly_t poly, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_berlekamp(fq_nmod_poly_factor_t factors, const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_with_berlekamp(fq_nmod_poly_factor_t res, fq_nmod_t leading_coeff, const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_with_cantor_zassenhaus(fq_nmod_poly_factor_t res, fq_nmod_t leading_coeff, const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_factor_with_kaltofen_shoup(fq_nmod_poly_factor_t res, fq_nmod_t leading_coeff, const fq_nmod_poly_t f, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_iterated_frobenius_preinv(fq_nmod_poly_t * rop, slong n, const fq_nmod_poly_t v, const fq_nmod_poly_t vinv, const fq_nmod_ctx_t ctx) + void fq_nmod_poly_roots(fq_nmod_poly_factor_t r, const fq_nmod_poly_t f, int with_multiplicity, const fq_nmod_ctx_t ctx) diff --git a/src/flint/flintlib/fq_poly.pxd b/src/flint/flintlib/fq_poly.pxd new file mode 100644 index 00000000..db4602de --- /dev/null +++ b/src/flint/flintlib/fq_poly.pxd @@ -0,0 +1,196 @@ +from flint.flintlib.flint cimport ulong, slong, flint_rand_t +from flint.flintlib.fq cimport fq_ctx_t, fq_t, fq_struct, fq_poly_t +from flint.flintlib.fq_mat cimport fq_mat_t +from flint.flintlib.fmpz_mod_poly cimport fmpz_mod_poly_t +from flint.flintlib.nmod_poly cimport nmod_poly_t +from flint.flintlib.fmpz cimport fmpz_t + +cdef extern from "flint/fq_poly.h": + # Parsed from here **********************************************/ + void fq_poly_init(fq_poly_t poly, const fq_ctx_t ctx) + void fq_poly_init2(fq_poly_t poly, slong alloc, const fq_ctx_t ctx) + void fq_poly_realloc(fq_poly_t poly, slong alloc, const fq_ctx_t ctx) + void fq_poly_fit_length(fq_poly_t poly, slong len, const fq_ctx_t ctx) + void _fq_poly_set_length(fq_poly_t poly, slong newlen, const fq_ctx_t ctx) + void fq_poly_clear(fq_poly_t poly, const fq_ctx_t ctx) + void _fq_poly_normalise(fq_poly_t poly, const fq_ctx_t ctx) + void _fq_poly_normalise2(const fq_struct * poly, slong * length, const fq_ctx_t ctx) + void fq_poly_truncate(fq_poly_t poly, slong newlen, const fq_ctx_t ctx) + void fq_poly_set_trunc(fq_poly_t poly1, fq_poly_t poly2, slong newlen, const fq_ctx_t ctx) + void _fq_poly_reverse(fq_struct * output, const fq_struct * input, slong len, slong m, const fq_ctx_t ctx) + void fq_poly_reverse(fq_poly_t output, const fq_poly_t input, slong m, const fq_ctx_t ctx) + slong fq_poly_degree(const fq_poly_t poly, const fq_ctx_t ctx) + slong fq_poly_length(const fq_poly_t poly, const fq_ctx_t ctx) + fq_struct * fq_poly_lead(const fq_poly_t poly, const fq_ctx_t ctx) + void fq_poly_randtest(fq_poly_t f, flint_rand_t state, slong len, const fq_ctx_t ctx) + void fq_poly_randtest_not_zero(fq_poly_t f, flint_rand_t state, slong len, const fq_ctx_t ctx) + void fq_poly_randtest_monic(fq_poly_t f, flint_rand_t state, slong len, const fq_ctx_t ctx) + void fq_poly_randtest_irreducible(fq_poly_t f, flint_rand_t state, slong len, const fq_ctx_t ctx) + void _fq_poly_set(fq_struct * rop, const fq_struct * op, slong len, const fq_ctx_t ctx) + void fq_poly_set(fq_poly_t poly1, const fq_poly_t poly2, const fq_ctx_t ctx) + void fq_poly_set_fq(fq_poly_t poly, const fq_t c, const fq_ctx_t ctx) + void fq_poly_set_fmpz_mod_poly(fq_poly_t rop, const fmpz_mod_poly_t op, const fq_ctx_t ctx) + void fq_poly_set_nmod_poly(fq_poly_t rop, const nmod_poly_t op, const fq_ctx_t ctx) + void fq_poly_swap(fq_poly_t op1, fq_poly_t op2, const fq_ctx_t ctx) + void _fq_poly_zero(fq_struct * rop, slong len, const fq_ctx_t ctx) + void fq_poly_zero(fq_poly_t poly, const fq_ctx_t ctx) + void fq_poly_one(fq_poly_t poly, const fq_ctx_t ctx) + void fq_poly_gen(fq_poly_t poly, const fq_ctx_t ctx) + void fq_poly_make_monic(fq_poly_t rop, const fq_poly_t op, const fq_ctx_t ctx) + void _fq_poly_make_monic(fq_struct * rop, const fq_struct * op, slong length, const fq_ctx_t ctx) + void fq_poly_get_coeff(fq_t x, const fq_poly_t poly, slong n, const fq_ctx_t ctx) + void fq_poly_set_coeff(fq_poly_t poly, slong n, const fq_t x, const fq_ctx_t ctx) + void fq_poly_set_coeff_fmpz(fq_poly_t poly, slong n, const fmpz_t x, const fq_ctx_t ctx) + int fq_poly_equal(const fq_poly_t poly1, const fq_poly_t poly2, const fq_ctx_t ctx) + int fq_poly_equal_trunc(const fq_poly_t poly1, const fq_poly_t poly2, slong n, const fq_ctx_t ctx) + int fq_poly_is_zero(const fq_poly_t poly, const fq_ctx_t ctx) + int fq_poly_is_one(const fq_poly_t op, const fq_ctx_t ctx) + int fq_poly_is_gen(const fq_poly_t op, const fq_ctx_t ctx) + int fq_poly_is_unit(const fq_poly_t op, const fq_ctx_t ctx) + int fq_poly_equal_fq(const fq_poly_t poly, const fq_t c, const fq_ctx_t ctx) + void _fq_poly_add(fq_struct * res, const fq_struct * poly1, slong len1, const fq_struct * poly2, slong len2, const fq_ctx_t ctx) + void fq_poly_add(fq_poly_t res, const fq_poly_t poly1, const fq_poly_t poly2, const fq_ctx_t ctx) + void fq_poly_add_si(fq_poly_t res, const fq_poly_t poly1, slong c, const fq_ctx_t ctx) + void fq_poly_add_series(fq_poly_t res, const fq_poly_t poly1, const fq_poly_t poly2, slong n, const fq_ctx_t ctx) + void _fq_poly_sub(fq_struct * res, const fq_struct * poly1, slong len1, const fq_struct * poly2, slong len2, const fq_ctx_t ctx) + void fq_poly_sub(fq_poly_t res, const fq_poly_t poly1, const fq_poly_t poly2, const fq_ctx_t ctx) + void fq_poly_sub_series(fq_poly_t res, const fq_poly_t poly1, const fq_poly_t poly2, slong n, const fq_ctx_t ctx) + void _fq_poly_neg(fq_struct * rop, const fq_struct * op, slong len, const fq_ctx_t ctx) + void fq_poly_neg(fq_poly_t res, const fq_poly_t poly, const fq_ctx_t ctx) + void _fq_poly_scalar_mul_fq(fq_struct * rop, const fq_struct * op, slong len, const fq_t x, const fq_ctx_t ctx) + void fq_poly_scalar_mul_fq(fq_poly_t rop, const fq_poly_t op, const fq_t x, const fq_ctx_t ctx) + void _fq_poly_scalar_addmul_fq(fq_struct * rop, const fq_struct * op, slong len, const fq_t x, const fq_ctx_t ctx) + void fq_poly_scalar_addmul_fq(fq_poly_t rop, const fq_poly_t op, const fq_t x, const fq_ctx_t ctx) + void _fq_poly_scalar_submul_fq(fq_struct * rop, const fq_struct * op, slong len, const fq_t x, const fq_ctx_t ctx) + void fq_poly_scalar_submul_fq(fq_poly_t rop, const fq_poly_t op, const fq_t x, const fq_ctx_t ctx) + void _fq_poly_scalar_div_fq(fq_struct * rop, const fq_struct * op, slong len, const fq_t x, const fq_ctx_t ctx) + void fq_poly_scalar_div_fq(fq_poly_t rop, const fq_poly_t op, const fq_t x, const fq_ctx_t ctx) + void _fq_poly_mul_classical(fq_struct * rop, const fq_struct * op1, slong len1, const fq_struct * op2, slong len2, const fq_ctx_t ctx) + void fq_poly_mul_classical(fq_poly_t rop, const fq_poly_t op1, const fq_poly_t op2, const fq_ctx_t ctx) + void _fq_poly_mul_reorder(fq_struct * rop, const fq_struct * op1, slong len1, const fq_struct * op2, slong len2, const fq_ctx_t ctx) + void fq_poly_mul_reorder(fq_poly_t rop, const fq_poly_t op1, const fq_poly_t op2, const fq_ctx_t ctx) + void _fq_poly_mul_univariate(fq_struct * rop, const fq_struct * op1, slong len1, const fq_struct * op2, slong len2, const fq_ctx_t ctx) + void fq_poly_mul_univariate(fq_poly_t rop, const fq_poly_t op1, const fq_poly_t op2, const fq_ctx_t ctx) + void _fq_poly_mul_KS(fq_struct * rop, const fq_struct * op1, slong len1, const fq_struct * op2, slong len2, const fq_ctx_t ctx) + void fq_poly_mul_KS(fq_poly_t rop, const fq_poly_t op1, const fq_poly_t op2, const fq_ctx_t ctx) + void _fq_poly_mul(fq_struct * rop, const fq_struct * op1, slong len1, const fq_struct * op2, slong len2, const fq_ctx_t ctx) + void fq_poly_mul(fq_poly_t rop, const fq_poly_t op1, const fq_poly_t op2, const fq_ctx_t ctx) + void _fq_poly_mullow_classical(fq_struct * rop, const fq_struct * op1, slong len1, const fq_struct * op2, slong len2, slong n, const fq_ctx_t ctx) + void fq_poly_mullow_classical(fq_poly_t rop, const fq_poly_t op1, const fq_poly_t op2, slong n, const fq_ctx_t ctx) + void _fq_poly_mullow_univariate(fq_struct * rop, const fq_struct * op1, slong len1, const fq_struct * op2, slong len2, slong n, const fq_ctx_t ctx) + void fq_poly_mullow_univariate(fq_poly_t rop, const fq_poly_t op1, const fq_poly_t op2, slong n, const fq_ctx_t ctx) + void _fq_poly_mullow_KS(fq_struct * rop, const fq_struct * op1, slong len1, const fq_struct * op2, slong len2, slong n, const fq_ctx_t ctx) + void fq_poly_mullow_KS(fq_poly_t rop, const fq_poly_t op1, const fq_poly_t op2, slong n, const fq_ctx_t ctx) + void _fq_poly_mullow(fq_struct * rop, const fq_struct * op1, slong len1, const fq_struct * op2, slong len2, slong n, const fq_ctx_t ctx) + void fq_poly_mullow(fq_poly_t rop, const fq_poly_t op1, const fq_poly_t op2, slong n, const fq_ctx_t ctx) + void _fq_poly_mulhigh_classical(fq_struct * res, const fq_struct * poly1, slong len1, const fq_struct * poly2, slong len2, slong start, const fq_ctx_t ctx) + void fq_poly_mulhigh_classical(fq_poly_t res, const fq_poly_t poly1, const fq_poly_t poly2, slong start, const fq_ctx_t ctx) + void _fq_poly_mulhigh(fq_struct * res, const fq_struct * poly1, slong len1, const fq_struct * poly2, slong len2, slong start, fq_ctx_t ctx) + void fq_poly_mulhigh(fq_poly_t res, const fq_poly_t poly1, const fq_poly_t poly2, slong start, const fq_ctx_t ctx) + void _fq_poly_mulmod(fq_struct * res, const fq_struct * poly1, slong len1, const fq_struct * poly2, slong len2, const fq_struct * f, slong lenf, const fq_ctx_t ctx) + void fq_poly_mulmod(fq_poly_t res, const fq_poly_t poly1, const fq_poly_t poly2, const fq_poly_t f, const fq_ctx_t ctx) + void _fq_poly_mulmod_preinv(fq_struct * res, const fq_struct * poly1, slong len1, const fq_struct * poly2, slong len2, const fq_struct * f, slong lenf, const fq_struct * finv, slong lenfinv, const fq_ctx_t ctx) + void fq_poly_mulmod_preinv(fq_poly_t res, const fq_poly_t poly1, const fq_poly_t poly2, const fq_poly_t f, const fq_poly_t finv, const fq_ctx_t ctx) + void _fq_poly_sqr_classical(fq_struct * rop, const fq_struct * op, slong len, const fq_ctx_t ctx) + void fq_poly_sqr_classical(fq_poly_t rop, const fq_poly_t op, const fq_ctx_t ctx) + void _fq_poly_sqr_reorder(fq_struct * rop, const fq_struct * op, slong len, const fq_ctx_t ctx) + void fq_poly_sqr_reorder(fq_poly_t rop, const fq_poly_t op, const fq_ctx_t ctx) + void _fq_poly_sqr_KS(fq_struct * rop, const fq_struct * op, slong len, const fq_ctx_t ctx) + void fq_poly_sqr_KS(fq_poly_t rop, const fq_poly_t op, const fq_ctx_t ctx) + void _fq_poly_sqr(fq_struct * rop, const fq_struct * op, slong len, const fq_ctx_t ctx) + void fq_poly_sqr(fq_poly_t rop, const fq_poly_t op, const fq_ctx_t ctx) + void _fq_poly_pow(fq_struct * rop, const fq_struct * op, slong len, ulong e, const fq_ctx_t ctx) + void fq_poly_pow(fq_poly_t rop, const fq_poly_t op, ulong e, const fq_ctx_t ctx) + void _fq_poly_powmod_ui_binexp(fq_struct * res, const fq_struct * poly, ulong e, const fq_struct * f, slong lenf, const fq_ctx_t ctx) + void fq_poly_powmod_ui_binexp(fq_poly_t res, const fq_poly_t poly, ulong e, const fq_poly_t f, const fq_ctx_t ctx) + void _fq_poly_powmod_ui_binexp_preinv(fq_struct * res, const fq_struct * poly, ulong e, const fq_struct * f, slong lenf, const fq_struct * finv, slong lenfinv, const fq_ctx_t ctx) + void fq_poly_powmod_ui_binexp_preinv(fq_poly_t res, const fq_poly_t poly, ulong e, const fq_poly_t f, const fq_poly_t finv, const fq_ctx_t ctx) + void _fq_poly_powmod_fmpz_binexp(fq_struct * res, const fq_struct * poly, const fmpz_t e, const fq_struct * f, slong lenf, const fq_ctx_t ctx) + void fq_poly_powmod_fmpz_binexp(fq_poly_t res, const fq_poly_t poly, const fmpz_t e, const fq_poly_t f, const fq_ctx_t ctx) + void _fq_poly_powmod_fmpz_binexp_preinv(fq_struct * res, const fq_struct * poly, const fmpz_t e, const fq_struct * f, slong lenf, const fq_struct * finv, slong lenfinv, const fq_ctx_t ctx) + void fq_poly_powmod_fmpz_binexp_preinv(fq_poly_t res, const fq_poly_t poly, const fmpz_t e, const fq_poly_t f, const fq_poly_t finv, const fq_ctx_t ctx) + void _fq_poly_powmod_fmpz_sliding_preinv(fq_struct * res, const fq_struct * poly, const fmpz_t e, ulong k, const fq_struct * f, slong lenf, const fq_struct * finv, slong lenfinv, const fq_ctx_t ctx) + void fq_poly_powmod_fmpz_sliding_preinv(fq_poly_t res, const fq_poly_t poly, const fmpz_t e, ulong k, const fq_poly_t f, const fq_poly_t finv, const fq_ctx_t ctx) + void _fq_poly_powmod_x_fmpz_preinv(fq_struct * res, const fmpz_t e, const fq_struct * f, slong lenf, const fq_struct * finv, slong lenfinv, const fq_ctx_t ctx) + void fq_poly_powmod_x_fmpz_preinv(fq_poly_t res, const fmpz_t e, const fq_poly_t f, const fq_poly_t finv, const fq_ctx_t ctx) + void _fq_poly_pow_trunc_binexp(fq_struct * res, const fq_struct * poly, ulong e, slong trunc, const fq_ctx_t ctx) + void fq_poly_pow_trunc_binexp(fq_poly_t res, const fq_poly_t poly, ulong e, slong trunc, const fq_ctx_t ctx) + void _fq_poly_pow_trunc(fq_struct * res, const fq_struct * poly, ulong e, slong trunc, const fq_ctx_t mod) + void fq_poly_pow_trunc(fq_poly_t res, const fq_poly_t poly, ulong e, slong trunc, const fq_ctx_t ctx) + void _fq_poly_shift_left(fq_struct * rop, const fq_struct * op, slong len, slong n, const fq_ctx_t ctx) + void fq_poly_shift_left(fq_poly_t rop, const fq_poly_t op, slong n, const fq_ctx_t ctx) + void _fq_poly_shift_right(fq_struct * rop, const fq_struct * op, slong len, slong n, const fq_ctx_t ctx) + void fq_poly_shift_right(fq_poly_t rop, const fq_poly_t op, slong n, const fq_ctx_t ctx) + slong _fq_poly_hamming_weight(const fq_struct * op, slong len, const fq_ctx_t ctx) + slong fq_poly_hamming_weight(const fq_poly_t op, const fq_ctx_t ctx) + void _fq_poly_divrem(fq_struct * Q, fq_struct * R, const fq_struct * A, slong lenA, const fq_struct * B, slong lenB, const fq_t invB, const fq_ctx_t ctx) + void fq_poly_divrem(fq_poly_t Q, fq_poly_t R, const fq_poly_t A, const fq_poly_t B, const fq_ctx_t ctx) + void fq_poly_divrem_f(fq_t f, fq_poly_t Q, fq_poly_t R, const fq_poly_t A, const fq_poly_t B, const fq_ctx_t ctx) + void _fq_poly_rem(fq_struct * R, const fq_struct * A, slong lenA, const fq_struct * B, slong lenB, const fq_t invB, const fq_ctx_t ctx) + void fq_poly_rem(fq_poly_t R, const fq_poly_t A, const fq_poly_t B, const fq_ctx_t ctx) + void _fq_poly_div(fq_struct * Q, const fq_struct * A, slong lenA, const fq_struct * B, slong lenB, const fq_t invB, const fq_ctx_t ctx) + void fq_poly_div(fq_poly_t Q, const fq_poly_t A, const fq_poly_t B, const fq_ctx_t ctx) + void _fq_poly_div_newton_n_preinv(fq_struct * Q, const fq_struct * A, slong lenA, const fq_struct * B, slong lenB, const fq_struct * Binv, slong lenBinv, const fq_ctx_t ctx) + void fq_poly_div_newton_n_preinv(fq_poly_t Q, const fq_poly_t A, const fq_poly_t B, const fq_poly_t Binv, const fq_ctx_t ctx) + void _fq_poly_divrem_newton_n_preinv(fq_struct * Q, fq_struct * R, const fq_struct * A, slong lenA, const fq_struct * B, slong lenB, const fq_struct * Binv, slong lenBinv, const fq_ctx_t ctx) + void fq_poly_divrem_newton_n_preinv(fq_poly_t Q, fq_poly_t R, const fq_poly_t A, const fq_poly_t B, const fq_poly_t Binv, const fq_ctx_t ctx) + void _fq_poly_inv_series_newton(fq_struct * Qinv, const fq_struct * Q, slong n, const fq_t cinv, const fq_ctx_t ctx) + void fq_poly_inv_series_newton(fq_poly_t Qinv, const fq_poly_t Q, slong n, const fq_ctx_t ctx) + void _fq_poly_inv_series(fq_struct * Qinv, const fq_struct * Q, slong n, const fq_t cinv, const fq_ctx_t ctx) + void fq_poly_inv_series(fq_poly_t Qinv, const fq_poly_t Q, slong n, const fq_ctx_t ctx) + void _fq_poly_div_series(fq_struct * Q, const fq_struct * A, slong Alen, const fq_struct * B, slong Blen, slong n, const fq_ctx_t ctx) + void fq_poly_div_series(fq_poly_t Q, const fq_poly_t A, const fq_poly_t B, slong n, const fq_ctx_t ctx) + void fq_poly_gcd(fq_poly_t rop, const fq_poly_t op1, const fq_poly_t op2, const fq_ctx_t ctx) + slong _fq_poly_gcd(fq_struct * G, const fq_struct * A, slong lenA, const fq_struct * B, slong lenB, const fq_ctx_t ctx) + slong _fq_poly_gcd_euclidean_f(fq_t f, fq_struct * G, const fq_struct * A, slong lenA, const fq_struct * B, slong lenB, const fq_ctx_t ctx) + void fq_poly_gcd_euclidean_f(fq_t f, fq_poly_t G, const fq_poly_t A, const fq_poly_t B, const fq_ctx_t ctx) + slong _fq_poly_xgcd(fq_struct * G, fq_struct * S, fq_struct * T, const fq_struct * A, slong lenA, const fq_struct * B, slong lenB, const fq_ctx_t ctx) + void fq_poly_xgcd(fq_poly_t G, fq_poly_t S, fq_poly_t T, const fq_poly_t A, const fq_poly_t B, const fq_ctx_t ctx) + slong _fq_poly_xgcd_euclidean_f(fq_t f, fq_struct * G, fq_struct * S, fq_struct * T, const fq_struct * A, slong lenA, const fq_struct * B, slong lenB, const fq_ctx_t ctx) + void fq_poly_xgcd_euclidean_f(fq_t f, fq_poly_t G, fq_poly_t S, fq_poly_t T, const fq_poly_t A, const fq_poly_t B, const fq_ctx_t ctx) + int _fq_poly_divides(fq_struct * Q, const fq_struct * A, slong lenA, const fq_struct * B, slong lenB, const fq_t invB, const fq_ctx_t ctx) + int fq_poly_divides(fq_poly_t Q, const fq_poly_t A, const fq_poly_t B, const fq_ctx_t ctx) + void _fq_poly_derivative(fq_struct * rop, const fq_struct * op, slong len, const fq_ctx_t ctx) + void fq_poly_derivative(fq_poly_t rop, const fq_poly_t op, const fq_ctx_t ctx) + void _fq_poly_invsqrt_series(fq_struct * g, const fq_struct * h, slong n, fq_ctx_t mod) + void fq_poly_invsqrt_series(fq_poly_t g, const fq_poly_t h, slong n, fq_ctx_t ctx) + void _fq_poly_sqrt_series(fq_struct * g, const fq_struct * h, slong n, fq_ctx_t ctx) + void fq_poly_sqrt_series(fq_poly_t g, const fq_poly_t h, slong n, fq_ctx_t ctx) + int _fq_poly_sqrt(fq_struct * s, const fq_struct * p, slong n, fq_ctx_t mod) + int fq_poly_sqrt(fq_poly_t s, const fq_poly_t p, fq_ctx_t mod) + void _fq_poly_evaluate_fq(fq_t rop, const fq_struct * op, slong len, const fq_t a, const fq_ctx_t ctx) + void fq_poly_evaluate_fq(fq_t rop, const fq_poly_t f, const fq_t a, const fq_ctx_t ctx) + void _fq_poly_compose(fq_struct * rop, const fq_struct * op1, slong len1, const fq_struct * op2, slong len2, const fq_ctx_t ctx) + void fq_poly_compose(fq_poly_t rop, const fq_poly_t op1, const fq_poly_t op2, const fq_ctx_t ctx) + void _fq_poly_compose_mod_horner(fq_struct * res, const fq_struct * f, slong lenf, const fq_struct * g, const fq_struct * h, slong lenh, const fq_ctx_t ctx) + void fq_poly_compose_mod_horner(fq_poly_t res, const fq_poly_t f, const fq_poly_t g, const fq_poly_t h, const fq_ctx_t ctx) + void _fq_poly_compose_mod_horner_preinv(fq_struct * res, const fq_struct * f, slong lenf, const fq_struct * g, const fq_struct * h, slong lenh, const fq_struct * hinv, slong lenhiv, const fq_ctx_t ctx) + void fq_poly_compose_mod_horner_preinv(fq_poly_t res, const fq_poly_t f, const fq_poly_t g, const fq_poly_t h, const fq_poly_t hinv, const fq_ctx_t ctx) + void _fq_poly_compose_mod_brent_kung(fq_struct * res, const fq_struct * f, slong lenf, const fq_struct * g, const fq_struct * h, slong lenh, const fq_ctx_t ctx) + void fq_poly_compose_mod_brent_kung(fq_poly_t res, const fq_poly_t f, const fq_poly_t g, const fq_poly_t h, const fq_ctx_t ctx) + void _fq_poly_compose_mod_brent_kung_preinv(fq_struct * res, const fq_struct * f, slong lenf, const fq_struct * g, const fq_struct * h, slong lenh, const fq_struct * hinv, slong lenhiv, const fq_ctx_t ctx) + void fq_poly_compose_mod_brent_kung_preinv(fq_poly_t res, const fq_poly_t f, const fq_poly_t g, const fq_poly_t h, const fq_poly_t hinv, const fq_ctx_t ctx) + void _fq_poly_compose_mod(fq_struct * res, const fq_struct * f, slong lenf, const fq_struct * g, const fq_struct * h, slong lenh, const fq_ctx_t ctx) + void fq_poly_compose_mod(fq_poly_t res, const fq_poly_t f, const fq_poly_t g, const fq_poly_t h, const fq_ctx_t ctx) + void _fq_poly_compose_mod_preinv(fq_struct * res, const fq_struct * f, slong lenf, const fq_struct * g, const fq_struct * h, slong lenh, const fq_struct * hinv, slong lenhiv, const fq_ctx_t ctx) + void fq_poly_compose_mod_preinv(fq_poly_t res, const fq_poly_t f, const fq_poly_t g, const fq_poly_t h, const fq_poly_t hinv, const fq_ctx_t ctx) + void _fq_poly_reduce_matrix_mod_poly (fq_mat_t A, const fq_mat_t B, const fq_poly_t f, const fq_ctx_t ctx) + void _fq_poly_precompute_matrix (fq_mat_t A, const fq_struct * f, const fq_struct * g, slong leng, const fq_struct * ginv, slong lenginv, const fq_ctx_t ctx) + void fq_poly_precompute_matrix (fq_mat_t A, const fq_poly_t f, const fq_poly_t g, const fq_poly_t ginv, const fq_ctx_t ctx) + void _fq_poly_compose_mod_brent_kung_precomp_preinv(fq_struct * res, const fq_struct * f, slong lenf, const fq_mat_t A, const fq_struct * h, slong lenh, const fq_struct * hinv, slong lenhinv, const fq_ctx_t ctx) + void fq_poly_compose_mod_brent_kung_precomp_preinv(fq_poly_t res, const fq_poly_t f, const fq_mat_t A, const fq_poly_t h, const fq_poly_t hinv, const fq_ctx_t ctx) + # int _fq_poly_fprint_pretty(FILE * file, const fq_struct * poly, slong len, const char * x, const fq_ctx_t ctx) + # int fq_poly_fprint_pretty(FILE * file, const fq_poly_t poly, const char * x, const fq_ctx_t ctx) + int _fq_poly_print_pretty(const fq_struct * poly, slong len, const char * x, const fq_ctx_t ctx) + int fq_poly_print_pretty(const fq_poly_t poly, const char * x, const fq_ctx_t ctx) + # int _fq_poly_fprint(FILE * file, const fq_struct * poly, slong len, const fq_ctx_t ctx) + # int fq_poly_fprint(FILE * file, const fq_poly_t poly, const fq_ctx_t ctx) + int _fq_poly_print(const fq_struct * poly, slong len, const fq_ctx_t ctx) + int fq_poly_print(const fq_poly_t poly, const fq_ctx_t ctx) + char * _fq_poly_get_str(const fq_struct * poly, slong len, const fq_ctx_t ctx) + char * fq_poly_get_str(const fq_poly_t poly, const fq_ctx_t ctx) + char * _fq_poly_get_str_pretty(const fq_struct * poly, slong len, const char * x, const fq_ctx_t ctx) + char * fq_poly_get_str_pretty(const fq_poly_t poly, const char * x, const fq_ctx_t ctx) + void fq_poly_inflate(fq_poly_t result, const fq_poly_t input, ulong inflation, const fq_ctx_t ctx) + void fq_poly_deflate(fq_poly_t result, const fq_poly_t input, ulong deflation, const fq_ctx_t ctx) + ulong fq_poly_deflation(const fq_poly_t input, const fq_ctx_t ctx) diff --git a/src/flint/flintlib/fq_poly_factor.pxd b/src/flint/flintlib/fq_poly_factor.pxd new file mode 100644 index 00000000..e51761a9 --- /dev/null +++ b/src/flint/flintlib/fq_poly_factor.pxd @@ -0,0 +1,45 @@ +from flint.flintlib.flint cimport ulong, slong, flint_rand_t +from flint.flintlib.fq cimport fq_t, fq_struct, fq_ctx_t +from flint.flintlib.fq cimport fq_poly_struct, fq_poly_t + + +cdef extern from "flint/fq_poly_factor.h": + # Type definitions **********************************************/ + ctypedef struct fq_poly_factor_struct: + fq_poly_struct * poly + slong * exp + slong num + slong alloc + ctypedef fq_poly_factor_struct fq_poly_factor_t[1] + + # Parsed from here **********************************************/ + void fq_poly_factor_init(fq_poly_factor_t fac, const fq_ctx_t ctx) + void fq_poly_factor_clear(fq_poly_factor_t fac, const fq_ctx_t ctx) + void fq_poly_factor_realloc(fq_poly_factor_t fac, slong alloc, const fq_ctx_t ctx) + void fq_poly_factor_fit_length(fq_poly_factor_t fac, slong len, const fq_ctx_t ctx) + void fq_poly_factor_set(fq_poly_factor_t res, const fq_poly_factor_t fac, const fq_ctx_t ctx) + void fq_poly_factor_print_pretty(const fq_poly_factor_t fac, const char * var, const fq_ctx_t ctx) + void fq_poly_factor_print(const fq_poly_factor_t fac, const fq_ctx_t ctx) + void fq_poly_factor_insert(fq_poly_factor_t fac, const fq_poly_t poly, slong exp, const fq_ctx_t ctx) + void fq_poly_factor_concat(fq_poly_factor_t res, const fq_poly_factor_t fac, const fq_ctx_t ctx) + void fq_poly_factor_pow(fq_poly_factor_t fac, slong exp, const fq_ctx_t ctx) + ulong fq_poly_remove(fq_poly_t f, const fq_poly_t p, const fq_ctx_t ctx) + int fq_poly_is_irreducible(const fq_poly_t f, const fq_ctx_t ctx) + int fq_poly_is_irreducible_ddf(const fq_poly_t f, const fq_ctx_t ctx) + int fq_poly_is_irreducible_ben_or(const fq_poly_t f, const fq_ctx_t ctx) + int _fq_poly_is_squarefree(const fq_struct * f, slong len, const fq_ctx_t ctx) + int fq_poly_is_squarefree(const fq_poly_t f, const fq_ctx_t ctx) + int fq_poly_factor_equal_deg_prob(fq_poly_t factor, flint_rand_t state, const fq_poly_t pol, slong d, const fq_ctx_t ctx) + void fq_poly_factor_equal_deg(fq_poly_factor_t factors, const fq_poly_t pol, slong d, const fq_ctx_t ctx) + void fq_poly_factor_split_single(fq_poly_t linfactor, const fq_poly_t input, const fq_ctx_t ctx) + void fq_poly_factor_distinct_deg(fq_poly_factor_t res, const fq_poly_t poly, slong * const * degs, const fq_ctx_t ctx) + void fq_poly_factor_squarefree(fq_poly_factor_t res, const fq_poly_t f, const fq_ctx_t ctx) + void fq_poly_factor(fq_poly_factor_t res, fq_t lead, const fq_poly_t f, const fq_ctx_t ctx) + void fq_poly_factor_cantor_zassenhaus(fq_poly_factor_t res, const fq_poly_t f, const fq_ctx_t ctx) + void fq_poly_factor_kaltofen_shoup(fq_poly_factor_t res, const fq_poly_t poly, const fq_ctx_t ctx) + void fq_poly_factor_berlekamp(fq_poly_factor_t factors, const fq_poly_t f, const fq_ctx_t ctx) + void fq_poly_factor_with_berlekamp(fq_poly_factor_t res, fq_t leading_coeff, const fq_poly_t f, const fq_ctx_t ctx) + void fq_poly_factor_with_cantor_zassenhaus(fq_poly_factor_t res, fq_t leading_coeff, const fq_poly_t f, const fq_ctx_t ctx) + void fq_poly_factor_with_kaltofen_shoup(fq_poly_factor_t res, fq_t leading_coeff, const fq_poly_t f, const fq_ctx_t ctx) + void fq_poly_iterated_frobenius_preinv(fq_poly_t * rop, slong n, const fq_poly_t v, const fq_poly_t vinv, const fq_ctx_t ctx) + void fq_poly_roots(fq_poly_factor_t r, const fq_poly_t f, int with_multiplicity, const fq_ctx_t ctx) diff --git a/src/flint/flintlib/fq_zech.pxd b/src/flint/flintlib/fq_zech.pxd index 531536ee..8b20aef3 100644 --- a/src/flint/flintlib/fq_zech.pxd +++ b/src/flint/flintlib/fq_zech.pxd @@ -6,6 +6,7 @@ from flint.flintlib.fq_nmod cimport fq_nmod_t, fq_nmod_ctx_t, fq_nmod_ctx_struct cdef extern from "flint/fq_zech.h": + # Type definitions **********************************************/ ctypedef struct fq_zech_struct: mp_limb_t value ctypedef fq_zech_struct fq_zech_t[1] @@ -26,7 +27,20 @@ cdef extern from "flint/fq_zech.h": int is_conway # whether field was generated using Flint Conway tables (assures primitivity) ctypedef fq_zech_ctx_struct fq_zech_ctx_t[1] - # PArsed from here + ctypedef struct fq_zech_mat_struct: + fq_zech_struct * entries + slong r + slong s + fq_zech_struct ** rows + ctypedef fq_zech_mat_struct fq_zech_mat_t[1] + + ctypedef struct fq_zech_poly_struct: + fq_zech_struct * coeffs + slong alloc + slong length + ctypedef fq_zech_poly_struct fq_zech_poly_t[1] + + # Parsed from here **********************************************/ void fq_zech_ctx_init(fq_zech_ctx_t ctx, const fmpz_t p, slong d, const char *var) int _fq_zech_ctx_init_conway(fq_zech_ctx_t ctx, const fmpz_t p, slong d, const char *var) void fq_zech_ctx_init_conway(fq_zech_ctx_t ctx, const fmpz_t p, slong d, const char *var) diff --git a/src/flint/flintlib/fq_zech_mat.pxd b/src/flint/flintlib/fq_zech_mat.pxd new file mode 100644 index 00000000..ea840072 --- /dev/null +++ b/src/flint/flintlib/fq_zech_mat.pxd @@ -0,0 +1,68 @@ +from flint.flintlib.fmpz_mod_mat cimport fmpz_mod_mat_t +from flint.flintlib.flint cimport slong, flint_rand_t +from flint.flintlib.nmod_mat cimport nmod_mat_t +from flint.flintlib.fq_zech cimport fq_zech_t, fq_zech_struct, fq_zech_ctx_t, fq_zech_mat_t, fq_zech_poly_t + +cdef extern from "flint/fq_zech_mat.h": + # Parsed from here **********************************************/ + void fq_zech_mat_init(fq_zech_mat_t mat, slong rows, slong cols, const fq_zech_ctx_t ctx) + void fq_zech_mat_init_set(fq_zech_mat_t mat, const fq_zech_mat_t src, const fq_zech_ctx_t ctx) + void fq_zech_mat_clear(fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + void fq_zech_mat_set(fq_zech_mat_t mat, const fq_zech_mat_t src, const fq_zech_ctx_t ctx) + fq_zech_struct * fq_zech_mat_entry(const fq_zech_mat_t mat, slong i, slong j) + void fq_zech_mat_entry_set(fq_zech_mat_t mat, slong i, slong j, const fq_zech_t x, const fq_zech_ctx_t ctx) + slong fq_zech_mat_nrows(const fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + slong fq_zech_mat_ncols(const fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + void fq_zech_mat_swap(fq_zech_mat_t mat1, fq_zech_mat_t mat2, const fq_zech_ctx_t ctx) + void fq_zech_mat_swap_entrywise(fq_zech_mat_t mat1, fq_zech_mat_t mat2, const fq_zech_ctx_t ctx) + void fq_zech_mat_zero(fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + void fq_zech_mat_one(fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + void fq_zech_mat_set_nmod_mat(fq_zech_mat_t mat1, const nmod_mat_t mat2, const fq_zech_ctx_t ctx) + void fq_zech_mat_set_fmpz_mod_mat(fq_zech_mat_t mat1, const fmpz_mod_mat_t mat2, const fq_zech_ctx_t ctx) + void fq_zech_mat_concat_vertical(fq_zech_mat_t res, const fq_zech_mat_t mat1, const fq_zech_mat_t mat2, const fq_zech_ctx_t ctx) + void fq_zech_mat_concat_horizontal(fq_zech_mat_t res, const fq_zech_mat_t mat1, const fq_zech_mat_t mat2, const fq_zech_ctx_t ctx) + int fq_zech_mat_print_pretty(const fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + # int fq_zech_mat_fprint_pretty(FILE * file, const fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + int fq_zech_mat_print(const fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + # int fq_zech_mat_fprint(FILE * file, const fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + void fq_zech_mat_window_init(fq_zech_mat_t window, const fq_zech_mat_t mat, slong r1, slong c1, slong r2, slong c2, const fq_zech_ctx_t ctx) + void fq_zech_mat_window_clear(fq_zech_mat_t window, const fq_zech_ctx_t ctx) + void fq_zech_mat_randtest(fq_zech_mat_t mat, flint_rand_t state, const fq_zech_ctx_t ctx) + int fq_zech_mat_randpermdiag(fq_zech_mat_t mat, flint_rand_t state, fq_zech_struct * diag, slong n, const fq_zech_ctx_t ctx) + void fq_zech_mat_randrank(fq_zech_mat_t mat, flint_rand_t state, slong rank, const fq_zech_ctx_t ctx) + void fq_zech_mat_randops(fq_zech_mat_t mat, flint_rand_t state, slong count, const fq_zech_ctx_t ctx) + void fq_zech_mat_randtril(fq_zech_mat_t mat, flint_rand_t state, int unit, const fq_zech_ctx_t ctx) + void fq_zech_mat_randtriu(fq_zech_mat_t mat, flint_rand_t state, int unit, const fq_zech_ctx_t ctx) + int fq_zech_mat_equal(const fq_zech_mat_t mat1, const fq_zech_mat_t mat2, const fq_zech_ctx_t ctx) + int fq_zech_mat_is_zero(const fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + int fq_zech_mat_is_one(const fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + int fq_zech_mat_is_empty(const fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + int fq_zech_mat_is_square(const fq_zech_mat_t mat, const fq_zech_ctx_t ctx) + void fq_zech_mat_add(fq_zech_mat_t C, const fq_zech_mat_t A, const fq_zech_mat_t B, const fq_zech_ctx_t ctx) + void fq_zech_mat_sub(fq_zech_mat_t C, const fq_zech_mat_t A, const fq_zech_mat_t B, const fq_zech_ctx_t ctx) + void fq_zech_mat_neg(fq_zech_mat_t A, const fq_zech_mat_t B, const fq_zech_ctx_t ctx) + void fq_zech_mat_mul(fq_zech_mat_t C, const fq_zech_mat_t A, const fq_zech_mat_t B, const fq_zech_ctx_t ctx) + void fq_zech_mat_mul_classical(fq_zech_mat_t C, const fq_zech_mat_t A, const fq_zech_mat_t B, const fq_zech_ctx_t ctx) + void fq_zech_mat_mul_KS(fq_zech_mat_t C, const fq_zech_mat_t A, const fq_zech_mat_t B, const fq_zech_ctx_t ctx) + void fq_zech_mat_submul(fq_zech_mat_t D, const fq_zech_mat_t C, const fq_zech_mat_t A, const fq_zech_mat_t B, const fq_zech_ctx_t ctx) + void fq_zech_mat_mul_vec(fq_zech_struct * c, const fq_zech_mat_t A, const fq_zech_struct * b, slong blen, const fq_zech_ctx_t ctx) + void fq_zech_mat_mul_vec_ptr(fq_zech_struct * const * c, const fq_zech_mat_t A, const fq_zech_struct * const * b, slong blen, const fq_zech_ctx_t ctx) + void fq_zech_mat_vec_mul(fq_zech_struct * c, const fq_zech_struct * a, slong alen, const fq_zech_mat_t B, const fq_zech_ctx_t ctx) + void fq_zech_mat_vec_mul_ptr(fq_zech_struct * const * c, const fq_zech_struct * const * a, slong alen, const fq_zech_mat_t B, const fq_zech_ctx_t ctx) + slong fq_zech_mat_lu(slong * P, fq_zech_mat_t A, int rank_check, const fq_zech_ctx_t ctx) + slong fq_zech_mat_lu_classical(slong * P, fq_zech_mat_t A, int rank_check, const fq_zech_ctx_t ctx) + slong fq_zech_mat_lu_recursive(slong * P, fq_zech_mat_t A, int rank_check, const fq_zech_ctx_t ctx) + slong fq_zech_mat_rref(fq_zech_mat_t B, const fq_zech_mat_t A, const fq_zech_ctx_t ctx) + slong fq_zech_mat_reduce_row(fq_zech_mat_t A, slong * P, slong * L, slong n, const fq_zech_ctx_t ctx) + void fq_zech_mat_solve_tril(fq_zech_mat_t X, const fq_zech_mat_t L, const fq_zech_mat_t B, int unit, const fq_zech_ctx_t ctx) + void fq_zech_mat_solve_tril_classical(fq_zech_mat_t X, const fq_zech_mat_t L, const fq_zech_mat_t B, int unit, const fq_zech_ctx_t ctx) + void fq_zech_mat_solve_tril_recursive(fq_zech_mat_t X, const fq_zech_mat_t L, const fq_zech_mat_t B, int unit, const fq_zech_ctx_t ctx) + void fq_zech_mat_solve_triu(fq_zech_mat_t X, const fq_zech_mat_t U, const fq_zech_mat_t B, int unit, const fq_zech_ctx_t ctx) + void fq_zech_mat_solve_triu_classical(fq_zech_mat_t X, const fq_zech_mat_t U, const fq_zech_mat_t B, int unit, const fq_zech_ctx_t ctx) + void fq_zech_mat_solve_triu_recursive(fq_zech_mat_t X, const fq_zech_mat_t U, const fq_zech_mat_t B, int unit, const fq_zech_ctx_t ctx) + int fq_zech_mat_solve(fq_zech_mat_t X, const fq_zech_mat_t A, const fq_zech_mat_t B, const fq_zech_ctx_t ctx) + int fq_zech_mat_can_solve(fq_zech_mat_t X, const fq_zech_mat_t A, const fq_zech_mat_t B, const fq_zech_ctx_t ctx) + void fq_zech_mat_similarity(fq_zech_mat_t M, slong r, fq_zech_t d, const fq_zech_ctx_t ctx) + void fq_zech_mat_charpoly_danilevsky(fq_zech_poly_t p, const fq_zech_mat_t M, const fq_zech_ctx_t ctx) + void fq_zech_mat_charpoly(fq_zech_poly_t p, const fq_zech_mat_t M, const fq_zech_ctx_t ctx) + void fq_zech_mat_minpoly(fq_zech_poly_t p, const fq_zech_mat_t M, const fq_zech_ctx_t ctx) diff --git a/src/flint/flintlib/fq_zech_poly.pxd b/src/flint/flintlib/fq_zech_poly.pxd new file mode 100644 index 00000000..4a88a150 --- /dev/null +++ b/src/flint/flintlib/fq_zech_poly.pxd @@ -0,0 +1,189 @@ +from flint.flintlib.fmpz_mod_poly cimport fmpz_mod_poly_t +from flint.flintlib.flint cimport flint_rand_t, slong, ulong +from flint.flintlib.nmod_poly cimport nmod_poly_t +from flint.flintlib.fmpz cimport fmpz_t +from flint.flintlib.fq_zech cimport fq_zech_struct, fq_zech_t, fq_zech_ctx_t, fq_zech_mat_t, fq_zech_poly_t + +cdef extern from "flint/fq_zech_poly.h": + # Parsed from here **********************************************/ + void fq_zech_poly_init(fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + void fq_zech_poly_init2(fq_zech_poly_t poly, slong alloc, const fq_zech_ctx_t ctx) + void fq_zech_poly_realloc(fq_zech_poly_t poly, slong alloc, const fq_zech_ctx_t ctx) + void fq_zech_poly_fit_length(fq_zech_poly_t poly, slong len, const fq_zech_ctx_t ctx) + void _fq_zech_poly_set_length(fq_zech_poly_t poly, slong newlen, const fq_zech_ctx_t ctx) + void fq_zech_poly_clear(fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + void _fq_zech_poly_normalise(fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + void _fq_zech_poly_normalise2(const fq_zech_struct * poly, slong * length, const fq_zech_ctx_t ctx) + void fq_zech_poly_truncate(fq_zech_poly_t poly, slong newlen, const fq_zech_ctx_t ctx) + void fq_zech_poly_set_trunc(fq_zech_poly_t poly1, fq_zech_poly_t poly2, slong newlen, const fq_zech_ctx_t ctx) + void _fq_zech_poly_reverse(fq_zech_struct * output, const fq_zech_struct * input, slong len, slong m, const fq_zech_ctx_t ctx) + void fq_zech_poly_reverse(fq_zech_poly_t output, const fq_zech_poly_t input, slong m, const fq_zech_ctx_t ctx) + slong fq_zech_poly_degree(const fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + slong fq_zech_poly_length(const fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + fq_zech_struct * fq_zech_poly_lead(const fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + void fq_zech_poly_randtest(fq_zech_poly_t f, flint_rand_t state, slong len, const fq_zech_ctx_t ctx) + void fq_zech_poly_randtest_not_zero(fq_zech_poly_t f, flint_rand_t state, slong len, const fq_zech_ctx_t ctx) + void fq_zech_poly_randtest_monic(fq_zech_poly_t f, flint_rand_t state, slong len, const fq_zech_ctx_t ctx) + void fq_zech_poly_randtest_irreducible(fq_zech_poly_t f, flint_rand_t state, slong len, const fq_zech_ctx_t ctx) + void _fq_zech_poly_set(fq_zech_struct * rop, const fq_zech_struct * op, slong len, const fq_zech_ctx_t ctx) + void fq_zech_poly_set(fq_zech_poly_t poly1, const fq_zech_poly_t poly2, const fq_zech_ctx_t ctx) + void fq_zech_poly_set_fq_zech(fq_zech_poly_t poly, const fq_zech_t c, const fq_zech_ctx_t ctx) + void fq_zech_poly_set_fmpz_mod_poly(fq_zech_poly_t rop, const fmpz_mod_poly_t op, const fq_zech_ctx_t ctx) + void fq_zech_poly_set_nmod_poly(fq_zech_poly_t rop, const nmod_poly_t op, const fq_zech_ctx_t ctx) + void fq_zech_poly_swap(fq_zech_poly_t op1, fq_zech_poly_t op2, const fq_zech_ctx_t ctx) + void _fq_zech_poly_zero(fq_zech_struct * rop, slong len, const fq_zech_ctx_t ctx) + void fq_zech_poly_zero(fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + void fq_zech_poly_one(fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + void fq_zech_poly_gen(fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + void fq_zech_poly_make_monic(fq_zech_poly_t rop, const fq_zech_poly_t op, const fq_zech_ctx_t ctx) + void _fq_zech_poly_make_monic(fq_zech_struct * rop, const fq_zech_struct * op, slong length, const fq_zech_ctx_t ctx) + void fq_zech_poly_get_coeff(fq_zech_t x, const fq_zech_poly_t poly, slong n, const fq_zech_ctx_t ctx) + void fq_zech_poly_set_coeff(fq_zech_poly_t poly, slong n, const fq_zech_t x, const fq_zech_ctx_t ctx) + void fq_zech_poly_set_coeff_fmpz(fq_zech_poly_t poly, slong n, const fmpz_t x, const fq_zech_ctx_t ctx) + int fq_zech_poly_equal(const fq_zech_poly_t poly1, const fq_zech_poly_t poly2, const fq_zech_ctx_t ctx) + int fq_zech_poly_equal_trunc(const fq_zech_poly_t poly1, const fq_zech_poly_t poly2, slong n, const fq_zech_ctx_t ctx) + int fq_zech_poly_is_zero(const fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + int fq_zech_poly_is_one(const fq_zech_poly_t op, const fq_zech_ctx_t ctx) + int fq_zech_poly_is_gen(const fq_zech_poly_t op, const fq_zech_ctx_t ctx) + int fq_zech_poly_is_unit(const fq_zech_poly_t op, const fq_zech_ctx_t ctx) + int fq_zech_poly_equal_fq_zech(const fq_zech_poly_t poly, const fq_zech_t c, const fq_zech_ctx_t ctx) + void _fq_zech_poly_add(fq_zech_struct * res, const fq_zech_struct * poly1, slong len1, const fq_zech_struct * poly2, slong len2, const fq_zech_ctx_t ctx) + void fq_zech_poly_add(fq_zech_poly_t res, const fq_zech_poly_t poly1, const fq_zech_poly_t poly2, const fq_zech_ctx_t ctx) + void fq_zech_poly_add_si(fq_zech_poly_t res, const fq_zech_poly_t poly1, slong c, const fq_zech_ctx_t ctx) + void fq_zech_poly_add_series(fq_zech_poly_t res, const fq_zech_poly_t poly1, const fq_zech_poly_t poly2, slong n, const fq_zech_ctx_t ctx) + void _fq_zech_poly_sub(fq_zech_struct * res, const fq_zech_struct * poly1, slong len1, const fq_zech_struct * poly2, slong len2, const fq_zech_ctx_t ctx) + void fq_zech_poly_sub(fq_zech_poly_t res, const fq_zech_poly_t poly1, const fq_zech_poly_t poly2, const fq_zech_ctx_t ctx) + void fq_zech_poly_sub_series(fq_zech_poly_t res, const fq_zech_poly_t poly1, const fq_zech_poly_t poly2, slong n, const fq_zech_ctx_t ctx) + void _fq_zech_poly_neg(fq_zech_struct * rop, const fq_zech_struct * op, slong len, const fq_zech_ctx_t ctx) + void fq_zech_poly_neg(fq_zech_poly_t res, const fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + void _fq_zech_poly_scalar_mul_fq_zech(fq_zech_struct * rop, const fq_zech_struct * op, slong len, const fq_zech_t x, const fq_zech_ctx_t ctx) + void fq_zech_poly_scalar_mul_fq_zech(fq_zech_poly_t rop, const fq_zech_poly_t op, const fq_zech_t x, const fq_zech_ctx_t ctx) + void _fq_zech_poly_scalar_addmul_fq_zech(fq_zech_struct * rop, const fq_zech_struct * op, slong len, const fq_zech_t x, const fq_zech_ctx_t ctx) + void fq_zech_poly_scalar_addmul_fq_zech(fq_zech_poly_t rop, const fq_zech_poly_t op, const fq_zech_t x, const fq_zech_ctx_t ctx) + void _fq_zech_poly_scalar_submul_fq_zech(fq_zech_struct * rop, const fq_zech_struct * op, slong len, const fq_zech_t x, const fq_zech_ctx_t ctx) + void fq_zech_poly_scalar_submul_fq_zech(fq_zech_poly_t rop, const fq_zech_poly_t op, const fq_zech_t x, const fq_zech_ctx_t ctx) + void _fq_zech_poly_scalar_div_fq_zech(fq_zech_struct * rop, const fq_zech_struct * op, slong len, const fq_zech_t x, const fq_zech_ctx_t ctx) + void fq_zech_poly_scalar_div_fq_zech(fq_zech_poly_t rop, const fq_zech_poly_t op, const fq_zech_t x, const fq_zech_ctx_t ctx) + void _fq_zech_poly_mul_classical(fq_zech_struct * rop, const fq_zech_struct * op1, slong len1, const fq_zech_struct * op2, slong len2, const fq_zech_ctx_t ctx) + void fq_zech_poly_mul_classical(fq_zech_poly_t rop, const fq_zech_poly_t op1, const fq_zech_poly_t op2, const fq_zech_ctx_t ctx) + void _fq_zech_poly_mul_reorder(fq_zech_struct * rop, const fq_zech_struct * op1, slong len1, const fq_zech_struct * op2, slong len2, const fq_zech_ctx_t ctx) + void fq_zech_poly_mul_reorder(fq_zech_poly_t rop, const fq_zech_poly_t op1, const fq_zech_poly_t op2, const fq_zech_ctx_t ctx) + void _fq_zech_poly_mul_KS(fq_zech_struct * rop, const fq_zech_struct * op1, slong len1, const fq_zech_struct * op2, slong len2, const fq_zech_ctx_t ctx) + void fq_zech_poly_mul_KS(fq_zech_poly_t rop, const fq_zech_poly_t op1, const fq_zech_poly_t op2, const fq_zech_ctx_t ctx) + void _fq_zech_poly_mul(fq_zech_struct * rop, const fq_zech_struct * op1, slong len1, const fq_zech_struct * op2, slong len2, const fq_zech_ctx_t ctx) + void fq_zech_poly_mul(fq_zech_poly_t rop, const fq_zech_poly_t op1, const fq_zech_poly_t op2, const fq_zech_ctx_t ctx) + void _fq_zech_poly_mullow_classical(fq_zech_struct * rop, const fq_zech_struct * op1, slong len1, const fq_zech_struct * op2, slong len2, slong n, const fq_zech_ctx_t ctx) + void fq_zech_poly_mullow_classical(fq_zech_poly_t rop, const fq_zech_poly_t op1, const fq_zech_poly_t op2, slong n, const fq_zech_ctx_t ctx) + void _fq_zech_poly_mullow_KS(fq_zech_struct * rop, const fq_zech_struct * op1, slong len1, const fq_zech_struct * op2, slong len2, slong n, const fq_zech_ctx_t ctx) + void fq_zech_poly_mullow_KS(fq_zech_poly_t rop, const fq_zech_poly_t op1, const fq_zech_poly_t op2, slong n, const fq_zech_ctx_t ctx) + void _fq_zech_poly_mullow(fq_zech_struct * rop, const fq_zech_struct * op1, slong len1, const fq_zech_struct * op2, slong len2, slong n, const fq_zech_ctx_t ctx) + void fq_zech_poly_mullow(fq_zech_poly_t rop, const fq_zech_poly_t op1, const fq_zech_poly_t op2, slong n, const fq_zech_ctx_t ctx) + void _fq_zech_poly_mulhigh_classical(fq_zech_struct * res, const fq_zech_struct * poly1, slong len1, const fq_zech_struct * poly2, slong len2, slong start, const fq_zech_ctx_t ctx) + void fq_zech_poly_mulhigh_classical(fq_zech_poly_t res, const fq_zech_poly_t poly1, const fq_zech_poly_t poly2, slong start, const fq_zech_ctx_t ctx) + void _fq_zech_poly_mulhigh(fq_zech_struct * res, const fq_zech_struct * poly1, slong len1, const fq_zech_struct * poly2, slong len2, slong start, fq_zech_ctx_t ctx) + void fq_zech_poly_mulhigh(fq_zech_poly_t res, const fq_zech_poly_t poly1, const fq_zech_poly_t poly2, slong start, const fq_zech_ctx_t ctx) + void _fq_zech_poly_mulmod(fq_zech_struct * res, const fq_zech_struct * poly1, slong len1, const fq_zech_struct * poly2, slong len2, const fq_zech_struct * f, slong lenf, const fq_zech_ctx_t ctx) + void fq_zech_poly_mulmod(fq_zech_poly_t res, const fq_zech_poly_t poly1, const fq_zech_poly_t poly2, const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + void _fq_zech_poly_mulmod_preinv(fq_zech_struct * res, const fq_zech_struct * poly1, slong len1, const fq_zech_struct * poly2, slong len2, const fq_zech_struct * f, slong lenf, const fq_zech_struct * finv, slong lenfinv, const fq_zech_ctx_t ctx) + void fq_zech_poly_mulmod_preinv(fq_zech_poly_t res, const fq_zech_poly_t poly1, const fq_zech_poly_t poly2, const fq_zech_poly_t f, const fq_zech_poly_t finv, const fq_zech_ctx_t ctx) + void _fq_zech_poly_sqr_classical(fq_zech_struct * rop, const fq_zech_struct * op, slong len, const fq_zech_ctx_t ctx) + void fq_zech_poly_sqr_classical(fq_zech_poly_t rop, const fq_zech_poly_t op, const fq_zech_ctx_t ctx) + void _fq_zech_poly_sqr_KS(fq_zech_struct * rop, const fq_zech_struct * op, slong len, const fq_zech_ctx_t ctx) + void fq_zech_poly_sqr_KS(fq_zech_poly_t rop, const fq_zech_poly_t op, const fq_zech_ctx_t ctx) + void _fq_zech_poly_sqr(fq_zech_struct * rop, const fq_zech_struct * op, slong len, const fq_zech_ctx_t ctx) + void fq_zech_poly_sqr(fq_zech_poly_t rop, const fq_zech_poly_t op, const fq_zech_ctx_t ctx) + void _fq_zech_poly_pow(fq_zech_struct * rop, const fq_zech_struct * op, slong len, ulong e, const fq_zech_ctx_t ctx) + void fq_zech_poly_pow(fq_zech_poly_t rop, const fq_zech_poly_t op, ulong e, const fq_zech_ctx_t ctx) + void _fq_zech_poly_powmod_ui_binexp(fq_zech_struct * res, const fq_zech_struct * poly, ulong e, const fq_zech_struct * f, slong lenf, const fq_zech_ctx_t ctx) + void fq_zech_poly_powmod_ui_binexp(fq_zech_poly_t res, const fq_zech_poly_t poly, ulong e, const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + void _fq_zech_poly_powmod_ui_binexp_preinv(fq_zech_struct * res, const fq_zech_struct * poly, ulong e, const fq_zech_struct * f, slong lenf, const fq_zech_struct * finv, slong lenfinv, const fq_zech_ctx_t ctx) + void fq_zech_poly_powmod_ui_binexp_preinv(fq_zech_poly_t res, const fq_zech_poly_t poly, ulong e, const fq_zech_poly_t f, const fq_zech_poly_t finv, const fq_zech_ctx_t ctx) + void _fq_zech_poly_powmod_fmpz_binexp(fq_zech_struct * res, const fq_zech_struct * poly, const fmpz_t e, const fq_zech_struct * f, slong lenf, const fq_zech_ctx_t ctx) + void fq_zech_poly_powmod_fmpz_binexp(fq_zech_poly_t res, const fq_zech_poly_t poly, const fmpz_t e, const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + void _fq_zech_poly_powmod_fmpz_binexp_preinv(fq_zech_struct * res, const fq_zech_struct * poly, const fmpz_t e, const fq_zech_struct * f, slong lenf, const fq_zech_struct * finv, slong lenfinv, const fq_zech_ctx_t ctx) + void fq_zech_poly_powmod_fmpz_binexp_preinv(fq_zech_poly_t res, const fq_zech_poly_t poly, const fmpz_t e, const fq_zech_poly_t f, const fq_zech_poly_t finv, const fq_zech_ctx_t ctx) + void _fq_zech_poly_powmod_fmpz_sliding_preinv(fq_zech_struct * res, const fq_zech_struct * poly, const fmpz_t e, ulong k, const fq_zech_struct * f, slong lenf, const fq_zech_struct * finv, slong lenfinv, const fq_zech_ctx_t ctx) + void fq_zech_poly_powmod_fmpz_sliding_preinv(fq_zech_poly_t res, const fq_zech_poly_t poly, const fmpz_t e, ulong k, const fq_zech_poly_t f, const fq_zech_poly_t finv, const fq_zech_ctx_t ctx) + void _fq_zech_poly_powmod_x_fmpz_preinv(fq_zech_struct * res, const fmpz_t e, const fq_zech_struct * f, slong lenf, const fq_zech_struct * finv, slong lenfinv, const fq_zech_ctx_t ctx) + void fq_zech_poly_powmod_x_fmpz_preinv(fq_zech_poly_t res, const fmpz_t e, const fq_zech_poly_t f, const fq_zech_poly_t finv, const fq_zech_ctx_t ctx) + void _fq_zech_poly_pow_trunc_binexp(fq_zech_struct * res, const fq_zech_struct * poly, ulong e, slong trunc, const fq_zech_ctx_t ctx) + void fq_zech_poly_pow_trunc_binexp(fq_zech_poly_t res, const fq_zech_poly_t poly, ulong e, slong trunc, const fq_zech_ctx_t ctx) + void _fq_zech_poly_pow_trunc(fq_zech_struct * res, const fq_zech_struct * poly, ulong e, slong trunc, const fq_zech_ctx_t mod) + void fq_zech_poly_pow_trunc(fq_zech_poly_t res, const fq_zech_poly_t poly, ulong e, slong trunc, const fq_zech_ctx_t ctx) + void _fq_zech_poly_shift_left(fq_zech_struct * rop, const fq_zech_struct * op, slong len, slong n, const fq_zech_ctx_t ctx) + void fq_zech_poly_shift_left(fq_zech_poly_t rop, const fq_zech_poly_t op, slong n, const fq_zech_ctx_t ctx) + void _fq_zech_poly_shift_right(fq_zech_struct * rop, const fq_zech_struct * op, slong len, slong n, const fq_zech_ctx_t ctx) + void fq_zech_poly_shift_right(fq_zech_poly_t rop, const fq_zech_poly_t op, slong n, const fq_zech_ctx_t ctx) + slong _fq_zech_poly_hamming_weight(const fq_zech_struct * op, slong len, const fq_zech_ctx_t ctx) + slong fq_zech_poly_hamming_weight(const fq_zech_poly_t op, const fq_zech_ctx_t ctx) + void _fq_zech_poly_divrem(fq_zech_struct * Q, fq_zech_struct * R, const fq_zech_struct * A, slong lenA, const fq_zech_struct * B, slong lenB, const fq_zech_t invB, const fq_zech_ctx_t ctx) + void fq_zech_poly_divrem(fq_zech_poly_t Q, fq_zech_poly_t R, const fq_zech_poly_t A, const fq_zech_poly_t B, const fq_zech_ctx_t ctx) + void fq_zech_poly_divrem_f(fq_zech_t f, fq_zech_poly_t Q, fq_zech_poly_t R, const fq_zech_poly_t A, const fq_zech_poly_t B, const fq_zech_ctx_t ctx) + void _fq_zech_poly_rem(fq_zech_struct * R, const fq_zech_struct * A, slong lenA, const fq_zech_struct * B, slong lenB, const fq_zech_t invB, const fq_zech_ctx_t ctx) + void fq_zech_poly_rem(fq_zech_poly_t R, const fq_zech_poly_t A, const fq_zech_poly_t B, const fq_zech_ctx_t ctx) + void _fq_zech_poly_div(fq_zech_struct * Q, const fq_zech_struct * A, slong lenA, const fq_zech_struct * B, slong lenB, const fq_zech_t invB, const fq_zech_ctx_t ctx) + void fq_zech_poly_div(fq_zech_poly_t Q, const fq_zech_poly_t A, const fq_zech_poly_t B, const fq_zech_ctx_t ctx) + void _fq_zech_poly_div_newton_n_preinv(fq_zech_struct * Q, const fq_zech_struct * A, slong lenA, const fq_zech_struct * B, slong lenB, const fq_zech_struct * Binv, slong lenBinv, const fq_zech_ctx_t ctx) + void fq_zech_poly_div_newton_n_preinv(fq_zech_poly_t Q, const fq_zech_poly_t A, const fq_zech_poly_t B, const fq_zech_poly_t Binv, const fq_zech_ctx_t ctx) + void _fq_zech_poly_divrem_newton_n_preinv(fq_zech_struct * Q, fq_zech_struct * R, const fq_zech_struct * A, slong lenA, const fq_zech_struct * B, slong lenB, const fq_zech_struct * Binv, slong lenBinv, const fq_zech_ctx_t ctx) + void fq_zech_poly_divrem_newton_n_preinv(fq_zech_poly_t Q, fq_zech_poly_t R, const fq_zech_poly_t A, const fq_zech_poly_t B, const fq_zech_poly_t Binv, const fq_zech_ctx_t ctx) + void _fq_zech_poly_inv_series_newton(fq_zech_struct * Qinv, const fq_zech_struct * Q, slong n, const fq_zech_t cinv, const fq_zech_ctx_t ctx) + void fq_zech_poly_inv_series_newton(fq_zech_poly_t Qinv, const fq_zech_poly_t Q, slong n, const fq_zech_ctx_t ctx) + void _fq_zech_poly_inv_series(fq_zech_struct * Qinv, const fq_zech_struct * Q, slong n, const fq_zech_t cinv, const fq_zech_ctx_t ctx) + void fq_zech_poly_inv_series(fq_zech_poly_t Qinv, const fq_zech_poly_t Q, slong n, const fq_zech_ctx_t ctx) + void _fq_zech_poly_div_series(fq_zech_struct * Q, const fq_zech_struct * A, slong Alen, const fq_zech_struct * B, slong Blen, slong n, const fq_zech_ctx_t ctx) + void fq_zech_poly_div_series(fq_zech_poly_t Q, const fq_zech_poly_t A, const fq_zech_poly_t B, slong n, const fq_zech_ctx_t ctx) + void fq_zech_poly_gcd(fq_zech_poly_t rop, const fq_zech_poly_t op1, const fq_zech_poly_t op2, const fq_zech_ctx_t ctx) + slong _fq_zech_poly_gcd(fq_zech_struct * G, const fq_zech_struct * A, slong lenA, const fq_zech_struct * B, slong lenB, const fq_zech_ctx_t ctx) + slong _fq_zech_poly_gcd_euclidean_f(fq_zech_t f, fq_zech_struct * G, const fq_zech_struct * A, slong lenA, const fq_zech_struct * B, slong lenB, const fq_zech_ctx_t ctx) + void fq_zech_poly_gcd_euclidean_f(fq_zech_t f, fq_zech_poly_t G, const fq_zech_poly_t A, const fq_zech_poly_t B, const fq_zech_ctx_t ctx) + slong _fq_zech_poly_xgcd(fq_zech_struct * G, fq_zech_struct * S, fq_zech_struct * T, const fq_zech_struct * A, slong lenA, const fq_zech_struct * B, slong lenB, const fq_zech_ctx_t ctx) + void fq_zech_poly_xgcd(fq_zech_poly_t G, fq_zech_poly_t S, fq_zech_poly_t T, const fq_zech_poly_t A, const fq_zech_poly_t B, const fq_zech_ctx_t ctx) + slong _fq_zech_poly_xgcd_euclidean_f(fq_zech_t f, fq_zech_struct * G, fq_zech_struct * S, fq_zech_struct * T, const fq_zech_struct * A, slong lenA, const fq_zech_struct * B, slong lenB, const fq_zech_ctx_t ctx) + void fq_zech_poly_xgcd_euclidean_f(fq_zech_t f, fq_zech_poly_t G, fq_zech_poly_t S, fq_zech_poly_t T, const fq_zech_poly_t A, const fq_zech_poly_t B, const fq_zech_ctx_t ctx) + int _fq_zech_poly_divides(fq_zech_struct * Q, const fq_zech_struct * A, slong lenA, const fq_zech_struct * B, slong lenB, const fq_zech_t invB, const fq_zech_ctx_t ctx) + int fq_zech_poly_divides(fq_zech_poly_t Q, const fq_zech_poly_t A, const fq_zech_poly_t B, const fq_zech_ctx_t ctx) + void _fq_zech_poly_derivative(fq_zech_struct * rop, const fq_zech_struct * op, slong len, const fq_zech_ctx_t ctx) + void fq_zech_poly_derivative(fq_zech_poly_t rop, const fq_zech_poly_t op, const fq_zech_ctx_t ctx) + void _fq_zech_poly_invsqrt_series(fq_zech_struct * g, const fq_zech_struct * h, slong n, fq_zech_ctx_t mod) + void fq_zech_poly_invsqrt_series(fq_zech_poly_t g, const fq_zech_poly_t h, slong n, fq_zech_ctx_t ctx) + void _fq_zech_poly_sqrt_series(fq_zech_struct * g, const fq_zech_struct * h, slong n, fq_zech_ctx_t ctx) + void fq_zech_poly_sqrt_series(fq_zech_poly_t g, const fq_zech_poly_t h, slong n, fq_zech_ctx_t ctx) + int _fq_zech_poly_sqrt(fq_zech_struct * s, const fq_zech_struct * p, slong n, fq_zech_ctx_t mod) + int fq_zech_poly_sqrt(fq_zech_poly_t s, const fq_zech_poly_t p, fq_zech_ctx_t mod) + void _fq_zech_poly_evaluate_fq_zech(fq_zech_t rop, const fq_zech_struct * op, slong len, const fq_zech_t a, const fq_zech_ctx_t ctx) + void fq_zech_poly_evaluate_fq_zech(fq_zech_t rop, const fq_zech_poly_t f, const fq_zech_t a, const fq_zech_ctx_t ctx) + void _fq_zech_poly_compose(fq_zech_struct * rop, const fq_zech_struct * op1, slong len1, const fq_zech_struct * op2, slong len2, const fq_zech_ctx_t ctx) + void fq_zech_poly_compose(fq_zech_poly_t rop, const fq_zech_poly_t op1, const fq_zech_poly_t op2, const fq_zech_ctx_t ctx) + void _fq_zech_poly_compose_mod_horner(fq_zech_struct * res, const fq_zech_struct * f, slong lenf, const fq_zech_struct * g, const fq_zech_struct * h, slong lenh, const fq_zech_ctx_t ctx) + void fq_zech_poly_compose_mod_horner(fq_zech_poly_t res, const fq_zech_poly_t f, const fq_zech_poly_t g, const fq_zech_poly_t h, const fq_zech_ctx_t ctx) + void _fq_zech_poly_compose_mod_horner_preinv(fq_zech_struct * res, const fq_zech_struct * f, slong lenf, const fq_zech_struct * g, const fq_zech_struct * h, slong lenh, const fq_zech_struct * hinv, slong lenhiv, const fq_zech_ctx_t ctx) + void fq_zech_poly_compose_mod_horner_preinv(fq_zech_poly_t res, const fq_zech_poly_t f, const fq_zech_poly_t g, const fq_zech_poly_t h, const fq_zech_poly_t hinv, const fq_zech_ctx_t ctx) + void _fq_zech_poly_compose_mod_brent_kung(fq_zech_struct * res, const fq_zech_struct * f, slong lenf, const fq_zech_struct * g, const fq_zech_struct * h, slong lenh, const fq_zech_ctx_t ctx) + void fq_zech_poly_compose_mod_brent_kung(fq_zech_poly_t res, const fq_zech_poly_t f, const fq_zech_poly_t g, const fq_zech_poly_t h, const fq_zech_ctx_t ctx) + void _fq_zech_poly_compose_mod_brent_kung_preinv(fq_zech_struct * res, const fq_zech_struct * f, slong lenf, const fq_zech_struct * g, const fq_zech_struct * h, slong lenh, const fq_zech_struct * hinv, slong lenhiv, const fq_zech_ctx_t ctx) + void fq_zech_poly_compose_mod_brent_kung_preinv(fq_zech_poly_t res, const fq_zech_poly_t f, const fq_zech_poly_t g, const fq_zech_poly_t h, const fq_zech_poly_t hinv, const fq_zech_ctx_t ctx) + void _fq_zech_poly_compose_mod(fq_zech_struct * res, const fq_zech_struct * f, slong lenf, const fq_zech_struct * g, const fq_zech_struct * h, slong lenh, const fq_zech_ctx_t ctx) + void fq_zech_poly_compose_mod(fq_zech_poly_t res, const fq_zech_poly_t f, const fq_zech_poly_t g, const fq_zech_poly_t h, const fq_zech_ctx_t ctx) + void _fq_zech_poly_compose_mod_preinv(fq_zech_struct * res, const fq_zech_struct * f, slong lenf, const fq_zech_struct * g, const fq_zech_struct * h, slong lenh, const fq_zech_struct * hinv, slong lenhiv, const fq_zech_ctx_t ctx) + void fq_zech_poly_compose_mod_preinv(fq_zech_poly_t res, const fq_zech_poly_t f, const fq_zech_poly_t g, const fq_zech_poly_t h, const fq_zech_poly_t hinv, const fq_zech_ctx_t ctx) + void _fq_zech_poly_reduce_matrix_mod_poly (fq_zech_mat_t A, const fq_zech_mat_t B, const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + void _fq_zech_poly_precompute_matrix (fq_zech_mat_t A, const fq_zech_struct * f, const fq_zech_struct * g, slong leng, const fq_zech_struct * ginv, slong lenginv, const fq_zech_ctx_t ctx) + void fq_zech_poly_precompute_matrix (fq_zech_mat_t A, const fq_zech_poly_t f, const fq_zech_poly_t g, const fq_zech_poly_t ginv, const fq_zech_ctx_t ctx) + void _fq_zech_poly_compose_mod_brent_kung_precomp_preinv(fq_zech_struct * res, const fq_zech_struct * f, slong lenf, const fq_zech_mat_t A, const fq_zech_struct * h, slong lenh, const fq_zech_struct * hinv, slong lenhinv, const fq_zech_ctx_t ctx) + void fq_zech_poly_compose_mod_brent_kung_precomp_preinv(fq_zech_poly_t res, const fq_zech_poly_t f, const fq_zech_mat_t A, const fq_zech_poly_t h, const fq_zech_poly_t hinv, const fq_zech_ctx_t ctx) + # int _fq_zech_poly_fprint_pretty(FILE * file, const fq_zech_struct * poly, slong len, const char * x, const fq_zech_ctx_t ctx) + # int fq_zech_poly_fprint_pretty(FILE * file, const fq_zech_poly_t poly, const char * x, const fq_zech_ctx_t ctx) + int _fq_zech_poly_print_pretty(const fq_zech_struct * poly, slong len, const char * x, const fq_zech_ctx_t ctx) + int fq_zech_poly_print_pretty(const fq_zech_poly_t poly, const char * x, const fq_zech_ctx_t ctx) + # int _fq_zech_poly_fprint(FILE * file, const fq_zech_struct * poly, slong len, const fq_zech_ctx_t ctx) + # int fq_zech_poly_fprint(FILE * file, const fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + int _fq_zech_poly_print(const fq_zech_struct * poly, slong len, const fq_zech_ctx_t ctx) + int fq_zech_poly_print(const fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + char * _fq_zech_poly_get_str(const fq_zech_struct * poly, slong len, const fq_zech_ctx_t ctx) + char * fq_zech_poly_get_str(const fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + char * _fq_zech_poly_get_str_pretty(const fq_zech_struct * poly, slong len, const char * x, const fq_zech_ctx_t ctx) + char * fq_zech_poly_get_str_pretty(const fq_zech_poly_t poly, const char * x, const fq_zech_ctx_t ctx) + void fq_zech_poly_inflate(fq_zech_poly_t result, const fq_zech_poly_t input, ulong inflation, const fq_zech_ctx_t ctx) + void fq_zech_poly_deflate(fq_zech_poly_t result, const fq_zech_poly_t input, ulong deflation, const fq_zech_ctx_t ctx) + ulong fq_zech_poly_deflation(const fq_zech_poly_t input, const fq_zech_ctx_t ctx) diff --git a/src/flint/flintlib/fq_zech_poly_factor.pxd b/src/flint/flintlib/fq_zech_poly_factor.pxd new file mode 100644 index 00000000..106c5788 --- /dev/null +++ b/src/flint/flintlib/fq_zech_poly_factor.pxd @@ -0,0 +1,44 @@ +from flint.flintlib.flint cimport flint_rand_t, slong, ulong +from flint.flintlib.fq_zech cimport fq_zech_ctx_t, fq_zech_t, fq_zech_struct +from flint.flintlib.fq_zech cimport fq_zech_poly_struct, fq_zech_poly_t + +cdef extern from "flint/fq_zech_poly_factor.h": + # Type definitions **********************************************/ + ctypedef struct fq_zech_poly_factor_struct: + fq_zech_poly_struct * poly + slong * exp + slong num + slong alloc + ctypedef fq_zech_poly_factor_struct fq_zech_poly_factor_t[1] + + # Parsed from here **********************************************/ + void fq_zech_poly_factor_init(fq_zech_poly_factor_t fac, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_clear(fq_zech_poly_factor_t fac, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_realloc(fq_zech_poly_factor_t fac, slong alloc, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_fit_length(fq_zech_poly_factor_t fac, slong len, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_set(fq_zech_poly_factor_t res, const fq_zech_poly_factor_t fac, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_print_pretty(const fq_zech_poly_factor_t fac, const char * var, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_print(const fq_zech_poly_factor_t fac, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_insert(fq_zech_poly_factor_t fac, const fq_zech_poly_t poly, slong exp, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_concat(fq_zech_poly_factor_t res, const fq_zech_poly_factor_t fac, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_pow(fq_zech_poly_factor_t fac, slong exp, const fq_zech_ctx_t ctx) + ulong fq_zech_poly_remove(fq_zech_poly_t f, const fq_zech_poly_t p, const fq_zech_ctx_t ctx) + int fq_zech_poly_is_irreducible(const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + int fq_zech_poly_is_irreducible_ddf(const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + int fq_zech_poly_is_irreducible_ben_or(const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + int _fq_zech_poly_is_squarefree(const fq_zech_struct * f, slong len, const fq_zech_ctx_t ctx) + int fq_zech_poly_is_squarefree(const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + int fq_zech_poly_factor_equal_deg_prob(fq_zech_poly_t factor, flint_rand_t state, const fq_zech_poly_t pol, slong d, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_equal_deg(fq_zech_poly_factor_t factors, const fq_zech_poly_t pol, slong d, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_split_single(fq_zech_poly_t linfactor, const fq_zech_poly_t input, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_distinct_deg(fq_zech_poly_factor_t res, const fq_zech_poly_t poly, slong * const * degs, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_squarefree(fq_zech_poly_factor_t res, const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor(fq_zech_poly_factor_t res, fq_zech_t lead, const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_cantor_zassenhaus(fq_zech_poly_factor_t res, const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_kaltofen_shoup(fq_zech_poly_factor_t res, const fq_zech_poly_t poly, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_berlekamp(fq_zech_poly_factor_t factors, const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_with_berlekamp(fq_zech_poly_factor_t res, fq_zech_t leading_coeff, const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_with_cantor_zassenhaus(fq_zech_poly_factor_t res, fq_zech_t leading_coeff, const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + void fq_zech_poly_factor_with_kaltofen_shoup(fq_zech_poly_factor_t res, fq_zech_t leading_coeff, const fq_zech_poly_t f, const fq_zech_ctx_t ctx) + void fq_zech_poly_iterated_frobenius_preinv(fq_zech_poly_t * rop, slong n, const fq_zech_poly_t v, const fq_zech_poly_t vinv, const fq_zech_ctx_t ctx) + void fq_zech_poly_roots(fq_zech_poly_factor_t r, const fq_zech_poly_t f, int with_multiplicity, const fq_zech_ctx_t ctx) diff --git a/src/flint/test/__main__.py b/src/flint/test/__main__.py index 580e90c6..21124c51 100644 --- a/src/flint/test/__main__.py +++ b/src/flint/test/__main__.py @@ -72,6 +72,7 @@ def run_doctests(verbose=None): flint.types.nmod_mat, flint.types.nmod_series, flint.types.fq_default, + flint.types.fq_default_poly, flint.types.arf, flint.types.arb, flint.types.arb_poly, @@ -88,9 +89,12 @@ def run_doctests(verbose=None): modules.append(acb_theta) except ImportError: pass - results = [doctest.testmod(x) for x in modules] -# ffmpz, tfmpz = doctest.testmod(flint._fmpz, verbose=verbose) -# failed, total = doctest.testmod(flint.pyflint, verbose=verbose) + + results = [] + for x in modules: + if verbose: + print(f" {x.__name__}") + results.append(doctest.testmod(x)) return tuple(sum(res) for res in zip(*results)) diff --git a/src/flint/test/test_all.py b/src/flint/test/test_all.py index 991c0291..272e533a 100644 --- a/src/flint/test/test_all.py +++ b/src/flint/test/test_all.py @@ -2497,12 +2497,29 @@ def _all_polys(): (lambda *a: flint.fmpz_mod_poly(*a, flint.fmpz_mod_poly_ctx(2**255 - 19)), lambda x: flint.fmpz_mod(x, flint.fmpz_mod_ctx(2**255 - 19)), True), + (lambda *a: flint.fq_default_poly(*a, flint.fq_default_poly_ctx(2**127 - 1)), + lambda x: flint.fq_default(x, flint.fq_default_ctx(2**127 - 1)), + True), + (lambda *a: flint.fq_default_poly(*a, flint.fq_default_poly_ctx(2**127 - 1, 2)), + lambda x: flint.fq_default(x, flint.fq_default_ctx(2**127 - 1, 2)), + True), + (lambda *a: flint.fq_default_poly(*a, flint.fq_default_poly_ctx(65537)), + lambda x: flint.fq_default(x, flint.fq_default_ctx(65537)), + True), + (lambda *a: flint.fq_default_poly(*a, flint.fq_default_poly_ctx(65537, 5)), + lambda x: flint.fq_default(x, flint.fq_default_ctx(65537, 5)), + True), + (lambda *a: flint.fq_default_poly(*a, flint.fq_default_poly_ctx(11)), + lambda x: flint.fq_default(x, flint.fq_default_ctx(11)), + True), + (lambda *a: flint.fq_default_poly(*a, flint.fq_default_poly_ctx(11, 5)), + lambda x: flint.fq_default(x, flint.fq_default_ctx(11, 5)), + True), ] def test_polys(): for P, S, is_field in _all_polys(): - assert P([S(1)]) == P([1]) == P(P([1])) == P(1) assert raises(lambda: P([None]), TypeError) @@ -2591,6 +2608,8 @@ def setbad(obj, i, val): assert P(v).repr() == f'nmod_poly({v!r}, 17)' elif type(p) == flint.fmpz_mod_poly: pass # fmpz_mod_poly does not have .repr() ... + elif type(p) == flint.fq_default_poly: + pass # fq_default_poly does not have .repr() ... else: assert False @@ -2697,7 +2716,7 @@ def setbad(obj, i, val): # XXX: Not sure what this should do in general: p = P([1, 1]) mod = P([1, 1]) - if type(p) not in [flint.fmpz_mod_poly, flint.nmod_poly]: + if type(p) not in [flint.fmpz_mod_poly, flint.nmod_poly, flint.fq_default_poly]: assert raises(lambda: pow(p, 2, mod), NotImplementedError) else: assert p * p % mod == pow(p, 2, mod) @@ -2727,8 +2746,11 @@ def setbad(obj, i, val): assert P([1, 2, 1]).derivative() == P([2, 2]) - if is_field: - assert P([1, 2, 1]).integral() == P([0, 1, 1, S(1)/3]) + p = P([1, 2, 1]) + if is_field and type(p) != flint.fq_default_poly: + assert p.integral() == P([0, 1, 1, S(1)/3]) + if type(p) == flint.fq_default_poly: + assert raises(lambda: p.integral(), NotImplementedError) def _all_mpolys(): return [ @@ -3649,24 +3671,57 @@ def test_matrices_transpose(): def test_fq_default(): # test fq_default context creation - # TODO + + # fq_type parsing + assert raises(lambda: flint.fq_default_ctx(5, fq_type="A"), ValueError) + assert raises(lambda: flint.fq_default_ctx(5, fq_type=[]), TypeError) + assert raises(lambda: flint.fq_default_ctx(5, fq_type=-1), ValueError) + assert raises(lambda: flint.fq_default_ctx("ABC"), TypeError) + + # var must be one character + assert raises(lambda: flint.fq_default_ctx(5, var="XXX"), ValueError) + + # p must be set if modulus has no characteristic / modulus + assert raises(lambda: flint.fq_default_ctx(modulus=[0,1,0]), ValueError) + + # prime must be prime when setting from modulus + assert raises(lambda: flint.fq_default_ctx(10, modulus=[0,1,0]), ValueError) + mod_not_prime = flint.fmpz_mod_poly_ctx(10)([1,0,1]) + assert raises(lambda: flint.fq_default_ctx(modulus=mod_not_prime), ValueError) + mod_not_irr = flint.fmpz_mod_poly_ctx(11)([0,0,1]) + assert raises(lambda: flint.fq_default_ctx(modulus=mod_not_irr), ValueError) + + # modulus must be able to be cast to fmpz_mod_poly + assert raises(lambda: flint.fq_default_ctx(11, modulus="AAA"), TypeError) + + # either p or modulus must be set + assert raises(lambda: flint.fq_default_ctx(p=None, modulus=None), ValueError) + + # p must be prime + assert raises(lambda: flint.fq_default_ctx(10), ValueError) + + # degree must be positive + assert raises(lambda: flint.fq_default_ctx(11, -1), ValueError) # GF(5) - gf_5 = flint.fq_default_ctx(5) - gf_5_ = flint.fq_default_ctx(5) + gf_5 = flint.fq_default_ctx(5, fq_type='NMOD') + gf_5_ = flint.fq_default_ctx(5, fq_type='NMOD') # GF(5^2) - gf_5_2 = flint.fq_default_ctx(5, 2) - gf_5_2_ = flint.fq_default_ctx(5, 2) + gf_5_2 = flint.fq_default_ctx(5, 2, fq_type='FQ_ZECH') + gf_5_2_ = flint.fq_default_ctx(5, 2, fq_type='FQ_ZECH') # GF((2**127 - 1)^2) gf_127 = flint.fq_default_ctx(2**127 - 1, 2) gf_127_2 = flint.fq_default_ctx(2**127 - 1, 2) assert (gf_5 == gf_5_) is True + assert (hash(gf_5) == hash(gf_5_)) is True assert (gf_5 != gf_5_) is False assert (gf_5 == gf_5_2) is False assert (gf_5 != gf_5_2) is True + assert (gf_5 == "a") is False + assert (gf_5 != "a") is True assert gf_5.prime() == gf_5_2.prime() == 5 assert gf_5_2.order() == 5*5 @@ -3678,9 +3733,13 @@ def test_fq_default(): assert gf_5_2.gen() == gf_5_2([0, 1]) assert str(gf_5) == "Context for fq_default in GF(5)" - assert str(gf_5_2) == "Context for fq_default in GF(5^2)[x]/(x^2 + 4*x + 2)" + assert str(gf_5_2) == "Context for fq_default in GF(5^2)[z]/(z^2 + 4*z + 2)" + + assert repr(gf_5) == "fq_default_ctx(5, var='z' type='NMOD')" + assert repr(gf_5_2) == "fq_default_ctx(5, 2, 'z', x^2 + 4*x + 2, 'FQ_ZECH')" # coercision + assert gf_5.one() == flint.fq_default(1, gf_5) assert gf_5(1) == gf_5.one() assert gf_5(flint.fmpz(1)) == gf_5.one() assert gf_5(-1) == -gf_5.one() @@ -3695,13 +3754,17 @@ def test_fq_default(): R = flint.fmpz_mod_poly_ctx(5) assert gf_5.gen() == gf_5(R.gen()) assert gf_5.gen() == gf_5(flint.nmod_poly([0, 1], 5)) - - + assert gf_5(flint.fmpz(2**64)) == gf_5(2**64) + assert raises(lambda: flint.fq_default(1, "AAA"), TypeError) + assert raises(lambda: flint.fq_default.__init__(1, "AAA"), TypeError) + assert raises(lambda: flint.fq_default("AAA", gf_5), TypeError) + assert raises(lambda: gf_5.one() + gf_5_2.one(), ValueError) # testing various equalties between types # integers are the same if charactersitic is the same # even with extensions assert gf_5.one() == gf_5_.one() + assert hash(gf_5.one()) == hash(gf_5_.one()) assert gf_5.one() == gf_5_2.one() assert gf_5.one() != gf_127.one() @@ -3787,6 +3850,7 @@ def test_fq_default(): assert (a / b) / c == a / (b * c) assert a + 0 == 0 + a == a + assert a - 0 == -(0 - a) == a assert a + gf.zero() == a assert a * 1 == 1 * a == a assert a * gf.one() == a @@ -3796,13 +3860,191 @@ def test_fq_default(): assert raises(lambda: a / 0, ZeroDivisionError) assert raises(lambda: ~gf.zero(), ZeroDivisionError) assert raises(lambda: pow(gf.zero(), -1), ZeroDivisionError) + assert raises(lambda: pow(gf.zero(), "A"), TypeError) assert 1/a == pow(a, -1) == ~a assert gf.one() == pow(a, 0) assert gf.zero() == pow(gf.zero(), 2**64) assert a == pow(a, 1) - + assert pow(a, flint.fmpz(2**64)) == pow(a, 2**64) assert (a*a).is_square() + assert (a*a).sqrt() in [a, -a] + + while True: + nqr = gf.random_element() + if not nqr.is_square(): + break + assert raises(lambda: nqr.sqrt(), ValueError) + + +def test_fq_default_poly(): + F = flint.fq_default_ctx(11, 3) + R1 = flint.fq_default_poly_ctx(F) + R2 = flint.fq_default_poly_ctx(11, 3) + R3 = flint.fq_default_poly_ctx(13, 5) + + assert raises(lambda: flint.fq_default_poly_ctx("AAA"), TypeError) + assert (R1 == R1) is True + assert hash(R1) == hash(R2) + assert (R1 != R1) is False + assert (R1 == R2) is True + assert (R1 != R2) is False + assert (R1 != R3) is True + assert (R1 == R3) is False + assert (R1 != "AAA") is True + assert (R1 == "AAA") is False + + assert str(R1) == "Context for fq_default_poly with field: Context for fq_default in GF(11^3)[z]/(z^3 + 2*z + 9)" + assert str(R1) == str(R2) + assert repr(R3) == "fq_default_poly_ctx(fq_default_ctx(13, 5, 'z', x^5 + 4*x + 11, 'FQ_NMOD'))" + + # random element failure + f = R1.random_element(not_zero=True) + assert not f.is_zero() + assert raises(lambda: R1.random_element(monic="AAA"), TypeError) + assert raises(lambda: R1.random_element(degree=-1), ValueError) + + assert raises(lambda: flint.fq_default_poly([1,2,3], "AAA"), TypeError) + + assert R1(0).leading_coefficient() == 0 + assert raises(lambda: R1.random_element().reverse(degree=-1), ValueError) + + # some coersion + assert raises(lambda: R3(F(1)), ValueError) + assert R1.one() == R1(1) + assert R1.one() == R1([1]) + assert R1.one() == R1(flint.fmpz(1)) + assert R1.one() == R1(flint.fmpz_poly([1])) + assert R1.one() == R1(flint.fmpz_mod_ctx(11)(1)) + assert R1.one() == R1(flint.fmpz_mod_poly_ctx(11)(1)) + assert R1.one() == R1(flint.nmod_poly(1, 11)) + + R_sml = flint.fq_default_poly_ctx(5) + R_med = flint.fq_default_poly_ctx(65537) + R_big = flint.fq_default_poly_ctx(2**127 - 1) + R_sml_ext = flint.fq_default_poly_ctx(5, 5) + R_med_ext = flint.fq_default_poly_ctx(65537, 3) + R_big_ext = flint.fq_default_poly_ctx(2**127 - 1, 2) + + F_cmp = flint.fq_default_ctx(11) + R_cmp = flint.fq_default_poly_ctx(F_cmp) + f_cmp = R_cmp([1,2,3,4,5]) + + for R_test in [R_sml, R_med, R_big, R_sml_ext, R_med_ext, R_big_ext]: + F_test = R_test.base_field() + while True: + nqr = F_test.random_element() + if not nqr.is_square(): + break + + f = R_test([-1,-2]) + g = R_test([-3,-4]) + assert (f == f) is True + assert (f != g) is True + assert (hash(f) == hash(f)) is True + assert (hash(f) != hash(g)) is True + + # Exact division + assert raises(lambda: f.exact_division(f_cmp), ValueError) + assert raises(lambda: f.exact_division("AAA"), TypeError) + assert raises(lambda: f.exact_division(0), ZeroDivisionError) + assert (f * g).exact_division(g) == f + assert raises(lambda: f.exact_division(g), DomainError) + assert raises(lambda: f / "AAA", TypeError) + assert raises(lambda: "AAA" / f, TypeError) + + + # ZeroDivisionError + assert raises(lambda: f / 0, ZeroDivisionError) + assert raises(lambda: f // 0, ZeroDivisionError) + assert raises(lambda: 1 / R_test.zero(), ZeroDivisionError) + assert raises(lambda: 1 // R_test.zero(), ZeroDivisionError) + assert raises(lambda: 1 % R_test.zero(), ZeroDivisionError) + + # pow + # assert ui and fmpz exp agree for polynomials and generators + R_gen = R_test.gen() + assert raises(lambda: f**(-2), ValueError) + assert pow(f, 2**60, g) == pow(pow(f, 2**30, g), 2**30, g) + assert pow(R_gen, 2**60, g) == pow(pow(R_gen, 2**30, g), 2**30, g) + assert raises(lambda: pow(f, -2, g), ValueError) + assert raises(lambda: pow(f, 1, "A"), TypeError) + assert raises(lambda: pow(f, "A", g), TypeError) + assert raises(lambda: f.pow_mod(2**32, g, mod_rev_inv="A"), TypeError) + + # Shifts + assert raises(lambda: R_test([1,2,3]).left_shift(-1), ValueError) + assert raises(lambda: R_test([1,2,3]).right_shift(-1), ValueError) + assert R_test([1,2,3]).left_shift(3) == R_test([0,0,0,1,2,3]) + assert R_test([1,2,3]).right_shift(1) == R_test([2,3]) + + # mulmod + assert f.mul_mod(f, g) == (f*f) % g + assert raises(lambda: f.mul_mod(f, "AAA"), TypeError) + assert raises(lambda: f.mul_mod("AAA", g), TypeError) + + # pow_mod + assert f.pow_mod(2, g) == (f*f) % g + assert raises(lambda: f.pow_mod(2, "AAA"), TypeError) + assert raises(lambda: f.complex_roots(), DomainError) + + # compose errors + assert raises(lambda: f.compose("A"), TypeError) + assert raises(lambda: f.compose_mod("A", g), TypeError) + assert raises(lambda: f.compose_mod(g, "A"), TypeError) + assert raises(lambda: f.compose_mod(g, R_test.zero()), ZeroDivisionError) + + # inverse_mod + f = R_test.random_element() + while True: + h = R_test.random_element() + if f.gcd(h).is_one(): + break + g = f.inverse_mod(h) + assert f.mul_mod(g, h).is_one() + assert raises(lambda: f.inverse_mod(2*f), ValueError) + + # series + f_non_square = R_test([nqr, 1, 1, 1]) + f_zero = R_test([0, 1, 1, 1]) + assert raises(lambda: f_non_square.sqrt_trunc(1), ValueError) + assert raises(lambda: f_zero.sqrt_trunc(1), ZeroDivisionError) + assert raises(lambda: f_non_square.inv_sqrt_trunc(1), ValueError) + assert raises(lambda: f_zero.inv_sqrt_trunc(1), ZeroDivisionError) + f_inv = f.inverse_series_trunc(2) + assert (f * f_inv) % R_test([0,0,1]) == 1 + assert raises(lambda: R_test([0,1]).inverse_series_trunc(2), ZeroDivisionError) + + # deflation + f1 = R_test([1,0,2,0,3]) + assert raises(lambda: f1.deflate(100), ValueError) + assert f1.deflate(2) == R_test([1,2,3]) + + # truncate things + f = R_test.random_element() + g = R_test.random_element() + h = R_test.random_element() + x = R_test.gen() + f_trunc = f % x**3 + + assert f.equal_trunc(f_trunc, 3) + assert not f.equal_trunc("A", 3) + assert not f.equal_trunc(f_cmp, 3) + + assert raises(lambda: f.add_trunc("A", 1), TypeError) + assert raises(lambda: f.add_trunc(f_cmp, 1), ValueError) + assert f.add_trunc(g, 3) == (f + g) % x**3 + + assert raises(lambda: f.sub_trunc("A", 1), TypeError) + assert raises(lambda: f.sub_trunc(f_cmp, 1), ValueError) + assert f.sub_trunc(g, 3) == (f - g) % x**3 + + assert raises(lambda: f.mul_low("A", 1), TypeError) + assert raises(lambda: f.mul_low(g, "A"), TypeError) + assert raises(lambda: f.mul_low(f_cmp, 1), ValueError) + assert f.mul_low(g, 3) == (f * g) % x**3 + + assert raises(lambda: f.pow_trunc(-1, 5), ValueError) def test_all_tests(): test_funcs = {f for name, f in globals().items() if name.startswith("test_")} @@ -3870,6 +4112,7 @@ def test_all_tests(): test_matrices_solve, test_fq_default, + test_fq_default_poly, test_arb, diff --git a/src/flint/types/fmpz.pxd b/src/flint/types/fmpz.pxd index dee5b194..eaf8cad3 100644 --- a/src/flint/types/fmpz.pxd +++ b/src/flint/types/fmpz.pxd @@ -1,7 +1,6 @@ from cpython.long cimport PyLong_Check from flint.flint_base.flint_base cimport flint_scalar from flint.utils.conversion cimport chars_from_str - from flint.flintlib.flint cimport slong, pylong_as_slong from flint.flintlib.flint cimport PyObject from flint.flintlib.fmpz cimport fmpz_t, fmpz_set_str, fmpz_set_si diff --git a/src/flint/types/fmpz_mod_poly.pyx b/src/flint/types/fmpz_mod_poly.pyx index 5830da03..d9532f75 100644 --- a/src/flint/types/fmpz_mod_poly.pyx +++ b/src/flint/types/fmpz_mod_poly.pyx @@ -188,10 +188,7 @@ cdef class fmpz_mod_poly_ctx: return 0 cdef set_any_as_fmpz_mod_poly(self, fmpz_mod_poly_t poly, obj): - if typecheck(obj, list): - return self.set_list_as_fmpz_mod_poly(poly, obj) - - # Set val from fmpz_mod_poly + # Set val from fmpz_mod_poly if typecheck(obj, fmpz_mod_poly): if self != (obj).ctx: raise ValueError("moduli must match") @@ -330,6 +327,10 @@ cdef class fmpz_mod_poly(flint_poly): fmpz_mod_poly_clear(self.val, self.ctx.mod.val) def __init__(self, val, ctx): + if typecheck(val, list): + self.ctx.set_list_as_fmpz_mod_poly(self.val, val) + return + check = self.ctx.set_any_as_fmpz_mod_poly(self.val, val) if check is NotImplemented: raise TypeError @@ -1900,4 +1901,4 @@ cdef class fmpz_mod_poly(flint_poly): This method is not implemented for polynomials in :math:`(\mathbb{Z}/N\mathbb{Z})[X]` """ - raise DomainError("Cannot compute compex roots for polynomials over integers modulo N") + raise DomainError("Cannot compute complex roots for polynomials over integers modulo N") diff --git a/src/flint/types/fq_default.pxd b/src/flint/types/fq_default.pxd index 265cd962..178c6169 100644 --- a/src/flint/types/fq_default.pxd +++ b/src/flint/types/fq_default.pxd @@ -1,7 +1,4 @@ from flint.flintlib.fq_default cimport * -from flint.flintlib.fq_zech cimport fq_zech_is_primitive, fq_zech_multiplicative_order -from flint.flintlib.fq_nmod cimport fq_nmod_is_primitive, fq_nmod_multiplicative_order -from flint.flintlib.fq cimport fq_is_primitive, fq_multiplicative_order from flint.types.fmpz cimport fmpz from flint.flint_base.flint_base cimport flint_scalar @@ -37,10 +34,7 @@ cdef class fq_default_ctx: cdef any_as_fq_default(self, obj) cdef _set_from_order(self, p, d, var, fq_type=*, check_prime=*) - cdef _set_from_modulus(self, modulus, var, fq_type=*, check_modulus=*) - - cdef _c_set_from_order(self, fmpz p, int d, char *var, fq_default_type fq_type=*) - cdef _c_set_from_modulus(self, modulus, char *var, fq_default_type fq_type=*) + cdef _set_from_modulus(self, modulus, var, fq_type=*, check_prime=*, check_modulus=*) cdef class fq_default(flint_scalar): cdef fq_default_ctx ctx diff --git a/src/flint/types/fq_default.pyx b/src/flint/types/fq_default.pyx index 4b0a128e..0f92fe30 100644 --- a/src/flint/types/fq_default.pyx +++ b/src/flint/types/fq_default.pyx @@ -32,7 +32,7 @@ cdef class fq_default_ctx: >>> from flint import fmpz_mod_poly_ctx >>> mod = fmpz_mod_poly_ctx(11)([1,0,1]) >>> fq_default_ctx(modulus=mod, fq_type='FQ_NMOD') - fq_default_ctx(11, 2, 'x', x^2 + 1, 'FQ_NMOD') + fq_default_ctx(11, 2, 'z', x^2 + 1, 'FQ_NMOD') For more details, see the documentation of :method:`~._set_from_order` and :method:`~._set_from_modulus`. @@ -64,7 +64,7 @@ cdef class fq_default_ctx: def _parse_input_var(var): # If no variable is given, use x if var is None: - var = b"x" + var = b"z" # Encode to bytes for cython to parse if isinstance(var, str): @@ -76,10 +76,11 @@ cdef class fq_default_ctx: return var - def __init__(self, p=None, degree=None, var=None, modulus=None, fq_type=fq_default_type.DEFAULT): + def __init__(self, p=None, degree=None, var=None, modulus=None, fq_type=fq_default_type.DEFAULT, + check_prime=True, check_modulus=True): # Ensure the var used for the generator of GF(p^d) is a single byte - # TODO: this var is meaningless for GF(p) -- we could handle this somehow? var = self._parse_input_var(var) + self.var = var # Ensure the fq_type is an integer between 0, 5 -- we allow users to # input a string which is converted as an enum @@ -89,16 +90,17 @@ cdef class fq_default_ctx: if modulus is not None: # If the polynomial has no known characteristic, we can try and create one # using the supplied prime - if not (typecheck(modulus, fmpz_mod_poly) or typecheck(modulus, nmod_poly)): + if not typecheck(modulus, fmpz_mod_poly): if p is None: raise ValueError("cannot create from modulus if no characteristic is known") - ring_ctx = fmpz_mod_poly_ctx(p) + if not ring_ctx.is_prime(): + raise ValueError("characteristic is not prime") modulus = ring_ctx.any_as_fmpz_mod_poly(modulus) if modulus is NotImplemented: raise TypeError("modulus cannot be cast to fmpz_mod_poly") - self._set_from_modulus(modulus, var, fq_type) + self._set_from_modulus(modulus, var, fq_type, check_prime=check_prime, check_modulus=check_modulus) return # If there's no modulus and no prime, we can't continue @@ -110,23 +112,16 @@ cdef class fq_default_ctx: degree = 1 # Construct the field from the prime and degree GF(p^d) - self._set_from_order(p, degree, var, fq_type) - - cdef _c_set_from_order(self, fmpz p, int d, char *var, - fq_default_type fq_type=fq_default_type.DEFAULT): - self.var = var - fq_default_ctx_init_type(self.val, p.val, d, self.var, fq_type) - self._initialized = True + self._set_from_order(p, degree, var, fq_type, check_prime=check_prime) - cdef _set_from_order(self, p, d, var, - fq_type=fq_default_type.DEFAULT, check_prime=True): + cdef _set_from_order(self, p, d, var, fq_type=fq_default_type.DEFAULT, check_prime=True): """ Construct a context for the finite field GF(p^d). `var` is a name for the ring generator of this field over GF(p). The optional parameter `type` select the implementation. For more - information about the types available, see :class:`~.fq_default_type` + information about the types available, see :class:`~.fq_default_type` for possible types. """ # c_from_order expects the characteristic to be fmpz type @@ -141,24 +136,11 @@ cdef class fq_default_ctx: if d < 1: raise ValueError(f"the degree must be positive, got {d = }") - # Cython type conversion and context initalisation - self._c_set_from_order(prime, d, var, fq_type) - - cdef _c_set_from_modulus(self, modulus, char *var, - fq_default_type fq_type=fq_default_type.DEFAULT): - self.var = var - if typecheck(modulus, fmpz_mod_poly): - fq_default_ctx_init_modulus_type(self.val, (modulus).val, - (modulus).ctx.mod.val, self.var, fq_type) - elif typecheck(modulus, nmod_poly): - fq_default_ctx_init_modulus_nmod_type(self.val, (modulus).val, - self.var, fq_type) - else: - raise TypeError(f"modulus must be fmpz_mod_poly or nmod_poly, got {modulus!r}") + fq_default_ctx_init_type(self.val, (prime).val, d, self.var, fq_type) self._initialized = True - cdef _set_from_modulus(self, modulus, var, - fq_type=fq_default_type.DEFAULT, check_modulus=True): + cdef _set_from_modulus(self, modulus, var, fq_type=fq_default_type.DEFAULT, + check_prime=True, check_modulus=True): """ Construct a context for a finite field from an irreducible polynomial. @@ -167,14 +149,18 @@ cdef class fq_default_ctx: `var` is a name for the ring generator of this field over the prime field. The optional parameter `type` select the implementation. For more - information about the types available, see :class:`~.fq_default_type` + information about the types available, see :class:`~.fq_default_type` for possible types. """ + if check_prime and not (modulus).ctx.is_prime(): + raise ValueError("characteristic is not prime") + if check_modulus and not modulus.is_irreducible(): raise ValueError("modulus must be irreducible") - # Cython type conversion and context initalisation - self._c_set_from_modulus(modulus, var, fq_type) + fq_default_ctx_init_modulus_type(self.val, (modulus).val, + (modulus).ctx.mod.val, self.var, fq_type) + self._initialized = True @property def fq_type(self): @@ -383,7 +369,7 @@ cdef class fq_default_ctx: # convert from fq_default if typecheck(obj, fq_default): if self != (obj).ctx: - raise ValueError("contexts dont match") + raise ValueError("fields must match") return obj cdef fq_default res @@ -419,7 +405,7 @@ cdef class fq_default_ctx: return False def __hash__(self): - return hash((self.type, self.var, self.prime(), self.modulus())) + return hash((self.fq_type, self.var, self.prime(), self.modulus())) def __str__(self): if self.degree() == 1: @@ -517,9 +503,6 @@ cdef class fq_default(flint_scalar): def str(self): return self.polynomial().str(var=self.ctx.var.decode()) - def repr(self): - return f"fq_default({self.to_list(), self.ctx.__repr__()})" - def __hash__(self): return hash((self.polynomial(), hash(self.ctx))) @@ -572,10 +555,10 @@ cdef class fq_default(flint_scalar): # Conversion failed, element was not a compatible scalar if check is NotImplemented: - res = False - else: - # We now have an fq_default element with the same context, so compare value only - res = fq_default_equal(self.val, (cmp).val, self.ctx.val) + return NotImplemented + + # We now have an fq_default element with the same context, so compare value only + res = fq_default_equal(self.val, (cmp).val, self.ctx.val) # Flip the result of res if we're doing not equals if op == 2: @@ -686,7 +669,7 @@ cdef class fq_default(flint_scalar): >>> a = gf([1,2,3]) >>> b = a.inverse() >>> b - 68*x^2 + 17*x + 116 + 68*z^2 + 17*z + 116 >>> a*b == gf.one() True """ @@ -701,7 +684,7 @@ cdef class fq_default(flint_scalar): >>> a.square() == a*a True >>> a.square() - 110*x^2 + 101*x + 25 + 110*z^2 + 101*z + 25 """ cdef fq_default res res = self.ctx.new_ctype_fq_default() @@ -721,7 +704,7 @@ cdef class fq_default(flint_scalar): >>> pow(a, 2**128) == pow(a, 2**128 % (163**3 - 1)) True >>> pow(a, 123) - 46*x^2 + 110*x + 155 + 46*z^2 + 110*z + 155 """ cdef fq_default res @@ -741,11 +724,8 @@ cdef class fq_default(flint_scalar): fq_default_pow_ui(res.val, res.val, e, self.ctx.val) return res - # Attempt to cast the exponent to an fmpz type then exponentiate + # Cast the exponent to fmpz type e_fmpz = any_as_fmpz(e) - if e_fmpz is NotImplemented: - raise TypeError(f"exponent {e = } cannot be cast to fmpz") - fq_default_pow(res.val, res.val, (e_fmpz).val, self.ctx.val) return res @@ -761,7 +741,7 @@ cdef class fq_default(flint_scalar): True >>> b = a.sqrt() >>> b - 95*x^2 + 36*x + 34 + 95*z^2 + 36*z + 34 >>> b**2 in [a, -a] True """ @@ -796,7 +776,7 @@ cdef class fq_default(flint_scalar): >>> gf = fq_default_ctx(163, 3) >>> a = gf([1,2,3]) >>> a.pth_root() - 5*x^2 + 152*x + 119 + 5*z^2 + 152*z + 119 """ cdef fq_default res res = self.ctx.new_ctype_fq_default() @@ -840,9 +820,9 @@ cdef class fq_default(flint_scalar): >>> gf = fq_default_ctx(163, 3) >>> a = gf([1,2,3]) >>> a.frobenius() - 155*x^2 + 9*x + 4 + 155*z^2 + 9*z + 4 >>> a.frobenius(2) - 5*x^2 + 152*x + 119 + 5*z^2 + 152*z + 119 >>> a == a.frobenius(3) True >>> a.frobenius(2) == a.frobenius(-1) diff --git a/src/flint/types/fq_default_poly.pxd b/src/flint/types/fq_default_poly.pxd new file mode 100644 index 00000000..cec35dcf --- /dev/null +++ b/src/flint/types/fq_default_poly.pxd @@ -0,0 +1,20 @@ +from flint.flintlib.fq_default_poly cimport * +from flint.flintlib.fq_default_poly_factor cimport * +from flint.flintlib.fq_default cimport fq_default_neg + +from flint.flint_base.flint_base cimport flint_poly +from flint.types.fq_default cimport fq_default_ctx + + +cdef class fq_default_poly_ctx: + cdef fq_default_ctx field + cdef any_as_fq_default_poly(self, obj) + cdef set_any_as_fq_default_poly(self, fq_default_poly_t poly, obj) + cdef set_list_as_fq_default_poly(self, fq_default_poly_t poly, val) + cdef new_ctype_poly(self) + +cdef class fq_default_poly(flint_poly): + cdef fq_default_poly_t val + cdef fq_default_poly_ctx ctx + cpdef long length(self) + cpdef long degree(self) diff --git a/src/flint/types/fq_default_poly.pyx b/src/flint/types/fq_default_poly.pyx new file mode 100644 index 00000000..1ee8aabf --- /dev/null +++ b/src/flint/types/fq_default_poly.pyx @@ -0,0 +1,1669 @@ +from cpython.list cimport PyList_GET_SIZE +from flint.flint_base.flint_base cimport flint_poly + +from flint.types.fmpz cimport fmpz, any_as_fmpz +from flint.types.fmpz_poly cimport fmpz_poly +from flint.types.fmpz_mod_poly cimport fmpz_mod_poly +from flint.types.nmod_poly cimport nmod_poly +from flint.types.fq_default cimport fq_default_ctx, fq_default + +from flint.pyflint cimport global_random_state + +from flint.utils.typecheck cimport typecheck + +from flint.utils.flint_exceptions import DomainError + +cdef class fq_default_poly_ctx: + r""" + Context object for creating :class:`~.fq_default_poly` initalised + with a finite field `GF(p^d)`. + + >>> fq_default_poly_ctx(163, 3, fq_type="FQ_NMOD") + fq_default_poly_ctx(fq_default_ctx(163, 3, 'z', x^3 + 7*x + 161, 'FQ_NMOD')) + """ + def __cinit__(self): + pass + + def __dealloc__(self): + pass + + def __init__(self, *args, **kwargs): + # Allow context to be made from fq_default_ctx + if len(args) == 1 and typecheck(args[0], fq_default_ctx): + self.field = args[0] + else: # Otherwise attempt to create context from moduli + self.field = fq_default_ctx(*args, **kwargs) + + cdef set_list_as_fq_default_poly(self, fq_default_poly_t poly, val): + cdef long i, n + cdef fmpz_t x + + # Get size of list and create a polynomial of length n + n = PyList_GET_SIZE(val) + fq_default_poly_fit_length(poly, n, self.field.val) + + # Iterate through the list and attempt to coerce every element + # to an fq_type using the context + for i in range(n): + # First coerce the list element as an fq_default type + v = self.field.any_as_fq_default(val[i]) + if v is NotImplemented: + raise TypeError(f"unsupported coefficient in list: {val[i] = }, {type(val[i]) = }") + + # Set the coefficient of the polynomial + fq_default_poly_set_coeff( + poly, i, (v).val, self.field.val + ) + + cdef set_any_as_fq_default_poly(self, fq_default_poly_t poly, obj): + # First try and coerce polynomials to polynomials + if typecheck(obj, fq_default_poly): + if self != (obj).ctx: + raise ValueError("fields must match") + fq_default_poly_set(poly, (obj).val, self.field.val) + return + + if typecheck(obj, fmpz_poly): + fq_default_poly_set_fmpz_poly(poly, (obj).val, self.field.val) + return + + if typecheck(obj, fmpz_mod_poly) and self.prime() == (obj).ctx.modulus(): + fq_default_poly_set_fmpz_mod_poly(poly, (obj).val, self.field.val) + return + + if typecheck(obj, nmod_poly) and self.prime() == (obj).modulus(): + fq_default_poly_set_nmod_poly(poly, (obj).val, self.field.val) + return + + # Otherwise attempt to coerce the object to fq_default and + # set a constant polynomial + v = self.field.any_as_fq_default(obj) + if v is NotImplemented: + return NotImplemented + + fq_default_poly_set_fq_default(poly, (v).val, self.field.val) + + cdef any_as_fq_default_poly(self, obj): + # If fq_default_poly, return if fields match + if typecheck(obj, fq_default_poly): + if self != (obj).ctx: + raise ValueError("fields must match") + return obj + + # For all other types attempt to coerce to a fq_default_poly + cdef fq_default_poly res + res = self.new_ctype_poly() + check = self.set_any_as_fq_default_poly(res.val, obj) + if check is NotImplemented: + return NotImplemented + return res + + def base_field(self): + """ + Return the base field of the polynomial ring + + >>> R = fq_default_poly_ctx(65537, 3) + >>> R.base_field() + fq_default_ctx(65537, 3, 'z', x^3 + 3*x^2 + 30077, 'FQ_NMOD') + + """ + return self.field + + def characteristic(self): + """ + Return the characteristic of the field from the context + as an ``fmpz`` type + + >>> R = fq_default_poly_ctx(65537, 3) + >>> R.characteristic() + 65537 + + """ + return self.field.characteristic() + + prime = characteristic + + def zero(self): + """ + Return the zero element of this polynomial ring + + >>> R = fq_default_poly_ctx(163) + >>> R.zero() + 0 + """ + cdef fq_default_poly res + res = self.new_ctype_poly() + fq_default_poly_zero(res.val, self.field.val) + return res + + def one(self): + """ + Return the one element of this polynomial ring + + >>> R = fq_default_poly_ctx(163) + >>> R.one() + 1 + """ + cdef fq_default_poly res + res = self.new_ctype_poly() + fq_default_poly_one(res.val, self.field.val) + return res + + def gen(self): + """ + Return the generator of the polynomial: `x` + + >>> R = fq_default_poly_ctx(163) + >>> R.gen() + x + """ + cdef fq_default_poly res + res = self.new_ctype_poly() + fq_default_poly_gen(res.val, self.field.val) + return res + + def random_element(self, degree=3, not_zero=False, monic=False, irreducible=False): + """ + Return a random element of degree ``degree``. If ``not_zero`` + is ``True``, ensures the output is not zero, if ``monic`` is + ``True``, ensures the output is monic. If ``irreducible`` is + ``True``, ensures that the output is irreducible. + + >>> R = fq_default_poly_ctx(163, 3) + >>> f = R.random_element() + >>> f.degree() <= 3 + True + >>> f = R.random_element(degree=123) + >>> f.degree() <= 123 + True + >>> f = R.random_element(monic=True) + >>> f.is_monic() + True + >>> f = R.random_element(degree=13, monic=True, irreducible=True) + >>> f.degree() <= 13 + True + >>> f.is_monic() + True + >>> f.is_irreducible() + True + """ + cdef slong length + if not (isinstance(monic, bool) and isinstance(irreducible, bool) and isinstance(not_zero, bool)): + raise TypeError("All of `not_zero`, `monic` and `irreducible` must be of type bool") + + length = degree + 1 + if length <= 0: + raise ValueError("The degree argument must be non-negative") + + cdef fq_default_poly res + res = self.new_ctype_poly() + # all irreducible elements are returned as monic polynomials + if irreducible: + fq_default_poly_randtest_irreducible( + res.val, global_random_state, length, self.field.val + ) + elif monic: + fq_default_poly_randtest_monic( + res.val, global_random_state, length, self.field.val + ) + elif not_zero: + fq_default_poly_randtest_not_zero( + res.val, global_random_state, length, self.field.val + ) + else: + fq_default_poly_randtest( + res.val, global_random_state, length, self.field.val + ) + return res + + cdef new_ctype_poly(self): + return fq_default_poly.__new__(fq_default_poly, None, self) + + def __eq__(self, other): + # Most often, we expect both `fq_default_poly` to be pointing + # to the same ctx, so this seems the fastest way to check + if self is other: + return True + + # If they're not the same object in memory, they may have the + # same field, which is good enough + if typecheck(other, fq_default_poly_ctx): + return self.field == (other).field + return False + + def __hash__(self): + return hash(("polynomial_ring", self.field)) + + def __str__(self): + return f"Context for fq_default_poly with field: {self.field}" + + def __repr__(self): + return f"fq_default_poly_ctx({repr(self.field)})" + + def __call__(self, val): + return fq_default_poly(val, self) + + +cdef class fq_default_poly(flint_poly): + """ + The *fq_default_poly* type represents univariate polynomials + over a finite field. + + An *fq_default_poly* element is constructed from an :class:`~.fq_default_poly_ctx` + either by passing it as an argument to the type, or + by directly calling the context: + + >>> fq_default_poly([1,-2,3], fq_default_poly_ctx(2**127 - 1)) + 3*x^2 + 170141183460469231731687303715884105725*x + 1 + >>> R = fq_default_poly_ctx(2**127 - 1) + >>> R([4,5,6]) + 6*x^2 + 5*x + 4 + + """ + def __cinit__(self, val, ctx): + if not typecheck(ctx, fq_default_poly_ctx): + raise TypeError + self.ctx = ctx + fq_default_poly_init(self.val, self.ctx.field.val) + + def __dealloc__(self): + if self.ctx is not None: + fq_default_poly_clear(self.val, self.ctx.field.val) + + def __init__(self, val, ctx): + if typecheck(val, list): + self.ctx.set_list_as_fq_default_poly(self.val, val) + return + + check = self.ctx.set_any_as_fq_default_poly(self.val, val) + if check is NotImplemented: + raise TypeError + + def __getitem__(self, long i): + cdef fq_default x + x = self.ctx.field.new_ctype_fq_default() + if i < 0: + return x + fq_default_poly_get_coeff( + x.val, self.val, i, self.ctx.field.val + ) + return x + + def __setitem__(self, long i, x): + if i < 0: + raise ValueError("cannot assign to index < 0 of polynomial") + v = self.ctx.field.any_as_fq_default(x) + if v is NotImplemented: + raise TypeError + fq_default_poly_set_coeff( + self.val, i, (v).val, self.ctx.field.val + ) + + def __richcmp__(self, other, int op): + cdef bint res + if op != 2 and op != 3: + raise TypeError("fq_default_poly cannot be ordered") + + if not typecheck(other, fq_default_poly): + other = self.ctx.any_as_fq_default_poly(other) + + if typecheck(other, fq_default_poly): + res = (self.ctx == (other).ctx) and \ + fq_default_poly_equal(self.val, (other).val, self.ctx.field.val) + if op == 2: + return res + else: + return not res + else: + return NotImplemented + + def __len__(self): + return self.length() + + def __hash__(self): + return hash(tuple(self.coeffs())) + + cpdef long length(self): + """ + Return the length of the polynomial + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3]) + >>> f.length() + 3 + + """ + return fq_default_poly_length(self.val, self.ctx.field.val) + + cpdef long degree(self): + """ + Return the degree of the polynomial + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3]) + >>> f.degree() + 2 + + """ + return fq_default_poly_degree(self.val, self.ctx.field.val) + + def constant_coefficient(self): + """ + Return the constant coefficient of this polynomial. + + >>> R = fq_default_poly_ctx(163, 3) + >>> f = R([1,2,3]) + >>> f.constant_coefficient() + 1 + """ + return self[0] + + def leading_coefficient(self): + """ + Return the leading coefficient of this polynomial. + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3]) + >>> f.leading_coefficient() + 3 + """ + d = self.degree() + if d < 0: + return self.ctx.field.zero() + return self[self.degree()] + + def reverse(self, degree=None): + """ + Return a polynomial with the coefficients of this polynomial + reversed. + + If ``degree`` is not None, the output polynomial will be zero-padded + or truncated before being reversed. NOTE: degree must be non-negative. + + >>> R = fq_default_poly_ctx(163, 3) + >>> f = R([1,2,3,4,5]) + >>> f.reverse() + x^4 + 2*x^3 + 3*x^2 + 4*x + 5 + >>> f.reverse(degree=1) + x + 2 + >>> f.reverse(degree=100) + x^100 + 2*x^99 + 3*x^98 + 4*x^97 + 5*x^96 + """ + cdef fq_default_poly res + cdef slong d + + if degree is not None: + d = degree + if d != degree or d < 0: + raise ValueError(f"degree argument must be a non-negative integer, got {degree}") + else: + d = fq_default_poly_degree(self.val, self.ctx.field.val) + + length = d + 1 + + res = self.ctx.new_ctype_poly() + fq_default_poly_reverse(res.val, self.val, length, self.ctx.field.val) + return res + + def truncate(self, slong n): + """ + Notionally truncate the polynomial to have length ``n``. If + ``n`` is larger than the length of the input, then ``self`` is + returned. If ``n`` is not positive, then the zero polynomial + is returned. + + Effectively returns this polynomial :math:`\mod x^n`. + + >>> R = fq_default_poly_ctx(163, 5) + >>> f = R([1,2,3]) + >>> f.truncate(3) == f + True + >>> f.truncate(2) + 2*x + 1 + >>> f.truncate(1) + 1 + >>> f.truncate(0) + 0 + >>> f.truncate(-1) + 0 + """ + cdef fq_default_poly res + + length = fq_default_poly_degree(self.val, self.ctx.field.val) + res = self.ctx.new_ctype_poly() + + if n <= 0: # return zero + return res + elif n > length: # do nothing + fq_default_poly_set( + res.val, self.val, self.ctx.field.val + ) + else: + fq_default_poly_set_trunc( + res.val, self.val, n, self.ctx.field.val + ) + return res + + def monic(self): + """ + Return this polynomial divided by its leading coefficient. + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3]) + >>> f.monic() + x^2 + 55*x + 109 + """ + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + fq_default_poly_make_monic( + res.val, self.val, self.ctx.field.val + ) + return res + + def is_zero(self): + """ + Return ``True`` if the polynomial is the zero polynomial + and ``False`` otherwise + + >>> R = fq_default_poly_ctx(163, 3) + >>> f = R.zero() + >>> f.is_zero() + True + """ + return 0 != fq_default_poly_is_zero(self.val, self.ctx.field.val) + + def is_one(self): + """ + Return ``True`` if the polynomial is equal to one + and ``False`` otherwise + + >>> R = fq_default_poly_ctx(163, 3) + >>> f = R.one() + >>> f.is_one() + True + """ + return 0 != fq_default_poly_is_one(self.val, self.ctx.field.val) + + def is_gen(self): + """ + Return ``True`` if the polynomial is the generator + of the polynomial, `x`, and ``False`` otherwise + + >>> R = fq_default_poly_ctx(163, 3) + >>> f = R([0,1]) + >>> f.is_gen() + True + """ + return 0 != fq_default_poly_is_gen(self.val, self.ctx.field.val) + + def is_constant(self): + """ + Return ``True`` if this is a constant polynomial. + + >>> R = fq_default_poly_ctx(163, 3) + >>> x = R.gen() + >>> x.is_constant() + False + >>> R(123).is_constant() + True + """ + return self.degree() <= 0 + + def is_monic(self): + """ + Return whether this polynomial is monic. + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = x**2 + 5*x + 3 + >>> f.is_monic() + True + >>> f = 5*x**2 + x + 3 + >>> f.is_monic() + False + """ + return self.leading_coefficient().is_one() + + def is_irreducible(self): + """ + Return whether this polynomial is irreducible. + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = x**2 + 5*x + 3 + >>> f.is_irreducible() + True + >>> f = x**2 + x + 3 + >>> f.is_irreducible() + False + """ + return 1 == fq_default_poly_is_irreducible(self.val, self.ctx.field.val) + + def is_squarefree(self): + """ + Return whether this polynomial is squarefree. + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = (x + 1)**2 * (x + 3) + >>> f.is_squarefree() + False + >>> f = (x + 1) * (x + 3) + >>> f.is_squarefree() + True + + """ + return 1 == fq_default_poly_is_squarefree(self.val, self.ctx.field.val) + + # ==================================== + # Native Arithmetic + # ==================================== + + def __pos__(self): + return self + + def __neg__(self): + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + fq_default_poly_neg( + res.val, self.val, self.ctx.field.val + ) + return res + + def __add__(self, other): + cdef fq_default_poly res + + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + return NotImplemented + + res = self.ctx.new_ctype_poly() + fq_default_poly_add( + res.val, self.val, (other).val, self.ctx.field.val + ) + return res + + def __radd__(self, other): + return self.__add__(other) + + def __sub__(self, other): + cdef fq_default_poly res + + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + return NotImplemented + + res = self.ctx.new_ctype_poly() + fq_default_poly_sub( + res.val, self.val, (other).val, self.ctx.field.val + ) + return res + + def __rsub__(self, other): + cdef fq_default_poly res + + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + return NotImplemented + + res = self.ctx.new_ctype_poly() + fq_default_poly_sub( + res.val, (other).val, self.val, self.ctx.field.val + ) + return res + + def __mul__(self, other): + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + + # First try scalar multiplication + if not typecheck(other, fq_default_poly): + scalar = self.ctx.field.any_as_fq_default(other) + if scalar is not NotImplemented: + fq_default_poly_scalar_mul_fq_default( + res.val, self.val, (scalar).val, self.ctx.field.val + ) + return res + + # Otherwise treat other as an fq_default_poly + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + return NotImplemented + fq_default_poly_mul( + res.val, self.val, (other).val, self.ctx.field.val + ) + return res + + def __rmul__(self, other): + return self.__mul__(other) + + def __pow__(self, e, mod=None): + if mod is not None: + return self.pow_mod(e, mod) + + cdef fq_default_poly res + if e < 0: + raise ValueError("Exponent must be non-negative") + + if e == 2: + return self.square() + + res = self.ctx.new_ctype_poly() + fq_default_poly_pow( + res.val, self.val, e, self.ctx.field.val + ) + return res + + def pow_mod(self, e, modulus): + """ + Returns ``self`` raised to the power ``e`` modulo ``modulus``: + :math:`f^e \mod g`/ + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = 30*x**6 + 104*x**5 + 76*x**4 + 33*x**3 + 70*x**2 + 44*x + 65 + >>> mod = x**4 + 93*x**3 + 78*x**2 + 72*x + 149 + >>> f.pow_mod(123, mod) + 3*x^3 + 25*x^2 + 115*x + 161 + >>> f.pow_mod(2**64, mod) + 52*x^3 + 96*x^2 + 136*x + 9 + """ + cdef fq_default_poly res + + if e < 0: + raise ValueError("Exponent must be non-negative") + + modulus = self.ctx.any_as_fq_default_poly(modulus) + if modulus is NotImplemented: + raise TypeError(f"Cannot interpret {modulus} as a polynomial") + + # Output polynomial + res = self.ctx.new_ctype_poly() + + # For small exponents, use a simple binary exponentiation method + if e.bit_length() < 32: + fq_default_poly_powmod_ui_binexp( + res.val, self.val, e, (modulus).val, res.ctx.field.val + ) + return res + + # For larger exponents we need to cast e to an fmpz first + e_fmpz = any_as_fmpz(e) + fq_default_poly_powmod_fmpz_binexp( + res.val, self.val, (e_fmpz).val, (modulus).val, res.ctx.field.val + ) + return res + + def divmod(self, other): + """ + Return `Q`, `R` such that for ``self`` = `F` and ``other`` = `G`, + `F = Q*G + R` + + >>> R = fq_default_poly_ctx(163) + >>> f = R([123, 129, 63, 14, 51, 76, 133]) + >>> g = R([106, 134, 32, 41, 158, 115, 115]) + >>> f.divmod(g) + (21, 106*x^5 + 156*x^4 + 131*x^3 + 43*x^2 + 86*x + 16) + """ + cdef fmpz_t f + cdef fq_default_poly Q, R + + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + raise TypeError(f"Cannot interpret {other} as a polynomial") + + if other.is_zero(): + raise ZeroDivisionError(f"Cannot compute divmod as {other =}") + + Q = self.ctx.new_ctype_poly() + R = self.ctx.new_ctype_poly() + fq_default_poly_divrem( + Q.val, R.val, self.val, (other).val, self.ctx.field.val + ) + return Q, R + + def __divmod__(self, other): + return self.divmod(other) + + def __rdivmod__(self, other): + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + return other + return other.divmod(self) + + def exact_division(self, other): + """ + Attempt to compute the exact quotient of self with other + Raises a value error if divison without remainer is not + possible. + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,1]) + >>> g = R([1,1]) + >>> f.exact_division(g) + x + 1 + """ + cdef bint check + cdef fq_default_poly res + + # Case when right is not fq_default_poly, try to convert to fmpz + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + raise TypeError(f"Cannot convert {other} to `fq_default_poly` type.") + + if other.is_zero(): + raise ZeroDivisionError(f"Cannot divide by zero") + + res = self.ctx.new_ctype_poly() + check = fq_default_poly_divides( + res.val, self.val, (other).val, res.ctx.field.val + ) + if check == 0: + raise DomainError( + f"{other} does not divide {self}" + ) + + return res + + def __truediv__(self, other): + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + + # First try scalar division + if not typecheck(other, fq_default_poly): + scalar = self.ctx.field.any_as_fq_default(other) + if scalar is not NotImplemented: + if scalar.is_zero(): + raise ZeroDivisionError(f"Cannot divide by zero") + fq_default_poly_scalar_div_fq_default( + res.val, self.val, (scalar).val, self.ctx.field.val + ) + return res + + # Otherwise treat other as an fq_default_poly + return self.exact_division(other) + + def __rtruediv__(self, other): + if self.is_zero(): + raise ZeroDivisionError(f"Cannot divide by zero") + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + return other + return other.exact_division(self) + + def __floordiv__(self, other): + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + + # First try scalar division + if not typecheck(other, fq_default_poly): + scalar = self.ctx.field.any_as_fq_default(other) + if scalar is not NotImplemented: + if scalar.is_zero(): + raise ZeroDivisionError(f"Cannot divide by zero") + fq_default_poly_scalar_div_fq_default( + res.val, self.val, (scalar).val, self.ctx.field.val + ) + return res + + # Coerce right element to fq_default_poly + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + return other + + # Do not divide by zero + if other.is_zero(): + raise ZeroDivisionError(f"Cannot divide by zero") + + # floor division uses divmod but ignores the rem term + cdef fq_default_poly rem + rem = self.ctx.new_ctype_poly() + + fq_default_poly_divrem( + res.val, rem.val, self.val, (other).val, self.ctx.field.val + ) + return res + + def __rfloordiv__(self, other): + cdef fq_default_poly res + cdef fq_default_poly rem + + # Do not divide by zero + if self.is_zero(): + raise ZeroDivisionError("Cannot divide by zero") + + # Coerce right element to fq_default_poly + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + return other + + # floor division uses divmod but ignores the rem term + res = self.ctx.new_ctype_poly() + rem = self.ctx.new_ctype_poly() + fq_default_poly_divrem( + res.val, rem.val, (other).val, self.val, self.ctx.field.val + ) + return res + + def __mod__(self, other): + cdef fq_default_poly res + + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + return NotImplemented + + if other.is_zero(): + raise ZeroDivisionError("Cannot compute remainder modulo 0") + + res = self.ctx.new_ctype_poly() + fq_default_poly_rem( + res.val, self.val, (other).val, self.ctx.field.val + ) + return res + + def __rmod__(self, other): + cdef fq_default_poly res + + if self.is_zero(): + raise ZeroDivisionError("Cannot compute remainder modulo 0") + + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + return NotImplemented + + res = self.ctx.new_ctype_poly() + fq_default_poly_rem( + res.val, (other).val, self.val, self.ctx.field.val + ) + return res + + # ==================================== + # Additional Arithmetic + # ==================================== + + def square(self): + """ + Returns the square of ``self`` + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3]) + >>> f.square() + 9*x^4 + 12*x^3 + 10*x^2 + 4*x + 1 + """ + cdef fq_default_poly res + + res = self.ctx.new_ctype_poly() + fq_default_poly_sqr( + res.val, self.val, self.ctx.field.val + ) + return res + + def left_shift(self, slong n): + """ + Returns ``self`` shifted left by ``n`` coefficients by inserting + zero coefficients. This is equivalent to multiplying the polynomial + by x^n + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3]) + >>> f.left_shift(0) + 3*x^2 + 2*x + 1 + >>> f.left_shift(1) + 3*x^3 + 2*x^2 + x + >>> f.left_shift(4) + 3*x^6 + 2*x^5 + x^4 + + """ + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + + if n < 0: + raise ValueError("Value must be shifted by a non-negative integer") + + if n > 0: + fq_default_poly_shift_left( + res.val, self.val, n, self.ctx.field.val + ) + else: # do nothing, just copy self + fq_default_poly_set( + res.val, self.val, self.ctx.field.val + ) + + return res + + def right_shift(self, slong n): + """ + Returns ``self`` shifted right by ``n`` coefficients. + This is equivalent to the floor division of the polynomial + by x^n + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3]) + >>> f.right_shift(0) + 3*x^2 + 2*x + 1 + >>> f.right_shift(1) + 3*x + 2 + >>> f.right_shift(4) + 0 + """ + cdef fq_default_poly res + + if n < 0: + raise ValueError("Value must be shifted by a non-negative integer") + + res = self.ctx.new_ctype_poly() + + if n > 0: + fq_default_poly_shift_right( + res.val, self.val, n, self.ctx.field.val + ) + else: # do nothing, just copy self + fq_default_poly_set( + res.val, self.val, self.ctx.field.val + ) + + return res + + def sqrt(self): + """ + If ``self`` is a perfect square, compute the square root + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,1]) + >>> (f*f).sqrt() + x + 1 + + """ + cdef fq_default_poly res + cdef int check + + res = self.ctx.new_ctype_poly() + check = fq_default_poly_sqrt( + res.val, self.val, res.ctx.field.val + ) + if check != 1: + raise ValueError( + f"Cannot compute square-root {self}" + ) + return res + + def mul_mod(self, other, modulus): + """ + Computes the multiplication of ``self`` with ``other`` + modulo the polynomial ``modulus`` + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = 30*x**6 + 104*x**5 + 76*x**4 + 33*x**3 + 70*x**2 + 44*x + 65 + >>> g = 43*x**6 + 91*x**5 + 77*x**4 + 113*x**3 + 71*x**2 + 132*x + 60 + >>> mod = x**4 + 93*x**3 + 78*x**2 + 72*x + 149 + >>> + >>> f.mul_mod(g, mod) + 106*x^3 + 44*x^2 + 53*x + 77 + """ + cdef fq_default_poly res + + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + raise TypeError(f"Cannot interpret {other} as a polynomial") + + modulus = self.ctx.any_as_fq_default_poly(modulus) + if modulus is NotImplemented: + raise TypeError(f"Cannot interpret {modulus} as a polynomial") + + res = self.ctx.new_ctype_poly() + + fq_default_poly_mulmod( + res.val, self.val, (other).val, (modulus).val, res.ctx.field.val + ) + return res + + # ==================================== + # Truncated Arithmetic + # ==================================== + + def equal_trunc(self, other, slong n): + """ + Returns if two polynomials are equal when truncated to the first ``n`` terms + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3,4,5]) + >>> h = R([1,2,3]) + >>> f.equal_trunc(h, 3) + True + >>> f.equal_trunc(h, 4) + False + """ + # Only allow comparison with other fmpz_mod_poly + if not typecheck(other, fq_default_poly): + return False + + # Ensure the contexts match + other_c = other + if self.ctx != other_c.ctx: + return False + + return 1 == fq_default_poly_equal_trunc(self.val, other_c.val, n, self.ctx.field.val) + + def add_trunc(self, other, slong n): + """ + Truncate ``self`` and ``other`` to polynomials of length ``n`` and return their sum + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3,4,5]) + >>> h = R([1,2,3]) + >>> f.add_trunc(h, 2) + 4*x + 2 + >>> f.add_trunc(h, 3) + 6*x^2 + 4*x + 2 + """ + # Only allow addition with other fq_default_poly + if not typecheck(other, fq_default_poly): + raise TypeError("other polynomial must be of type fq_default_poly") + + # Ensure the contexts match + other_c = other + if self.ctx != other_c.ctx: + raise ValueError("other polynomial's context does not match") + + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + fq_default_poly_add_series( + res.val, self.val, other_c.val, n, res.ctx.field.val + ) + return res + + def sub_trunc(self, other, slong n): + """ + Truncate ``self`` and ``other`` to polynomials of length ``n`` and return their difference + + >>> R = fq_default_poly_ctx(163) + >>> f = R([2,3,5,7,11]) + >>> h = R([1,2,4,8,16]) + >>> f.sub_trunc(h, 2) + x + 1 + >>> f.sub_trunc(h, 4) + 162*x^3 + x^2 + x + 1 + """ + # Only allow subtraction with other fq_default_poly + if not typecheck(other, fq_default_poly): + raise TypeError("other polynomial must be of type fq_default_poly") + + # Ensure the contexts match + other_c = other + if self.ctx != other_c.ctx: + raise ValueError("other polynomial's context does not match") + + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + fq_default_poly_sub_series( + res.val, self.val, other_c.val, n, res.ctx.field.val + ) + return res + + def mul_low(self, other, slong n): + r""" + Returns the lowest ``n`` coefficients of the multiplication of ``self`` with ``other`` + + Equivalent to computing `f(x) \cdot g(x) \mod x^n` + + >>> R = fq_default_poly_ctx(163) + >>> f = R([2,3,5,7,11]) + >>> g = R([1,2,4,8,16]) + >>> f.mul_low(g, 5) + 101*x^4 + 45*x^3 + 19*x^2 + 7*x + 2 + >>> f.mul_low(g, 3) + 19*x^2 + 7*x + 2 + >>> f.mul_low(g, 1) + 2 + """ + # Only allow multiplication with other fq_default_poly + if not typecheck(other, fq_default_poly): + raise TypeError("other polynomial must be of type fq_default_poly") + + # Ensure the contexts match + other_c = other + if self.ctx != other_c.ctx: + raise ValueError("other polynomial's context does not match") + + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + fq_default_poly_mullow( + res.val, self.val, other_c.val, n, res.ctx.field.val + ) + return res + + def pow_trunc(self, slong e, slong n): + """ + Returns ``self`` raised to the power ``e`` modulo `x^n`: + :math:`f^e \mod x^n`/ + + Note: For exponents larger that 2^31 (which do not fit inside a ulong) use the + method :method:`~.pow_mod` with the explicit modulus `x^n`. + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = 30*x**6 + 104*x**5 + 76*x**4 + 33*x**3 + 70*x**2 + 44*x + 65 + >>> f.pow_trunc(2**20, 30) == pow(f, 2**20, x**30) + True + >>> f.pow_trunc(2**20, 5) + 132*x^4 + 113*x^3 + 36*x^2 + 48*x + 6 + """ + if e < 0: + raise ValueError("Exponent must be non-negative") + + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + fq_default_poly_pow_trunc(res.val, self.val, e, n, res.ctx.field.val) + return res + + def sqrt_trunc(self, slong n): + """ + Returns the square root of ``self`` modulo `x^n`. + + Requires that the constant coefficient of the polynomial is one. + + >>> R = fq_default_poly_ctx(163, 3) + >>> x = R.gen() + >>> z = R.base_field().gen() + >>> f = (37*z + 54)*x**3 + (8*z + 94)*x**2 + (52*z + 142)*x + 1 + >>> h = f.sqrt_trunc(4) + >>> h + (7*z^2 + 17*z + 148)*x^3 + (151*z^2 + 114*z + 53)*x^2 + (26*z + 71)*x + 1 + >>> h.mul_low(h, 4) == f + True + """ + cdef fq_default_poly res + + # FLINT requires the constant term is one, so we need to normalise + c = self.constant_coefficient() + if c.is_zero(): + raise ZeroDivisionError("constant coefficient must be invertible (and a square in the field)") + if not c.is_square(): + raise ValueError("constant coefficient of the polynomial must be a square") + self = self / c + + res = self.ctx.new_ctype_poly() + fq_default_poly_sqrt_series( + res.val, self.val, n, res.ctx.field.val + ) + return res * c.sqrt() + + def inv_sqrt_trunc(self, slong n): + """ + Returns the inverse of the square root of ``self`` modulo `x^n`. + + Requires that the constant coefficient of the polynomial is one. + + >>> R = fq_default_poly_ctx(65537, 2) + >>> x = R.gen() + >>> z = R.base_field().gen() + >>> f = 28902*x**3 + (49416*z + 58229)*x**2 + 9441*z*x + (7944*z + 57534) + >>> h = f.inv_sqrt_trunc(3) + >>> h + (23030*z + 8965)*x^2 + (43656*z + 7173)*x + (27935*z + 28199) + >>> (h*h).mul_low(f, 3).is_one() + True + """ + cdef fq_default_poly res + + # FLINT requires the constant term is one, so we need to normalise + c = self.constant_coefficient() + if c.is_zero(): + raise ZeroDivisionError("constant coefficient must be invertible (and a square in the field)") + if not c.is_square(): + raise ValueError("constant coefficient of the polynomial must be a square") + self = self / c + + res = self.ctx.new_ctype_poly() + fq_default_poly_invsqrt_series( + res.val, self.val, n, res.ctx.field.val + ) + return res / c.sqrt() + + def inverse_series_trunc(self, slong n): + """ + Returns the inverse of ``self`` modulo `x^n`. + + >>> R = fq_default_poly_ctx(163, 3) + >>> x = R.gen() + >>> z = R.base_field().gen() + >>> f = (37*z + 54)*x**3 + (8*z + 94)*x**2 + (52*z + 142)*x + 1 + >>> f.inverse_series_trunc(2) + (111*z + 21)*x + 1 + >>> f.inverse_series_trunc(3) + (96*z^2 + 90*z + 21)*x^2 + (111*z + 21)*x + 1 + >>> f.inverse_series_trunc(4) + (34*z^2 + z + 2)*x^3 + (96*z^2 + 90*z + 21)*x^2 + (111*z + 21)*x + 1 + >>> h = f.inverse_series_trunc(4) + >>> f.mul_low(h, 4).is_one() + True + """ + cdef fmpz_t f + cdef fq_default_poly res + + if self.constant_coefficient().is_zero(): + raise ZeroDivisionError("constant coefficient must be invertible") + + res = self.ctx.new_ctype_poly() + fq_default_poly_inv_series( + res.val, self.val, n, res.ctx.field.val + ) + return res + + # ==================================== + # GCD and Extended GCD + # ==================================== + + def gcd(self, other): + """ + Return the greatest common divisor of self and other. + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = x*(x + 1) + >>> f.gcd(x+1) + x + 1 + >>> f.gcd(x*x) + x + + """ + cdef fq_default_poly res + + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + raise TypeError(f"Cannot interpret {other} as a polynomial") + + res = self.ctx.new_ctype_poly() + fq_default_poly_gcd( + res.val, self.val, (other).val, self.ctx.field.val + ) + return res + + def xgcd(self, other): + r""" + Computes the extended gcd of self and other: (`G`, `S`, `T`) + where `G` is the ``gcd(self, other)`` and `S`, `T` are such that: + + :math:`G = \textrm{self}*S + \textrm{other}*T` + + >>> R = fq_default_poly_ctx(163) + >>> f = R([143, 19, 37, 138, 102, 127, 95]) + >>> g = R([139, 9, 35, 154, 87, 120, 24]) + >>> f.xgcd(g) + (x^3 + 128*x^2 + 123*x + 91, 17*x^2 + 49*x + 104, 21*x^2 + 5*x + 25) + >>> G, S, T = f.xgcd(g) + >>> assert G == f*S + g*T + + """ + cdef fq_default_poly G, S, T + cdef fmpz_t f + + other = self.ctx.any_as_fq_default_poly(other) + if other is NotImplemented: + raise TypeError(f"Cannot interpret {other} as a polynomial") + + G = self.ctx.new_ctype_poly() + S = self.ctx.new_ctype_poly() + T = self.ctx.new_ctype_poly() + + fq_default_poly_xgcd( + G.val, S.val, T.val, self.val, (other).val, self.ctx.field.val + ) + + return (G, S, T) + + def inverse_mod(self, other): + """ + Returns the inverse of ``self`` modulo ``other`` + + >>> R = fq_default_poly_ctx(163) + >>> f = R([123, 129, 63, 14, 51, 76, 133]) + >>> h = R([139, 9, 35, 154, 87, 120, 24]) + >>> g = f.inverse_mod(h) + >>> g + 41*x^5 + 121*x^4 + 47*x^3 + 41*x^2 + 6*x + 5 + >>> assert f.mul_mod(g, h).is_one() + """ + G, S, _ = self.xgcd(other) + if not G.is_one(): + raise ValueError(f"polynomial has no inverse modulo {other = }") + return S + + # ==================================== + # Derivative + # ==================================== + + def derivative(self): + """ + The formal derivative of this polynomial + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = 111*x**4 + 58*x**3 + 98*x**2 + 117*x + 7 + >>> f.derivative() + 118*x^3 + 11*x^2 + 33*x + 117 + + """ + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + fq_default_poly_derivative( + res.val, self.val, self.ctx.field.val + ) + return res + + def radical(self): + """ + Return the radical of ``self``, the product of the irreducible + factors of the polynomial. This is also referred to as the + square-free part of the polynomial. + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = (x + 1)**3 * (x + 2) + >>> f.radical() + x^2 + 3*x + 2 + + """ + return self.exact_division(self.gcd(self.derivative())) + + def integral(self): + raise NotImplementedError("fq_default_integral is not available from FLINT") + + # ==================================== + # Evaluation and Composition + # ==================================== + + def evaluate(self, input): + """ + Evaluate ``self`` at a point in the base ring. This is + the same as calling the polynomial directly. + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3,4,5,6]) + >>> f.evaluate(-1) + 160 + >>> f.evaluate(-1) == f(-1) + True + """ + val = self.ctx.field.any_as_fq_default(input) + if val is NotImplemented: + raise TypeError(f"Cannot evaluate the polynomial with input: {input}") + + # When the fq_default type is FMPZ_MOD this function Segfaults for older + # FLINT versions + # See: https://github.com/flintlib/flint/issues/2046 + # TODO: + # Hack for converting self to an fmpz_mod type, needs to be improved + # and could be done when we decide exactly how to handle fq_default to + # fq_type conversions more generally + if self.ctx.field.fq_type == 5: + from flint import fmpz_mod_poly_ctx + ring = fmpz_mod_poly_ctx(self.ctx.characteristic()) + poly = ring([int(i) for i in self.coeffs()]) + return poly(int(input)) + + cdef fq_default res + res = self.ctx.field.new_ctype_fq_default() + fq_default_poly_evaluate_fq_default(res.val, self.val, (val).val, self.ctx.field.val) + return res + + def compose(self, other): + """ + Returns the composition of two polynomials + + To be precise about the order of composition, given ``self``, and ``other`` + by `f(x)`, `g(x)`, returns `f(g(x))`. + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3]) + >>> g = R([0,0,1]) + >>> f.compose(g) + 3*x^4 + 2*x^2 + 1 + >>> g.compose(f) + 9*x^4 + 12*x^3 + 10*x^2 + 4*x + 1 + """ + cdef fq_default_poly res + val = self.ctx.any_as_fq_default_poly(other) + if val is NotImplemented: + raise TypeError(f"Cannot compose the polynomial with input: {other}") + + res = self.ctx.new_ctype_poly() + fq_default_poly_compose(res.val, self.val, (val).val, self.ctx.field.val) + return res + + def compose_mod(self, other, modulus): + """ + Returns the composition of two polynomials modulo a third. + + To be precise about the order of composition, given ``self``, and ``other`` + and ``modulus`` by `f(x)`, `g(x)` and `h(x)`, returns `f(g(x)) \mod h(x)`. + We require that `h(x)` is non-zero. + + >>> R = fq_default_poly_ctx(163) + >>> f = R([1,2,3,4,5]) + >>> g = R([3,2,1]) + >>> h = R([1,0,1,0,1]) + >>> f.compose_mod(g, h) + 63*x^3 + 100*x^2 + 17*x + 63 + >>> g.compose_mod(f, h) + 147*x^3 + 159*x^2 + 4*x + 7 + """ + cdef fq_default_poly res + val = self.ctx.any_as_fq_default_poly(other) + if val is NotImplemented: + raise TypeError(f"cannot compose the polynomial with input: {other}") + + h = self.ctx.any_as_fq_default_poly(modulus) + if h is NotImplemented: + raise TypeError(f"cannot reduce the polynomial with input: {modulus}") + + if h.is_zero(): + raise ZeroDivisionError("cannot reduce modulo zero") + + res = self.ctx.new_ctype_poly() + fq_default_poly_compose_mod(res.val, self.val, (val).val, (h).val, self.ctx.field.val) + return res + + def __call__(self, input): + if typecheck(input, fq_default_poly): + return self.compose(input) + return self.evaluate(input) + + # ==================================== + # Factoring and Root Finding + # ==================================== + + def factor_squarefree(self): + """ + Factors self into irreducible, squarefree factors, returning a tuple + ``(c, factors)`` where `c` is the content of the coefficients and + factors is a list of ``(poly, exp)`` pairs. + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = (x + 1) * (x + 2) + >>> f.factor_squarefree() + (1, [(x^2 + 3*x + 2, 1)]) + >>> f = (x + 1) * (x + 2)**5 + >>> f.factor_squarefree() + (1, [(x + 1, 1), (x + 2, 5)]) + """ + cdef fq_default_poly_factor_t fac + cdef int i + + fq_default_poly_factor_init(fac, self.ctx.field.val) + fq_default_poly_factor_squarefree(fac, self.val, self.ctx.field.val) + + num = fq_default_poly_factor_length(fac, self.ctx.field.val) + res = [0] * num + + cdef fq_default_poly u + for i in range(num): + u = self.ctx.new_ctype_poly() + fq_default_poly_factor_get_poly(u.val, fac, i, self.ctx.field.val) + exp = fq_default_poly_factor_exp(fac, i, self.ctx.field.val) + res[i] = (u, exp) + return self.leading_coefficient(), res + + def factor(self): + """ + Factors self into irreducible factors, returning a tuple + ``(c, factors)`` where `c` is the content of the coefficients and + factors is a list of ``(poly, exp)`` pairs. + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = 6*x**4 + 7*x**3 + 7*x**2 + 8*x + 6 + >>> f.factor() + (6, [(x^4 + 137*x^3 + 137*x^2 + 110*x + 1, 1)]) + >>> f = (x + 1)**3 * (x + 2) + >>> f.factor() + (1, [(x + 2, 1), (x + 1, 3)]) + """ + cdef fq_default_poly_factor_t fac + cdef int i + + fq_default_poly_factor_init(fac, self.ctx.field.val) + + lead = self.leading_coefficient() + fq_default_poly_factor(fac, (lead).val, self.val, self.ctx.field.val) + + num = fq_default_poly_factor_length(fac, self.ctx.field.val) + res = [0] * num + + cdef fq_default_poly u + for i in range(num): + u = self.ctx.new_ctype_poly() + fq_default_poly_factor_get_poly(u.val, fac, i, self.ctx.field.val) + exp = fq_default_poly_factor_exp(fac, i, self.ctx.field.val) + res[i] = (u, exp) + return self.leading_coefficient(), res + + def roots(self, multiplicities=True): + r""" + Return the roots of the polynomial in the finite field + + >>> R = fq_default_poly_ctx(163) + >>> x = R.gen() + >>> f = (x - 1) * (x - 2)**3 * (x - 3)**5 + >>> f.roots() + [(1, 1), (2, 3), (3, 5)] + >>> f.roots(multiplicities=False) + [1, 2, 3] + """ + cdef fq_default_poly_factor_t fac + cdef int i, with_multiplicity + + with_multiplicity = 0 + if multiplicities: + with_multiplicity = 1 + + fq_default_poly_factor_init(fac, self.ctx.field.val) + fq_default_poly_roots(fac, self.val, with_multiplicity, self.ctx.field.val) + + num = fq_default_poly_factor_length(fac, self.ctx.field.val) + res = [0] * num + + cdef fq_default_poly linear_factor + cdef fq_default root + + for i in range(num): + # Get a factor of the form (x - a) + linear_factor = self.ctx.new_ctype_poly() + fq_default_poly_factor_get_poly(linear_factor.val, fac, i, self.ctx.field.val) + + # Compute a from (x - a) + root = self.ctx.field.new_ctype_fq_default() + fq_default_poly_get_coeff( + root.val, linear_factor.val, 0, root.ctx.val + ) + fq_default_neg( + root.val, root.val, root.ctx.val + ) + if multiplicities: + mul = fq_default_poly_factor_exp(fac, i, self.ctx.field.val) + res[i] = (root, mul) + else: + res[i] = root + return res + + def complex_roots(self): + """ + This method is not implemented for polynomials in finite fields + """ + raise DomainError("Cannot compute complex roots for polynomials over finite fields") + + # ==================================== + # Inflation and Deflation + # ==================================== + + def inflate(self, ulong n): + r""" + Returns the result of the polynomial `f = \textrm{self}` to + `f(x^n)` + + >>> R = fq_default_poly_ctx(163, 3) + >>> f = R([1,2,3]) + >>> f.inflate(10) + 3*x^20 + 2*x^10 + 1 + + """ + cdef fq_default_poly res + res = self.ctx.new_ctype_poly() + fq_default_poly_inflate( + res.val, self.val, n, res.ctx.field.val + ) + return res + + def deflate(self, ulong n): + r""" + Returns the result of the polynomial `f = \textrm{self}` to + `f(x^{1/n})` + + >>> R = fq_default_poly_ctx(163, 3) + >>> f = R([1,0,2,0,3]) + >>> f + 3*x^4 + 2*x^2 + 1 + >>> f.deflate(2) + 3*x^2 + 2*x + 1 + + """ + cdef fq_default_poly res + + n_max = fq_default_poly_deflation( + self.val, self.ctx.field.val + ) + if n > n_max: + raise ValueError(f"Cannot deflate with {n = }, maximum allowed value is {n_max = }") + + res = self.ctx.new_ctype_poly() + fq_default_poly_deflate( + res.val, self.val, n, res.ctx.field.val + ) + return res + + def deflation(self): + r""" + Returns the tuple (g, n) where for `f = \textrm{self}` to + `g = f(x^{1/n})` where n is the largest allowed integer + + >>> R = fq_default_poly_ctx(163, 3) + >>> f = R([1,0,2,0,3]) + >>> f + 3*x^4 + 2*x^2 + 1 + >>> f.deflate(2) + 3*x^2 + 2*x + 1 + + """ + cdef fq_default_poly res + if self.is_zero(): + return self, 1 + n = fq_default_poly_deflation( + self.val, self.ctx.field.val + ) + res = self.ctx.new_ctype_poly() + fq_default_poly_deflate( + res.val, self.val, n, res.ctx.field.val + ) + return res, int(n) diff --git a/src/flint/types/meson.build b/src/flint/types/meson.build index d256d389..faf7f31e 100644 --- a/src/flint/types/meson.build +++ b/src/flint/types/meson.build @@ -27,6 +27,7 @@ exts = [ 'fmpz_mod_mat', 'fq_default', + 'fq_default_poly', 'arf',