Skip to content

Commit

Permalink
Merge pull request #1898 from flintlib/mpnmod
Browse files Browse the repository at this point in the history
mpn representation of integers mod n
  • Loading branch information
fredrik-johansson authored Mar 28, 2024
2 parents a146a88 + 32c4d71 commit 2c3b759
Show file tree
Hide file tree
Showing 7 changed files with 1,650 additions and 3 deletions.
10 changes: 10 additions & 0 deletions doc/source/gr_domains.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,18 @@ Base rings and fields
of integers modulo *n* where
elements have type :type:`fmpz`. The modulus must be positive.

.. function:: int gr_ctx_init_mpn_mod(gr_ctx_t ctx, const fmpz_t n)

Initializes *ctx* to the ring `\mathbb{Z}/n\mathbb{Z}`
of integers modulo *n* where
elements are flat ``mpn`` arrays with the same number of limbs as
*n*. We currently require that the number of limbs *s* satisfies
`2 \le s \le 16`. This constructor does no initialization and returns
``GR_UNABLE`` if the modulus is not in bounds.

.. function:: void gr_ctx_nmod_set_primality(gr_ctx_t ctx, truth_t is_prime)
void gr_ctx_fmpz_mod_set_primality(gr_ctx_t ctx, truth_t is_prime)
void gr_ctx_mpn_mod_set_primality(gr_ctx_t ctx, truth_t is_prime)

