File: Mathlib/Data/Nat/Bits.lean

full_name: _aux_Mathlib_Data_Nat_Bits___unexpand_xor_1
code: /-- `bxor` denotes the `xor` function i.e. the exclusive-or function on type `Bool`. -/
local notation "bxor" => _root_.xor
goal: Lean.PrettyPrinter.Unexpander

full_name: _aux_Mathlib_Data_Nat_Bits___macroRules_termBxor_1
code: /-- `bxor` denotes the `xor` function i.e. the exclusive-or function on type `Bool`. -/
local notation "bxor" => _root_.xor
goal: Lean.Macro

full_name: Nat.boddDiv2
code: /-- `boddDiv2 n` returns a 2-tuple of type `(Bool, Nat)` where the `Bool` value indicates whether
`n` is odd or not and the `Nat` value returns `⌊n/2⌋` -/
def boddDiv2 : ℕ → Bool × ℕ
  
goal: ℕ → Bool × ℕ

full_name: Nat.div2
code: /-- `div2 n = ⌊n/2⌋` the greatest integer smaller than `n/2`-/
def div2 (n : ℕ) : ℕ 
goal: ℕ

full_name: Nat.bodd
code: /-- `bodd n` returns `true` if `n` is odd-/
def bodd (n : ℕ) : Bool 
goal: Bool

full_name: Nat.bodd_zero
code: @[simp] lemma bodd_zero : bodd 0 = false 
goal: Nat.bodd 0 = false

full_name: Nat.bodd_one
code: lemma bodd_one : bodd 1 = true 
goal: Nat.bodd 1 = true

full_name: Nat.bodd_two
code: lemma bodd_two : bodd 2 = false 
goal: Nat.bodd 2 = false

full_name: Nat.bodd_succ
code: @[simp]
lemma bodd_succ (n : ℕ) : bodd (succ n) = not (bodd n) 
goal: n.succ.bodd = !n.bodd

full_name: Nat.bodd_add
code: @[simp]
lemma bodd_add (m n : ℕ) : bodd (m + n) = bxor (bodd m) (bodd n) 
goal: (m + n).bodd = bxor m.bodd n.bodd

full_name: Nat.bodd_mul
code: @[simp]
lemma bodd_mul (m n : ℕ) : bodd (m * n) = (bodd m && bodd n) 
goal: (m * n).bodd = (m.bodd && n.bodd)

full_name: Nat.mod_two_of_bodd
code: lemma mod_two_of_bodd (n : ℕ) : n % 2 = cond (bodd n) 1 0 
goal: n % 2 = bif n.bodd then 1 else 0

full_name: Nat.div2_zero
code: @[simp] lemma div2_zero : div2 0 = 0 
goal: Nat.div2 0 = 0

full_name: Nat.div2_one
code: lemma div2_one : div2 1 = 0 
goal: Nat.div2 1 = 0

full_name: Nat.div2_two
code: lemma div2_two : div2 2 = 1 
goal: Nat.div2 2 = 1

full_name: Nat.div2_succ
code: @[simp]
lemma div2_succ (n : ℕ) : div2 (succ n) = cond (bodd n) (succ (div2 n)) (div2 n) 
goal: n.succ.div2 = bif n.bodd then n.div2.succ else n.div2

full_name: Nat.bodd_add_div2
code: lemma bodd_add_div2 : ∀ n, cond (bodd n) 1 0 + 2 * div2 n = n
  
goal: (bif n.bodd then 1 else 0) + 2 * n.div2 = n

full_name: Nat.div2_val
code: lemma div2_val (n) : div2 n = n / 2 
goal: n.div2 = n / 2

full_name: Nat.bit
code: /-- `bit b` appends the digit `b` to the binary representation of its natural number input. -/
def bit (b : Bool) : ℕ → ℕ 
goal: ℕ → ℕ

full_name: Nat.bit_val
code: lemma bit_val (b n) : bit b n = 2 * n + cond b 1 0 
goal: Nat.bit b n = 2 * n + bif b then 1 else 0

full_name: Nat.bit_decomp
code: lemma bit_decomp (n : Nat) : bit (bodd n) (div2 n) = n 
goal: Nat.bit n.bodd n.div2 = n

full_name: Nat.bitCasesOn
code: /-- For a predicate `C : Nat → Sort*`, if instances can be
  constructed for natural numbers of the form `bit b n`,
  they can be constructed for any given natural number. -/
def bitCasesOn {C : Nat → Sort u} (n) (h : ∀ b n, C (bit b n)) : C n 
goal: C n

full_name: Nat.bit_zero
code: lemma bit_zero : bit false 0 = 0 
goal: Nat.bit false 0 = 0

full_name: Nat.shiftLeft'
code: /-- `shiftLeft' b m n` performs a left shift of `m` `n` times
 and adds the bit `b` as the least significant bit each time.
 Returns the corresponding natural number-/
def shiftLeft' (b : Bool) (m : ℕ) : ℕ → ℕ
  
goal: ℕ → ℕ

full_name: Nat.shiftLeft'_false
code: @[simp]
lemma shiftLeft'_false : ∀ n, shiftLeft' false m n = m <<< n
  
goal: Nat.shiftLeft' false m n = m <<< n

full_name: Nat.shiftLeft_eq'
code: /-- Lean takes the unprimed name for `Nat.shiftLeft_eq m n : m <<< n = m * 2 ^ n`. -/
@[simp] lemma shiftLeft_eq' (m n : Nat) : shiftLeft m n = m <<< n 
goal: m.shiftLeft n = m <<< n

full_name: Nat.shiftRight_eq
code: @[simp] lemma shiftRight_eq (m n : Nat) : shiftRight m n = m >>> n 
goal: m.shiftRight n = m >>> n

full_name: Nat.binaryRec_decreasing
code: lemma binaryRec_decreasing (h : n ≠ 0) : div2 n < n 
goal: n.div2 < n

full_name: Nat.binaryRec
code: /-- A recursion principle for `bit` representations of natural numbers.
  For a predicate `C : Nat → Sort*`, if instances can be
  constructed for natural numbers of the form `bit b n`,
  they can be constructed for all natural numbers. -/
def binaryRec {C : Nat → Sort u} (z : C 0) (f : ∀ b n, C n → C (bit b n)) : ∀ n, C n 
goal: C n

full_name: Nat.size
code: /-- `size n` : Returns the size of a natural number in
bits i.e. the length of its binary representation -/
def size : ℕ → ℕ 
goal: ℕ → ℕ

full_name: Nat.bits
code: /-- `bits n` returns a list of Bools which correspond to the binary representation of n, where
    the head of the list represents the least significant bit -/
def bits : ℕ → List Bool 
goal: ℕ → List Bool

full_name: Nat.ldiff
code: /-- `ldiff a b` performs bitwise set difference. For each corresponding
  pair of bits taken as booleans, say `aᵢ` and `bᵢ`, it applies the
  boolean operation `aᵢ ∧ ¬bᵢ` to obtain the `iᵗʰ` bit of the result. -/
def ldiff : ℕ → ℕ → ℕ 
goal: ℕ → ℕ → ℕ

full_name: Nat.binaryRec_zero
code: @[simp]
lemma binaryRec_zero {C : Nat → Sort u} (z : C 0) (f : ∀ b n, C n → C (bit b n)) :
    binaryRec z f 0 = z 
goal: Nat.binaryRec z f 0 = z

full_name: Nat.bodd_bit
code: lemma bodd_bit (b n) : bodd (bit b n) = b 
goal: (Nat.bit b n).bodd = b

full_name: Nat.div2_bit
code: lemma div2_bit (b n) : div2 (bit b n) = n 
goal: (Nat.bit b n).div2 = n

full_name: Nat.shiftLeft'_add
code: lemma shiftLeft'_add (b m n) : ∀ k, shiftLeft' b m (n + k) = shiftLeft' b (shiftLeft' b m n) k
  
goal: Nat.shiftLeft' b m (n + k) = Nat.shiftLeft' b (Nat.shiftLeft' b m n) k

full_name: Nat.shiftLeft'_sub
code: lemma shiftLeft'_sub (b m) : ∀ {n k}, k ≤ n → shiftLeft' b m (n - k) = (shiftLeft' b m n) >>> k
  
goal: k ≤ n → Nat.shiftLeft' b m (n - k) = Nat.shiftLeft' b m n >>> k

full_name: Nat.shiftLeft_sub
code: lemma shiftLeft_sub : ∀ (m : Nat) {n k}, k ≤ n → m <<< (n - k) = (m <<< n) >>> k 
goal: k ≤ n → m <<< (n - k) = m <<< n >>> k

full_name: Nat.testBit_bit_zero
code: lemma testBit_bit_zero (b n) : testBit (bit b n) 0 = b 
goal: (Nat.bit b n).testBit 0 = b

full_name: Nat.bodd_eq_one_and_ne_zero
code: lemma bodd_eq_one_and_ne_zero : ∀ n, bodd n = (1 &&& n != 0)
  
goal: n.bodd = (1 &&& n != 0)

full_name: Nat.testBit_bit_succ
code: lemma testBit_bit_succ (m b n) : testBit (bit b n) (succ m) = testBit n m 
goal: (Nat.bit b n).testBit m.succ = n.testBit m

full_name: Nat.binaryRec_eq
code: lemma binaryRec_eq {C : Nat → Sort u} {z : C 0} {f : ∀ b n, C n → C (bit b n)}
    (h : f false 0 z = z) (b n) : binaryRec z f (bit b n) = f b n (binaryRec z f n) 
goal: Nat.binaryRec z f (Nat.bit b n) = f b n (Nat.binaryRec z f n)

full_name: Nat.boddDiv2_eq
code: @[simp]
theorem boddDiv2_eq (n : ℕ) : boddDiv2 n = (bodd n, div2 n) 
goal: n.boddDiv2 = (n.bodd, n.div2)

full_name: Nat.div2_bit0
code: @[simp]
theorem div2_bit0 (n) : div2 (2 * n) = n 
goal: (2 * n).div2 = n

full_name: Nat.div2_bit1
code: theorem div2_bit1 (n) : div2 (2 * n + 1) = n 
goal: (2 * n + 1).div2 = n

full_name: Nat.bit_add
code: theorem bit_add : ∀ (b : Bool) (n m : ℕ), bit b (n + m) = bit false n + bit b m
  
goal: Nat.bit b (n + m) = Nat.bit false n + Nat.bit b m

full_name: Nat.bit_add'
code: theorem bit_add' : ∀ (b : Bool) (n m : ℕ), bit b (n + m) = bit b n + bit false m
  
goal: Nat.bit b (n + m) = Nat.bit b n + Nat.bit false m

full_name: Nat.bit_ne_zero
code: theorem bit_ne_zero (b) {n} (h : n ≠ 0) : bit b n ≠ 0 
goal: Nat.bit b n ≠ 0

full_name: Nat.bitCasesOn_bit
code: @[simp]
theorem bitCasesOn_bit {C : ℕ → Sort u} (H : ∀ b n, C (bit b n)) (b : Bool) (n : ℕ) :
    bitCasesOn (bit b n) H = H b n 
goal: (Nat.bit b n).bitCasesOn H = H b n

full_name: Nat.bitCasesOn_bit0
code: @[simp]
theorem bitCasesOn_bit0 {C : ℕ → Sort u} (H : ∀ b n, C (bit b n)) (n : ℕ) :
    bitCasesOn (2 * n) H = H false n 
goal: (2 * n).bitCasesOn H = H false n

full_name: Nat.bitCasesOn_bit1
code: @[simp]
theorem bitCasesOn_bit1 {C : ℕ → Sort u} (H : ∀ b n, C (bit b n)) (n : ℕ) :
    bitCasesOn (2 * n + 1) H = H true n 
goal: (2 * n + 1).bitCasesOn H = H true n

full_name: Nat.bit_cases_on_injective
code: theorem bit_cases_on_injective {C : ℕ → Sort u} :
    Function.Injective fun H : ∀ b n, C (bit b n) => fun n => bitCasesOn n H 
goal: Function.Injective fun H n => n.bitCasesOn H

full_name: Nat.bit_cases_on_inj
code: @[simp]
theorem bit_cases_on_inj {C : ℕ → Sort u} (H₁ H₂ : ∀ b n, C (bit b n)) :
    ((fun n => bitCasesOn n H₁) = fun n => bitCasesOn n H₂) ↔ H₁ = H₂ 
goal: ((fun n => n.bitCasesOn H₁) = fun n => n.bitCasesOn H₂) ↔ H₁ = H₂

full_name: Nat.bit_eq_zero_iff
code: theorem bit_eq_zero_iff {n : ℕ} {b : Bool} : bit b n = 0 ↔ n = 0 ∧ b = false 
goal: Nat.bit b n = 0 ↔ n = 0 ∧ b = false

full_name: Nat.bit_le
code: lemma bit_le : ∀ (b : Bool) {m n : ℕ}, m ≤ n → bit b m ≤ bit b n
  
goal: m ≤ n → Nat.bit b m ≤ Nat.bit b n

full_name: Nat.bit_lt_bit
code: lemma bit_lt_bit (a b) (h : m < n) : bit a m < bit b n 
goal: Nat.bit a m < Nat.bit b n

full_name: Nat.binaryRec_eq'
code: /--
The same as `binaryRec_eq`,
but that one unfortunately requires `f` to be the identity when appending `false` to `0`.
Here, we allow you to explicitly say that that case is not happening,
i.e. supplying `n = 0 → b = true`. -/
theorem binaryRec_eq' {C : ℕ → Sort*} {z : C 0} {f : ∀ b n, C n → C (bit b n)} (b n)
    (h : f false 0 z = z ∨ (n = 0 → b = true)) :
    binaryRec z f (bit b n) = f b n (binaryRec z f n) 
goal: Nat.binaryRec z f (Nat.bit b n) = f b n (Nat.binaryRec z f n)

full_name: Nat.binaryRec'
code: /-- The same as `binaryRec`, but the induction step can assume that if `n=0`,
  the bit being appended is `true`-/
@[elab_as_elim]
def binaryRec' {C : ℕ → Sort*} (z : C 0) (f : ∀ b n, (n = 0 → b = true) → C n → C (bit b n)) :
    ∀ n, C n 
goal: C n

full_name: Nat.binaryRecFromOne
code: /-- The same as `binaryRec`, but special casing both 0 and 1 as base cases -/
@[elab_as_elim]
def binaryRecFromOne {C : ℕ → Sort*} (z₀ : C 0) (z₁ : C 1) (f : ∀ b n, n ≠ 0 → C n → C (bit b n)) :
    ∀ n, C n 
goal: C n

full_name: Nat.zero_bits
code: @[simp]
theorem zero_bits : bits 0 = [] 
goal: Nat.bits 0 = []

full_name: Nat.bits_append_bit
code: @[simp]
theorem bits_append_bit (n : ℕ) (b : Bool) (hn : n = 0 → b = true) :
    (bit b n).bits = b :: n.bits 
goal: (Nat.bit b n).bits = b :: n.bits

full_name: Nat.bit0_bits
code: @[simp]
theorem bit0_bits (n : ℕ) (hn : n ≠ 0) : (2 * n).bits = false :: n.bits 
goal: (2 * n).bits = false :: n.bits

full_name: Nat.bit1_bits
code: @[simp]
theorem bit1_bits (n : ℕ) : (2 * n + 1).bits = true :: n.bits 
goal: (2 * n + 1).bits = true :: n.bits

full_name: Nat.one_bits
code: @[simp]
theorem one_bits : Nat.bits 1 = [true] 
goal: Nat.bits 1 = [true]

full_name: Nat.bodd_eq_bits_head
code: theorem bodd_eq_bits_head (n : ℕ) : n.bodd = n.bits.headI 
goal: n.bodd = n.bits.headI

full_name: Nat.div2_bits_eq_tail
code: theorem div2_bits_eq_tail (n : ℕ) : n.div2.bits = n.bits.tail 
goal: n.div2.bits = n.bits.tail