-
Notifications
You must be signed in to change notification settings - Fork 354
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
[Merged by Bors] - chore: bump Std, changes for leanprover/std4#366 #8700
Conversation
EDIT: I didn't notice the broken lemmas were about |
This fixes the Int.testbit_bitwise proofs
All of the previously commented out theorems should now have proper proofs |
Mathlib/Data/Nat/Bitwise.lean
Outdated
theorem zero_land (n : ℕ) : 0 &&& n = 0 := by simp | ||
#align nat.zero_land Nat.zero_land | ||
|
||
@[simp] | ||
theorem land_zero (n : ℕ) : n &&& 0 = 0 := by | ||
simp only [HAnd.hAnd, AndOp.and, land, bitwise_zero_right, ite_false, Bool.and_false] | ||
theorem land_zero (n : ℕ) : n &&& 0 = 0 := by simp | ||
#align nat.land_zero Nat.land_zero | ||
|
||
@[simp] | ||
theorem zero_lor (n : ℕ) : 0 ||| n = n := by | ||
simp only [HOr.hOr, OrOp.or, lor, bitwise_zero_left, ite_true, Bool.or_true] | ||
theorem zero_lor (n : ℕ) : 0 ||| n = n := by simp | ||
#align nat.zero_lor Nat.zero_lor | ||
|
||
@[simp] | ||
theorem lor_zero (n : ℕ) : n ||| 0 = n := by | ||
simp only [HOr.hOr, OrOp.or, lor, bitwise_zero_right, ite_true, Bool.or_false] | ||
theorem lor_zero (n : ℕ) : n ||| 0 = n := by simp | ||
#align nat.lor_zero Nat.lor_zero |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should just be removed, and the aligns changed to drop the l
.
/-- Bitwise extensionality: Two numbers agree if they agree at every bit position. -/ | ||
theorem eq_of_testBit_eq {n m : ℕ} (h : ∀ i, testBit n i = testBit m i) : n = m := by | ||
induction' n using Nat.binaryRec with b n hn generalizing m | ||
· simp only [zero_testBit] at h | ||
exact (zero_of_testBit_eq_false fun i => (h i).symm).symm | ||
induction' m using Nat.binaryRec with b' m | ||
· simp only [zero_testBit] at h | ||
exact zero_of_testBit_eq_false h | ||
suffices h' : n = m by | ||
rw [h', show b = b' by simpa using h 0] | ||
exact hn fun i => by convert h (i + 1) using 1 <;> rw [testBit_succ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This proof looks much nicer to me than the one (for the converse, ne_implies_bit_diff
) that landed in Std4 :(.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that is inevitable, since we don't have Nat.binaryRec
in std yet (at least, leanprover-community/batteries#314 is still open, and I'm not aware of any alternative PRs)
Co-authored-by: Eric Wieser <[email protected]>
|
||
theorem toNat_append (msbs : BitVec w) (lsbs : BitVec v) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -60,14 +50,9 @@ lemma extractLsb_eq {w : ℕ} (hi lo : ℕ) (a : BitVec w) : | |||
|
|||
theorem toNat_extractLsb' {i j} {x : BitVec w} : | |||
(extractLsb' i j x).toNat = x.toNat / 2 ^ i % (2 ^ j) := by | |||
simp only [extractLsb', ofNat_eq_mod_two_pow, shiftRight_eq_div_pow] | |||
|
|||
theorem getLsb_eq_testBit {i} {x : BitVec w} : getLsb x i = x.toNat.testBit i := by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did this go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The RHS is now the definition of getLsb
, so this is replaced by unfolding getLsb
, no need for a theorem
bors merge I've updated the PR description to summarize some concerns for a follow-up. |
Notably leanprover-community/batteries#366 changed the definition of `testBit` (to something equivalent) when upstreaming it, which broke a handful of proofs. Other conflicting changes in Std, resolved for now by priming the mathlib name: * `Std.BitVec.adc`: the type was changed from `BitVec (n + 1)` to `Bool × BitVec w` * `Nat.mul_add_mod`: the type was changed from `(a * b + c) % b = c % b` to `(b * a + c) % b = c % b` [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/348111-std4/topic/Mathlib.20bump.20for.20.22Operations.20for.20bit.20representation.20of.20.2E.2E.2E.22/near/404801443) Co-authored-by: Scott Morrison <[email protected]> Co-authored-by: Alex Keizer <[email protected]> Co-authored-by: Eric Wieser <[email protected]>
bors p=10 |
Pull request successfully merged into master. Build succeeded: |
Notably leanprover-community/batteries#366 changed the definition of `testBit` (to something equivalent) when upstreaming it, which broke a handful of proofs. Other conflicting changes in Std, resolved for now by priming the mathlib name: * `Std.BitVec.adc`: the type was changed from `BitVec (n + 1)` to `Bool × BitVec w` * `Nat.mul_add_mod`: the type was changed from `(a * b + c) % b = c % b` to `(b * a + c) % b = c % b` [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/348111-std4/topic/Mathlib.20bump.20for.20.22Operations.20for.20bit.20representation.20of.20.2E.2E.2E.22/near/404801443) Co-authored-by: Scott Morrison <[email protected]> Co-authored-by: Alex Keizer <[email protected]> Co-authored-by: Eric Wieser <[email protected]>
Notably leanprover-community/batteries#366 changed the definition of
testBit
(to something equivalent) when upstreaming it, which broke a handful of proofs.Other conflicting changes in Std, resolved for now by priming the mathlib name:
Std.BitVec.adc
: the type was changed fromBitVec (n + 1)
toBool × BitVec w
Nat.mul_add_mod
: the type was changed from(a * b + c) % b = c % b
to(b * a + c) % b = c % b
Zulip thread
This still has some breakages arising from leanprover-community/batteries#366, around
testBit
. Fixes welcome!Please see also #8705, which keeps everything, but renames
Nat.testBit
toNat.testBit'
, so for now it can exist alongside Std'sNat.testBit
.