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
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 9 additions & 28 deletions Mathlib/Data/BitVec/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,10 @@
theorem toNat_lt_toNat {x y : BitVec w} : x.toNat < y.toNat ↔ x < y :=
Iff.rfl

@[simp]
lemma ofNat_eq_mod_two_pow (n : Nat) : (BitVec.ofNat w n).toNat = n % 2^w := rfl

lemma toNat_ofNat {m} (h : m < 2^w) : (BitVec.ofNat w m).toNat = m := Fin.val_cast_of_lt h

@[simp]
lemma toNat_ofFin (x : Fin (2^w)) : (ofFin x).toNat = x.val := rfl
attribute [simp] toNat_ofNat toNat_ofFin

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.

(msbs ++ lsbs).toNat = msbs.toNat <<< v ||| lsbs.toNat := by
rcases msbs with ⟨msbs, hm⟩
rcases lsbs with ⟨lsbs, hl⟩
simp only [HAppend.hAppend, append, toNat_ofFin]
rw [toNat_ofNat (Nat.add_comm w v ▸ append_lt hl hm)]
lemma toNat_ofNat_of_lt {m} (h : m < 2^w) : (BitVec.ofNat w m).toNat = m := by
simp only [toNat_ofNat, mod_eq_of_lt h]

#noalign bitvec.bits_to_nat_to_bool

Expand All @@ -60,14 +50,9 @@

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

simp only [getLsb, Nat.shiftLeft_eq, one_mul, Nat.and_two_pow]
cases' testBit (BitVec.toNat x) i
<;> simp [pos_iff_ne_zero.mp (two_pow_pos i)]
simp only [extractLsb', toNat_ofNat, shiftRight_eq_div_pow]

theorem ofFin_val {n : ℕ} (i : Fin <| 2 ^ n) : (ofFin i).toNat = i.val := by
theorem ofFin_val {n : ℕ} (i : Fin <| 2 ^ n) : (ofFin i).toNat = i.val :=
rfl
#align bitvec.of_fin_val Std.BitVec.ofFin_val

Expand All @@ -91,16 +76,12 @@
simp [addLsb]
#align bitvec.to_bool_add_lsb_mod_two Std.BitVec.decide_addLsb_mod_two

@[simp]
lemma ofNat_toNat (x : BitVec w) : BitVec.ofNat w x.toNat = x := by
rcases x with ⟨x⟩
simp [BitVec.ofNat]
apply Fin.cast_val_eq_self x
#align bitvec.of_nat_to_nat Std.BitVec.ofNat_toNat
@[simp] lemma ofNat_toNat' (x : BitVec w) : (x.toNat)#w = x := by

Check failure on line 79 in Mathlib/Data/BitVec/Lemmas.lean

View workflow job for this annotation

GitHub Actions / Build

Std.BitVec.ofNat_toNat' simp can prove this:
rw [ofNat_toNat, truncate_eq]

lemma ofNat_toNat' (x : BitVec w) (h : w = v):
lemma ofNat_toNat_of_eq (x : BitVec w) (h : w = v):
BitVec.ofNat v x.toNat = x.cast h := by
cases h; rw [ofNat_toNat, cast_eq]
cases h; rw [ofNat_toNat', cast_eq]

theorem toFin_val {n : ℕ} (v : BitVec n) : (toFin v : ℕ) = v.toNat := by
rfl
Expand Down
Loading