Skip to content

Speed up the lifting of Groebner bases over QQ - #411

Open
mohabsafey wants to merge 8 commits into
algebraic-solving:masterfrom
mohabsafey:gb-lifting-qq
Open

mohabsafey wants to merge 8 commits into
algebraic-solving:masterfrom
mohabsafey:gb-lifting-qq

Conversation

@mohabsafey

Copy link
Copy Markdown
Contributor

This PR speeds up the lifting of Groebner bases over the rationals (-g 2), mostly by needing fewer primes. The output is unchanged.

Changes

  • LLL for the witness coefficients. The three witness coefficients of a polynomial share their denominator. When their rational reconstruction fails, up to 8 coefficients are now reconstructed simultaneously as a short vector found by LLL. This needs about bits(n) + bits(d)/k bits of modulus instead of bits(n) + 2 bits(d), where d is the part of the denominator not given by the guess.
  • LLL for the other coefficients. The coefficients whose denominator has a factor missing from the guess are reconstructed together by LLL in the same way, instead of making the whole polynomial wait for more primes. This is what bounded the number of primes on katsura and eco.
  • Integers lifted directly. For most coefficients, u times the guessed denominator is an integer: it is now obtained by one CRT, without a rational reconstruction.
  • Smaller LLL lattices. The lowest bits of the lattice entries, which cannot change the short vector, are dropped.
  • LLL without certification. fmpz_lll_d_heuristic is called first, with fmpz_lll only as a fallback: the candidates are checked anyway, and fmpz_lll is up to 10 times slower on these small lattices with FLINT 3.1.
  • Primes of 52 bits with AVX-512 IFMA. The trace is learned modulo a prime of 31 bits and applied modulo primes of 52 bits, which F4 handles at a lower cost per bit when msolve is built with AVX-512 IFMA. The new option --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.

