Skip to content

Commit

Permalink
feat: add BitVec.ofBool_[and|or|xor]_ofBool theorems (leanprover#5385)
Browse files Browse the repository at this point in the history
... and use them to simplify some proofs.
  • Loading branch information
tobiasgrosser authored Sep 18, 2024
1 parent fa6afa8 commit daf24ff
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Init/Data/BitVec/Lemmas.lean
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ theorem ofBool_eq_iff_eq : ∀ {b b' : Bool}, BitVec.ofBool b = BitVec.ofBool b'

@[simp] theorem not_ofBool : ~~~ (ofBool b) = ofBool (!b) := by cases b <;> rfl

@[simp] theorem ofBool_and_ofBool : ofBool b &&& ofBool b' = ofBool (b && b') := by
cases b <;> cases b' <;> rfl

@[simp] theorem ofBool_or_ofBool : ofBool b ||| ofBool b' = ofBool (b || b') := by
cases b <;> cases b' <;> rfl

@[simp] theorem ofBool_xor_ofBool : ofBool b ^^^ ofBool b' = ofBool (b ^^ b') := by
cases b <;> cases b' <;> rfl

@[simp, bv_toNat] theorem toNat_ofFin (x : Fin (2^n)) : (BitVec.ofFin x).toNat = x.val := rfl

@[simp] theorem toNat_ofNatLt (x : Nat) (p : x < 2^w) : (x#'p).toNat = x := rfl
Expand Down Expand Up @@ -1421,15 +1430,18 @@ theorem eq_msb_cons_setWidth (x : BitVec (w+1)) : x = (cons x.msb (x.setWidth w)

@[simp] theorem cons_or_cons (x y : BitVec w) (a b : Bool) :
(cons a x) ||| (cons b y) = cons (a || b) (x ||| y) := by
ext i; cases i using Fin.succRecOn <;> simp <;> split <;> rfl
ext i
simp [cons]

@[simp] theorem cons_and_cons (x y : BitVec w) (a b : Bool) :
(cons a x) &&& (cons b y) = cons (a && b) (x &&& y) := by
ext i; cases i using Fin.succRecOn <;> simp <;> split <;> rfl
ext i
simp [cons]

@[simp] theorem cons_xor_cons (x y : BitVec w) (a b : Bool) :
(cons a x) ^^^ (cons b y) = cons (a ^^ b) (x ^^^ y) := by
ext i; cases i using Fin.succRecOn <;> simp <;> split <;> rfl
ext i
simp [cons]

/-! ### concat -/

Expand Down
24 changes: 24 additions & 0 deletions tests/lean/interactive/completionPrv.lean.expected.out
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@
"position": {"line": 9, "character": 11}},
"id": {"const": {"declName": "BitVec.getMsbD_ofBoolListBE"}}}},
{"sortText": "4",
"label": "BitVec.ofBool_and_ofBool",
"kind": 3,
"data":
{"params":
{"textDocument": {"uri": "file:///completionPrv.lean"},
"position": {"line": 9, "character": 11}},
"id": {"const": {"declName": "BitVec.ofBool_and_ofBool"}}}},
{"sortText": "5",
"label": "BitVec.ofBool_or_ofBool",
"kind": 3,
"data":
{"params":
{"textDocument": {"uri": "file:///completionPrv.lean"},
"position": {"line": 9, "character": 11}},
"id": {"const": {"declName": "BitVec.ofBool_or_ofBool"}}}},
{"sortText": "6",
"label": "BitVec.ofBool_xor_ofBool",
"kind": 3,
"data":
{"params":
{"textDocument": {"uri": "file:///completionPrv.lean"},
"position": {"line": 9, "character": 11}},
"id": {"const": {"declName": "BitVec.ofBool_xor_ofBool"}}}},
{"sortText": "7",
"label": "BitVec.ofBoolListBE",
"kind": 3,
"documentation":
Expand Down

0 comments on commit daf24ff

Please sign in to comment.