Skip to content

fmpz_lll_mpf: use simple dot product instead of slow cancellation-checking dot product #2381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 27, 2025

Conversation

fredrik-johansson
Copy link
Collaborator

In fmpz_lll_check_babai_heuristic, there is an mpf dot product computation which attempts to guess if there is too much cancellation and then falls back to an exact fmpz dot product. Looking at all calls to LLL that occur in our test suite, it seems that this fallback is very rarely useful, while the cancellation check costs more than the actual dot product. We could optimize the cancellation check, but let's try to simplify things and just skip it.

It turns out that this gives a nearly 2x speedup in the polynomial factoring examples which are currently commented out in build/fmpz_poly_factor/profile/p-factor_hard due to being excessively slow.

Old:

H2 has 6 factors: 443192 ms
S9 has 1 factors: 364048 ms

New:

H2 has 6 factors: 235941 ms
S9 has 1 factors: 201570 ms

@fredrik-johansson
Copy link
Collaborator Author

Note: the fact that the cancellation check can be a slowdown is well discussed in Stehlé's book chapter. It would be good to revisit this in the future with more benchmarks to compare, but I feel confident disabling it for now.

@fredrik-johansson fredrik-johansson merged commit 78ae663 into flintlib:main Jul 27, 2025
13 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.

1 participant