For a ring initialized with :func:`gr_ctx_init_nmod`
or :func:`gr_ctx_init_fmpz_mod` respectively,
Expand Down
5 changes: 4 additions & 1 deletion src/gr.h
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ void gr_method_tab_init(gr_funcptr * methods, gr_method_tab_input * tab);
typedef enum
{
GR_CTX_FMPZ, GR_CTX_FMPQ, GR_CTX_FMPZI,
GR_CTX_FMPZ_MOD, GR_CTX_NMOD, GR_CTX_NMOD8, GR_CTX_NMOD32,
GR_CTX_FMPZ_MOD, GR_CTX_NMOD, GR_CTX_NMOD8, GR_CTX_NMOD32, GR_CTX_MPN_MOD,
GR_CTX_FQ, GR_CTX_FQ_NMOD, GR_CTX_FQ_ZECH,
GR_CTX_NF,
GR_CTX_REAL_ALGEBRAIC_QQBAR, GR_CTX_COMPLEX_ALGEBRAIC_QQBAR,
Expand Down Expand Up @@ -1367,6 +1367,9 @@ void gr_ctx_nmod_set_primality(gr_ctx_t ctx, truth_t is_prime);
void gr_ctx_init_nmod8(gr_ctx_t ctx, unsigned char n);
void gr_ctx_init_nmod32(gr_ctx_t ctx, unsigned int n);

int gr_ctx_init_mpn_mod(gr_ctx_t ctx, const fmpz_t n);
void gr_ctx_mpn_mod_set_primality(gr_ctx_t ctx, truth_t is_prime);

void gr_ctx_init_real_qqbar(gr_ctx_t ctx);
void gr_ctx_init_complex_qqbar(gr_ctx_t ctx);
void _gr_ctx_qqbar_set_limits(gr_ctx_t ctx, slong deg_limit, slong bits_limit);
Expand Down
33 changes: 31 additions & 2 deletions src/gr/fmpz_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,20 @@ _gr_fmpz_mod_vec_dot_rev(fmpz_t res, const fmpz_t initial, int subtract, const f
return GR_SUCCESS;
}

int
_gr_fmpz_mod_vec_mul_scalar(fmpz * res, const fmpz * vec, slong len, const fmpz_t c, gr_ctx_t ctx)
{
_fmpz_mod_vec_scalar_mul_fmpz_mod(res, vec, len, c, FMPZ_MOD_CTX(ctx));
return GR_SUCCESS;
}

int
_gr_fmpz_mod_scalar_mul_vec(fmpz * res, fmpz_t c, const fmpz * vec, slong len, gr_ctx_t ctx)
{
_fmpz_mod_vec_scalar_mul_fmpz_mod(res, vec, len, c, FMPZ_MOD_CTX(ctx));
return GR_SUCCESS;
}

int
_gr_fmpz_mod_vec_addmul_scalar(fmpz * res, const fmpz * vec, slong len, const fmpz_t c, gr_ctx_t ctx)
{
Expand Down Expand Up @@ -697,7 +711,7 @@ gr_method_tab_input _fmpz_mod_methods_input[] =
{GR_METHOD_CTX_IS_FINITE,
(gr_funcptr) gr_generic_ctx_predicate_true},
{GR_METHOD_CTX_IS_FINITE_CHARACTERISTIC,
(gr_funcptr) gr_generic_ctx_predicate_false},
(gr_funcptr) gr_generic_ctx_predicate_true},
{GR_METHOD_CTX_IS_EXACT, (gr_funcptr) gr_generic_ctx_predicate_true},
{GR_METHOD_CTX_IS_CANONICAL,
(gr_funcptr) gr_generic_ctx_predicate_true},
Expand Down Expand Up @@ -738,9 +752,24 @@ gr_method_tab_input _fmpz_mod_methods_input[] =
{GR_METHOD_POW_FMPZ, (gr_funcptr) _gr_fmpz_mod_pow_fmpz},
{GR_METHOD_SQRT, (gr_funcptr) _gr_fmpz_mod_sqrt},
{GR_METHOD_IS_SQUARE, (gr_funcptr) _gr_fmpz_mod_is_square},

/*
{GR_METHOD_VEC_INIT, (gr_funcptr) _gr_mpn_mod_vec_zero},
{GR_METHOD_VEC_CLEAR, (gr_funcptr) _gr_mpn_mod_vec_clear},
{GR_METHOD_VEC_SET, (gr_funcptr) _gr_mpn_mod_vec_set},
{GR_METHOD_VEC_SWAP, (gr_funcptr) _gr_mpn_mod_vec_swap},
{GR_METHOD_VEC_ZERO, (gr_funcptr) _gr_mpn_mod_vec_zero},
{GR_METHOD_VEC_NEG, (gr_funcptr) _gr_mpn_mod_vec_neg},
{GR_METHOD_VEC_ADD, (gr_funcptr) _gr_mpn_mod_vec_add},
{GR_METHOD_VEC_SUB, (gr_funcptr) _gr_mpn_mod_vec_sub},
{GR_METHOD_VEC_MUL, (gr_funcptr) _gr_mpn_mod_vec_mul},
*/
{GR_METHOD_VEC_MUL_SCALAR, (gr_funcptr) _gr_fmpz_mod_vec_mul_scalar},
{GR_METHOD_SCALAR_MUL_VEC, (gr_funcptr) _gr_fmpz_mod_scalar_mul_vec},
{GR_METHOD_VEC_ADDMUL_SCALAR, (gr_funcptr) _gr_fmpz_mod_vec_addmul_scalar},

{GR_METHOD_VEC_DOT, (gr_funcptr) _gr_fmpz_mod_vec_dot},
{GR_METHOD_VEC_DOT_REV, (gr_funcptr) _gr_fmpz_mod_vec_dot_rev},
{GR_METHOD_VEC_ADDMUL_SCALAR, (gr_funcptr) _gr_fmpz_mod_vec_addmul_scalar},
{GR_METHOD_POLY_MULLOW, (gr_funcptr) _gr_fmpz_mod_poly_mullow},
{GR_METHOD_POLY_INV_SERIES, (gr_funcptr) _gr_fmpz_mod_poly_inv_series},
{GR_METHOD_POLY_DIV_SERIES, (gr_funcptr) _gr_fmpz_mod_poly_div_series},
Expand Down
Loading

0 comments on commit 2c3b759

Please sign in to comment.