gr_ctx_init_nmod, gr_ctx_init_nmod8, gr_ctx_init_nmod32, gr_ctx_init_nmod_redc, gr_ctx_init_nmod_redc_fast
#include <flint/nmod.h>Initialise ctx for the ring \mathbb{Z}/n\mathbb{Z} in the given representation and return GR_SUCCESS. If n = 0, return GR_DOMAIN; if n violates the restrictions of the representation, return GR_UNABLE. In both cases ctx is not initialised.
| Function | Element type | Representation | Allowed n |
|---|---|---|---|
gr_ctx_init_nmod | ulong | reduced residue | n \ge 1 |
gr_ctx_init_nmod8 | uint8_t | reduced residue | 1 \le n \le 255 |
gr_ctx_init_nmod32 | uint32_t | reduced residue | 1 \le n < 2^{32} |
gr_ctx_init_nmod_redc | ulong | Montgomery form in [0, n) | odd n \ge 3 |
gr_ctx_init_nmod_redc_fast | ulong | Montgomery form in [0, 2n) | odd 3 \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 n 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#
- Getting started with generic rings (
gr) - Implementing a ring (
gr) - Getting started (
gr_dft) - Getting started with gr_poly (
gr_poly)
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-10-20).
@misc{flint-doc-nmod-gr-ctx-init-nmod,
author = {{The FLINT team}},
title = {{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)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/nmod/gr_ctx_init_nmod.html},
note = {Generated 2026-10-20}
}