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: getLsb_signExtend #4187

Merged
merged 11 commits into from
Jun 5, 2024
Merged

Conversation

bollu
Copy link
Contributor

@bollu bollu commented May 16, 2024

The key idea is to notice that signExtend behavior is controlled by the msb. When msb = false, sext behaves the same as trunc. When msb = true, sext behaves like trunc but adds high 1-bits. This is expressed using the negate-truncate-negate pattern. Lemma statements below:

theorem signExtend_eq_neg_truncate_neg_of_msb_false {x : BitVec w} {v : Nat} (hmsb : x.msb = false) :
    (x.signExtend v) = x.truncate v := by
 
theorem signExtend_eq_neg_truncate_neg_of_msb_true {x : BitVec w} {v : Nat} (hmsb : x.msb = true) :
    (x.signExtend v) = ~~~((~~~x).truncate v) := by

These give the final theorem statement:

theorem getLsb_signExtend {x  : BitVec w} {v i : Nat} :
    (x.signExtend v).getLsb i = (decide (i < v) && if i < w then x.getLsb i else x.msb) := by

@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 Jun 2, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

Mathlib CI status (docs):

  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2024-06-02 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. (2024-06-02 18:15:31)

bollu and others added 2 commits June 3, 2024 10:44
chore: truncate -> zext, to carry more semantic information.

Co-authored-by: Tobias Grosser <[email protected]>
@bollu bollu marked this pull request as ready for review June 3, 2024 10:22
@bollu bollu requested a review from semorrison as a code owner June 3, 2024 10:22
@bollu
Copy link
Contributor Author

bollu commented Jun 4, 2024

awaiting-review

@github-actions github-actions bot added the awaiting-review Waiting for someone to review the PR label Jun 4, 2024
@semorrison semorrison added awaiting-author Waiting for PR author to address issues and removed awaiting-review Waiting for someone to review the PR labels Jun 4, 2024
@semorrison
Copy link
Collaborator

Close now!

chore: change comment about msb=false into a sentence.

Co-authored-by: Kim Morrison <[email protected]>
src/Init/Data/BitVec/Lemmas.lean Outdated Show resolved Hide resolved
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 4, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jun 4, 2024
@bollu
Copy link
Contributor Author

bollu commented Jun 4, 2024

awaiting-review

@github-actions github-actions bot added awaiting-review Waiting for someone to review the PR and removed awaiting-author Waiting for PR author to address issues labels Jun 4, 2024
@tobiasgrosser
Copy link
Contributor

@bollu, can you update the commit message accordingly.

@semorrison semorrison added this pull request to the merge queue Jun 5, 2024
Merged via the queue into leanprover:master with commit fbb3055 Jun 5, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review Waiting for someone to review the PR 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.

None yet

5 participants