Skip to content

Commit

Permalink
feat: BitVec.(not_sshiftRight, not_sshiftRight_not, getMsb_not, msb_n…
Browse files Browse the repository at this point in the history
…ot) (#5492)
  • Loading branch information
luisacicolini authored Sep 27, 2024
1 parent 0733273 commit 48711ce
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Init/Data/BitVec/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,16 @@ theorem not_not {b : BitVec w} : ~~~(~~~b) = b := by
ext i
simp

@[simp] theorem getMsb_not {x : BitVec w} :
(~~~x).getMsbD i = (decide (i < w) && !(x.getMsbD i)) := by
simp only [getMsbD]
by_cases h : i < w
· simp [h]; omega
· simp [h];

@[simp] theorem msb_not {x : BitVec w} : (~~~x).msb = (decide (0 < w) && !x.msb) := by
simp [BitVec.msb]

/-! ### cast -/

@[simp] theorem not_cast {x : BitVec w} (h : w = w') : ~~~(cast h x) = cast h (~~~x) := by
Expand Down Expand Up @@ -1293,6 +1303,22 @@ theorem sshiftRight_add {x : BitVec w} {m n : Nat} :
omega
· simp [h₃, sshiftRight_msb_eq_msb]

theorem not_sshiftRight {b : BitVec w} :
~~~b.sshiftRight n = (~~~b).sshiftRight n := by
ext i
simp only [getLsbD_not, Fin.is_lt, decide_True, getLsbD_sshiftRight, Bool.not_and, Bool.not_not,
Bool.true_and, msb_not]
by_cases h : w ≤ i
<;> by_cases h' : n + i < w
<;> by_cases h'' : 0 < w
<;> simp [h, h', h'']
<;> omega

@[simp]
theorem not_sshiftRight_not {x : BitVec w} {n : Nat} :
~~~((~~~x).sshiftRight n) = x.sshiftRight n := by
simp [not_sshiftRight]

/-! ### sshiftRight reductions from BitVec to Nat -/

@[simp]
Expand Down

0 comments on commit 48711ce

Please sign in to comment.