File: Mathlib/Data/Int/Bitwise.lean

full_name: Int.div2
code: /-- `div2 n = n/2`-/
def div2 : ℤ → ℤ
  
goal: ℤ → ℤ

full_name: Int.bodd
code: /-- `bodd n` returns `true` if `n` is odd-/
def bodd : ℤ → Bool
  
goal: ℤ → Bool

full_name: Int.bit
code: /-- `bit b` appends the digit `b` to the binary representation of
  its integer input. -/
def bit (b : Bool) : ℤ → ℤ 
goal: ℤ → ℤ

full_name: Int.testBit
code: /-- `testBit m n` returns whether the `(n+1)ˢᵗ` least significant bit is `1` or `0`-/
def testBit : ℤ → ℕ → Bool
  
goal: ℤ → ℕ → Bool

full_name: Int.natBitwise
code: /-- `Int.natBitwise` is an auxiliary definition for `Int.bitwise`. -/
def natBitwise (f : Bool → Bool → Bool) (m n : ℕ) : ℤ 
goal: ℤ

full_name: Int.bitwise
code: /-- `Int.bitwise` applies the function `f` to pairs of bits in the same position in
  the binary representations of its inputs. -/
def bitwise (f : Bool → Bool → Bool) : ℤ → ℤ → ℤ
  
goal: ℤ → ℤ → ℤ

full_name: Int.lnot
code: /-- `lnot` flips all the bits in the binary representation of its input -/
def lnot : ℤ → ℤ
  
goal: ℤ → ℤ

full_name: Int.lor
code: /-- `lor` takes two integers and returns their bitwise `or`-/
def lor : ℤ → ℤ → ℤ
  
goal: ℤ → ℤ → ℤ

full_name: Int.land
code: /-- `land` takes two integers and returns their bitwise `and`-/
def land : ℤ → ℤ → ℤ
  
goal: ℤ → ℤ → ℤ

full_name: Int.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: Int.xor
code: /-- `xor` computes the bitwise `xor` of two natural numbers-/
protected def xor : ℤ → ℤ → ℤ
  
goal: ℤ → ℤ → ℤ

full_name: Int.instShiftLeft_mathlib
code: /-- `m <<< n` produces an integer whose binary representation
  is obtained by left-shifting the binary representation of `m` by `n` places -/
instance : ShiftLeft ℤ 
goal: ShiftLeft ℤ

full_name: Int.instShiftRight_mathlib
code: /-- `m >>> n` produces an integer whose binary representation
  is obtained by right-shifting the binary representation of `m` by `n` places -/
instance : ShiftRight ℤ 
goal: ShiftRight ℤ

full_name: Int.bodd_zero
code: @[simp]
theorem bodd_zero : bodd 0 = false 
goal: Int.bodd 0 = false

full_name: Int.bodd_one
code: @[simp]
theorem bodd_one : bodd 1 = true 
goal: Int.bodd 1 = true

full_name: Int.bodd_two
code: theorem bodd_two : bodd 2 = false 
goal: Int.bodd 2 = false

full_name: Int.bodd_coe
code: @[simp, norm_cast]
theorem bodd_coe (n : ℕ) : Int.bodd n = Nat.bodd n 
goal: (↑n).bodd = n.bodd

full_name: Int.bodd_subNatNat
code: @[simp]
theorem bodd_subNatNat (m n : ℕ) : bodd (subNatNat m n) = xor m.bodd n.bodd 
goal: (Int.subNatNat m n).bodd = xor m.bodd n.bodd

full_name: Int.bodd_negOfNat
code: @[simp]
theorem bodd_negOfNat (n : ℕ) : bodd (negOfNat n) = n.bodd 
goal: (Int.negOfNat n).bodd = n.bodd

full_name: Int.bodd_neg
code: @[simp]
theorem bodd_neg (n : ℤ) : bodd (-n) = bodd n 
goal: (-n).bodd = n.bodd

full_name: Int.bodd_add
code: @[simp]
theorem bodd_add (m n : ℤ) : bodd (m + n) = xor (bodd m) (bodd n) 
goal: (m + n).bodd = xor m.bodd n.bodd

full_name: Int.bodd_mul
code: @[simp]
theorem bodd_mul (m n : ℤ) : bodd (m * n) = (bodd m && bodd n) 
goal: (m * n).bodd = (m.bodd && n.bodd)

full_name: Int.bodd_add_div2
code: theorem 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: Int.div2_val
code: theorem div2_val : ∀ n, div2 n = n / 2
  
goal: n.div2 = n / 2

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

