diff --git a/src/Init/Data/BitVec/Lemmas.lean b/src/Init/Data/BitVec/Lemmas.lean index 1ecbdde3419c..fe5ef45838ab 100644 --- a/src/Init/Data/BitVec/Lemmas.lean +++ b/src/Init/Data/BitVec/Lemmas.lean @@ -269,6 +269,10 @@ theorem ofBool_eq_iff_eq : ∀ {b b' : Bool}, BitVec.ofBool b = BitVec.ofBool b' getLsbD (x#'lt) i = x.testBit i := by simp [getLsbD, BitVec.ofNatLt] +@[simp] theorem getMsbD_ofNatLt {n x i : Nat} (h : x < 2^n) : + getMsbD (x#'h) i = (decide (i < n) && x.testBit (n - 1 - i)) := by + simp [getMsbD, getLsbD] + @[simp, bv_toNat] theorem toNat_ofNat (x w : Nat) : (BitVec.ofNat w x).toNat = x % 2^w := by simp [BitVec.toNat, BitVec.ofNat, Fin.ofNat'] @@ -755,6 +759,10 @@ theorem extractLsb'_eq_extractLsb {w : Nat} (x : BitVec w) (start len : Nat) (h @[simp] theorem getLsbD_allOnes : (allOnes v).getLsbD i = decide (i < v) := by simp [allOnes] +@[simp] theorem getMsbD_allOnes : (allOnes v).getMsbD i = decide (i < v) := by + simp [allOnes] + omega + @[simp] theorem getElem_allOnes (i : Nat) (h : i < v) : (allOnes v)[i] = true := by simp [getElem_eq_testBit_toNat, h] @@ -1007,6 +1015,10 @@ theorem not_def {x : BitVec v} : ~~~x = allOnes v ^^^ x := rfl @[simp] theorem getLsbD_not {x : BitVec v} : (~~~x).getLsbD i = (decide (i < v) && ! x.getLsbD i) := by by_cases h' : i < v <;> simp_all [not_def] +@[simp] theorem getMsbD_not {x : BitVec v} : + (~~~x).getMsbD i = (decide (i < v) && ! x.getMsbD i) := by + by_cases h' : i < v <;> simp_all [not_def] + @[simp] theorem getElem_not {x : BitVec w} {i : Nat} (h : i < w) : (~~~x)[i] = !x[i] := by simp only [getElem_eq_testBit_toNat, toNat_not] rw [← Nat.sub_add_eq, Nat.add_comm 1]