Gröbner bases
#include <flint/fmpz_mod_mpoly.h>int fmpz_mod_mpoly_vec_is_groebner(const fmpz_mod_mpoly_vec_t G, const fmpz_mod_mpoly_vec_t F, const fmpz_mod_mpoly_ctx_t ctx)sourceReturns whether G is a Gröbner basis of the ideal it generates (all S-polynomials reduce to zero) and, if F is not NULL, every element of F reduces to zero modulo G, so that the ideal of F is contained in that of G. The converse inclusion is not checked.
int fmpz_mod_mpoly_vec_is_autoreduced(const fmpz_mod_mpoly_vec_t G, const fmpz_mod_mpoly_ctx_t ctx)sourceReturns whether G is autoreduced (inter-reduced).
void fmpz_mod_mpoly_vec_autoreduction_groebner(fmpz_mod_mpoly_vec_t H, const fmpz_mod_mpoly_vec_t G, const fmpz_mod_mpoly_ctx_t ctx)sourceSets H to the autoreduction of the Gröbner basis G, which is the reduced Gröbner basis of the ideal, unique up to the order of the entries.
void fmpz_mod_mpoly_buchberger_naive(fmpz_mod_mpoly_vec_t G, const fmpz_mod_mpoly_vec_t F, const fmpz_mod_mpoly_ctx_t ctx)sourceint fmpz_mod_mpoly_buchberger_naive_with_limits(fmpz_mod_mpoly_vec_t G, const fmpz_mod_mpoly_vec_t F, slong ideal_len_limit, slong poly_len_limit, const fmpz_mod_mpoly_ctx_t ctx)sourceSet G to a Gröbner basis of the ideal generated by F, by Buchberger's algorithm in the form GROEBNERNEW2 of [BW1993], which discards useless pairs with the criteria of Gebauer and Möller [GM1988]. The basis is not reduced in general; fmpz_mod_mpoly_vec_autoreduction_groebner reduces it. The second version stops if the basis gets more than ideal_len_limit elements or a polynomial gets more than poly_len_limit terms, and returns 0 in that case (G then generates the ideal but need not be a Gröbner basis); otherwise it returns 1.
A Gröbner basis of an ideal I \subseteq \mathbb{F}_p[x_1, \ldots, x_m] with respect to a monomial ordering is a finite generating set G of I such that the leading monomial of every nonzero element of I is divisible by the leading monomial of some element of G; equivalently, division by G (fmpz_mod_mpoly_divrem_ideal) leaves remainder zero exactly on the elements of I. A Gröbner basis is reduced if its elements are monic and no term of an element is divisible by the leading monomial of another element; the reduced Gröbner basis of an ideal is unique [BW1993] [CLO2015].
fmpz_mod_mpoly_buchberger_naive computes a Gröbner basis of the ideal generated by a vector of polynomials by Buchberger's algorithm [Buc1965]: it starts from the monic generators and repeatedly reduces the S-polynomial of a pair of basis elements (fmpz_mod_mpoly_spoly) modulo the current basis, adding the remainder to the basis when it is nonzero, until all pairs reduce to zero. Pairs are selected and discarded as in the algorithm GROEBNERNEW2 of Becker and Weispfenning [BW1993], which applies the criteria of Gebauer and Möller [GM1988]. The result is a Gröbner basis but in general not a reduced one; fmpz_mod_mpoly_vec_autoreduction_groebner turns it into the reduced Gröbner basis. The modulus must be prime.
The implementation is meant for small systems. Its running time and the size of the basis can grow very quickly (doubly exponentially in the number of variables in the worst case); the version fmpz_mod_mpoly_buchberger_naive_with_limits gives up, returning 0, when the basis gets more than ideal_len_limit elements or a polynomial more than poly_len_limit terms. fmpz_mod_mpoly_vec_is_groebner checks the Buchberger criterion (all S-polynomials reduce to zero) and, if F is given, that the generators reduce to zero modulo G.
Example#
The intersection of a sphere, a paraboloid and a plane over \mathbb{F}_{101}; with the lexicographic ordering x > y > z, the reduced Gröbner basis is triangular and gives the solutions by successive substitution:
#include <flint/flint.h>
#include <flint/fmpz_mod_mpoly.h>
int main(void)
{
fmpz_mod_mpoly_ctx_t ctx;
fmpz_mod_mpoly_vec_t F, G, H;
fmpz_mod_mpoly_t f;
fmpz_t p;
const char * vars[] = {"x", "y", "z"};
slong i;
fmpz_init_set_ui(p, 101);
fmpz_mod_mpoly_ctx_init(ctx, 3, ORD_LEX, p);
fmpz_mod_mpoly_vec_init(F, 0, ctx);
fmpz_mod_mpoly_vec_init(G, 0, ctx);
fmpz_mod_mpoly_vec_init(H, 0, ctx);
fmpz_mod_mpoly_init(f, ctx);
/* the intersection of a sphere, a paraboloid and a plane */
fmpz_mod_mpoly_set_str_pretty(f, "x^2 + y^2 + z^2 - 4", vars, ctx);
fmpz_mod_mpoly_vec_append(F, f, ctx);
fmpz_mod_mpoly_set_str_pretty(f, "x^2 + y^2 - 2*z", vars, ctx);
fmpz_mod_mpoly_vec_append(F, f, ctx);
fmpz_mod_mpoly_set_str_pretty(f, "x - y", vars, ctx);
fmpz_mod_mpoly_vec_append(F, f, ctx);
fmpz_mod_mpoly_buchberger_naive(G, F, ctx);
flint_printf("Groebner basis: %d, size %wd\n",
fmpz_mod_mpoly_vec_is_groebner(G, F, ctx), G->length);
fmpz_mod_mpoly_vec_autoreduction_groebner(H, G, ctx);
flint_printf("reduced basis (autoreduced: %d):\n",
fmpz_mod_mpoly_vec_is_autoreduced(H, ctx));
for (i = 0; i < H->length; i++)
{
fmpz_mod_mpoly_print_pretty(fmpz_mod_mpoly_vec_entry(H, i), vars, ctx);
flint_printf("\n");
}
fmpz_mod_mpoly_clear(f, ctx);
fmpz_mod_mpoly_vec_clear(F, ctx);
fmpz_mod_mpoly_vec_clear(G, ctx);
fmpz_mod_mpoly_vec_clear(H, ctx);
fmpz_mod_mpoly_ctx_clear(ctx);
fmpz_clear(p);
return 0;
}Groebner basis: 1, size 5 reduced basis (autoreduced: 1): x+100*y y^2+100*z z^2+2*z+97
The basis says x = y, y^2 = z and z^2 + 2z - 4 = 0. The unreduced basis returned by fmpz_mod_mpoly_buchberger_naive has five elements, two of which are redundant.
References#
- [BW1993] T. Becker and V. Weispfenning, Gröbner Bases: A Computational Approach to Commutative Algebra, Graduate Texts in Mathematics 141, Springer-Verlag (1993). https://doi.org/10.1007/978-1-4612-0913-3
- [GM1988] R. Gebauer and H. M. Möller. On an installation of Buchberger's algorithm. Journal of Symbolic Computation 6:2–3 (1988), 275–286.
- [CLO2015] D. Cox, J. Little and D. O'Shea. Ideals, Varieties, and Algorithms, fourth edition. Undergraduate Texts in Mathematics, Springer, 2015. https://doi.org/10.1007/978-3-319-16721-3
- [Buc1965] B. Buchberger. Ein Algorithmus zum Auffinden der Basiselemente des Restklassenringes nach einem nulldimensionalen Polynomideal. PhD thesis, University of Innsbruck, 1965.
The FLINT team, “Gröbner bases (fmpz_mod_mpoly.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/fmpz_mod_mpoly/groebner.html (generated 2026-10-20).
@misc{flint-doc-fmpz-mod-mpoly-groebner,
author = {{The FLINT team}},
title = {{Gröbner bases (fmpz\_mod\_mpoly.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/fmpz_mod_mpoly/groebner.html},
note = {Generated 2026-10-20}
}