From 4236d8a85b17fe1928613a1c300f89ace40a81f5 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Sun, 11 Aug 2024 10:40:07 +0100 Subject: [PATCH] feat: add Std.[Associative|Commutative] instances for BitVec.[and|or|xor] (#4981) --- src/Init/Data/BitVec/Lemmas.lean | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Init/Data/BitVec/Lemmas.lean b/src/Init/Data/BitVec/Lemmas.lean index 3d4a7d3445d3..9a7c671290cf 100644 --- a/src/Init/Data/BitVec/Lemmas.lean +++ b/src/Init/Data/BitVec/Lemmas.lean @@ -507,6 +507,13 @@ theorem or_assoc (x y z : BitVec w) : x ||| y ||| z = x ||| (y ||| z) := by ext i simp [Bool.or_assoc] +instance : Std.Associative (α := BitVec n) (· ||| ·) := ⟨BitVec.or_assoc⟩ + +theorem or_comm (x y : BitVec w) : + x ||| y = y ||| x := by + ext i + simp [Bool.or_comm] +instance : Std.Commutative (fun (x y : BitVec w) => x ||| y) := ⟨BitVec.or_comm⟩ /-! ### and -/ @@ -538,11 +545,13 @@ theorem and_assoc (x y z : BitVec w) : x &&& y &&& z = x &&& (y &&& z) := by ext i simp [Bool.and_assoc] +instance : Std.Associative (α := BitVec n) (· &&& ·) := ⟨BitVec.and_assoc⟩ theorem and_comm (x y : BitVec w) : x &&& y = y &&& x := by ext i simp [Bool.and_comm] +instance : Std.Commutative (fun (x y : BitVec w) => x &&& y) := ⟨BitVec.and_comm⟩ /-! ### xor -/ @@ -568,6 +577,13 @@ theorem xor_assoc (x y z : BitVec w) : x ^^^ y ^^^ z = x ^^^ (y ^^^ z) := by ext i simp [Bool.xor_assoc] +instance : Std.Associative (fun (x y : BitVec w) => x ^^^ y) := ⟨BitVec.xor_assoc⟩ + +theorem xor_comm (x y : BitVec w) : + x ^^^ y = y ^^^ x := by + ext i + simp [Bool.xor_comm] +instance : Std.Commutative (fun (x y : BitVec w) => x ^^^ y) := ⟨BitVec.xor_comm⟩ /-! ### not -/