FLINT3.7.0-dev
Module · 52 functions

fmpz_mod_mpoly_q.h

#include <flint/fmpz_mod_mpoly_q.h>

An fmpz_mod_mpoly_q_t represents an element of the rational function field \mathbb{F}_p(x_0, \ldots, x_{m-1}) as a fraction N/D of two fmpz_mod_mpoly_t. It is the analogue over \mathbb{F}_p of fmpz_mpoly_q (see fmpz_mpoly_q.h). The polynomial context fmpz_mod_mpoly_ctx_t (see fmpz_mod_mpoly.h) fixes the prime p, the number of variables and the monomial ordering; the user must make sure that p is prime, otherwise the GCD computations may fail or throw.

A fraction is in canonical form if \gcd(N, D) = 1 and D is monic (in particular nonzero); zero is 0/1. All functions assume canonical inputs and produce canonical outputs, which is not checked; values built directly through fmpz_mod_mpoly_q_numref and fmpz_mod_mpoly_q_denref must be passed through fmpz_mod_mpoly_q_canonicalise. Arithmetic keeps fractions reduced with as few GCD computations as possible, in the manner of fmpq arithmetic: for example a sum a/b + c/d first computes g = \gcd(b, d) and only needs to cancel common factors with g.

Types and macros#

A pair of fmpz_mod_mpoly_struct, the numerator num and the denominator den. An fmpz_mod_mpoly_q_t is an array of length one of fmpz_mod_mpoly_q_struct.

Pointers to the numerator and the denominator of x, usable as fmpz_mod_mpoly_t.

Memory management#

Initialise res to zero, and free it.

Assignment#

Set res to x (integers are reduced modulo p). The fmpq version returns 1 if the denominator of x is invertible modulo p and 0 otherwise, in which case res is undefined.

Canonicalisation#

Puts x in canonical form by dividing numerator and denominator by their GCD and making the denominator monic. The denominator must be nonzero.

Returns whether x is in canonical form: the numerator and denominator are canonical polynomials, the denominator is nonzero and monic, and the GCD of numerator and denominator is 1. Used for testing.

Properties and special values#

Set res to 0, 1, or the variable of index i, 0 \le i < m.

Input and output#

The array x (or vars) gives the variable names, starting with variable 0; if it is NULL, the variables are named x1, x2, and so on.

char * fmpz_mod_mpoly_q_get_str_pretty(const fmpz_mod_mpoly_q_t f, const char ** vars, const fmpz_mod_mpoly_ctx_t ctx)

Print f to standard output, or return it as a string that the caller frees with flint_free, in the form (N)/(D) (or just N if D = 1).

int fmpz_mod_mpoly_q_set_str_pretty(fmpz_mod_mpoly_q_t res, const char * s, const char ** vars, fmpz_mod_mpoly_ctx_t ctx)

Sets res to the rational function in the null-terminated string s, written with integers, the variable names, parentheses, +, -, *, / and ^ followed by an integer exponent. Returns 0 on success; on a parse error or a division by zero, sets res to zero and returns -1.

Random generation#

Sets res to a random canonical fraction whose numerator and denominator have at most length terms and exponents below exp_bound.

Comparison#

Returns whether x and y are equal.

Arithmetic#

The functions that take an fmpq or divide by a scalar return 1 if the denominator (resp. the divisor) is invertible modulo p and 0 otherwise; in the latter case res is undefined. The fmpz_mod versions require the scalar to be reduced modulo p.

Sets res to 1/x. Throws FLINT_ERROR if x = 0.

Internal functions#

void _fmpz_mod_mpoly_q_add(fmpz_mod_mpoly_t res_num, fmpz_mod_mpoly_t res_den, const fmpz_mod_mpoly_t x_num, const fmpz_mod_mpoly_t x_den, const fmpz_mod_mpoly_t y_num, const fmpz_mod_mpoly_t y_den, const fmpz_mod_mpoly_ctx_t ctx)
void _fmpz_mod_mpoly_q_sub(fmpz_mod_mpoly_t res_num, fmpz_mod_mpoly_t res_den, const fmpz_mod_mpoly_t x_num, const fmpz_mod_mpoly_t x_den, const fmpz_mod_mpoly_t y_num, const fmpz_mod_mpoly_t y_den, const fmpz_mod_mpoly_ctx_t ctx)
void _fmpz_mod_mpoly_q_mul(fmpz_mod_mpoly_t res_num, fmpz_mod_mpoly_t res_den, const fmpz_mod_mpoly_t x_num, const fmpz_mod_mpoly_t x_den, const fmpz_mod_mpoly_t y_num, const fmpz_mod_mpoly_t y_den, const fmpz_mod_mpoly_ctx_t ctx)
void _fmpz_mod_mpoly_q_div(fmpz_mod_mpoly_t res_num, fmpz_mod_mpoly_t res_den, const fmpz_mod_mpoly_t x_num, const fmpz_mod_mpoly_t x_den, const fmpz_mod_mpoly_t y_num, const fmpz_mod_mpoly_t y_den, const fmpz_mod_mpoly_ctx_t ctx)

Arithmetic on canonical fractions given as separate numerators and denominators; the outputs must not alias the inputs.

fmpz_mod_mpoly_gcd_assert_successful sets res to the GCD of x and y and throws if fmpz_mod_mpoly_gcd fails. _fmpz_mod_mpoly_q_mpoly_divexact sets res to x/y for an exact division, dividing by a constant y directly.

Cite this page

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