From 2f1dc878e4aaaf5ee17acc6c376fd65420c1face Mon Sep 17 00:00:00 2001 From: Luisa Cicolini <48860705+luisacicolini@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:10:02 +0000 Subject: [PATCH] feat: add `BitVec.(msb, getMsbD)_concat` (#5865) --- src/Init/Data/BitVec/Lemmas.lean | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Init/Data/BitVec/Lemmas.lean b/src/Init/Data/BitVec/Lemmas.lean index 9d6e7dce59..64174c3b3c 100644 --- a/src/Init/Data/BitVec/Lemmas.lean +++ b/src/Init/Data/BitVec/Lemmas.lean @@ -1917,6 +1917,31 @@ theorem toNat_shiftConcat_lt_of_lt {x : BitVec w} {b : Bool} {k : Nat} ext simp [getLsbD_concat] +@[simp] +theorem getMsbD_concat {i w : Nat} {b : Bool} {x : BitVec w} : + (x.concat b).getMsbD i = if i < w then x.getMsbD i else decide (i = w) && b := by + simp only [getMsbD_eq_getLsbD, Nat.add_sub_cancel, getLsbD_concat] + by_cases h₀ : i = w + · simp [h₀] + · by_cases h₁ : i < w + · simp [h₀, h₁, show ¬ w - i = 0 by omega, show i < w + 1 by omega, Nat.sub_sub, Nat.add_comm] + · simp only [show w - i = 0 by omega, ↓reduceIte, h₁, h₀, decide_False, Bool.false_and, + Bool.and_eq_false_imp, decide_eq_true_eq] + intro + omega + +@[simp] +theorem msb_concat {w : Nat} {b : Bool} {x : BitVec w} : + (x.concat b).msb = if 0 < w then x.msb else b := by + simp only [BitVec.msb, getMsbD_eq_getLsbD, Nat.zero_lt_succ, decide_True, Nat.add_one_sub_one, + Nat.sub_zero, Bool.true_and] + by_cases h₀ : 0 < w + · simp only [Nat.lt_add_one, getLsbD_eq_getElem, getElem_concat, h₀, ↓reduceIte, decide_True, + Bool.true_and, ite_eq_right_iff] + intro + omega + · simp [h₀, show w = 0 by omega] + /-! ### add -/ theorem add_def {n} (x y : BitVec n) : x + y = .ofNat n (x.toNat + y.toNat) := rfl