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.shiftLeft in terms of extractLsb' #6743

Merged

Conversation

bollu
Copy link
Contributor

@bollu bollu commented Jan 22, 2025

This PR adds rewrites that normalizes left shifts by extracting bits and concatenating zeroes. If the shift amount is larger than the bit-width, then the resulting bitvector is zero.

theorem shiftLeft_eq_zero {x : BitVec w} {n : Nat} (hn : w ≤ n) : x <<< n = 0#w

theorem shiftLeft_eq_concat_of_lt {x : BitVec w} {n : Nat} (hn : n < w) :
    x <<< n = ((x.extractLsb' 0 (w-n)).append (BitVec.zero n)).cast (by omega)

@bollu bollu requested a review from kim-em as a code owner January 22, 2025 17:09
@bollu bollu force-pushed the lean4-shiftLeft-concat-extract branch 2 times, most recently from fe80fdd to 8177439 Compare January 22, 2025 17:10
@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 22, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Jan 22, 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 6ebce421423445eeac59a6f4347a562897a99e8d --onto 9b74c07767dc50645efa00356a7724e7f7176227. (2025-01-22 17:30:10)
  • ✅ Mathlib branch lean-pr-testing-6743 has successfully built against this PR. (2025-01-24 16:01:43) View Log

@hargoniX hargoniX added the changelog-library Library label Jan 22, 2025
@hargoniX hargoniX added this pull request to the merge queue Jan 22, 2025
@hargoniX hargoniX removed this pull request from the merge queue due to a manual request Jan 22, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jan 22, 2025
This PR supports rewriting `ushiftRight` in terms of `extractLsb'`. This
is the companion PR to #6743 which adds the similar lemmas about
`shiftLeft`.


```lean
theorem ushiftRight_eq_zero {x : BitVec w} {n : Nat} (hn : w ≤ n) :
    x >>> n = 0#w

theorem ushiftRight_eq_extractLsb'_of_lt {x : BitVec w} {n : Nat} (hn : n < w) :
    x >>> n = ((0#n) ++ (x.extractLsb' n (w - n))).cast (by omega)
```
@bollu bollu force-pushed the lean4-shiftLeft-concat-extract branch 2 times, most recently from 6be7fd1 to d74a4e0 Compare January 24, 2025 14:40
@hargoniX hargoniX enabled auto-merge January 24, 2025 14:43
@tobiasgrosser
Copy link
Contributor

This PR adds rewrites that normalizes left shifts by extracting bits and concatenating zeroes. If the shift amount is larger than the bit-width, then the resulting bitvector is zero.

that normalize left shidts

Also, update the theorem names in the PR message to match their current names.

auto-merge was automatically disabled January 24, 2025 14:47

Head branch was pushed to by a user without write access

@bollu bollu force-pushed the lean4-shiftLeft-concat-extract branch from a49508a to d6ccd52 Compare January 24, 2025 14:48
This PR adds rewrites from Bitwuzla that normalize left shifts
in terms of extracting bits and concatenating zeroes.
If the shift amount is larger than the bitwidth, then the resulting bitvector is zero.

```lean
theorem shiftLeft_eq {x : BitVec w} {n : Nat} (hn : w ≤ n) : x <<< n = 0#w

theorem shiftLeft_eq_concat_of_lt {x : BitVec w} {n : Nat} (hn : n < w) :
    x <<< n = ((x.extractLsb' 0 (w-n)).append (BitVec.zero n)).cast (by omega)
```
@bollu bollu force-pushed the lean4-shiftLeft-concat-extract branch from d6ccd52 to 77ef60e Compare January 24, 2025 14:53
@hargoniX hargoniX enabled auto-merge January 24, 2025 15:04
@hargoniX hargoniX added this pull request to the merge queue Jan 24, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jan 24, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 24, 2025
Merged via the queue into leanprover:master with commit 1059e25 Jan 24, 2025
15 checks passed
@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jan 24, 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 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