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.[toFin|getMsbD]_setWidth and [getMsbD|msb]_signExtend #6338

Merged
merged 11 commits into from
Dec 10, 2024

Conversation

tobiasgrosser
Copy link
Contributor

@tobiasgrosser tobiasgrosser commented Dec 8, 2024

This PR adds BitVec.[toFin|getMsbD]_setWidth and [getMsb|msb]_signExtend as well as ofInt_toInt.

Also correct renamed the misnamed theorem for signExtend_eq_setWidth_of_msb_false.

@tobiasgrosser
Copy link
Contributor Author

changelog-library

@github-actions github-actions bot added the changelog-library Library label Dec 8, 2024
@tobiasgrosser tobiasgrosser force-pushed the bv_msb_signzeroextend branch 5 times, most recently from 3c600d0 to fd427df Compare December 8, 2024 17:10
@tobiasgrosser tobiasgrosser marked this pull request as ready for review December 8, 2024 17:12
@tobiasgrosser tobiasgrosser requested a review from kim-em as a code owner December 8, 2024 17:12
@tobiasgrosser tobiasgrosser changed the title feat: BitVec.[toFin|getMsbD]_setWidth and [getMsb|msb]_signExtend feat: BitVec.[toFin|getMsbD]_setWidth and [getMsbD|msb]_signExtend Dec 8, 2024
@tobiasgrosser tobiasgrosser force-pushed the bv_msb_signzeroextend branch 3 times, most recently from 0271ec3 to 1052987 Compare December 8, 2024 17:56
This patch adds BitVec.[toFin|getMsbD]_setWidth and [getMsb|msb]_signExtend as
well as ofInt_toInt and toInt_cast.
@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 Dec 8, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Dec 8, 2024

Mathlib CI status (docs):

  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2024-12-08 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-12-08 18:26:42)
  • ✅ Mathlib branch lean-pr-testing-6338 has successfully built against this PR. (2024-12-09 03:31:01) View Log
  • ✅ Mathlib branch lean-pr-testing-6338 has successfully built against this PR. (2024-12-09 15:31:45) View Log

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 9, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 9, 2024
@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Dec 9, 2024
@luisacicolini
Copy link
Contributor

lgtm!

src/Init/Data/BitVec/Lemmas.lean Outdated Show resolved Hide resolved
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 Dec 9, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 9, 2024
@kim-em kim-em self-assigned this Dec 10, 2024
@@ -645,6 +652,20 @@ theorem getElem?_setWidth (m : Nat) (x : BitVec n) (i : Nat) :
getLsbD (setWidth m x) i = (decide (i < m) && getLsbD x i) := by
simp [getLsbD, toNat_setWidth, Nat.testBit_mod_two_pow]

theorem getMsbD_setWidth {m : Nat} {x : BitVec n} {i : Nat} :
getMsbD (setWidth m x) i = (decide (m - n ≤ i) && getMsbD x (i + n - m)) := by
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objection on this PR, but increasingly I am skeptical that decide inequality && boolean is really what we want on the RHS of all these lemmas. It probably should just be if inequality then boolean else false. Without a mixed linear arithmetic + SAT solver, this is doing us no favours, and the if style makes it much easier to use split to get the inequalities in usable form (e.g. for omega).

Something to consider; it would be a big refactor.

@kim-em kim-em added this pull request to the merge queue Dec 10, 2024
Merged via the queue into leanprover:master with commit c5b82e0 Dec 10, 2024
15 checks passed
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.

6 participants