Skip to content

Compute elimination Groebner bases via a DRL Groebner basis - #408

Merged
mohabsafey merged 5 commits into
algebraic-solving:masterfrom
ederc:elim-drl
Nov 22, 2026
Merged

mohabsafey merged 5 commits into
algebraic-solving:masterfrom
ederc:elim-drl

Conversation

@ederc

@ederc ederc commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

For elimination orders F4 often reached very high degrees even when the final basis is small. A new basis element got the highest degree of all its terms, and the tails have a much higher degree than the leading terms. Its pairs were therefore postponed, and F4 worked through long chains of pairs, one per round.

This PR addresses that in two ways:

  • Degree of new elements: during F4 for an elimination order, new basis elements get the degree of the current round. The degree only steers the pair selection, so the criteria stay correct.
  • DRL first: a Groebner basis w.r.t. DRL is computed first, and the one w.r.t. the elimination order is computed from it. Over the rationals both steps are traced with the first prime, and the tracers are applied for all later primes. For later primes the DRL basis terms are only looked up in the input hash table. A missing term, or supports that differ from the first prime, mark the prime as bad.

The new option --elim-drl controls when the DRL step is done:

  • 0: never
  • 1: always
  • 2 (default): if there are at least as many equations as variables and more than one variable is eliminated

Reuse of hash table copies: over the rationals the basis hash table is copied for each prime and freed afterwards. For tables of the default initial size of 2^17 this allocation dominated computations with many primes and small modular computations each: glibc may give the memory back to the system, and each prime then touches new pages. A copy now remembers the table it was copied from. When freed it is kept in a list of spare copies of that table and reused by the next copy if the sizes still agree. The spare copies are freed with the original table, so a copy has to be freed before its original. This affects all multi-modular computations, not only elimination orders.

Benchmarks (seconds, -g 2 -t 1 -e k; cases that take 0.1 s or less on both builds are left out):

example k master this PR
cp-d3-n4-p2 1 0.38 0.30
cp-d3-n4-p2 2 21.3 6.2
cp-d3-n4-p2 3 >300 2.5
henrion5 3 0.15 0.11
henrion5 4 14.2 0.70
univariate-assign-left 3 55.1 0.09
reals-dim0-chgvar 2 / 3 0.46 / 0.59 0.32 / 0.23
rand128 1 / 2 / 3 / 4 0.67 / 0.68 / 1.60 / 0.49 0.54 / 0.65 / 1.43 / 0.44

The rand128 -e 1 case, which doesn't use the DRL step, shows the effect of reusing the hash table copies alone.

Testing:

  • make check passes, also with an AddressSanitizer build.
  • AddressSanitizer reports no leaks or memory errors on the elimination examples.
  • New tests elim-drl-31 and elim-drl-qq are added.
  • The output files are identical to master's for all of the examples above wherever master finishes:
    • over QQ with 1 and 4 threads
    • with --elim-drl 1
    • over GF(65521) and GF(1073741827)

Parts of this pull request were written with the assistance of generative AI.

@ederc

ederc commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

See also the discussion in #374

@ederc
ederc force-pushed the elim-drl branch 2 times, most recently from 3667278 to 9950939 Compare November 20, 2026 14:23
For elimination orders F4 often reached very high degrees although the
final basis is small: new basis elements got the maximal degree of all
their terms, and the tails have a much higher degree than the leading
terms. Thus their pairs were delayed and F4 walked down long chains of
pairs one per round, e.g. for -e 5 on a system in 6 variables beyond
degree 3000 without finishing.

Thus a Groebner basis w.r.t. DRL is now computed first and the one
w.r.t. the elimination order is computed from it. Over the rationals
the DRL computation is traced and replayed for each prime like the
elimination one. In this second step the new basis elements get the
degree of the current round, which may even be lower than the degree
of their leading term if the reduction made a tail term the leading
one; the degree only steers the pair selection. Without the DRL step
the degrees are computed as before, so the elimination is unchanged.

The new option --elim-drl chooses when the DRL step is done: 0 never,
1 always, 2 (default) if there are at least as many equations as
variables, since otherwise the ideal is positive-dimensional and the
DRL basis is often as expensive as the elimination, and if more than
one variable is eliminated, since then the direct computation is
usually faster.

On a benchmark of 74 eliminations of 25 systems the timeouts after 60
seconds drop from 23 to 0, some computations get several hundred times
faster, the worst slowdown is a factor of 13.

Assisted-by: Generative AI
Over the rationals the elimination step after the DRL Groebner basis
built new meta data with the prime as its field characteristic for each
prime. Thus it ran a full F4 without tracer for every prime and leaked
the trace it learnt. Now the meta data of this step and its input of
the first prime are kept: the tracer is learnt with the first prime and
applied for the next ones. For the next primes the terms of the DRL
basis are only looked up in the hash table of the input, which is
therefore not changed, a missing term or other supports than for the
first prime mark the prime as bad.

Moreover the hash table of the DRL computation starts with a size
depending on the number of terms of the input instead of the initial
size of 2^17, it is copied for each prime.

On the examples with elimination orders the computations get up to
three times faster, e.g. cp-d3-n4-p2 with -e 2 in 6.9 instead of 26.1
seconds, henrion5 with -e 4 in 0.74 instead of 2.42 seconds.

Assisted-by: Generative AI
Over the rationals the basis hash table is copied for each prime and the
copy is freed afterwards. For large hash tables, e.g. of the default
initial size 2^17, allocating them anew each time is expensive: glibc
may give the memory back to the system and each prime then touches new
pages, so the copy dominates the computation if there are many primes
with small computations each.

Now a copy remembers the hash table it is copied from and is kept in a
list of spare copies of this hash table when it is freed. The next copy
reuses it if the sizes still agree, only the data in use is copied. The
spare copies are freed with the original hash table, thus a copy has to
be freed before its original.

For example, rand128 with -e 2 and many small modular computations takes
0.65 instead of 1.25 seconds, with -e 1 0.54 instead of 0.70 seconds.

Assisted-by: Generative AI
The input files, the reference outputs and the shared script of the
tests of the option --elim-drl were not listed in configure.ac, thus
they were missing from the tarball and make distcheck failed.

Assisted-by: Generative AI
In convert_sparse_matrix_rows_to_basis_elements the degree of the new
basis elements was declared outside the parallel loop and was not
private, thus with several threads an element could get the degree of
another row. This did not make the results wrong since this degree
only steers the pair selection, but it is now declared inside the loop.

The check for a degree fall after the loop used the value left in this
variable, i.e. of an arbitrary row with several threads, and an
uninitialized one for an empty matrix. It now reads the degree of the
last new basis element, as in a run with one thread, and is skipped if
there is no new element.

Assisted-by: Generative AI
@mohabsafey
mohabsafey merged commit 41836f6 into algebraic-solving:master Nov 22, 2026
10 checks passed
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.

2 participants