Skip to content

Commit 08c36e4

Browse files
feat: add (msb, getMsbD)_twoPow (leanprover#5851)
1 parent 8f0328b commit 08c36e4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Init/Data/BitVec/Lemmas.lean

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,6 +2672,21 @@ theorem getElem_twoPow {i j : Nat} (h : j < w) : (twoPow w i)[j] = decide (j = i
26722672
simp [eq_comm]
26732673
omega
26742674

2675+
@[simp]
2676+
theorem getMsbD_twoPow {i j w: Nat} :
2677+
(twoPow w i).getMsbD j = (decide (i < w) && decide (j = w - i - 1)) := by
2678+
simp only [getMsbD_eq_getLsbD, getLsbD_twoPow]
2679+
by_cases h₀ : i < w <;> by_cases h₁ : j < w <;>
2680+
simp [h₀, h₁] <;> omega
2681+
2682+
@[simp]
2683+
theorem msb_twoPow {i w: Nat} :
2684+
(twoPow w i).msb = (decide (i < w) && decide (i = w - 1)) := by
2685+
simp only [BitVec.msb, getMsbD_eq_getLsbD, Nat.sub_zero, getLsbD_twoPow,
2686+
Bool.and_iff_right_iff_imp, Bool.and_eq_true, decide_eq_true_eq, and_imp]
2687+
intros
2688+
omega
2689+
26752690
theorem and_twoPow (x : BitVec w) (i : Nat) :
26762691
x &&& (twoPow w i) = if x.getLsbD i then twoPow w i else 0#w := by
26772692
ext j

0 commit comments

Comments
 (0)