|
1 | 1 | /- |
2 | 2 | Copyright (c) 2024 Lean FRO, LLC. All Rights Reserved. |
3 | 3 | Released under Apache 2.0 license as described in the file LICENSE. |
4 | | -Authors: Markus Himmel |
| 4 | +Authors: Markus Himmel, Mac Malone |
5 | 5 | -/ |
6 | 6 | prelude |
7 | | -import Init.Data.UInt.Basic |
| 7 | +import Init.Data.UInt.Lemmas |
8 | 8 | import Init.Data.Fin.Bitwise |
9 | 9 | import Init.Data.BitVec.Lemmas |
10 | 10 |
|
11 | 11 | set_option hygiene false in |
12 | | -macro "declare_bitwise_uint_theorems" typeName:ident : command => |
| 12 | +macro "declare_bitwise_uint_theorems" typeName:ident bits:term:arg : command => |
13 | 13 | `( |
14 | 14 | namespace $typeName |
15 | 15 |
|
16 | | -@[simp] protected theorem and_toNat (a b : $typeName) : (a &&& b).toNat = a.toNat &&& b.toNat := BitVec.toNat_and .. |
| 16 | +@[simp] protected theorem toBitVec_and (a b : $typeName) : (a &&& b).toBitVec = a.toBitVec &&& b.toBitVec := rfl |
| 17 | +@[simp] protected theorem toBitVec_or (a b : $typeName) : (a ||| b).toBitVec = a.toBitVec ||| b.toBitVec := rfl |
| 18 | +@[simp] protected theorem toBitVec_xor (a b : $typeName) : (a ^^^ b).toBitVec = a.toBitVec ^^^ b.toBitVec := rfl |
| 19 | +@[simp] protected theorem toBitVec_shiftLeft (a b : $typeName) : (a <<< b).toBitVec = a.toBitVec <<< (b.toBitVec % $bits) := rfl |
| 20 | +@[simp] protected theorem toBitVec_shiftRight (a b : $typeName) : (a >>> b).toBitVec = a.toBitVec >>> (b.toBitVec % $bits) := rfl |
| 21 | + |
| 22 | +@[simp] protected theorem toNat_and (a b : $typeName) : (a &&& b).toNat = a.toNat &&& b.toNat := by simp [toNat] |
| 23 | +@[simp] protected theorem toNat_or (a b : $typeName) : (a ||| b).toNat = a.toNat ||| b.toNat := by simp [toNat] |
| 24 | +@[simp] protected theorem toNat_xor (a b : $typeName) : (a ^^^ b).toNat = a.toNat ^^^ b.toNat := by simp [toNat] |
| 25 | +@[simp] protected theorem toNat_shiftLeft (a b : $typeName) : (a <<< b).toNat = a.toNat <<< (b.toNat % $bits) % 2 ^ $bits := by simp [toNat] |
| 26 | +@[simp] protected theorem toNat_shiftRight (a b : $typeName) : (a >>> b).toNat = a.toNat >>> (b.toNat % $bits) := by simp [toNat] |
| 27 | + |
| 28 | +open $typeName (toNat_and) in |
| 29 | +@[deprecated toNat_and (since := "2024-11-28")] |
| 30 | +protected theorem and_toNat (a b : $typeName) : (a &&& b).toNat = a.toNat &&& b.toNat := BitVec.toNat_and .. |
17 | 31 |
|
18 | 32 | end $typeName |
19 | 33 | ) |
20 | 34 |
|
21 | | -declare_bitwise_uint_theorems UInt8 |
22 | | -declare_bitwise_uint_theorems UInt16 |
23 | | -declare_bitwise_uint_theorems UInt32 |
24 | | -declare_bitwise_uint_theorems UInt64 |
25 | | -declare_bitwise_uint_theorems USize |
| 35 | +declare_bitwise_uint_theorems UInt8 8 |
| 36 | +declare_bitwise_uint_theorems UInt16 16 |
| 37 | +declare_bitwise_uint_theorems UInt32 32 |
| 38 | +declare_bitwise_uint_theorems UInt64 64 |
| 39 | +declare_bitwise_uint_theorems USize System.Platform.numBits |
0 commit comments