Skip to content
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

feat: bv_decide short-circuit a * x = b * x #6496

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

tobiasgrosser
Copy link
Contributor

@tobiasgrosser tobiasgrosser commented Jan 1, 2025

This PR adds short-circuit support to bv_decide to accelerate multiplications with shared coefficients. In particular, a * x = b * x can be extended to a = b v (a * x = b * x). The latter is faster if a = b is true, as a = b may be evaluated without considering the multiplication circuit. On the other hand, we require the multiplication circuit, as a * x = b * x -> a = b is not always true due to two's complement wrapping.

We currently do not canonicalize sequences of multiplications by default. While the optional acNF mode does this, it does not take into account shared terms across an equality, such that it may canonicalize to a * (b * c1) = a * (b * c2) instead of (a * b) * c1 = (a * b) * c2. As a result, the non-shared terms are not always lifted to the top. Consequently, a canonical rewrite for a single binary multiplication is not always sufficient. We commit a single test case that requires reasoning about three terms, and add the relevant theorem (with appropriate priority).

To further generalize this, we may consider evolving acNf to take into account term structures across (in)equalities.

@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jan 1, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Jan 1, 2025

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase fedaf850bb7c64d9149a3d204b969304e23fbecd --onto 2c87905d77b707c3283c1de759fd63269ac386a1. (2025-01-01 21:25:20)
  • 🟡 Mathlib branch lean-pr-testing-6496 build against this PR was cancelled. (2025-01-01 23:22:59) View Log
  • ✅ Mathlib branch lean-pr-testing-6496 has successfully built against this PR. (2025-01-02 00:01:50) View Log
  • 🟡 Mathlib branch lean-pr-testing-6496 build against this PR was cancelled. (2025-01-02 09:49:22) View Log
  • ✅ Mathlib branch lean-pr-testing-6496 has successfully built against this PR. (2025-01-02 10:28:10) View Log
  • 🟡 Mathlib branch lean-pr-testing-6496 build against this PR was cancelled. (2025-01-02 10:49:32) View Log
  • ✅ Mathlib branch lean-pr-testing-6496 has successfully built against this PR. (2025-01-02 11:28:36) View Log
  • ✅ Mathlib branch lean-pr-testing-6496 has successfully built against this PR. (2025-01-03 18:40:55) View Log

@tobiasgrosser tobiasgrosser force-pushed the bv_short_circuit branch 4 times, most recently from c84ad0e to c56e21f Compare January 1, 2025 21:41
@tobiasgrosser tobiasgrosser marked this pull request as ready for review January 1, 2025 21:41
This PR adds short-circuit support to bv_decide to accelerate certain
multiplications. In particular, `a * x = b * x` can be extended to `a = b v (a
* x = b * x)`. The latter is faster if `a = b` is indeed true.
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 1, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 1, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 1, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 1, 2025
@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jan 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 2, 2025
@tobiasgrosser tobiasgrosser changed the title feat: bv_decide short-circuit mul_eq_mul with shared left|right feat: bv_decide short-circuit a * x = b * x Jan 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 2, 2025
@tobiasgrosser
Copy link
Contributor Author

changelog-library

@github-actions github-actions bot added the changelog-library Library label Jan 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 2, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 3, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 3, 2025
@leanprover-bot leanprover-bot added the P-medium We may work on this issue if we find the time label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builds-mathlib CI has verified that Mathlib builds against this PR changelog-library Library P-medium We may work on this issue if we find the time toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants