Upgrade internal Lehmer GCD to 2-digit (64-bit) approximation#8877
Closed
Upgrade internal Lehmer GCD to 2-digit (64-bit) approximation#8877
Conversation
… tests Co-authored-by: levnach <5377127+levnach@users.noreply.github.com>
… tests Co-authored-by: levnach <5377127+levnach@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add GCD algorithms for multivariate polynomials in Z3
Add Heuristic GCD (GCDheu) fast-path for multivariate polynomial GCD
Mar 6, 2026
Contributor
|
According to the test at http://mtzguido.tplinkdns.com:8081/z3/compare_stats.html the new algorithm does not improve, but keep performance the same. Try to improve performance by improving the implementation of the new GCD algorithm, or try another method. |
…limit Co-authored-by: levnach <5377127+levnach@users.noreply.github.com>
Copilot
AI
changed the title
Add Heuristic GCD (GCDheu) fast-path for multivariate polynomial GCD
Fix GCDheu performance: use L∞ norm for evaluation base xi
Mar 6, 2026
…overflow safety Co-authored-by: levnach <5377127+levnach@users.noreply.github.com>
…ition Co-authored-by: levnach <5377127+levnach@users.noreply.github.com>
Copilot
AI
changed the title
Fix GCDheu performance: use L∞ norm for evaluation base xi
Improve GCD performance: 2-digit Lehmer integer GCD + corrected GCDheu polynomial evaluation base
Mar 7, 2026
…D improvement Co-authored-by: levnach <5377127+levnach@users.noreply.github.com>
Copilot
AI
changed the title
Improve GCD performance: 2-digit Lehmer integer GCD + corrected GCDheu polynomial evaluation base
Upgrade internal Lehmer GCD to 2-digit (64-bit) approximation
Mar 7, 2026
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.
Z3's internal big-integer GCD (used when building without libgmp) used a 1-digit (32-bit) Lehmer approximation, limiting each outer matrix application to ~30 simulated Euclidean steps. This upgrades to 2-digit (64-bit) approximations, roughly doubling the simulation depth per iteration and halving the number of expensive big-integer operations.
Changes (
src/util/mpz.cpp)2-digit approximation: Build
â/b̂from the top two 32-bit digits combined into a 62-bitint64_t(shifted right by 2 to preserve sign bit headroom), vs. the previous single leading digit:Overflow safety via
__int128: Cofactor products (q·C,q·D) can overflowint64_twith 62-bit approximations. Uses__int128arithmetic with an explicit overflow check on GCC/Clang; exits the inner loop safely if overflow is detected.b_sz == a_sz - 1alignment: Whenb1has one fewer digit thana1, its leading digit is placed in the lower 32 bits of the 64-bit window to maintain correct relative scale.<= 0break condition: The denominator check is upgraded from== 0to<= 0; with signed 64-bit cofactors, a negative denominator is equally invalid.1-digit fallback: The original 32-bit path is preserved under
#elsefor MSVC and other compilers without__int128.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.