Theorem: Nat.bitwise_eq_binaryRec
File: Mathlib/Data/Nat/Bitwise.lean

tactic: funext x y
state_before: f : Bool → Bool → Bool
⊢ bitwise f =
    binaryRec (fun n => bif f false true then n else 0) fun a m Ia =>
      binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)
state_after: case h.h
f : Bool → Bool → Bool
x y : ℕ
⊢ bitwise f x y =
    binaryRec (fun n => bif f false true then n else 0)
      (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x y

tactic: induction x using binaryRec' generalizing y with
| z => simp only [bitwise_zero_left, binaryRec_zero, Bool.cond_eq_ite]
| f xb x hxb ih =>
  rw [← bit_ne_zero_iff] at hxb
  simp_rw [binaryRec_of_ne_zero _ _ hxb, bodd_bit, div2_bit, eq_rec_constant]
  induction y using binaryRec' with
  | z => simp only [bitwise_zero_right, binaryRec_zero, Bool.cond_eq_ite]
  | f yb y hyb =>
    rw [← bit_ne_zero_iff] at hyb
    simp_rw [binaryRec_of_ne_zero _ _ hyb, bitwise_of_ne_zero hxb hyb, bodd_bit, ← div2_val,
      div2_bit, eq_rec_constant, ih]
state_before: case h.h
f : Bool → Bool → Bool
x y : ℕ
⊢ bitwise f x y =
    binaryRec (fun n => bif f false true then n else 0)
      (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x y
state_after: no goals

tactic: simp only [bitwise_zero_left, binaryRec_zero, Bool.cond_eq_ite]
state_before: case h.h.z
f : Bool → Bool → Bool
y : ℕ
⊢ bitwise f 0 y =
    binaryRec (fun n => bif f false true then n else 0)
      (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) 0 y
state_after: no goals

tactic: rw [← bit_ne_zero_iff] at hxb
state_before: case h.h.f
f : Bool → Bool → Bool
xb : Bool
x : ℕ
hxb : x = 0 → xb = true
ih :
  ∀ (y : ℕ),
    bitwise f x y =
      binaryRec (fun n => bif f false true then n else 0)
        (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x y
y : ℕ
⊢ bitwise f (bit xb x) y =
    binaryRec (fun n => bif f false true then n else 0)
      (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) (bit xb x) y
state_after: case h.h.f
f : Bool → Bool → Bool
xb : Bool
x : ℕ
hxb : bit xb x ≠ 0
ih :
  ∀ (y : ℕ),
    bitwise f x y =
      binaryRec (fun n => bif f false true then n else 0)
        (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x y
y : ℕ
⊢ bitwise f (bit xb x) y =
    binaryRec (fun n => bif f false true then n else 0)
      (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) (bit xb x) y

tactic: simp_rw [binaryRec_of_ne_zero _ _ hxb, bodd_bit, div2_bit, eq_rec_constant]
state_before: case h.h.f
f : Bool → Bool → Bool
xb : Bool
x : ℕ
hxb : bit xb x ≠ 0
ih :
  ∀ (y : ℕ),
    bitwise f x y =
      binaryRec (fun n => bif f false true then n else 0)
        (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x y
y : ℕ
⊢ bitwise f (bit xb x) y =
    binaryRec (fun n => bif f false true then n else 0)
      (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) (bit xb x) y
state_after: case h.h.f
f : Bool → Bool → Bool
xb : Bool
x : ℕ
hxb : bit xb x ≠ 0
ih :
  ∀ (y : ℕ),
    bitwise f x y =
      binaryRec (fun n => bif f false true then n else 0)
        (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x y
y : ℕ
⊢ bitwise f (bit xb x) y =
    binaryRec (bif f true false then bit xb x else 0)
      (fun b n x_1 =>
        bit (f xb b)
          (binaryRec (fun n => bif f false true then n else 0)
            (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x n))
      y

tactic: induction y using binaryRec' with
| z => simp only [bitwise_zero_right, binaryRec_zero, Bool.cond_eq_ite]
| f yb y hyb =>
  rw [← bit_ne_zero_iff] at hyb
  simp_rw [binaryRec_of_ne_zero _ _ hyb, bitwise_of_ne_zero hxb hyb, bodd_bit, ← div2_val,
    div2_bit, eq_rec_constant, ih]
state_before: case h.h.f
f : Bool → Bool → Bool
xb : Bool
x : ℕ
hxb : bit xb x ≠ 0
ih :
  ∀ (y : ℕ),
    bitwise f x y =
      binaryRec (fun n => bif f false true then n else 0)
        (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x y
y : ℕ
⊢ bitwise f (bit xb x) y =
    binaryRec (bif f true false then bit xb x else 0)
      (fun b n x_1 =>
        bit (f xb b)
          (binaryRec (fun n => bif f false true then n else 0)
            (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x n))
      y
state_after: no goals

tactic: simp only [bitwise_zero_right, binaryRec_zero, Bool.cond_eq_ite]
state_before: case h.h.f.z
f : Bool → Bool → Bool
xb : Bool
x : ℕ
hxb : bit xb x ≠ 0
ih :
  ∀ (y : ℕ),
    bitwise f x y =
      binaryRec (fun n => bif f false true then n else 0)
        (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x y
⊢ bitwise f (bit xb x) 0 =
    binaryRec (bif f true false then bit xb x else 0)
      (fun b n x_1 =>
        bit (f xb b)
          (binaryRec (fun n => bif f false true then n else 0)
            (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x n))
      0
state_after: no goals

tactic: rw [← bit_ne_zero_iff] at hyb
state_before: case h.h.f.f
f : Bool → Bool → Bool
xb : Bool
x : ℕ
hxb : bit xb x ≠ 0
ih :
  ∀ (y : ℕ),
    bitwise f x y =
      binaryRec (fun n => bif f false true then n else 0)
        (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x y
yb : Bool
y : ℕ
hyb : y = 0 → yb = true
a✝ :
  bitwise f (bit xb x) y =
    binaryRec (bif f true false then bit xb x else 0)
      (fun b n x_1 =>
        bit (f xb b)
          (binaryRec (fun n => bif f false true then n else 0)
            (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x n))
      y
⊢ bitwise f (bit xb x) (bit yb y) =
    binaryRec (bif f true false then bit xb x else 0)
      (fun b n x_1 =>
        bit (f xb b)
          (binaryRec (fun n => bif f false true then n else 0)
            (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x n))
      (bit yb y)
state_after: case h.h.f.f
f : Bool → Bool → Bool
xb : Bool
x : ℕ
hxb : bit xb x ≠ 0
ih :
  ∀ (y : ℕ),
    bitwise f x y =
      binaryRec (fun n => bif f false true then n else 0)
        (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x y
yb : Bool
y : ℕ
hyb : bit yb y ≠ 0
a✝ :
  bitwise f (bit xb x) y =
    binaryRec (bif f true false then bit xb x else 0)
      (fun b n x_1 =>
        bit (f xb b)
          (binaryRec (fun n => bif f false true then n else 0)
            (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x n))
      y
⊢ bitwise f (bit xb x) (bit yb y) =
    binaryRec (bif f true false then bit xb x else 0)
      (fun b n x_1 =>
        bit (f xb b)
          (binaryRec (fun n => bif f false true then n else 0)
            (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x n))
      (bit yb y)

tactic: simp_rw [binaryRec_of_ne_zero _ _ hyb, bitwise_of_ne_zero hxb hyb, bodd_bit, ← div2_val,
  div2_bit, eq_rec_constant, ih]
state_before: case h.h.f.f
f : Bool → Bool → Bool
xb : Bool
x : ℕ
hxb : bit xb x ≠ 0
ih :
  ∀ (y : ℕ),
    bitwise f x y =
      binaryRec (fun n => bif f false true then n else 0)
        (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x y
yb : Bool
y : ℕ
hyb : bit yb y ≠ 0
a✝ :
  bitwise f (bit xb x) y =
    binaryRec (bif f true false then bit xb x else 0)
      (fun b n x_1 =>
        bit (f xb b)
          (binaryRec (fun n => bif f false true then n else 0)
            (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x n))
      y
⊢ bitwise f (bit xb x) (bit yb y) =
    binaryRec (bif f true false then bit xb x else 0)
      (fun b n x_1 =>
        bit (f xb b)
          (binaryRec (fun n => bif f false true then n else 0)
            (fun a m Ia => binaryRec (bif f true false then bit a m else 0) fun b n x => bit (f a b) (Ia n)) x n))
      (bit yb y)
state_after: no goals