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

[Merged by Bors] - chore: bump Std, changes for leanprover/std4#366 #8700

Closed
wants to merge 27 commits into from

Conversation

kim-em
Copy link
Contributor

@kim-em kim-em commented Nov 29, 2023

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


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 to Nat.testBit', so for now it can exist alongside Std's Nat.testBit.

Open in Gitpod

@kim-em kim-em added help-wanted The author needs attention to resolve issues awaiting-review labels Nov 29, 2023
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 29, 2023
@alexkeizer
Copy link
Collaborator

alexkeizer commented Nov 29, 2023

I foresee testBit_bitwise and its corollaries being useful in the near future; I'll give fixing them a try

EDIT: I didn't notice the broken lemmas were about Int, rather than Nat, so I retract my statement about foreseeing their usefulness.
In any case, they have been fixed by marking Nat.testBit_bitwise as a simp lemma again (in Mathlib, not upstream), just like it was before being upstreamed.

@alexkeizer
Copy link
Collaborator

All of the previously commented out theorems should now have proper proofs

Comment on lines 352 to 362
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
Copy link
Member

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.

Comment on lines -234 to -244
/-- 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]
Copy link
Member

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 :(.

Copy link
Collaborator

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)

@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 29, 2023
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 30, 2023
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 30, 2023

theorem toNat_append (msbs : BitVec w) (lsbs : BitVec v) :
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Where did this go?

Copy link
Collaborator

@alexkeizer alexkeizer Nov 30, 2023

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

@eric-wieser
Copy link
Member

bors merge

I've updated the PR description to summarize some concerns for a follow-up.

@github-actions github-actions bot added ready-to-merge This PR has been sent to bors. and removed awaiting-review labels Nov 30, 2023
mathlib-bors bot pushed a commit that referenced this pull request Nov 30, 2023
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]>
@kim-em
Copy link
Contributor Author

kim-em commented Nov 30, 2023

bors p=10

@mathlib-bors
Copy link
Contributor

mathlib-bors bot commented Dec 1, 2023

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title chore: bump Std, changes for leanprover/std4#366 [Merged by Bors] - chore: bump Std, changes for leanprover/std4#366 Dec 1, 2023
@mathlib-bors mathlib-bors bot closed this Dec 1, 2023
@mathlib-bors mathlib-bors bot deleted the bump_std_20231129 branch December 1, 2023 00:51
awueth pushed a commit that referenced this pull request Dec 19, 2023
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted The author needs attention to resolve issues ready-to-merge This PR has been sent to bors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants