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: BitVec.toNat_{add,sub,mul_of_lt} for BitVector non-overflow reasoning #5411

Merged
merged 2 commits into from
Sep 24, 2024

Conversation

bollu
Copy link
Contributor

@bollu bollu commented Sep 20, 2024

These theorems are useful when one wants to simplify the goal state, under knowledge that the bitvector operations don't overflow. This can produce much smaller goal states that eventually allows bv_omega to quickly close the goal.

Note that the LHS of the theorem is not in simp normal form, since e.g. (x + y).toNat is normalized to (x.toNat + y.toNat) % 2^w. It's not immediately clear to me what should be done about this.

…soning

These theorems are useful when one wants to simplify the goal state,
under knowledge that the bitvector operations don't overflow.
This can produce much smaller goal states that eventually allows `bv_omega` to quickly close the goal.

A problem is that these theorems are *not* in `simp` normal form,
since e.g. `(x + y).toNat` is normalized to `(x.toNat + y.toNat) % 2^w`.
It's not immediately clear to me what should be done.
@bollu bollu requested a review from kim-em as a code owner September 20, 2024 16:59
@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 Sep 20, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Sep 20, 2024

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase a6830f90ab365e14ccb7ca31201de37f8c1e978c --onto d8e0fa425b3225fc0c35c07247ecb11b49bb00ed. (2024-09-20 17:19:33)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 5017b2bfbf3af3752db0d34dabc9d3119a352cdc --onto e551a366a0bbb27d5f853cc8e87cbd381a76ffc0. (2024-09-24 03:57:33)

@tobiasgrosser
Copy link
Contributor

Hey @bollu, which part of the theorem is not in simp normal form, the LHS or the hypothesis? With respect to the hypothesis, I am curious how you turn it into toNat in the first place?

@bollu
Copy link
Contributor Author

bollu commented Sep 20, 2024

@tobiasgrosser updated the message to be more accurate: It's the LHS of the equality that's not in simp normal form.

@kim-em
Copy link
Collaborator

kim-em commented Sep 24, 2024

It's fine if the LHS of a non-simp lemma is not in simp normal form --- it just means you'll only be able to rewrite by it prior to calling simp.

I'd consider the argument that toNat_add and so on should not be simp lemmas, but this would take some work to make viable, I think.

@kim-em kim-em enabled auto-merge September 24, 2024 03:31
@kim-em kim-em added this pull request to the merge queue Sep 24, 2024
Merged via the queue into leanprover:master with commit 0cae716 Sep 24, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants