File: Mathlib/Data/Num/Bitwise.lean

full_name: PosNum.lor
code: /-- Bitwise "or" for `PosNum`. -/
def lor : PosNum → PosNum → PosNum
  
goal: PosNum → PosNum → PosNum

full_name: PosNum.instOrOp
code: instance : OrOp PosNum 
goal: OrOp PosNum

full_name: PosNum.lor_eq_or
code: @[simp] lemma lor_eq_or (p q : PosNum) : p.lor q = p ||| q 
goal: p.lor q = p ||| q

full_name: PosNum.land
code: /-- Bitwise "and" for `PosNum`. -/
def land : PosNum → PosNum → Num
  
goal: PosNum → PosNum → Num

full_name: PosNum.instHAndNum
code: instance : HAnd PosNum PosNum Num 
goal: HAnd PosNum PosNum Num

full_name: PosNum.land_eq_and
code: @[simp] lemma land_eq_and (p q : PosNum) : p.land q = p &&& q 
goal: p.land q = p &&& q

full_name: PosNum.ldiff
code: /-- Bitwise `fun a b ↦ a && !b` for `PosNum`. For example, `ldiff 5 9 = 4`:
```
 101
1001
----
 100
```
-/
def ldiff : PosNum → PosNum → Num
  
goal: PosNum → PosNum → Num

full_name: PosNum.lxor
code: /-- Bitwise "xor" for `PosNum`. -/
def lxor : PosNum → PosNum → Num
  
goal: PosNum → PosNum → Num

full_name: PosNum.instHXorNum
code: instance : HXor PosNum PosNum Num 
goal: HXor PosNum PosNum Num

full_name: PosNum.lxor_eq_xor
code: @[simp] lemma lxor_eq_xor (p q : PosNum) : p.lxor q = p ^^^ q 
goal: p.lxor q = p ^^^ q

full_name: PosNum.testBit
code: /-- `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
  
goal: PosNum → ℕ → Bool

full_name: PosNum.oneBits
code: /-- `n.oneBits 0` is the list of indices of active bits in the binary representation of `n`. -/
def oneBits : PosNum → Nat → List Nat
  
goal: PosNum → ℕ → List ℕ

full_name: PosNum.shiftl
code: /-- Left-shift the binary representation of a `PosNum`. -/
def shiftl : PosNum → Nat → PosNum
  
goal: PosNum → ℕ → PosNum

full_name: PosNum.instHShiftLeftNat
code: instance : HShiftLeft PosNum Nat PosNum 
goal: HShiftLeft PosNum ℕ PosNum

full_name: PosNum.shiftl_eq_shiftLeft
code: @[simp] lemma shiftl_eq_shiftLeft (p : PosNum) (n : Nat) : p.shiftl n = p <<< n 
goal: p.shiftl n = p <<< n

full_name: PosNum.shiftl_succ_eq_bit0_shiftl
code: theorem shiftl_succ_eq_bit0_shiftl : ∀ (p : PosNum) (n : Nat), p <<< n.succ = bit0 (p <<< n)
  
goal: p <<< n.succ = (p <<< n).bit0

full_name: PosNum.shiftr
code: /-- Right-shift the binary representation of a `PosNum`. -/
def shiftr : PosNum → Nat → Num
  
goal: PosNum → ℕ → Num

full_name: PosNum.instHShiftRightNatNum
code: instance : HShiftRight PosNum Nat Num 
goal: HShiftRight PosNum ℕ Num

full_name: PosNum.shiftr_eq_shiftRight
code: @[simp] lemma shiftr_eq_shiftRight (p : PosNum) (n : Nat) : p.shiftr n = p >>> n 
goal: p.shiftr n = p >>> n

full_name: Num.lor
code: /-- Bitwise "or" for `Num`. -/
protected def lor : Num → Num → Num
  
goal: Num → Num → Num

full_name: Num.instOrOp
code: instance : OrOp Num 
goal: OrOp Num

full_name: Num.lor_eq_or
code: @[simp] lemma lor_eq_or (p q : Num) : p.lor q = p ||| q 
goal: p.lor q = p ||| q

full_name: Num.land
code: /-- Bitwise "and" for `Num`. -/
def land : Num → Num → Num
  
goal: Num → Num → Num

full_name: Num.instAndOp
code: instance : AndOp Num 
goal: AndOp Num

full_name: Num.land_eq_and
code: @[simp] lemma land_eq_and (p q : Num) : p.land q = p &&& q 
goal: p.land q = p &&& q

full_name: Num.ldiff
code: /-- Bitwise `fun a b ↦ a && !b` for `Num`. For example, `ldiff 5 9 = 4`:
```
 101
1001
----
 100
```
-/
def ldiff : Num → Num → Num
  
goal: Num → Num → Num

full_name: Num.lxor
code: /-- Bitwise "xor" for `Num`. -/
def lxor : Num → Num → Num
  
goal: Num → Num → Num

full_name: Num.instXor
code: instance : Xor Num 
goal: Xor Num

full_name: Num.lxor_eq_xor
code: @[simp] lemma lxor_eq_xor (p q : Num) : p.lxor q = p ^^^ q 
goal: p.lxor q = p ^^^ q

full_name: Num.shiftl
code: /-- Left-shift the binary representation of a `Num`. -/
def shiftl : Num → Nat → Num
  
goal: Num → ℕ → Num

full_name: Num.instHShiftLeftNat
code: instance : HShiftLeft Num Nat Num 
goal: HShiftLeft Num ℕ Num

full_name: Num.shiftl_eq_shiftLeft
code: @[simp] lemma shiftl_eq_shiftLeft (p : Num) (n : Nat) : p.shiftl n = p <<< n 
goal: p.shiftl n = p <<< n

full_name: Num.shiftr
code: /-- Right-shift the binary representation of a `Num`. -/
def shiftr : Num → Nat → Num
  
goal: Num → ℕ → Num

full_name: Num.instHShiftRightNat
code: instance : HShiftRight Num Nat Num 
goal: HShiftRight Num ℕ Num

full_name: Num.shiftr_eq_shiftRight
code: @[simp] lemma shiftr_eq_shiftRight (p : Num) (n : Nat) : p.shiftr n = p >>> n 
goal: p.shiftr n = p >>> n

full_name: Num.testBit
code: /-- `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
  
goal: Num → ℕ → Bool

full_name: Num.oneBits
code: /-- `n.oneBits` is the list of indices of active bits in the binary representation of `n`. -/
def oneBits : Num → List Nat
  
goal: Num → List ℕ

full_name: NzsNum.bit
code: /-- This is a nonzero (and "non minus one") version of `SNum`.
    See the documentation of `SNum` for more details. -/
inductive NzsNum : Type
  | msb : Bool → NzsNum
  /-- Add a bit at the end of a `NzsNum`. -/
  | bit : Bool → NzsNum → NzsNum
  deriving DecidableEq
goal: Bool → NzsNum → NzsNum

full_name: NzsNum
code: /-- This is a nonzero (and "non minus one") version of `SNum`.
    See the documentation of `SNum` for more details. -/
inductive NzsNum : Type
  | msb : Bool → NzsNum
  /-- Add a bit at the end of a `NzsNum`. -/
  | bit : Bool → NzsNum → NzsNum
  deriving DecidableEq
goal: Type

full_name: NzsNum.msb
code: /-- This is a nonzero (and "non minus one") version of `SNum`.
    See the documentation of `SNum` for more details. -/
inductive NzsNum : Type
  | msb : Bool → NzsNum
  /-- Add a bit at the end of a `NzsNum`. -/
  | bit : Bool → NzsNum → NzsNum
  deriving DecidableEq
goal: Bool → NzsNum

full_name: SNum.nz
code: /-- Alternative representation of integers using a sign bit at the end.
  The convention on sign here is to have the argument to `msb` denote
  the sign of the MSB itself, with all higher bits set to the negation
  of this sign. The result is interpreted in two's complement.

     13  = ..0001101(base 2) = nz (bit1 (bit0 (bit1 (msb true))))
     -13 = ..1110011(base 2) = nz (bit1 (bit1 (bit0 (msb false))))

  As with `Num`, a special case must be added for zero, which has no msb,
  but by two's complement symmetry there is a second special case for -1.
  Here the `Bool` field indicates the sign of the number.

     0  = ..0000000(base 2) = zero false
     -1 = ..1111111(base 2) = zero true -/
inductive SNum : Type
  | zero : Bool → SNum
  | nz : NzsNum → SNum
  deriving DecidableEq
goal: NzsNum → SNum

full_name: SNum.zero
code: /-- Alternative representation of integers using a sign bit at the end.
  The convention on sign here is to have the argument to `msb` denote
  the sign of the MSB itself, with all higher bits set to the negation
  of this sign. The result is interpreted in two's complement.

     13  = ..0001101(base 2) = nz (bit1 (bit0 (bit1 (msb true))))
     -13 = ..1110011(base 2) = nz (bit1 (bit1 (bit0 (msb false))))

  As with `Num`, a special case must be added for zero, which has no msb,
  but by two's complement symmetry there is a second special case for -1.
  Here the `Bool` field indicates the sign of the number.

     0  = ..0000000(base 2) = zero false
     -1 = ..1111111(base 2) = zero true -/