full_name: Int.bit_decomp
code: theorem bit_decomp (n : ℤ) : bit (bodd n) (div2 n) = n 
goal: Int.bit n.bodd n.div2 = n

full_name: Int.bitCasesOn
code: /-- Defines a function from `ℤ` conditionally, if it is defined for odd and even integers separately
  using `bit`. -/
def bitCasesOn.{u} {C : ℤ → Sort u} (n) (h : ∀ b n, C (bit b n)) : C n 
goal: C n

full_name: Int.bit_zero
code: @[simp]
theorem bit_zero : bit false 0 = 0 
goal: Int.bit false 0 = 0

full_name: Int.bit_coe_nat
code: @[simp]
theorem bit_coe_nat (b) (n : ℕ) : bit b n = Nat.bit b n 
goal: Int.bit b ↑n = ↑(Nat.bit b n)

full_name: Int.bit_negSucc
code: @[simp]
theorem bit_negSucc (b) (n : ℕ) : bit b -[n+1] = -[Nat.bit (not b) n+1] 
goal: Int.bit b (Int.negSucc n) = Int.negSucc (Nat.bit (!b) n)

full_name: Int.bodd_bit
code: @[simp]
theorem bodd_bit (b n) : bodd (bit b n) = b 
goal: (Int.bit b n).bodd = b

full_name: Int.testBit_bit_zero
code: @[simp]
theorem testBit_bit_zero (b) : ∀ n, testBit (bit b n) 0 = b
  
goal: (Int.bit b n).testBit 0 = b

full_name: Int.testBit_bit_succ
code: @[simp]
theorem testBit_bit_succ (m b) : ∀ n, testBit (bit b n) (Nat.succ m) = testBit n m
  
goal: (Int.bit b n).testBit m.succ = n.testBit m

full_name: Int.bitwise_or
code: theorem bitwise_or : bitwise or = lor 
goal: Int.bitwise or = Int.lor

full_name: Int.bitwise_and
code: theorem bitwise_and : bitwise and = land 
goal: Int.bitwise and = Int.land

full_name: Int.bitwise_diff
code: theorem bitwise_diff : (bitwise fun a b => a && not b) = ldiff 
goal: (Int.bitwise fun a b => a && !b) = Int.ldiff

full_name: Int.bitwise_xor
code: theorem bitwise_xor : bitwise xor = Int.xor 
goal: Int.bitwise xor = Int.xor

full_name: Int.bitwise_bit
code: @[simp]
theorem bitwise_bit (f : Bool → Bool → Bool) (a m b n) :
    bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) 
goal: Int.bitwise f (Int.bit a m) (Int.bit b n) = Int.bit (f a b) (Int.bitwise f m n)

full_name: Int.lor_bit
code: @[simp]
theorem lor_bit (a m b n) : lor (bit a m) (bit b n) = bit (a || b) (lor m n) 
goal: (Int.bit a m).lor (Int.bit b n) = Int.bit (a || b) (m.lor n)

full_name: Int.land_bit
code: @[simp]
theorem land_bit (a m b n) : land (bit a m) (bit b n) = bit (a && b) (land m n) 
goal: (Int.bit a m).land (Int.bit b n) = Int.bit (a && b) (m.land n)

full_name: Int.ldiff_bit
code: @[simp]
theorem ldiff_bit (a m b n) : ldiff (bit a m) (bit b n) = bit (a && not b) (ldiff m n) 
goal: (Int.bit a m).ldiff (Int.bit b n) = Int.bit (a && !b) (m.ldiff n)

full_name: Int.lxor_bit
code: @[simp]
theorem lxor_bit (a m b n) : Int.xor (bit a m) (bit b n) = bit (xor a b) (Int.xor m n) 
goal: (Int.bit a m).xor (Int.bit b n) = Int.bit (xor a b) (m.xor n)

full_name: Int.lnot_bit
code: @[simp]
theorem lnot_bit (b) : ∀ n, lnot (bit b n) = bit (not b) (lnot n)
  
goal: (Int.bit b n).lnot = Int.bit (!b) n.lnot

full_name: Int.testBit_bitwise
code: @[simp]
theorem testBit_bitwise (f : Bool → Bool → Bool) (m n k) :
    testBit (bitwise f m n) k = f (testBit m k) (testBit n k) 
goal: (Int.bitwise f m n).testBit k = f (m.testBit k) (n.testBit k)

full_name: Int.testBit_lor
code: @[simp]
theorem testBit_lor (m n k) : testBit (lor m n) k = (testBit m k || testBit n k) 
goal: (m.lor n).testBit k = (m.testBit k || n.testBit k)

