FLINT3.7.0-dev

gr_ctx_is_pretend_field, gr_ctx_set_is_pretend_field, gr_ctx_recover_zero_divisor

Synopsis#include <flint/gr.h>
truth_t gr_ctx_is_pretend_field(gr_ctx_t ctx)source
int gr_ctx_set_is_pretend_field(gr_ctx_t ctx, truth_t is_pretend_field)source
int gr_ctx_recover_zero_divisor(gr_ptr res, gr_ctx_t ctx)source

Let a ring that is not known to be a field compute as if it were one, in the style of dynamic evaluation [DDDD1985]. While the pretence is on, an inversion or division that meets a nonzero non-invertible element fails with GR_UNABLE (not GR_DOMAIN, which keeps its meaning of division by zero) and records that zero divisor in the context; gr_ctx_recover_zero_divisor sets res to the first recorded zero divisor, or returns GR_UNABLE if there is none.

For \mathbb{Z}/n\mathbb{Z} the recorded zero divisor a gives the nontrivial factor \gcd(a, n) of n, so a typical use is to run a field algorithm modulo an n that is probably prime and to split n when it fails. For gr_ctx_init_gr_poly_quotient the recorded element is a nontrivial monic factor of the modulus; see gr_domains.

gr_ctx_is_pretend_field returns T_TRUE if the ring is a field or pretends to be one; gr_ctx_is_field is not affected by the pretence. Algorithms that only need inversions to fail cleanly (the Euclidean and half-GCD algorithms for polynomials, LU decomposition, the default gr_gcd and gr_canonical_associate) check gr_ctx_is_pretend_field; algorithms whose correctness depends on the ring being a field (root finding and factorisation, for example) check gr_ctx_is_field. Setting the pretence to T_FALSE forgets the recorded zero divisor.

Supported by gr_ctx_init_nmod, gr_ctx_init_fmpz_mod, gr_ctx_init_mpn_mod and gr_ctx_init_gr_poly_quotient; the recording is thread-safe (see _gr_ctx_zero_divisor_lock). The other rings return GR_UNABLE from the setter and from the recovery function.

Guides#

References#

  • [DDDD1985] J. Della Dora, C. Dicrescenzo and D. Duval. About a new method for computing in algebraic number fields. EUROCAL '85, Lecture Notes in Computer Science 204, Springer, 1985, 289–290. https://doi.org/10.1007/3-540-15984-3_279
Cite this page

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