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: add Bitvec.(toInt, toFin)_twoPow #7225

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

Conversation

luisacicolini
Copy link
Contributor

@luisacicolini luisacicolini commented Feb 25, 2025

This PR contains BitVec.(toInt, toFin)_twoPow theorems, completing the API for BitVec.*_twoPow. It also expands the toNat_twoPow API with toNat_twoPow_of_le, toNat_twoPow_of_lt, as well as toNat_twoPow_eq_if and moves msb_twoPow up, as it is used in the toInt_msb proof.

@luisacicolini luisacicolini changed the title chore: add theorems feat: add Bitvec.(toInt, toFin)_twoPow Feb 25, 2025
@luisacicolini
Copy link
Contributor Author

changelog-library

@github-actions github-actions bot added changelog-library Library toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN labels Feb 25, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Feb 25, 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 2377f3542622e24dd1ad1ee49a20ea14e34f34d3 --onto 5cbeb22564c6caa0603612edfdabda4bdb34b780. (2025-02-25 13:43:44)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 2377f3542622e24dd1ad1ee49a20ea14e34f34d3 --onto c3402b85ab96b7ceec32e0b119837913da0051d0. (2025-02-26 09:30:34)

Copy link
Contributor Author

@luisacicolini luisacicolini left a comment

Choose a reason for hiding this comment

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

thank you @tobiasgrosser for this cute proof! looks good to me :)

tobiasgrosser and others added 2 commits February 26, 2025 22:15
Co-authored-by: Luisa Cicolini <[email protected]>
Co-authored-by: Siddharth <[email protected]>
apply Nat.mod_eq_of_lt
apply Nat.pow_lt_pow_of_lt (by omega) (by omega)

theorem toNat_twoPow_eq_if {i w : Nat} : (twoPow w i).toNat = if i < w then 2^i else 0 := by
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like for us to contemplate, in a subsequent PR, whether this should be the simp normal form of toNat_twoPow.

Copy link
Contributor

@tobiasgrosser tobiasgrosser Feb 26, 2025

Choose a reason for hiding this comment

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

I looked into this, but this breaks a couple of proofs in non-trivial ways, as several proofs use % 2 ^ ? instead of an if statement to express that the RHS can be zero. I am happy to investigate this further, but given that this is not a clear-cut, we should investigate this more broadly and likely in a future PR.

@luisacicolini luisacicolini marked this pull request as ready for review February 26, 2025 22:20
@luisacicolini
Copy link
Contributor Author

awaiting-review

@github-actions github-actions bot added the awaiting-review Waiting for someone to review the PR label Feb 26, 2025
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 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