full_name: Int.testBit_land
code: @[simp]
theorem testBit_land (m n k) : testBit (land m n) k = (testBit m k && testBit n k) 
goal: (m.land n).testBit k = (m.testBit k && n.testBit k)

full_name: Int.testBit_ldiff
code: @[simp]
theorem testBit_ldiff (m n k) : testBit (ldiff m n) k = (testBit m k && not (testBit n k)) 
goal: (m.ldiff n).testBit k = (m.testBit k && !n.testBit k)

full_name: Int.testBit_lxor
code: @[simp]
theorem testBit_lxor (m n k) : testBit (Int.xor m n) k = xor (testBit m k) (testBit n k) 
goal: (m.xor n).testBit k = xor (m.testBit k) (n.testBit k)

full_name: Int.testBit_lnot
code: @[simp]
theorem testBit_lnot : ∀ n k, testBit (lnot n) k = not (testBit n k)
  
goal: n.lnot.testBit k = !n.testBit k

full_name: Int.shiftLeft_neg
code: @[simp]
theorem shiftLeft_neg (m n : ℤ) : m <<< (-n) = m >>> n 
goal: m <<< (-n) = m >>> n

full_name: Int.shiftRight_neg
code: @[simp]
theorem shiftRight_neg (m n : ℤ) : m >>> (-n) = m <<< n 
goal: m >>> (-n) = m <<< n

full_name: Int.shiftLeft_coe_nat
code: @[simp]
theorem shiftLeft_coe_nat (m n : ℕ) : (m : ℤ) <<< (n : ℤ) = ↑(m <<< n) 
goal: ↑m <<< ↑n = ↑(m <<< n)

full_name: Int.shiftRight_coe_nat
code: @[simp]
theorem shiftRight_coe_nat (m n : ℕ) : (m : ℤ) >>> (n : ℤ) = m >>> n 
goal: ↑m >>> ↑n = ↑(m >>> n)

full_name: Int.shiftLeft_negSucc
code: @[simp]
theorem shiftLeft_negSucc (m n : ℕ) : -[m+1] <<< (n : ℤ) = -[Nat.shiftLeft' true m n+1] 
goal: Int.negSucc m <<< ↑n = Int.negSucc (Nat.shiftLeft' true m n)

full_name: Int.shiftRight_negSucc
code: @[simp]
theorem shiftRight_negSucc (m n : ℕ) : -[m+1] >>> (n : ℤ) = -[m >>> n+1] 
goal: Int.negSucc m >>> ↑n = Int.negSucc (m >>> n)

full_name: Int.shiftRight_add'
code: /-- Compare with `Int.shiftRight_add`, which doesn't have the coercions `ℕ → ℤ`. -/
theorem shiftRight_add' : ∀ (m : ℤ) (n k : ℕ), m >>> (n + k : ℤ) = (m >>> (n : ℤ)) >>> (k : ℤ)
  
goal: m >>> (↑n + ↑k) = m >>> ↑n >>> ↑k

full_name: Int.shiftLeft_add
code: theorem shiftLeft_add : ∀ (m : ℤ) (n : ℕ) (k : ℤ), m <<< (n + k) = (m <<< (n : ℤ)) <<< k
  
goal: m <<< (↑n + k) = m <<< ↑n <<< k

full_name: Int.shiftLeft_sub
code: theorem shiftLeft_sub (m : ℤ) (n : ℕ) (k : ℤ) : m <<< (n - k) = (m <<< (n : ℤ)) >>> k 
goal: m <<< (↑n - k) = m <<< ↑n >>> k

full_name: Int.shiftLeft_eq_mul_pow
code: theorem shiftLeft_eq_mul_pow : ∀ (m : ℤ) (n : ℕ), m <<< (n : ℤ) = m * (2 ^ n : ℕ)
  
goal: m <<< ↑n = m * ↑(2 ^ n)

full_name: Int.one_shiftLeft
code: theorem one_shiftLeft (n : ℕ) : 1 <<< (n : ℤ) = (2 ^ n : ℕ) 
goal: 1 <<< ↑n = ↑(2 ^ n)

full_name: Int.zero_shiftLeft
code: @[simp]
theorem zero_shiftLeft : ∀ n : ℤ, 0 <<< n = 0
  
goal: 0 <<< n = 0

full_name: Int.zero_shiftRight'
code: /-- Compare with `Int.zero_shiftRight`, which has `n : ℕ`. -/
@[simp]
theorem zero_shiftRight' (n : ℤ) : 0 >>> n = 0 
goal: 0 >>> n = 0