inductive SNum : Type
  | zero : Bool → SNum
  | nz : NzsNum → SNum
  deriving DecidableEq
goal: Bool → SNum

full_name: SNum
code: /-- Alternative representation of integers using a sign bit at the end.
  The convention on sign here is to have the argument to `msb` denote
  the sign of the MSB itself, with all higher bits set to the negation
  of this sign. The result is interpreted in two's complement.

     13  = ..0001101(base 2) = nz (bit1 (bit0 (bit1 (msb true))))
     -13 = ..1110011(base 2) = nz (bit1 (bit1 (bit0 (msb false))))

  As with `Num`, a special case must be added for zero, which has no msb,
  but by two's complement symmetry there is a second special case for -1.
  Here the `Bool` field indicates the sign of the number.

     0  = ..0000000(base 2) = zero false
     -1 = ..1111111(base 2) = zero true -/
inductive SNum : Type
  | zero : Bool → SNum
  | nz : NzsNum → SNum
  deriving DecidableEq
goal: Type

full_name: instCoeNzsNumSNum
code: instance : Coe NzsNum SNum 
goal: Coe NzsNum SNum

full_name: instZeroSNum
code: instance : Zero SNum 
goal: Zero SNum

full_name: instOneNzsNum
code: instance : One NzsNum 
goal: One NzsNum

full_name: instOneSNum
code: instance : One SNum 
goal: One SNum

full_name: instInhabitedNzsNum
code: instance : Inhabited NzsNum 
goal: Inhabited NzsNum

full_name: instInhabitedSNum
code: instance : Inhabited SNum 
goal: Inhabited SNum

full_name: NzsNum.«_aux_Mathlib_Data_Num_Bitwise___macroRules_NzsNum_term_::__1»
code: @[inherit_doc]
scoped notation a "::" b => bit a b
goal: Lean.Macro

full_name: NzsNum._aux_Mathlib_Data_Num_Bitwise___unexpand_NzsNum_bit_1
code: @[inherit_doc]
scoped notation a "::" b => bit a b
goal: Lean.PrettyPrinter.Unexpander

full_name: NzsNum.sign
code: /-- Sign of a `NzsNum`. -/
def sign : NzsNum → Bool
  
goal: NzsNum → Bool

full_name: NzsNum.not
code: /-- Bitwise `not` for `NzsNum`. -/
@[match_pattern]
def not : NzsNum → NzsNum
  
goal: NzsNum → NzsNum

full_name: NzsNum._aux_Mathlib_Data_Num_Bitwise___unexpand_NzsNum_not_1
code: @[inherit_doc]
scoped prefix:100 "~" => not
goal: Lean.PrettyPrinter.Unexpander

full_name: NzsNum.«_aux_Mathlib_Data_Num_Bitwise___macroRules_NzsNum_term~__1»
code: @[inherit_doc]
scoped prefix:100 "~" => not
goal: Lean.Macro

full_name: NzsNum.bit0
code: /-- Add an inactive bit at the end of a `NzsNum`. This mimics `PosNum.bit0`. -/
def bit0 : NzsNum → NzsNum 
goal: NzsNum → NzsNum

full_name: NzsNum.bit1
code: /-- Add an active bit at the end of a `NzsNum`. This mimics `PosNum.bit1`. -/
def bit1 : NzsNum → NzsNum 
goal: NzsNum → NzsNum

full_name: NzsNum.head
code: /-- The `head` of a `NzsNum` is the boolean value of its LSB. -/
def head : NzsNum → Bool
  
goal: NzsNum → Bool

full_name: NzsNum.tail
code: /-- The `tail` of a `NzsNum` is the `SNum` obtained by removing the LSB.
      Edge cases: `tail 1 = 0` and `tail (-2) = -1`. -/
def tail : NzsNum → SNum
  
goal: NzsNum → SNum

full_name: SNum.sign
code: /-- Sign of a `SNum`. -/
def sign : SNum → Bool
  
goal: SNum → Bool

full_name: SNum.not
code: /-- Bitwise `not` for `SNum`. -/
@[match_pattern]
def not : SNum → SNum
  
goal: SNum → SNum

full_name: SNum._aux_Mathlib_Data_Num_Bitwise___unexpand_SNum_not_1
code: @[inherit_doc]
scoped prefix:100 (priority := default + 1) "~" => not
goal: Lean.PrettyPrinter.Unexpander

full_name: SNum.«_aux_Mathlib_Data_Num_Bitwise___macroRules_SNum_term~__1»
code: @[inherit_doc]
scoped prefix:100 (priority := default + 1) "~" => not
goal: Lean.Macro

full_name: SNum.bit
code: /-- Add a bit at the end of a `SNum`. This mimics `NzsNum.bit`. -/
@[match_pattern]
def bit : Bool → SNum → SNum
  
