data.num.bitwise
⟷
Mathlib.Data.Num.Bitwise
The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(last sync)
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Data.Num.Basic
-import Data.Bitvec.Core
+import Data.BitVec.Defs
#align_import data.num.bitwise from "leanprover-community/mathlib"@"68d1483e8a718ec63219f0e227ca3f0140361086"
mathlib commit https://github.com/leanprover-community/mathlib/commit/b1abe23ae96fef89ad30d9f4362c307f72a55010
@@ -137,7 +137,7 @@ namespace Num
def or : Num → Num → Num
| 0, q => q
| p, 0 => p
- | Pos p, Pos q => pos (p.lor' q)
+ | Pos p, Pos q => pos (p.lor q)
#align num.lor OrOp.or
-/
@@ -146,7 +146,7 @@ def or : Num → Num → Num
def land : Num → Num → Num
| 0, q => 0
| p, 0 => 0
- | Pos p, Pos q => p.land' q
+ | Pos p, Pos q => p.land q
#align num.land Num.land
-/
@@ -162,7 +162,7 @@ def land : Num → Num → Num
def ldiff : Num → Num → Num
| 0, q => 0
| p, 0 => p
- | Pos p, Pos q => p.ldiff' q
+ | Pos p, Pos q => p.ldiff q
#align num.ldiff Num.ldiff
-/
@@ -171,7 +171,7 @@ def ldiff : Num → Num → Num
def lxor : Num → Num → Num
| 0, q => q
| p, 0 => p
- | Pos p, Pos q => p.lxor' q
+ | Pos p, Pos q => p.xor q
#align num.lxor Num.lxor
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/19c869efa56bbb8b500f2724c0b77261edbfa28c
@@ -132,13 +132,13 @@ end PosNum
namespace Num
-#print Num.lor /-
+#print OrOp.or /-
/-- Bitwise "or" for `num`. -/
-def lor : Num → Num → Num
+def or : Num → Num → Num
| 0, q => q
| p, 0 => p
| Pos p, Pos q => pos (p.lor' q)
-#align num.lor Num.lor
+#align num.lor OrOp.or
-/
#print Num.land /-
mathlib commit https://github.com/leanprover-community/mathlib/commit/ce64cd319bb6b3e82f31c2d38e79080d377be451
@@ -3,8 +3,8 @@ Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
-import Mathbin.Data.Num.Basic
-import Mathbin.Data.Bitvec.Core
+import Data.Num.Basic
+import Data.Bitvec.Core
#align_import data.num.bitwise from "leanprover-community/mathlib"@"68d1483e8a718ec63219f0e227ca3f0140361086"
mathlib commit https://github.com/leanprover-community/mathlib/commit/8ea5598db6caeddde6cb734aa179cc2408dbd345
@@ -2,15 +2,12 @@
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-
-! This file was ported from Lean 3 source module data.num.bitwise
-! leanprover-community/mathlib commit 68d1483e8a718ec63219f0e227ca3f0140361086
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathbin.Data.Num.Basic
import Mathbin.Data.Bitvec.Core
+#align_import data.num.bitwise from "leanprover-community/mathlib"@"68d1483e8a718ec63219f0e227ca3f0140361086"
+
/-!
# Bitwise operations using binary representation of integers
mathlib commit https://github.com/leanprover-community/mathlib/commit/9240e8be927a0955b9a82c6c85ef499ee3a626b8
@@ -514,7 +514,7 @@ def bits : SNum → ∀ n, Vector Bool n
#print SNum.cAdd /-
def cAdd : SNum → SNum → Bool → SNum :=
rec' (fun a p c => czAdd c a p) fun a p IH =>
- rec' (fun b c => czAdd c b (a::p)) fun b q _ c => Bitvec.xor3 a b c::IH q (Bitvec.carry a b c)
+ rec' (fun b c => czAdd c b (a::p)) fun b q _ c => Bool.xor3 a b c::IH q (Bool.carry a b c)
#align snum.cadd SNum.cAdd
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/9fb8964792b4237dac6200193a0d533f1b3f7423
@@ -271,7 +271,6 @@ and the negation of the MSB is sign-extended to all higher bits.
namespace NzsNum
--- mathport name: nznum.bit
notation a "::" b => bit a b
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
@@ -294,7 +293,6 @@ def not : NzsNum → NzsNum
#align nzsnum.not NzsNum.not
-/
--- mathport name: «expr~ »
prefix:100 "~" => not
#print NzsNum.bit0 /-
@@ -353,7 +351,6 @@ def not : SNum → SNum
#align snum.not SNum.not
-/
--- mathport name: snum.not
prefix:0 "~" => not
#print SNum.bit /-
@@ -365,7 +362,6 @@ def bit : Bool → SNum → SNum
#align snum.bit SNum.bit
-/
--- mathport name: snum.bit
notation a "::" b => bit a b
#print SNum.bit0 /-
@@ -389,8 +385,10 @@ theorem bit_zero (b) : (b::zero b) = zero b := by cases b <;> rfl
-/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
+#print SNum.bit_one /-
theorem bit_one (b) : (b::zero (not b)) = msb b := by cases b <;> rfl
#align snum.bit_one SNum.bit_one
+-/
end SNum
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -388,12 +388,6 @@ theorem bit_zero (b) : (b::zero b) = zero b := by cases b <;> rfl
#align snum.bit_zero SNum.bit_zero
-/
-/- warning: snum.bit_one -> SNum.bit_one is a dubious translation:
-lean 3 declaration is
- forall (b : Bool), Eq.{1} SNum (SNum.bit b (SNum.zero (not b))) ((fun (a : Type) (b : Type) [self : HasLiftT.{1, 1} a b] => self.0) NzsNum SNum (HasLiftT.mk.{1, 1} NzsNum SNum (CoeTCₓ.coe.{1, 1} NzsNum SNum (coeBase.{1, 1} NzsNum SNum SNum.hasCoe))) (NzsNum.msb b))
-but is expected to have type
- forall (b : Bool), Eq.{1} SNum (SNum.bit b (SNum.zero (Decidable.decide (Not (Eq.{1} Bool b Bool.true)) (instDecidableNot (Eq.{1} Bool b Bool.true) (instDecidableEqBool b Bool.true))))) (SNum.nz (NzsNum.msb b))
-Case conversion may be inaccurate. Consider using '#align snum.bit_one SNum.bit_oneₓ'. -/
/- ./././Mathport/Syntax/Translate/Expr.lean:177:8: unsupported: ambiguous notation -/
theorem bit_one (b) : (b::zero (not b)) = msb b := by cases b <;> rfl
#align snum.bit_one SNum.bit_one
mathlib commit https://github.com/leanprover-community/mathlib/commit/3180fab693e2cee3bff62675571264cb8778b212
@@ -140,7 +140,7 @@ namespace Num
def lor : Num → Num → Num
| 0, q => q
| p, 0 => p
- | Pos p, Pos q => pos (p.lor q)
+ | Pos p, Pos q => pos (p.lor' q)
#align num.lor Num.lor
-/
@@ -149,7 +149,7 @@ def lor : Num → Num → Num
def land : Num → Num → Num
| 0, q => 0
| p, 0 => 0
- | Pos p, Pos q => p.land q
+ | Pos p, Pos q => p.land' q
#align num.land Num.land
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/bd9851ca476957ea4549eb19b40e7b5ade9428cc
@@ -278,7 +278,6 @@ and the negation of the MSB is sign-extended to all higher bits.
namespace NzsNum
--- mathport name: nznum.bit
@[inherit_doc]
scoped notation a "::" b => bit a b
@@ -295,7 +294,6 @@ def not : NzsNum → NzsNum
| b :: p => Not b :: not p
#align nzsnum.not NzsNum.not
--- mathport name: «expr~ »
@[inherit_doc]
scoped prefix:100 "~" => not
@@ -342,7 +340,6 @@ def not : SNum → SNum
#align snum.not SNum.not
-- Porting note: Defined `priority` so that `~1 : SNum` is unambiguous.
--- mathport name: snum.not
@[inherit_doc]
scoped prefix:100 (priority := default + 1) "~" => not
@@ -353,7 +350,6 @@ def bit : Bool → SNum → SNum
| b, nz p => p.bit b
#align snum.bit SNum.bit
--- mathport name: snum.bit
@[inherit_doc]
scoped notation a "::" b => bit a b
This enables the existing |||
, &&&
, <<<
, >>>
, and ^^^
notation for Num
and PosNum
, and makes them simp-normal form.
@@ -34,6 +34,10 @@ def lor : PosNum → PosNum → PosNum
| bit1 p, bit1 q => bit1 (lor p q)
#align pos_num.lor PosNum.lor
+instance : OrOp PosNum where or := PosNum.lor
+
+@[simp] lemma lor_eq_or (p q : PosNum) : p.lor q = p ||| q := rfl
+
/-- Bitwise "and" for `PosNum`. -/
def land : PosNum → PosNum → Num
| 1, bit0 _ => 0
@@ -46,6 +50,10 @@ def land : PosNum → PosNum → Num
| bit1 p, bit1 q => Num.bit1 (land p q)
#align pos_num.land PosNum.land
+instance : HAnd PosNum PosNum Num where hAnd := PosNum.land
+
+@[simp] lemma land_eq_and (p q : PosNum) : p.land q = p &&& q := rfl
+
/-- Bitwise `fun a b ↦ a && !b` for `PosNum`. For example, `ldiff 5 9 = 4`:
```
101
@@ -78,6 +86,10 @@ def lxor : PosNum → PosNum → Num
| bit1 p, bit1 q => Num.bit0 (lxor p q)
#align pos_num.lxor PosNum.lxor
+instance : HXor PosNum PosNum Num where hXor := PosNum.lxor
+
+@[simp] lemma lxor_eq_xor (p q : PosNum) : p.lxor q = p ^^^ q := rfl
+
/-- `a.testBit n` is `true` iff the `n`-th bit (starting from the LSB) in the binary representation
of `a` is active. If the size of `a` is less than `n`, this evaluates to `false`. -/
def testBit : PosNum → Nat → Bool
@@ -102,9 +114,14 @@ def shiftl : PosNum → Nat → PosNum
| p, n + 1 => shiftl p.bit0 n
#align pos_num.shiftl PosNum.shiftl
+instance : HShiftLeft PosNum Nat PosNum where hShiftLeft := PosNum.shiftl
+
+@[simp] lemma shiftl_eq_shiftLeft (p : PosNum) (n : Nat) : p.shiftl n = p <<< n := rfl
+
+
-- Porting note: `PosNum.shiftl` is defined as tail-recursive in Lean4.
-- This theorem ensures the definition is same to one in Lean3.
-theorem shiftl_succ_eq_bit0_shiftl : ∀ (p : PosNum) (n : Nat), shiftl p n.succ = bit0 (shiftl p n)
+theorem shiftl_succ_eq_bit0_shiftl : ∀ (p : PosNum) (n : Nat), p <<< n.succ = bit0 (p <<< n)
| _, 0 => rfl
| p, .succ n => shiftl_succ_eq_bit0_shiftl p.bit0 n
@@ -116,24 +133,36 @@ def shiftr : PosNum → Nat → Num
| bit1 p, n + 1 => shiftr p n
#align pos_num.shiftr PosNum.shiftr
+instance : HShiftRight PosNum Nat Num where hShiftRight := PosNum.shiftr
+
+@[simp] lemma shiftr_eq_shiftRight (p : PosNum) (n : Nat) : p.shiftr n = p >>> n := rfl
+
end PosNum
namespace Num
/-- Bitwise "or" for `Num`. -/
-def lor : Num → Num → Num
+protected def lor : Num → Num → Num
| 0, q => q
| p, 0 => p
- | pos p, pos q => pos (p.lor q)
-#align num.lor Num.lor
+ | pos p, pos q => pos (p ||| q)
+#align num.lor OrOp.or
+
+instance : OrOp Num where or := Num.lor
+
+@[simp] lemma lor_eq_or (p q : Num) : p.lor q = p ||| q := rfl
/-- Bitwise "and" for `Num`. -/
def land : Num → Num → Num
| 0, _ => 0
| _, 0 => 0
- | pos p, pos q => p.land q
+ | pos p, pos q => p &&& q
#align num.land Num.land
+instance : AndOp Num where and := Num.land
+
+@[simp] lemma land_eq_and (p q : Num) : p.land q = p &&& q := rfl
+
/-- Bitwise `fun a b ↦ a && !b` for `Num`. For example, `ldiff 5 9 = 4`:
```
101
@@ -152,21 +181,33 @@ def ldiff : Num → Num → Num
def lxor : Num → Num → Num
| 0, q => q
| p, 0 => p
- | pos p, pos q => p.lxor q
+ | pos p, pos q => p ^^^ q
#align num.lxor Num.lxor
+instance : Xor Num where xor := Num.lxor
+
+@[simp] lemma lxor_eq_xor (p q : Num) : p.lxor q = p ^^^ q := rfl
+
/-- Left-shift the binary representation of a `Num`. -/
def shiftl : Num → Nat → Num
| 0, _ => 0
- | pos p, n => pos (p.shiftl n)
+ | pos p, n => pos (p <<< n)
#align num.shiftl Num.shiftl
+instance : HShiftLeft Num Nat Num where hShiftLeft := Num.shiftl
+
+@[simp] lemma shiftl_eq_shiftLeft (p : Num) (n : Nat) : p.shiftl n = p <<< n := rfl
+
/-- Right-shift the binary representation of a `Num`. -/
def shiftr : Num → Nat → Num
| 0, _ => 0
- | pos p, n => p.shiftr n
+ | pos p, n => p >>> n
#align num.shiftr Num.shiftr
+instance : HShiftRight Num Nat Num where hShiftRight := Num.shiftr
+
+@[simp] lemma shiftr_eq_shiftRight (p : Num) (n : Nat) : p.shiftr n = p >>> n := rfl
+
/-- `a.testBit n` is `true` iff the `n`-th bit (starting from the LSB) in the binary representation
of `a` is active. If the size of `a` is less than `n`, this evaluates to `false`. -/
def testBit : Num → Nat → Bool
Type _
and Sort _
(#6499)
We remove all possible occurences of Type _
and Sort _
in favor of Type*
and Sort*
.
This has nice performance benefits.
@@ -340,7 +340,7 @@ open SNum
/-- A dependent induction principle for `NzsNum`, with base cases
`0 : SNum` and `(-1) : SNum`. -/
-def drec' {C : SNum → Sort _} (z : ∀ b, C (SNum.zero b)) (s : ∀ b p, C p → C (b :: p)) :
+def drec' {C : SNum → Sort*} (z : ∀ b, C (SNum.zero b)) (s : ∀ b p, C p → C (b :: p)) :
∀ p : NzsNum, C p
| msb b => by rw [← bit_one]; exact s b (SNum.zero (Not b)) (z (Not b))
| bit b p => s b p (drec' z s p)
@@ -366,7 +366,7 @@ def tail : SNum → SNum
#align snum.tail SNum.tail
/-- A dependent induction principle for `SNum` which avoids relying on `NzsNum`. -/
-def drec' {C : SNum → Sort _} (z : ∀ b, C (SNum.zero b)) (s : ∀ b p, C p → C (b :: p)) : ∀ p, C p
+def drec' {C : SNum → Sort*} (z : ∀ b, C (SNum.zero b)) (s : ∀ b p, C p → C (b :: p)) : ∀ p, C p
| zero b => z b
| nz p => p.drec' z s
#align snum.drec' SNum.drec'
@@ -2,16 +2,13 @@
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-
-! This file was ported from Lean 3 source module data.num.bitwise
-! leanprover-community/mathlib commit f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathlib.Data.Num.Basic
import Mathlib.Data.Bool.Basic
import Mathlib.Data.Vector.Basic
+#align_import data.num.bitwise from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c"
+
/-!
# Bitwise operations using binary representation of integers
This is the second half of the changes originally in #5699, removing all occurrences of ;
after a space and implementing a linter rule to enforce it.
In most cases this 2-character substring has a space after it, so the following command was run first:
find . -type f -name "*.lean" -exec sed -i -E 's/ ; /; /g' {} \;
The remaining cases were few enough in number that they were done manually.
@@ -345,7 +345,7 @@ open SNum
`0 : SNum` and `(-1) : SNum`. -/
def drec' {C : SNum → Sort _} (z : ∀ b, C (SNum.zero b)) (s : ∀ b p, C p → C (b :: p)) :
∀ p : NzsNum, C p
- | msb b => by rw [← bit_one] ; exact s b (SNum.zero (Not b)) (z (Not b))
+ | msb b => by rw [← bit_one]; exact s b (SNum.zero (Not b)) (z (Not b))
| bit b p => s b p (drec' z s p)
#align nzsnum.drec' NzsNum.drec'
This eliminates an unnecessary dependency from Num.Bitwise to Bitvec.Defs.
@@ -9,7 +9,8 @@ Authors: Mario Carneiro
! if you have ported upstream changes.
-/
import Mathlib.Data.Num.Basic
-import Mathlib.Data.Bitvec.Defs
+import Mathlib.Data.Bool.Basic
+import Mathlib.Data.Vector.Basic
/-!
# Bitwise operations using binary representation of integers
@@ -426,7 +427,7 @@ def bits : SNum → ∀ n, Vector Bool n
`a` represents a carry bit. -/
def cAdd : SNum → SNum → Bool → SNum :=
rec' (fun a p c ↦ czAdd c a p) fun a p IH ↦
- rec' (fun b c ↦ czAdd c b (a :: p)) fun b q _ c ↦ Bitvec.xor3 a b c :: IH q (Bitvec.carry a b c)
+ rec' (fun b c ↦ czAdd c b (a :: p)) fun b q _ c ↦ Bool.xor3 a b c :: IH q (Bool.carry a b c)
#align snum.cadd SNum.cAdd
/-- Add two `SNum`s. -/
The Core
file was just dumped from Lean3 core. I've split it into Defs
and Lemmas
in the style of the List
folder for example.
@@ -9,7 +9,7 @@ Authors: Mario Carneiro
! if you have ported upstream changes.
-/
import Mathlib.Data.Num.Basic
-import Mathlib.Data.Bitvec.Core
+import Mathlib.Data.Bitvec.Defs
/-!
# Bitwise operations using binary representation of integers
@@ -104,6 +104,12 @@ def shiftl : PosNum → Nat → PosNum
| p, n + 1 => shiftl p.bit0 n
#align pos_num.shiftl PosNum.shiftl
+-- Porting note: `PosNum.shiftl` is defined as tail-recursive in Lean4.
+-- This theorem ensures the definition is same to one in Lean3.
+theorem shiftl_succ_eq_bit0_shiftl : ∀ (p : PosNum) (n : Nat), shiftl p n.succ = bit0 (shiftl p n)
+ | _, 0 => rfl
+ | p, .succ n => shiftl_succ_eq_bit0_shiftl p.bit0 n
+
/-- Right-shift the binary representation of a `PosNum`. -/
def shiftr : PosNum → Nat → Num
| p, 0 => Num.pos p
@@ -235,7 +235,7 @@ namespace NzsNum
-- mathport name: nznum.bit
@[inherit_doc]
-notation a "::" b => bit a b
+scoped notation a "::" b => bit a b
/-- Sign of a `NzsNum`. -/
def sign : NzsNum → Bool
@@ -252,7 +252,7 @@ def not : NzsNum → NzsNum
-- mathport name: «expr~ »
@[inherit_doc]
-prefix:100 "~" => not
+scoped prefix:100 "~" => not
/-- Add an inactive bit at the end of a `NzsNum`. This mimics `PosNum.bit0`. -/
def bit0 : NzsNum → NzsNum :=
@@ -299,7 +299,7 @@ def not : SNum → SNum
-- Porting note: Defined `priority` so that `~1 : SNum` is unambiguous.
-- mathport name: snum.not
@[inherit_doc]
-prefix:100 (priority := default + 1) "~" => not
+scoped prefix:100 (priority := default + 1) "~" => not
/-- Add a bit at the end of a `SNum`. This mimics `NzsNum.bit`. -/
@[match_pattern]
@@ -310,7 +310,7 @@ def bit : Bool → SNum → SNum
-- mathport name: snum.bit
@[inherit_doc]
-notation a "::" b => bit a b
+scoped notation a "::" b => bit a b
/-- Add an inactive bit at the end of a `SNum`. This mimics `ZNum.bit0`. -/
def bit0 : SNum → SNum :=
The unported dependencies are