Skip to content

Commit cdc2534

Browse files
committed
feat: BitVec.getMsbD in bv_decide
1 parent ebc02fc commit cdc2534

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Std/Tactic/BVDecide/Normalize/BitVec.lean

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ attribute [bv_normalize] Bool.cond_eq_if
122122
attribute [bv_normalize] BitVec.abs_eq
123123
attribute [bv_normalize] BitVec.twoPow_eq
124124

125+
@[bv_normalize]
126+
theorem BitVec.getElem_eq_getLsbD (a : BitVec w) (i : Nat) (h : i < w) :
127+
a[i]'h = a.getLsbD i := by
128+
simp [BitVec.getLsbD_eq_getElem?_getD, BitVec.getElem?_eq, h]
129+
130+
-- The side condition about gets resolved if i and w are constant.
131+
attribute [bv_normalize] BitVec.getMsbD_eq_getLsbD
132+
125133
end Reduce
126134

127135
section Constant
@@ -137,6 +145,10 @@ attribute [bv_normalize] BitVec.mul_one
137145
attribute [bv_normalize] BitVec.one_mul
138146
attribute [bv_normalize] BitVec.not_not
139147

148+
attribute [bv_normalize] decide_true
149+
attribute [bv_normalize] decide_false
150+
attribute [bv_normalize] decide_not
151+
140152
end Constant
141153

142154
attribute [bv_normalize] BitVec.zero_and
@@ -280,12 +292,6 @@ theorem BitVec.max_ult' (a : BitVec w) : (BitVec.ult (-1#w) a) = false := by
280292
simp [this]
281293

282294
attribute [bv_normalize] BitVec.replicate_zero_eq
283-
284-
@[bv_normalize]
285-
theorem BitVec.getElem_eq_getLsbD (a : BitVec w) (i : Nat) (h : i < w) :
286-
a[i] = a.getLsbD i := by
287-
simp [BitVec.getLsbD_eq_getElem?_getD, BitVec.getElem?_eq, h]
288-
289295
attribute [bv_normalize] BitVec.add_eq_xor
290296
attribute [bv_normalize] BitVec.mul_eq_and
291297

tests/lean/run/bv_bitwise.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ theorem bitwise_unit_9 (x y : BitVec 32) :
3838
BitVec.ofBool (x.getLsbD 0 ^^ y.getLsbD 0) = BitVec.ofBool ((x ^^^ y).getLsbD 0) := by
3939
bv_decide
4040

41+
theorem bitwise_unit_10 (x : BitVec 2): (x.getMsbD 0) = x.msb := by
42+
bv_decide

0 commit comments

Comments
 (0)