FLINT3.7.0-dev

gr_ctx_init_nmod, gr_ctx_init_nmod8, gr_ctx_init_nmod32, gr_ctx_init_nmod_redc, gr_ctx_init_nmod_redc_fast

Synopsis#include <flint/nmod.h>
int gr_ctx_init_nmod(gr_ctx_t ctx, ulong n)source
int gr_ctx_init_nmod8(gr_ctx_t ctx, ulong n)source
int gr_ctx_init_nmod32(gr_ctx_t ctx, ulong n)source
int gr_ctx_init_nmod_redc(gr_ctx_t ctx, ulong n)source
int gr_ctx_init_nmod_redc_fast(gr_ctx_t ctx, ulong n)source

Initialise ctx for the ring Z/nZ\mathbb{Z}/n\mathbb{Z} in the given representation and return GR_SUCCESS. If n=0n = 0, return GR_DOMAIN; if nn violates the restrictions of the representation, return GR_UNABLE. In both cases ctx is not initialised.

FunctionElement typeRepresentationAllowed nn
gr_ctx_init_nmodulongreduced residuen≥1n \ge 1
gr_ctx_init_nmod8uint8_treduced residue1≤n≤2551 \le n \le 255
gr_ctx_init_nmod32uint32_treduced residue1≤n<2321 \le n < 2^{32}
gr_ctx_init_nmod_redculongMontgomery form in [0,n)[0, n)odd n≥3n \ge 3
gr_ctx_init_nmod_redc_fastulongMontgomery form in [0,2n)[0, 2n)odd 3≤n<2FLINT_BITS−23 \le n < 2^{\mathtt{FLINT\_BITS} - 2}

Some generic algorithms ask whether the ring is a field. For the nmod, nmod_redc and nmod_redc_fast contexts, the answer is computed with n_is_prime on every query, unless it has been set with gr_ctx_set_is_field(ctx, T_TRUE) or gr_ctx_set_is_field(ctx, T_FALSE). Setting it is recommended when the primality of nn is known. It is not done automatically, as it would slow down creating a context that is only used for basic arithmetic. The nmod8 and nmod32 contexts behave in the same way.

Many operations of the nmod8, nmod32, nmod_redc and nmod_redc_fast contexts are not as optimised as those of nmod. Use nmod8 and nmod32 mainly to save memory.

Guides#

Cite this page

The FLINT team, “gr_ctx_init_nmod, gr_ctx_init_nmod8, gr_ctx_init_nmod32, gr_ctx_init_nmod_redc, gr_ctx_init_nmod_redc_fast (nmod.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/nmod/gr_ctx_init_nmod.html (generated 2026-11-02).