Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Std/Tactic/BVDecide/Normalize/BitVec.lean
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ theorem BitVec.sle_eq_ult (x y : BitVec w) :
theorem BitVec.ofNatLT_reduce (n : Nat) (h) : BitVec.ofNatLT n h = BitVec.ofNat w n := by
simp [BitVec.ofNatLT, BitVec.ofNat, Fin.ofNat, Nat.mod_eq_of_lt h]

@[bv_normalize]
theorem BitVec.ofNat_toNat' (w : Nat) (b : Bool) :
BitVec.ofNat w b.toNat = (BitVec.ofBool b).zeroExtend w := by
cases b <;> simp [BitVec.setWidth_ofNat_one_eq_ofNat_one_of_lt]

@[bv_normalize]
theorem BitVec.ofBool_eq_ite (b : Bool) : BitVec.ofBool b = bif b then 1#1 else 0#1 := by
revert b
Expand Down Expand Up @@ -146,6 +151,19 @@ theorem BitVec.abs_eq (x : BitVec w) : x.abs = bif x.getLsbD (w - 1) then -x els

attribute [bv_normalize] BitVec.twoPow_eq

@[bv_normalize]
theorem BitVec.carry_eq_ite_le_lt (i : Nat) (x y : BitVec w) (c : Bool) :
BitVec.carry i x y c =
bif c then
(~~~(x.setWidth i)).ule (y.setWidth i)
else
(~~~(x.setWidth i)).ult (y.setWidth i) := by
have : 0 < 2 ^ i := Nat.two_pow_pos i
cases c
all_goals
simp [BitVec.carry, BitVec.ult_eq_decide, BitVec.ule_eq_decide]
omega

@[bv_normalize]
theorem BitVec.getElem_eq_getLsbD (a : BitVec w) (i : Nat) (h : i < w) :
a[i]'h = a.getLsbD i := by
Expand All @@ -159,6 +177,7 @@ end Reduce

section Constant

attribute [bv_normalize] BitVec.zero_eq
attribute [bv_normalize] BitVec.add_zero
attribute [bv_normalize] BitVec.zero_add
attribute [bv_normalize] BitVec.mul_one
Expand Down
20 changes: 20 additions & 0 deletions tests/elab/15580.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module
import Std.Tactic.BVDecide
meta import Std.Tactic.BVDecide


example (x y : BitVec 64) : BitVec.carry 64 x y false = (x.zeroExtend 65 + y.zeroExtend 65).msb := by
bv_decide

example (x y : BitVec 64) : BitVec.carry 64 x y true = BitVec.carry 64 y x true := by
bv_decide

example (x y : BitVec 64) (b : Bool) : BitVec.carry 32 x y b = BitVec.carry 32 y x b := by
bv_decide

example (x : BitVec 64) (c : Bool) :
x + BitVec.ofNat 64 c.toNat = x + (BitVec.ofBool c).zeroExtend 64 := by
bv_decide

example (x : BitVec 64) : x + BitVec.zero 64 = x := by
bv_decide
Loading