FLINT3.7.0-dev

mpn_ctx_init, mpn_ctx_clear

Synopsis#include <flint/fft_small.h>
void mpn_ctx_init(mpn_ctx_t R, ulong p)source
void mpn_ctx_clear(mpn_ctx_t R)source

Initialises R from the initial prime p and frees it. FLINT itself always uses p = 63 \cdot 2^{44} + 1 (0x0003f00000000001), the value get_default_mpn_ctx passes.

The eight primes are p_0 = p (or, if p is not prime, the first prime in the sequence below) and then the next primes of the sequence obtained by repeatedly subtracting 2^{v + 1} from the previous value, where 2^v \| p - 1; when that would lose a bit, the bit size is kept and the two-adic valuation is decreased by one. Each prime must pass fft_small_mulmod_satisfies_bounds and have 2^4 \mid p - 1, or sd_fft_ctx_init_prime throws. Other starting values are meant only for testing: the packing profiles, the two-prime pipeline and the shortcut for moduli that are context primes all assume 50-bit primes.

Initialisation computes the twiddle factors for transforms of length up to 2^{12}, the cofactors P/p_i for the Chinese remainder theorem, and the tables 2^j \bmod p_i for j < 256. Longer twiddle tables are added on first use.

Cite this page

The FLINT team, “mpn_ctx_init, mpn_ctx_clear (fft_small.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/fft_small/mpn_ctx_init.html (generated 2026-10-20).