goal: Bool → SNum → SNum

full_name: SNum.«_aux_Mathlib_Data_Num_Bitwise___macroRules_SNum_term_::__1»
code: @[inherit_doc]
scoped notation a "::" b => bit a b
goal: Lean.Macro

full_name: SNum._aux_Mathlib_Data_Num_Bitwise___unexpand_SNum_bit_1
code: @[inherit_doc]
scoped notation a "::" b => bit a b
goal: Lean.PrettyPrinter.Unexpander

full_name: SNum.bit0
code: /-- Add an inactive bit at the end of a `SNum`. This mimics `ZNum.bit0`. -/
def bit0 : SNum → SNum 
goal: SNum → SNum

full_name: SNum.bit1
code: /-- Add an active bit at the end of a `SNum`. This mimics `ZNum.bit1`. -/
def bit1 : SNum → SNum 
goal: SNum → SNum

full_name: SNum.bit_zero
code: theorem bit_zero (b : Bool) : (b :: zero b) = zero b 
goal: SNum.bit b (SNum.zero b) = SNum.zero b

full_name: SNum.bit_one
code: theorem bit_one (b : Bool) : (b :: zero (Not b)) = msb b 
goal: SNum.bit b (SNum.zero (decide ¬b = true)) = SNum.nz (NzsNum.msb b)

full_name: NzsNum.drec'
code: /-- 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)) :
    ∀ p : NzsNum, C p
  
goal: C (SNum.nz p)

full_name: SNum.head
code: /-- The `head` of a `SNum` is the boolean value of its LSB. -/
def head : SNum → Bool
  
goal: SNum → Bool

full_name: SNum.tail
code: /-- The `tail` of a `SNum` is obtained by removing the LSB.
      Edge cases: `tail 1 = 0`, `tail (-2) = -1`, `tail 0 = 0` and `tail (-1) = -1`. -/
def tail : SNum → SNum
  
goal: SNum → SNum

full_name: SNum.drec'
code: /-- 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
  
goal: C p

full_name: SNum.rec'
code: /-- An induction principle for `SNum` which avoids relying on `NzsNum`. -/
def rec' {α} (z : Bool → α) (s : Bool → SNum → α → α) : SNum → α 
goal: SNum → α

full_name: SNum.testBit
code: /-- `SNum.testBit n a` is `true` iff the `n`-th bit (starting from the LSB) of `a` is active.
      If the size of `a` is less than `n`, this evaluates to `false`. -/
def testBit : Nat → SNum → Bool
  
goal: ℕ → SNum → Bool

full_name: SNum.succ
code: /-- The successor of a `SNum` (i.e. the operation adding one). -/
def succ : SNum → SNum 
goal: SNum → SNum

full_name: SNum.pred
code: /-- The predecessor of a `SNum` (i.e. the operation of removing one). -/
def pred : SNum → SNum 
goal: SNum → SNum

full_name: SNum.neg
code: /-- The opposite of a `SNum`. -/
protected def neg (n : SNum) : SNum 
goal: SNum

full_name: SNum.instNeg
code: instance : Neg SNum 
goal: Neg SNum

full_name: SNum.czAdd
code: /-- `SNum.czAdd a b n` is `n + a - b` (where `a` and `b` should be read as either 0 or 1).
      This is useful to implement the carry system in `cAdd`. -/
def czAdd : Bool → Bool → SNum → SNum
  
goal: Bool → Bool → SNum → SNum

full_name: SNum.bits
code: /-- `a.bits n` is the vector of the `n` first bits of `a` (starting from the LSB). -/
def bits : SNum → ∀ n, Vector Bool n
  
goal: SNum → (n : ℕ) → Mathlib.Vector Bool n

full_name: SNum.cAdd
code: /-- `SNum.cAdd n m a` is `n + m + a` (where `a` should be read as either 0 or 1).
      `a` represents a carry bit. -/
def cAdd : SNum → SNum → Bool → SNum 
goal: SNum → SNum → Bool → SNum

full_name: SNum.add
code: /-- Add two `SNum`s. -/
protected def add (a b : SNum) : SNum 
goal: SNum

full_name: SNum.instAdd
code: instance : Add SNum 
goal: Add SNum

full_name: SNum.sub
code: /-- Subtract two `SNum`s. -/
protected def sub (a b : SNum) : SNum 
goal: SNum

full_name: SNum.instSub
code: instance : Sub SNum 
goal: Sub SNum

full_name: SNum.mul
code: /-- Multiply two `SNum`s. -/
protected def mul (a : SNum) : SNum → SNum 
goal: SNum → SNum

full_name: SNum.instMul
code: instance : Mul SNum 
goal: Mul SNum