Repository navigation
Speed up the lifting of Groebner bases over QQ - #411
Open
mohabsafey wants to merge 8 commits into
Open
mohabsafey wants to merge 8 commits into
mohabsafey wants to merge 8 commits into
Conversation
mohabsafey
force-pushed
the
gb-lifting-qq
branch
from
November 23, 2026 14:57
0ae303d to
f0d18a4
Compare
When lifting a Groebner basis over QQ (-g 2), the denominator of each polynomial is guessed from the previous one, and three witness coefficients are rationally reconstructed before the whole polynomial is lifted. When the denominator of a polynomial has a large factor which does not divide the previous ones (e.g. the first polynomial, or one where the denominators jump), this reconstruction needs about bits(n) + 2 bits(d) bits of modulus, d being the new factor, while the numerators n only need bits(n). The witnesses of a polynomial share their denominator. Up to 8 of them (the three witnesses and nonzero coefficients spread over the polynomial) are now reconstructed simultaneously as a short vector of a lattice found by LLL, which needs about bits(n) + bits(d) / k bits. LLL is tried when the rational reconstruction of the witnesses fails, first with the guessed denominator (the first column of the lattice is scaled by its bitsize), then without it with 4 witnesses, since the guess inflates the numerators when it shares little with the denominator. The candidate is stored as the reconstructed witnesses, hence it is checked with the next prime and used as the denominator of the full lifting, as before. LLL is not tried before the modulus has the bitsize of the guessed denominator, then again each time the number of primes grows by max(5%, sqrt(2A/n)), A being the cost of an attempt in units of the cost of a prime, and its estimated cost is kept below 10% of the estimated cost of the primes. These estimates use the operations recorded in the trace with the weights of the cost model of hensel.c, and not timings, so that the number of primes used stays reproducible. Without this bound, LLL made random2_8_8 three times slower. Fewer primes on bruno (1089 -> 629), KLYZ22 (725 -> 481), cyclic8 (46 -> 30), vor1 (124 -> 95) and minrank_d_2_p_3_q_7_r_3 (1633 -> 1417), for speedups of 2.04, 1.67, 1.39, 1.25 and 1.23 (-g 2 -t 1); no change on random2, kat and eco. The output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Once the witness coefficients of a polynomial are checked, all its coefficients are reconstructed with the lcm of the denominators found so far as a guess. A coefficient whose denominator has a factor which divides none of these needs about bits(n) + 2 bits(d) bits of modulus, d being this factor, and the whole polynomial waits for it. This is what bounds the number of primes on katsura and eco. A coefficient whose reconstruction fails is now kept with its CRT image, and up to 8 of them are reconstructed simultaneously by LLL with the guessed denominator, as the witnesses are, together with already reconstructed coefficients when less than 8 fail. On success, the guess is multiplied by the factor found and they are reconstructed again with it. The cost of these calls is bounded as for the witnesses, with a schedule of their own. A wrong factor makes the lifted polynomial fail the check with the next primes, as a wrong reconstruction does, and the content of the lifted polynomial is removed in case LLL found a multiple of the missing factor. The lattice reduction is shared with the reconstruction of the witnesses (lll_common_den). The reconstruction of the witnesses without guessed denominator, on a lattice where LLL is much slower, only pays when the guess carries factors foreign to the denominator. It is now tried only once, for some lifted polynomial, at least 1/8 of the bits of the denominator of the previous polynomial do not divide its own. On many systems (random, minrank, cp_d) all denominators divide about the same integer and LLL then only cost time: minrank_d_3_p_3_q_6_r_3 and random2_9_9 are no longer slower than before the reconstruction by LLL. henrion7 needs 161 primes instead of 202 (1.33 times faster with -g 2 -t 1), kat12 35 instead of 43, kat11 27 instead of 28, kat9 12 instead of 13 and chandra-11 67 instead of 69. The output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Once the witnesses of a polynomial are checked, each coefficient u was lifted by CRT, then rationally reconstructed with the guessed denominator g, the lcm of the denominators found so far. For most coefficients the denominator divides g, so that u g is an integer and the rational reconstruction only finds it again. On systems needing thousands of primes (random, minrank, cp_d), this took about as much time as the CRT, 15 to 25% of the total. The CRT is now applied to the residues of u g modulo the primes, which gives u g as the symmetric remainder modulo their product M. It is accepted as an integer when it has RR_MARGIN bits less than M, else u is lifted by CRT and rationally reconstructed as before. Most coefficients thus cost one CRT, and neither the product u g of large integers nor a rational reconstruction. As with a rational reconstruction, a wrong integer (probability about 2^(-RR_MARGIN)) is rejected when checking the lifted polynomial with the next primes. The CRT is now taken over the primes whose product is M only: it was also taken over the prime used for checking, with an old residue, which was harmless since the result was then reduced modulo M. The time of the rational reconstructions is divided by 3 to 9 on minrank, random, cp_d and henrion7 (minrank_d_3_p_3_q_6_r_3: 14.4 to 1.5 s, 1.39 times faster in total, cp_d_3_n_6_p_2 1.25, random2_9_9 1.13 with -g 2 -t 1). Integers are also accepted with fewer bits than the bounds of the rational reconstruction required: kat12 needs 34 primes instead of 35, eco12 12 instead of 13. The output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the coefficients of a Groebner basis polynomial are reconstructed by LLL with a guessed denominator g of s bits, the numerators of the short vector have about s plus the bitsize of the missing factor d of the denominator. The s - 64 lowest bits of the lattice entries therefore do not change the short vector: LLL now runs on the lattice whose entries are shifted right by these bits, d is read from the reduced basis, and the numerators are recomputed exactly from d before the unchanged acceptance test. This makes each call 2 to 4 times faster for large guesses, which is where LLL is wasted on random systems: their last stalled polynomials are reconstructed by rational reconstruction at about the bitsize of their integers, so that LLL cannot save primes there. The cost model deciding the attempts is kept as an upper bound, so that the number of primes is unchanged. On random2_10_10, LLL time drops from 74 to 21 s for the same 15749 primes; outputs are identical on all systems tested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The multi-modular computation of Groebner bases over the rationals (-g 2) used primes of 31 bits only. F4 computes modulo primes of up to 52 bits with 64 bit integers, and with AVX-512 IFMA its cost per bit of the modulus is then lower than with primes of 31 bits. The trace is still learned modulo a prime of 31 bits, since learning modulo a larger prime is slower; it is then applied modulo primes of 52 bits, whose images are stored on 64 bits (the images modulo 31 bit primes keep their 32 bit storage). The modular arithmetic of the lifting, the CRT updates and the checks handle primes of 64 bits, and copy_basis_mod_p supports the 64 bit coefficients. Primes of 52 bits are used by default when msolve is built with AVX-512 IFMA, else primes of 31 bits; the new option --gb-prime-bits (31 or 52) selects them explicitly. With 31 bit primes, the primes used and the outputs are unchanged. On a Xeon Gold 6354 (Ice Lake, AVX-512 IFMA), 26 systems, 5 seeds (2 for the largest ones), identical outputs: about 40% fewer primes, 1.16 times faster on geometric mean (from 0.96 to 1.33, 1.17 on random2_10_10). Without IFMA, on an AVX2 machine, the gain is only 1.02 with losses up to 0.84, hence the default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lattices used to reconstruct coefficients by LLL are small, and fmpz_lll spends most of its time on them beyond the floating-point reduction: on lattices of dimension 9 with a modulus of 360 to 900 bits, it takes 1.2 to 1.6 ms with FLINT 3.6 and 10 to 13 ms with FLINT 3.1, against 0.1 to 0.4 ms for fmpz_lll_d_heuristic alone, which finds the same short vectors. A certified reduction is not needed, since the candidates are checked by their sizes and then with new primes, so fmpz_lll is now only called when the heuristic reduction fails. With FLINT 3.1, LLL took about 1 s out of 4.5 s on kat11-qq. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the check of a lifted polynomial fails, the lifting restarts from this polynomial, and the following ones, which were lifted but not checked yet, are lifted again. Their counter of checks was incremented instead of being reset, so that their new lift was taken as checked without being compared to the images modulo a prime not used to lift it. Since the coefficients are accepted as integers when they are small enough, such a lift may be wrong: this happened on chandra-15 when lifting with batches of 32 primes. A lifted polynomial is now marked as unchecked, whether it was lifted before or not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jerebertho
force-pushed
the
gb-lifting-qq
branch
from
November 27, 2026 15:34
0ced999 to
30330b9
Compare
On Windows, unsigned long has 32 bits, so that the GMP functions mpz_*_ui truncate the primes of 52 bits used for the Groebner bases over the rationals when AVX-512 IFMA is available: the reductions of the input coefficients modulo the primes, the products of the CRT modulus by the primes, the CRT itself and the checks of the lifted coefficients were wrong, so that the lifted polynomials never passed their checks. On the Windows runners of the CI with AMD Zen 4 and Zen 5 processors, four tests failed and diff_elim-drl-qq did not end. The primes and the coefficients modulo the primes are now passed to GMP as limbs, which have 64 bits on all 64 bit platforms (new header gmp_u64.h), and they are printed with PRIu64. The failures are reproduced on Linux by truncating to 32 bits the arguments of the GMP functions taking an unsigned long: with this change, make check passes in that setting, with a random seed and with the seed of the CI. Otherwise, the outputs and the timings are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 speeds up the lifting of Groebner bases over the rationals (
-g 2), mostly by needing fewer primes. The output is unchanged.Changes
fmpz_lll_d_heuristicis called first, withfmpz_lllonly as a fallback: the candidates are checked anyway, andfmpz_lllis up to 10 times slower on these small lattices with FLINT 3.1.--gb-prime-bits(31 or 52) selects the size explicitly; the default stays 31 bits without IFMA.The LLL attempts are scheduled and bounded (at most 10% of the cost of the primes) with estimates computed from the operations recorded in the trace, not from timings, so that the number of primes used is reproducible.
Benchmarks
On a machine with an Intel Xeon Gold 6354 (Ice Lake, AVX-512 IFMA), FLINT 3.1,
-g 2 -t 1, 5 seeds per system. The times are those of the computation only, without writing the output (measured as in #409). Release is v0.11.0, master is aba4fe3 (before the merge of #408). Memory is the peak resident size.For the 12 systems where LLL took a noticeable part of the time (kat11-13, chandra-10-12, henrion7, zimmermann, bruno, vor1, KLYZ22, minrank_d_2_p_3_q_7_r_3), "PR" is this branch; there, the time of writing the output, measured in the runs of the previous version of the branch, is subtracted from the total time. For the other systems, "PR" is the branch before its last commit (LLL without certification), which spends less than 2% of their time in LLL.
Master and this PR give identical outputs for all systems and seeds. So does v0.11.0, except on chandra-14 with seed 1, where its output is wrong (polynomial 26 is not in the ideal modulo a prime), and on chandra-13 with seed 5, where it differs too.
On these 35 systems, the PR is 1.44 times faster than master (from 1.00 on noon8 to 2.15 on bruno) and 5.28 times faster than v0.11.0 (from 1.57 on noon8 to 10.21 on random2_9_9), as geometric means; the total time goes from 8993 s (v0.11.0) and 2059 s (master) to 1428 s.
Larger systems, with a time limit of one hour, 2 seeds per system. v0.11.0 exceeds the limit on all of them; its times are estimated from the primes it processed within the hour and the number of primes needed. On cyclic9, master also exceeds the limit (64% of the basis lifted after 256 primes); its estimate assumes about 360 primes, as needed by plain rational reconstruction for coefficients of 5462 bits.
On the 41 systems, with these estimates, the PR is 1.44 times faster than master (from 0.97 on eco15 to 2.15 on bruno) and 5.55 times faster than v0.11.0 (from 1.57 on noon8 to about 11.8 on random2_10_10), as geometric means.
eco15 and noon9 are the only systems where the PR is not faster than master: on these, LLL saves no bits of modulus, and a prime of 52 bits costs 7 to 8% more per bit than a prime of 31 bits (against 4 to 47% less on the other systems). No feature of the computation that we found predicts this, so 52 bits remain the default with IFMA;
--gb-prime-bits 31avoids the loss.Without AVX-512 IFMA, the PR uses primes of 31 bits and still gains, from LLL (fewer primes on bruno, KLYZ22, zimmermann, henrion7, cyclic8, chandra, kat) and from the integers lifted directly (faster CRT and reconstruction on random, minrank and cp_d, with the same primes). On the same machine with
--gb-prime-bits 31(35 systems, seed 1, identical outputs), the PR is 1.20 times faster than master as a geometric mean, from 0.96 (vor1, eco13) to 1.65 (bruno): 1.47 on KLYZ22, 1.48 on cp_d_4_n_4_p_3, 1.36 on zimmermann, 1.2 to 1.3 on random and minrank, 1.0 to 1.15 on kat, eco and noon. The total time goes from 2056 s (master) to 1675 s.Some of the changes in this PR were made with the assistance of generative AI (Claude Code).
🤖 Generated with Claude Code