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.neg_neg #4977

Merged
merged 5 commits into from
Aug 12, 2024
Merged

feat: add BitVec.neg_neg #4977

merged 5 commits into from
Aug 12, 2024

Conversation

tobiasgrosser
Copy link
Contributor

@tobiasgrosser tobiasgrosser commented Aug 10, 2024

.. as well as neg_neq_iff_neq_neg.

@tobiasgrosser
Copy link
Contributor Author

Draft PR to indicate that @bollu or @alexkeizer should maybe double-check my style choices before Kim does his review.

.. as well as neg_neq_iff_neq_neg.
@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 Aug 10, 2024
@tobiasgrosser
Copy link
Contributor Author

tobiasgrosser commented Aug 10, 2024

I am currently still unhappy with the BitVec.neg_neg proof, as the explicit use of Nat.mod_eq_of_lt is something that comes up very often also in other proofs and is always tedious to write:

theorem neg_neg {x : BitVec w} : - - x = x := by
  by_cases h : x = 0
  · simp [h]
  · simp only [toNat_eq, ofNat_eq_ofNat, toNat_ofNat, Nat.zero_mod] at h
    simp only [toNat_eq, toNat_neg]
    rw [Nat.mod_eq_of_lt (a := 2 ^ w - x.toNat) (by omega)]
    rw [Nat.mod_eq_of_lt (by omega)]
    omega

@tobiasgrosser
Copy link
Contributor Author

I found a neat way to clean this up with two helper theorems sub_toNat_mod_cancel and sub_sub_toNat_cancel.

@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Aug 10, 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 6dd502321f2b57a4b19c4b2a467ad900eeed8b91 --onto dd6ed124baef64a26ef5860f49597fdcef371239. (2024-08-10 06:06:43)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 6dd502321f2b57a4b19c4b2a467ad900eeed8b91 --onto 5f31e938c1bf5bb2d6d2d29b26ea932ade115357. (2024-08-11 10:02:55)

@tobiasgrosser
Copy link
Contributor Author

This is now clean from my perspective and ready to review.

@tobiasgrosser tobiasgrosser marked this pull request as ready for review August 11, 2024 09:04
@tobiasgrosser tobiasgrosser requested a review from kim-em as a code owner August 11, 2024 09:04
src/Init/Data/BitVec/Lemmas.lean Outdated Show resolved Hide resolved
src/Init/Data/BitVec/Lemmas.lean Outdated Show resolved Hide resolved
@kim-em kim-em added this pull request to the merge queue Aug 12, 2024
Merged via the queue into leanprover:master with commit 37f9063 Aug 12, 2024
12 checks passed
Parcly-Taxel pushed a commit to Parcly-Taxel/lean4 that referenced this pull request Aug 12, 2024
.. as well as neg_neq_iff_neq_neg.

---------

Co-authored-by: Henrik Böving <[email protected]>
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