Repository navigation
Conversation
la_zz.c reduces the matrices of F4 over the integers. The rows generate a lattice which the reduction keeps: if the lead coefficient a of a pivot does not divide the lead coefficient b of a row, both are replaced by a unimodular combination, a new pivot with lead coefficient gcd(a, b) and a row which is zero in this column. Such gcd steps add neither rows nor columns. All other entries in pivot columns are reduced into the residue system (-a/2, a/2], content is never removed. The reduced rows are unique, so the result does not depend on the number of threads. Rows with 32 bit coefficients are reduced in 64 bit integers with AVX512, AVX2 or NEON as long as a bound on their entries stays below 2^62, other rows with GMP. The rows are reduced in parallel, pivots are set by compare and swap. A pivot with unreduced entries in the columns of later pivots is reduced again before it is used, otherwise the entries of the rows it reduces grow very fast. The linear algebra is used if the new meta data flag zz is set. The test compares the results on random matrices with Hermite normal forms computed independently and checks that 1 and 8 threads give the same result. Assisted-by: Generative AI
With the meta data flag zz F4 computes strong Groebner bases: - Pairs: a pair stands for its S- and its G-polynomial. All multiplied generators of a pair become rows to be reduced, the linear algebra over the integers computes both polynomials. A separate update applies only criteria which hold over the integers: the product criterion needs coprime lead monomials and coprime lead coefficients, the chain criterion a new element whose lead coefficient divides the gcd of the lead coefficients of the pair, and an element is only redundant if a lead term divides its lead term including the coefficient. A new element is never redundant itself, its pairs reduce it. - Reducers: among the basis elements dividing a monomial the one with the smallest lead coefficient is chosen, also for the lcms of the pairs. - Columns: the rows keep reduced entries in the columns of known pivots, so all columns are sorted by the monomial order and all of them are mapped back to the basis hash table. - Only the constant 1 generates the whole ring. Assisted-by: Generative AI
The field line ZZ in the input file asks for the reduced strong Groebner basis over the integers (option -g). It is computed directly by F4 with integer coefficients, no modular methods are used. All coefficients must be integers. The input polynomials are not made primitive, only their lead coefficients are made positive. The basis is printed with integer coefficients. initialize_gba_input_data_zz() initializes the input data for this computation. Assisted-by: Generative AI
Katsura 4 and three quadrics in three variables over the integers, with 1 and 2 threads. The expected bases have the same lead terms as the ones computed by Oscar (Singular), the second one also the same polynomials. Assisted-by: Generative AI
Over the integers only the chain criterion was applied to the old pairs, the new pairs of an element were not checked against each other. So far more pairs were kept than over prime fields, e.g. for mayr42 about 16 times as many. A new pair (i, n) is now removed if the lcm of a remaining pair (j, n) divides its lcm, the first one of the pairs with equal lcms remains, and lc(j) divides gcd(lc(i), lc(n)). Then the S-polynomial of (i, n) is a combination of the S-polynomials of (i, j) and (j, n), and lt(j) divides the lead term of its G-polynomial. For lc(j) = +-1 this is the criterion over fields. As there, pairs removed by the product criterion take part. The divisibility checks use the variables in which lm(j) exceeds lm(n), as the update over fields does, lead coefficients +-1 avoid calls to GMP, and the candidates are sorted by counting sort. For mayr42 the number of pairs per round is now the one over prime fields. Assisted-by: Generative AI
…egers The dense row of a row was scanned column by column from its lead column on, also when looking for its remaining entries. For very sparse rows of large matrices this dominated the computation. As over prime fields, very sparse rows with 64 bit entries now keep the columns of their possibly nonzero entries in a heap and collect the ones which stay nonzero, the new row is built from them. A row goes back to scanning all columns when its entries are promoted to GMP integers or when it is loaded again. For mayr42 the linear algebra takes 0.7 instead of 19 seconds. Assisted-by: Generative AI
Over the integers all generators of the selected pairs became rows to be reduced, the reducer of an lcm was chosen in the symbolic preprocessing. A generator with lead coefficient +-1 is the best reducer of its lcm, so the first such one becomes the known pivot of the lcm, as over fields. Without one nothing changes. For mayr42 the matrices have the sizes of the ones over prime fields. Assisted-by: Generative AI
A gcd step replaces the pivot p of a column by u * p + v * row. The entries of the row right of this column are not reduced yet at this point, still the new pivot was marked as reduced when the reduction of the row started. So it was not reduced again, and the rows it reduced and the following gcd steps carried its large entries on. The new pivot is now reduced right of its lead column before it is set. For dc5 the largest coefficients of the gcd pivots drop from about 11000 to 6500 bits, with one thread the computation takes 3.9 instead of 11 seconds. Assisted-by: Generative AI
…gers With several threads the rows were reduced and became new pivots concurrently, also gcd steps replaced pivots concurrently. The new pivots of different threads were not reduced by each other, and the coefficients blew up: for dc5 with 8 threads the largest coefficients had about 290000 instead of 11000 bits, the computation took more time than with one thread and much more memory. Now the rows are handled in chunks of 8 rows per thread. The rows of a chunk are first reduced in parallel by the pivots present without changing them, up to their first column which has no pivot, needs a gcd step or has a pivot which has to be reduced again. Then they are reduced further and become new pivots one after the other. So the computation does the same work for any number of threads. With one and with ten threads, dc5 takes 3.6 and 3.1 instead of 11 and 15 seconds, dq7 2.5 and 1.8 instead of 8.3 and 3.8 seconds, katsura7 32 and 5.9 instead of 35 and 5.8 seconds. Assisted-by: Generative AI
Over the integers the selection often takes several pairs with the same lcm t. Let h be one of their generators with a smallest lead coefficient c, up to sign. A pair (f, g) with f, g != h is not needed if c divides the lead coefficients a of f and b of g and for both f and g the pair with h is selected as well or has an lcm properly dividing t. With L = lcm(a, b) and u * a + v * b = gcd(a, b) the S-polynomial and the G-polynomial of f and g are S(f, g) = L/a * S(f, h) - L/b * S(g, h), G(f, g) = u * S(f, h) + v * S(g, h) + gcd(a, b)/c * t/lm(h) * h, and the pairs with h are reduced in the same matrix or were handled in a lower degree. The chain criterion of the update misses these pairs since it needs both lcms with h to differ from t. The selection now removes them, so fewer rows and often fewer reducers enter the matrix. With one and with ten threads, katsura8 takes 682 and 164 instead of 1323 and 268 seconds, katsura7 18 and 4.4 instead of 32 and 5.9 seconds. sp6 takes 717 instead of 1174 seconds with ten threads. The bases are the same as before for all tested systems. Assisted-by: Generative AI
The rows of a matrix generate a lattice M which the linear algebra over the integers keeps, all its elements reduce to zero by the pivots, a new element n with lead monomial m is one of them. So a pair (f, n) with lm(f) | m is not needed if the matrix has the row m/lm(f) * f: its S- and its G-polynomial are in M. Otherwise it is not needed if f is an old element and the matrix has a row r' = m/lm(r) * r with lc(r) | lc(f) and lcm(lm(f), lm(r)) a proper divisor of m: with a = lc(f), b = lc(n), L = lcm(a, b), L' = lcm(lc(r), b) and u * a + v * b = gcd(a, b), S(f, n) = L/a * S(f, r) + L/L' * S(r, n), G(f, n) = u * S(f, r) + (u * a/lc(r) * r' + v * n), the pair (r, n) is handled by the matrix and (f, r) has a lower degree. These pairs made up the second rounds of a degree, e.g. for sp6 they took 17 to 29 seconds each from degree 14 on, although all their rows reduce to zero. The matrix rows over the integers now store their basis indices, the F4 loop keeps for each new element the basis indices of the rows with its lead column, and the update removes these pairs. With ten threads, sp6 takes 562 instead of 717 seconds, katsura8 154 instead of 164 seconds. The bases are the same as before for all tested systems. Assisted-by: Generative AI
New pivots which have an entry in a column whose pivot was set later have to be reduced again. Up to now, the rows of a chunk stopped at such a pivot in the parallel phase and were finished in the sequential phase, which dominated the first rounds of larger systems. These pivots are now reduced before each chunk, from the right to the left, so that the rows of the chunk run past them in parallel. The rows still become pivots in the same order, so the coefficients do not grow more than before. Deferring rows after a gcd step to the next chunk was tried as well, but it changes the order in which rows become pivots and makes the lead coefficients of the new pivots explode. Assisted-by: Generative AI
The chain criterion for the old pairs required the lead coefficient of the new element to divide the gcd of the lead coefficients of the pair. Dividing one of them is enough: the S- and the G-polynomial of the pair are still combinations of the S-polynomials with the new element, of lower lcm, and of its G-polynomial with the other generator. Old pairs of an element which the new one makes redundant are now also removed when the pair of the other generator with the new element has the same lcm and is kept or handled otherwise. On sp8, these pairs made up a large part of the degree 9 matrix: the number of selected pairs drops from 28664 to 20079 and the rows to reduce from 13747 to 10557. Assisted-by: Generative AI
In the parallel phase, a row whose lead coefficient is not divisible by the one of its pivot stopped there, and all its entries to the right were reduced in the sequential phase, before and after the gcd step. The new pivot of the gcd step had these unreduced entries, so most of the sequential time went into reducing it again. Such a row now keeps the column as its lead column and its entries to the right are reduced in parallel by the present pivots. The gcd steps are still done one after the other in the same order, but the new pivots come out small and are cheap to reduce. With 4 threads, dq8 goes from 39.0 to 24.5 seconds and dc5 from 2.63 to 1.40 seconds, and the large rounds of sp8 become 10 to 30 percent faster. Assisted-by: Generative AI
Each new pivot and each gcd step in the sequential phase makes the new pivots with an entry in its column stale. The next row then reduced them again one by one as it met them, and this took most of the time of the sequential phase: in the largest round of dq8, 3.6 of 5.3 seconds. Before each row of the sequential phase is inserted, and before each chunk, the stale pivots right of its first column are now reduced in parallel. They are handed out from the right to the left, and the reduction of a pivot waits at the columns whose pivots are still being reduced, so the result is the same as reducing them one after the other. With 10 threads, dq8 goes from 19.1 to 14.0 seconds, and the first 23 rounds of sp8 spend 241 instead of 370 seconds in the linear algebra. With one thread, the pivots are not reduced before each row: this would also reduce pivots the row does not meet, so a row reduces the stale pivots it meets as before. Letting the rows of the sequential phase run concurrently, each column still seeing the pivot changes in the sequential order, was tried as well. It gains nothing: the row doing a gcd step holds its column while the new pivot is reduced, and the later rows wait for it. Assisted-by: Generative AI
For strong Groebner bases over the integers the computation modulo a prime is the image of the integer computation as long as all new pivots have lead coefficients +-1, F4 over the integers then does no gcd steps. With the meta data flag zz_unit the exact sparse linear algebra modulo primes checks this before normalizing a new pivot, the dense path is not used then. F4 stops at the first other lead coefficient, sets zz_nonunit and records the number of rounds done before in zz_rd. With zz_max_rd F4 stops after the given number of rounds. When F4 stops with an error while learning the trace, the basis shares the hash table of the global basis, it must not be freed, and the trace learnt so far is freed. Assisted-by: Generative AI
…tegers If all input lead coefficients are +-1, the strong Groebner basis over the integers is first computed by the multi-modular computation over the rationals, checking modulo every prime that all new pivots have lead coefficients +-1. Then the reduced basis is monic and integral, and it is the reduced strong Groebner basis. If another lead coefficient occurs after some rounds, the basis after these rounds is computed modulo primes, keeping all elements, and lifted via the Chinese remainder theorem until the lift does not change for two more primes. F4 over the integers starts with the lifted elements, which include the input generators. Otherwise it starts with the input. As for the rationals, the result is correct with high probability: a lead coefficient other than +-1 is missed only if it is congruent to +-1 modulo all primes used. Assisted-by: Generative AI
A binomial system in seven variables is computed completely by the multi-modular computation, for Cyclic 5 a lead coefficient other than +-1 occurs after three rounds and F4 over the integers starts with the lifted basis. The expected bases are the ones computed by F4 over the integers only. Assisted-by: Generative AI
GMP's mpz_set_si takes a long, which has only 32 bits on Windows. The linear algebra over the integers passed it the 64 bit entries of dense rows, when promoting them to GMP integers and when building rows whose entries do not fit into 32 bits, so on Windows these entries were cut to 32 bits. The CI tests diff_katsura4-zz.sh and neogb_zz failed there. zz_set_i64 sets a GMP integer from an int64_t, from two 32 bit halves if a long has only 32 bits. Truncating the entries to 32 bits on Linux makes exactly these two tests fail, with the new function they pass, also when its 32 bit path is used on Linux. Assisted-by: Generative AI
jerebertho
force-pushed
the
strong-zz
branch
from
November 27, 2026 15:34
cba6523 to
bef6901
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the computation of reduced strong Groebner bases over the integers (DRL order, option
-g 2). Such a basis decides ideal membership over the integers, and its elements with constant lead monomial describe the integers in the ideal.Usage
The field line
ZZin the input file selects the integers. All coefficients must be integers:The basis is printed with integer coefficients, under
#coefficient ring: integers. Only strong Groebner bases are computed over the integers: other computations (solving, signatures, saturation, colon ideals, normal forms) report an error.How it works
Linear algebra over the integers (
src/neogb/la_zz.c)The rows of a matrix generate a lattice, which the reduction keeps.
Each column gets at most one pivot. If the lead coefficient
aof the pivot doesn't divide the lead coefficientbof a row, a gcd step replaces both by a unimodular combination:gcd(a, b);Gcd steps add neither rows nor columns.
Other entries in pivot columns are reduced into the residue system
(-a/2, a/2]. Content is never removed:xand2xgenerate different ideals.The reduced echelon form is unique, so the result doesn't depend on the number of threads.
Rows with 32-bit coefficients are reduced in 64-bit integers, with AVX512, AVX2 or NEON, as long as a bound on their entries stays below 2^62. Other rows use GMP. Very sparse rows are reduced via a heap of their columns, as over prime fields.
Coefficient growth. A pivot that has unreduced entries in the columns of later pivots is reduced again before it is used ("stale" pivots, tracked by generations). The new pivot of a gcd step is reduced right away.
Parallelization. Rows are handled in chunks of 8 rows per thread:
F4 for strong Groebner bases (
f4.c,update.c,symbol.c,convert.c)A pair stands for both its S-polynomial and its G-polynomial. All multiplied generators of a pair become rows, and the linear algebra produces both polynomials.
Only criteria that hold over the integers are applied:
The identities behind each rule are in the commit messages and the code comments.
An element is redundant only if a lead term divides its lead term, coefficient included. Only the constant 1 generates the whole ring.
Reducers: the basis element with the smallest lead coefficient is chosen. A generator with lead coefficient ±1 becomes the known pivot of its lcm, as over fields.
Multi-modular computation (
msolve.c)Performance
Timings in seconds with 1 and 10 threads. All results agree between 1 and 10 threads.
Some larger systems with many gcd steps (e.g. sp8) don't finish within 30 minutes yet.
Tests
test/neogb/la/zz.c: the linear algebra on random matrices, compared with Hermite normal forms computed independently, checking that 1 and 8 threads give the same result.diff_katsura4-zz.sh,diff_quadrics3-zz.sh: F4 over the integers, with 1 and 2 threads. The expected bases have the same lead terms as the ones computed by Oscar (Singular).diff_binomial7-zz.sh,diff_cyclic5-zz.sh: the multi-modular path, computed completely modulo primes resp. continued over the integers after three rounds.make checkpasses. On 237 further systems (random dense and binomial systems, Katsura, Cyclic, Mayr and others), the bases with 1 and 4 threads are identical to those of the reference build.AI assistance
Parts of this PR (code, tests, commit messages and this description) were written with the assistance of generative AI. All commits containing such changes carry the trailer
Assisted-by: Generative AI.