system primes release / master / PR time release / master / PR (s) PR vs master PR vs release memory release / master / PR (MB)
minrank_d_2_p_2_q_8_r_2 7282 / 3713 / 2177 1820.4 / 368.4 / 231.3 1.59 7.87 4673 / 2401 / 2538
eco14-qq 35 / 26 / 16 1297.8 / 255.1 / 246.6 1.03 5.26 4162 / 1226 / 1328
chandra-14-qq 166 / 136 / 66 746.6 / 248.0 / 178.3 1.39 4.19 5993 / 3152 / 3530
kat13-qq 70 / 57 / 29 805.0 / 176.7 / 139.4 1.27 5.77 2225 / 1289 / 1271
random2_9_9 12417 / 6273 / 3681 920.7 / 152.5 / 90.2 1.69 10.21 1696 / 830 / 854
KLYZ22 727 / 729 / 283 350.7 / 127.5 / 69.2 1.84 5.07 207 / 147 / 128
minrank_d_3_p_3_q_6_r_3 2466 / 1641 / 965 358.4 / 95.1 / 57.7 1.65 6.21 1631 / 844 / 890
bruno 1087 / 1089 / 389 172.7 / 80.0 / 37.2 2.15 4.64 126 / 110 / 97
cp_d_3_n_6_p_2 3457 / 2225 / 1305 323.6 / 69.0 / 41.2 1.67 7.85 1072 / 563 / 590
zimmermann 1521 / 1489 / 609 444.1 / 66.5 / 46.7 1.42 9.51 81 / 74 / 63
random3_6_6 4306 / 2209 / 1297 327.1 / 61.2 / 39.2 1.56 8.34 691 / 387 / 414
minrank_d_2_p_3_q_4_r_2 3537 / 2289 / 1337 283.7 / 58.2 / 41.1 1.42 6.90 806 / 448 / 491
chandra-13-qq 146 / 112 / 58 151.5 / 51.4 / 38.1 1.35 3.98 1711 / 824 / 984
henrion7 227 / 203 / 99 199.8 / 50.7 / 31.0 1.64 6.45 613 / 582 / 486
minrank_d_2_p_3_q_7_r_3 2529 / 1633 / 897 193.9 / 47.2 / 30.7 1.54 6.32 844 / 444 / 464
eco13-qq 24 / 18 / 11 123.7 / 26.4 / 21.5 1.23 5.75 423 / 262 / 308
kat12-qq 56 / 43 / 21 82.6 / 22.2 / 17.7 1.25 4.67 485 / 278 / 307
minrank_d_2_p_2_q_7_r_2 2337 / 1321 / 777 93.0 / 20.7 / 11.6 1.78 8.02 336 / 191 / 192
random2_8_8 3905 / 2593 / 1529 80.1 / 16.6 / 9.2 1.80 8.71 216 / 121 / 131
chandra-12-qq 131 / 107 / 52 33.3 / 12.5 / 8.4 1.49 3.96 459 / 230 / 271
noon9-qq 5 / 6 / 4 17.2 / 9.6 / 9.5 1.01 1.81 636 / 279 / 368
cp_d_4_n_4_p_3 2121 / 1090 / 637 48.1 / 8.1 / 7.1 1.14 6.77 158 / 95 / 102
vor1 135 / 125 / 60 20.7 / 6.3 / 4.3 1.47 4.81 91 / 65 / 59
cyclic8-qq 48 / 46 / 19 17.6 / 5.9 / 3.1 1.90 5.68 62 / 52 / 56
eco12-qq 15 / 13 / 8 15.6 / 4.2 / 3.9 1.08 4.00 152 / 74 / 83
minrank_d_3_p_2_q_5_r_2 817 / 541 / 319 14.0 / 3.4 / 2.2 1.55 6.36 85 / 52 / 57
kat11-qq 39 / 28 / 17 11.3 / 3.0 / 2.5 1.20 4.52 119 / 66 / 74
cp_d_3_n_5_p_2 929 / 637 / 373 11.3 / 2.9 / 1.8 1.61 6.28 64 / 41 / 46
chandra-11-qq 101 / 80 / 42 6.8 / 2.6 / 1.8 1.44 3.78 136 / 71 / 71
random2_7_7 1441 / 989 / 581 7.4 / 1.6 / 1.2 1.33 6.17 32 / 21 / 22
noon8-qq 5 / 5 / 4 2.2 / 1.4 / 1.4 1.00 1.57 120 / 52 / 68
minrank_d_2_p_3_q_6_r_3 586 / 409 / 241 3.7 / 1.3 / 0.8 1.62 4.62 42 / 27 / 31
minrank_d_2_p_2_q_6_r_2 697 / 445 / 263 4.2 / 1.2 / 0.7 1.71 6.00 32 / 22 / 24
chandra-10-qq 89 / 80 / 48 1.7 / 0.8 / 0.6 1.33 2.83 39 / 24 / 25
eco11-qq 11 / 10 / 7 2.2 / 0.7 / 0.6 1.17 3.67 45 / 26 / 29

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.

system primes master / PR time release (estimated) / master / PR (s) PR vs master PR vs release (estimated) memory master / PR (MB)
random3_7_7 9159 / 5409 ~20000 / 3016.2 / 1858.9 1.62 ~10.8 11313 / 12102
eco15-qq 32 / 19 ~14000 / 2525.4 / 2608.6 0.97 ~5.4 4926 / 5382
cyclic9-qq > 256 / 136 ~20000 / > 3600 (~5000) / 2680.9 > 1.34 (~1.9) ~7.5 - / 1778
random2_10_10 15749 / 9281 ~14200 / 1885.3 / 1200.7 1.57 ~11.8 7417 / 7846
kat14-qq 89 / 38 ~9700 / 1723.6 / 1297.1 1.33 ~7.5 6215 / 5854
chandra-15-qq 156 / 77 ~4000 / 1238.9 / 909.1 1.36 ~4.4 12873 / 13720

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 31 avoids 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

mohabsafey and others added 7 commits November 27, 2026 16:34
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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant