l3lab/ntp-mathlib huggingface dataset:
lemma binaryRec_decreasing (h : n ≠ 0) : div2 n < n := by
  rw [div2_val]
  apply (div_lt_iff_lt_mul <| succ_pos 1).2
  

Proof state:
n : ℕ
h : n ≠ 0
⊢ n < n * succ 1

Next tactic:
have := Nat.mul_lt_mul_of_pos_left (lt_succ_self 1)
    (lt_of_le_of_ne n.zero_le h.symm)
lemma binaryRec_decreasing (h : n ≠ 0) : div2 n < n := by
  rw [div2_val]
  apply (div_lt_iff_lt_mul <| succ_pos 1).2
  have := Nat.mul_lt_mul_of_pos_left (lt_succ_self 1)
    (lt_of_le_of_ne n.zero_le h.symm)
  

Proof state:
n : ℕ
h : n ≠ 0
this : n * 1 < n * succ 1
⊢ n < n * succ 1

Next tactic:
rwa [Nat.mul_one] at this
/-- 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 :=
  fun n =>
    if n0 : n = 0 then by
      

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
n : ℕ
n0 : n = 0
⊢ C n

Next tactic:
simp only [n0]
/-- 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 :=
  fun n =>
    if n0 : n = 0 then by
      simp only [n0]
      

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
n : ℕ
n0 : n = 0
⊢ C 0

Next tactic:
exact z
/-- 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 :=
  fun n =>
    if n0 : n = 0 then by
      simp only [n0]
      exact z
    else by
      

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
n : ℕ
n0 : ¬n = 0
⊢ C n

Next tactic:
let n' := div2 n
/-- 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 :=
  fun n =>
    if n0 : n = 0 then by
      simp only [n0]
      exact z
    else by
      let n' := div2 n
      

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
n : ℕ
n0 : ¬n = 0
n' : ℕ := div2 n
⊢ C n

Next tactic:
have _x : bit (bodd n) n' = n := by
        apply bit_decomp n
/-- 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 :=
  fun n =>
    if n0 : n = 0 then by
      simp only [n0]
      exact z
    else by
      let n' := div2 n
      have _x : bit (bodd n) n' = n := by
        

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
n : ℕ
n0 : ¬n = 0
n' : ℕ := div2 n
⊢ bit (bodd n) n' = n

Next tactic:
apply bit_decomp n
/-- 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 :=
  fun n =>
    if n0 : n = 0 then by
      simp only [n0]
      exact z
    else by
      let n' := div2 n
      have _x : bit (bodd n) n' = n := by
        apply bit_decomp n
      

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
n : ℕ
n0 : ¬n = 0
n' : ℕ := div2 n
_x : bit (bodd n) n' = n
⊢ C n

Next tactic:
rw [← _x]
/-- 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 :=
  fun n =>
    if n0 : n = 0 then by
      simp only [n0]
      exact z
    else by
      let n' := div2 n
      have _x : bit (bodd n) n' = n := by
        apply bit_decomp n
      rw [← _x]
      

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
n : ℕ
n0 : ¬n = 0
n' : ℕ := div2 n
_x : bit (bodd n) n' = n
⊢ C (bit (bodd n) n')

Next tactic:
exact f (bodd n) n' (binaryRec z f n')
/-- 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 :=
  fun n =>
    if n0 : n = 0 then by
      simp only [n0]
      exact z
    else by
      let n' := div2 n
      have _x : bit (bodd n) n' = n := by
        apply bit_decomp n
      rw [← _x]
      exact f (bodd n) n' (binaryRec z f n')
  decreasing_by 

Proof state:
n : ℕ
n0 : ¬n = 0
n' : ℕ := div2 n
_x : bit (bodd n) n' = n
⊢ (invImage (fun a => sizeOf a) instWellFoundedRelation).1 n' n

Next tactic:
exact binaryRec_decreasing n0
@[simp]
theorem binaryRec_zero {C : Nat → Sort u} (z : C 0) (f : ∀ b n, C n → C (bit b n)) :
    binaryRec z f 0 = z := by
  

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
⊢ binaryRec z f 0 = z

Next tactic:
rw [binaryRec]
@[simp]
theorem binaryRec_zero {C : Nat → Sort u} (z : C 0) (f : ∀ b n, C n → C (bit b n)) :
    binaryRec z f 0 = z := by
  rw [binaryRec]
  

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
⊢ (if n0 : 0 = 0 then Eq.mpr (_ : C 0 = C 0) z
    else
      let n' := div2 0;
      let_fun _x := (_ : bit (bodd 0) (div2 0) = 0);
      Eq.mpr (_ : C 0 = C (bit (bodd 0) n')) (f (bodd 0) n' (binaryRec z f n'))) =
    z

Next tactic:
rfl
theorem bodd_bit (b n) : bodd (bit b n) = b := by
  

Proof state:
b : Bool
n : ℕ
⊢ bodd (bit b n) = b

Next tactic:
rw [bit_val]
theorem bodd_bit (b n) : bodd (bit b n) = b := by
  rw [bit_val]
  

Proof state:
b : Bool
n : ℕ
⊢ bodd (2 * n + bif b then 1 else 0) = b

Next tactic:
simp only [Nat.mul_comm, Nat.add_comm, bodd_add, bodd_mul, bodd_succ, bodd_zero, Bool.not_false,
    Bool.not_true, Bool.and_false, Bool.xor_false]
theorem bodd_bit (b n) : bodd (bit b n) = b := by
  rw [bit_val]
  simp only [Nat.mul_comm, Nat.add_comm, bodd_add, bodd_mul, bodd_succ, bodd_zero, Bool.not_false,
    Bool.not_true, Bool.and_false, Bool.xor_false]
  

Proof state:
b : Bool
n : ℕ
⊢ bodd (bif b then 1 else 0) = b

Next tactic:
cases b
theorem bodd_bit (b n) : bodd (bit b n) = b := by
  rw [bit_val]
  simp only [Nat.mul_comm, Nat.add_comm, bodd_add, bodd_mul, bodd_succ, bodd_zero, Bool.not_false,
    Bool.not_true, Bool.and_false, Bool.xor_false]
  cases b <;> 

Proof state:
case false
n : ℕ
⊢ bodd (bif false then 1 else 0) = false

Next tactic:
cases bodd n
theorem bodd_bit (b n) : bodd (bit b n) = b := by
  rw [bit_val]
  simp only [Nat.mul_comm, Nat.add_comm, bodd_add, bodd_mul, bodd_succ, bodd_zero, Bool.not_false,
    Bool.not_true, Bool.and_false, Bool.xor_false]
  cases b <;> 

Proof state:
case true
n : ℕ
⊢ bodd (bif true then 1 else 0) = true

Next tactic:
cases bodd n
theorem bodd_bit (b n) : bodd (bit b n) = b := by
  rw [bit_val]
  simp only [Nat.mul_comm, Nat.add_comm, bodd_add, bodd_mul, bodd_succ, bodd_zero, Bool.not_false,
    Bool.not_true, Bool.and_false, Bool.xor_false]
  cases b <;> cases bodd n <;> 

Proof state:
case false.false
n : ℕ
⊢ bodd (bif false then 1 else 0) = false

Next tactic:
rfl
theorem bodd_bit (b n) : bodd (bit b n) = b := by
  rw [bit_val]
  simp only [Nat.mul_comm, Nat.add_comm, bodd_add, bodd_mul, bodd_succ, bodd_zero, Bool.not_false,
    Bool.not_true, Bool.and_false, Bool.xor_false]
  cases b <;> cases bodd n <;> 

Proof state:
case false.true
n : ℕ
⊢ bodd (bif false then 1 else 0) = false

Next tactic:
rfl
theorem bodd_bit (b n) : bodd (bit b n) = b := by
  rw [bit_val]
  simp only [Nat.mul_comm, Nat.add_comm, bodd_add, bodd_mul, bodd_succ, bodd_zero, Bool.not_false,
    Bool.not_true, Bool.and_false, Bool.xor_false]
  cases b <;> cases bodd n <;> 

Proof state:
case true.false
n : ℕ
⊢ bodd (bif true then 1 else 0) = true

Next tactic:
rfl
theorem bodd_bit (b n) : bodd (bit b n) = b := by
  rw [bit_val]
  simp only [Nat.mul_comm, Nat.add_comm, bodd_add, bodd_mul, bodd_succ, bodd_zero, Bool.not_false,
    Bool.not_true, Bool.and_false, Bool.xor_false]
  cases b <;> cases bodd n <;> 

Proof state:
case true.true
n : ℕ
⊢ bodd (bif true then 1 else 0) = true

Next tactic:
rfl
theorem div2_bit (b n) : div2 (bit b n) = n := by
  

Proof state:
b : Bool
n : ℕ
⊢ div2 (bit b n) = n

Next tactic:
rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
theorem div2_bit (b n) : div2 (bit b n) = n := by
  rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
  <;> 

Proof state:
b : Bool
n : ℕ
⊢ (bif b then 1 else 0) < 2

Next tactic:
cases b
theorem div2_bit (b n) : div2 (bit b n) = n := by
  rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
  <;> 

Proof state:
case H
b : Bool
n : ℕ
⊢ 0 < 2

Next tactic:
cases b
theorem div2_bit (b n) : div2 (bit b n) = n := by
  rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
  <;> cases b
  <;> 

Proof state:
case false
n : ℕ
⊢ (bif false then 1 else 0) < 2

Next tactic:
exact by decide
theorem div2_bit (b n) : div2 (bit b n) = n := by
  rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
  <;> cases b
  <;> exact by 

Proof state:
n : ℕ
⊢ (bif false then 1 else 0) < 2

Next tactic:
decide
theorem div2_bit (b n) : div2 (bit b n) = n := by
  rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
  <;> cases b
  <;> 

Proof state:
case true
n : ℕ
⊢ (bif true then 1 else 0) < 2

Next tactic:
exact by decide
theorem div2_bit (b n) : div2 (bit b n) = n := by
  rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
  <;> cases b
  <;> exact by 

Proof state:
n : ℕ
⊢ (bif true then 1 else 0) < 2

Next tactic:
decide
theorem div2_bit (b n) : div2 (bit b n) = n := by
  rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
  <;> cases b
  <;> 

Proof state:
case H.false
n : ℕ
⊢ 0 < 2

Next tactic:
exact by decide
theorem div2_bit (b n) : div2 (bit b n) = n := by
  rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
  <;> cases b
  <;> exact by 

Proof state:
n : ℕ
⊢ 0 < 2

Next tactic:
decide
theorem div2_bit (b n) : div2 (bit b n) = n := by
  rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
  <;> cases b
  <;> 

Proof state:
case H.true
n : ℕ
⊢ 0 < 2

Next tactic:
exact by decide
theorem shiftLeft_add (m n : Nat) : ∀ k, m <<< (n + k) = (m <<< n) <<< k := by
  

Proof state:
m n : ℕ
⊢ ∀ (k : ℕ), m <<< (n + k) = m <<< n <<< k

Next tactic:
intro k
theorem shiftLeft_add (m n : Nat) : ∀ k, m <<< (n + k) = (m <<< n) <<< k := by
  intro k; 

Proof state:
m n k : ℕ
⊢ m <<< (n + k) = m <<< n <<< k

Next tactic:
simp only [← shiftLeft'_false, shiftLeft'_add]
theorem shiftLeft'_sub (b m) : ∀ {n k}, k ≤ n → shiftLeft' b m (n - k) = (shiftLeft' b m n) >>> k
  | n, 0, _ => rfl
  | n + 1, k + 1, h => by
    

Proof state:
b : Bool
m n k : ℕ
h : k + 1 ≤ n + 1
⊢ shiftLeft' b m (n + 1 - (k + 1)) = shiftLeft' b m (n + 1) >>> (k + 1)

Next tactic:
rw [succ_sub_succ_eq_sub, shiftLeft', Nat.add_comm, shiftRight_add]
theorem shiftLeft'_sub (b m) : ∀ {n k}, k ≤ n → shiftLeft' b m (n - k) = (shiftLeft' b m n) >>> k
  | n, 0, _ => rfl
  | n + 1, k + 1, h => by
    rw [succ_sub_succ_eq_sub, shiftLeft', Nat.add_comm, shiftRight_add]
    

Proof state:
b : Bool
m n k : ℕ
h : k + 1 ≤ n + 1
⊢ shiftLeft' b m (n - k) = bit b (shiftLeft' b m n) >>> 1 >>> k

Next tactic:
simp only [shiftLeft'_sub, Nat.le_of_succ_le_succ h, shiftRight_succ, shiftRight_zero]
theorem shiftLeft'_sub (b m) : ∀ {n k}, k ≤ n → shiftLeft' b m (n - k) = (shiftLeft' b m n) >>> k
  | n, 0, _ => rfl
  | n + 1, k + 1, h => by
    rw [succ_sub_succ_eq_sub, shiftLeft', Nat.add_comm, shiftRight_add]
    simp only [shiftLeft'_sub, Nat.le_of_succ_le_succ h, shiftRight_succ, shiftRight_zero]
    

Proof state:
b : Bool
m n k : ℕ
h : k + 1 ≤ n + 1
⊢ shiftLeft' b m n >>> k = (bit b (shiftLeft' b m n) / 2) >>> k

Next tactic:
simp [← div2_val, div2_bit]
theorem shiftLeft_sub : ∀ (m : Nat) {n k}, k ≤ n → m <<< (n - k) = (m <<< n) >>> k :=
  fun _ _ _ hk => by 

Proof state:
x✝² x✝¹ x✝ : ℕ
hk : x✝ ≤ x✝¹
⊢ x✝² <<< (x✝¹ - x✝) = x✝² <<< x✝¹ >>> x✝

Next tactic:
simp only [← shiftLeft'_false, shiftLeft'_sub false _ hk]
@[simp]
theorem testBit_zero (b n) : testBit (bit b n) 0 = b := by
  

Proof state:
b : Bool
n : ℕ
⊢ testBit (bit b n) 0 = b

Next tactic:
rw [testBit, bit]
@[simp]
theorem testBit_zero (b n) : testBit (bit b n) 0 = b := by
  rw [testBit, bit]
  

Proof state:
b : Bool
n : ℕ
⊢ (cond b bit1 bit0 n >>> 0 &&& 1 != 0) = b

Next tactic:
cases b
@[simp]
theorem testBit_zero (b n) : testBit (bit b n) 0 = b := by
  rw [testBit, bit]
  cases b
  · 

Proof state:
case false
n : ℕ
⊢ (cond false bit1 bit0 n >>> 0 &&& 1 != 0) = false

Next tactic:
simp [bit0, ← Nat.mul_two]
@[simp]
theorem testBit_zero (b n) : testBit (bit b n) 0 = b := by
  rw [testBit, bit]
  cases b
  · simp [bit0, ← Nat.mul_two]
  · 

Proof state:
case true
n : ℕ
⊢ (cond true bit1 bit0 n >>> 0 &&& 1 != 0) = true

Next tactic:
simp only [cond_true, bit1, bit0, shiftRight_zero, and_one_is_mod, bne_iff_ne]
@[simp]
theorem testBit_zero (b n) : testBit (bit b n) 0 = b := by
  rw [testBit, bit]
  cases b
  · simp [bit0, ← Nat.mul_two]
  · simp only [cond_true, bit1, bit0, shiftRight_zero, and_one_is_mod, bne_iff_ne]
    

Proof state:
case true
n : ℕ
⊢ (n + n + 1) % 2 ≠ 0

Next tactic:
simp only [← Nat.mul_two]
@[simp]
theorem testBit_zero (b n) : testBit (bit b n) 0 = b := by
  rw [testBit, bit]
  cases b
  · simp [bit0, ← Nat.mul_two]
  · simp only [cond_true, bit1, bit0, shiftRight_zero, and_one_is_mod, bne_iff_ne]
    simp only [← Nat.mul_two]
    

Proof state:
case true
n : ℕ
⊢ (n * 2 + 1) % 2 ≠ 0

Next tactic:
rw [Nat.add_mod]
@[simp]
theorem testBit_zero (b n) : testBit (bit b n) 0 = b := by
  rw [testBit, bit]
  cases b
  · simp [bit0, ← Nat.mul_two]
  · simp only [cond_true, bit1, bit0, shiftRight_zero, and_one_is_mod, bne_iff_ne]
    simp only [← Nat.mul_two]
    rw [Nat.add_mod]
    

Proof state:
case true
n : ℕ
⊢ (n * 2 % 2 + 1 % 2) % 2 ≠ 0

Next tactic:
simp
theorem bodd_eq_and_one_ne_zero : ∀ n, bodd n = (n &&& 1 != 0)
  | 0 => rfl
  | 1 => rfl
  | n + 2 => by 

Proof state:
n : ℕ
⊢ bodd (n + 2) = (n + 2 &&& 1 != 0)

Next tactic:
simpa using bodd_eq_and_one_ne_zero n
theorem testBit_succ (m b n) : testBit (bit b n) (succ m) = testBit n m := by
  

Proof state:
m : ℕ
b : Bool
n : ℕ
⊢ testBit (bit b n) (succ m) = testBit n m

Next tactic:
have : bodd (((bit b n) >>> 1) >>> m) = bodd (n >>> m) := by
    simp only [shiftRight_eq_div_pow]
    simp [← div2_val, div2_bit]
theorem testBit_succ (m b n) : testBit (bit b n) (succ m) = testBit n m := by
  have : bodd (((bit b n) >>> 1) >>> m) = bodd (n >>> m) := by
    

Proof state:
m : ℕ
b : Bool
n : ℕ
⊢ bodd (bit b n >>> 1 >>> m) = bodd (n >>> m)

Next tactic:
simp only [shiftRight_eq_div_pow]
theorem testBit_succ (m b n) : testBit (bit b n) (succ m) = testBit n m := by
  have : bodd (((bit b n) >>> 1) >>> m) = bodd (n >>> m) := by
    simp only [shiftRight_eq_div_pow]
    

Proof state:
m : ℕ
b : Bool
n : ℕ
⊢ bodd (bit b n / 2 ^ 1 / 2 ^ m) = bodd (n / 2 ^ m)

Next tactic:
simp [← div2_val, div2_bit]
theorem testBit_succ (m b n) : testBit (bit b n) (succ m) = testBit n m := by
  have : bodd (((bit b n) >>> 1) >>> m) = bodd (n >>> m) := by
    simp only [shiftRight_eq_div_pow]
    simp [← div2_val, div2_bit]
  

Proof state:
m : ℕ
b : Bool
n : ℕ
this : bodd (bit b n >>> 1 >>> m) = bodd (n >>> m)
⊢ testBit (bit b n) (succ m) = testBit n m

Next tactic:
rw [← shiftRight_add, Nat.add_comm] at this
theorem testBit_succ (m b n) : testBit (bit b n) (succ m) = testBit n m := by
  have : bodd (((bit b n) >>> 1) >>> m) = bodd (n >>> m) := by
    simp only [shiftRight_eq_div_pow]
    simp [← div2_val, div2_bit]
  rw [← shiftRight_add, Nat.add_comm] at this
  

Proof state:
m : ℕ
b : Bool
n : ℕ
this : bodd (bit b n >>> (m + 1)) = bodd (n >>> m)
⊢ testBit (bit b n) (succ m) = testBit n m

Next tactic:
simp only [bodd_eq_and_one_ne_zero] at this
theorem testBit_succ (m b n) : testBit (bit b n) (succ m) = testBit n m := by
  have : bodd (((bit b n) >>> 1) >>> m) = bodd (n >>> m) := by
    simp only [shiftRight_eq_div_pow]
    simp [← div2_val, div2_bit]
  rw [← shiftRight_add, Nat.add_comm] at this
  simp only [bodd_eq_and_one_ne_zero] at this
  

Proof state:
m : ℕ
b : Bool
n : ℕ
this : (bit b n >>> (m + 1) &&& 1 != 0) = (n >>> m &&& 1 != 0)
⊢ testBit (bit b n) (succ m) = testBit n m

Next tactic:
exact this
theorem 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) := by
  

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
h : f false 0 z = z
b : Bool
n : ℕ
⊢ binaryRec z f (bit b n) = f b n (binaryRec z f n)

Next tactic:
rw [binaryRec]
theorem 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) := by
  rw [binaryRec]
  

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
h : f false 0 z = z
b : Bool
n : ℕ
⊢ (if n0 : bit b n = 0 then Eq.mpr (_ : C (bit b n) = C 0) z
    else
      let n' := div2 (bit b n);
      let_fun _x := (_ : bit (bodd (bit b n)) (div2 (bit b n)) = bit b n);
      Eq.mpr (_ : C (bit b n) = C (bit (bodd (bit b n)) n')) (f (bodd (bit b n)) n' (binaryRec z f n'))) =
    f b n (binaryRec z f n)

Next tactic:
by_cases h : bit b n = 0
theorem 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) := by
  rw [binaryRec]
  by_cases h : bit b n = 0
  -- Note: this renames the original `h : f false 0 z = z` to `h'` and leaves `h : bit b n = 0`
  

Proof state:
case pos
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
h✝ : f false 0 z = z
b : Bool
n : ℕ
h : bit b n = 0
⊢ (if n0 : bit b n = 0 then Eq.mpr (_ : C (bit b n) = C 0) z
    else
      let n' := div2 (bit b n);
      let_fun _x := (_ : bit (bodd (bit b n)) (div2 (bit b n)) = bit b n);
      Eq.mpr (_ : C (bit b n) = C (bit (bodd (bit b n)) n')) (f (bodd (bit b n)) n' (binaryRec z f n'))) =
    f b n (binaryRec z f n)
case neg
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
h✝ : f false 0 z = z
b : Bool
n : ℕ
h : ¬bit b n = 0
⊢ (if n0 : bit b n = 0 then Eq.mpr (_ : C (bit b n) = C 0) z
    else
      let n' := div2 (bit b n);
      let_fun _x := (_ : bit (bodd (bit b n)) (div2 (bit b n)) = bit b n);
      Eq.mpr (_ : C (bit b n) = C (bit (bodd (bit b n)) n')) (f (bodd (bit b n)) n' (binaryRec z f n'))) =
    f b n (binaryRec z f n)

Next tactic:
case pos h' =>
    simp only [dif_pos h]
    generalize binaryRec z f (bit b n) = e
    revert e
    have bf := bodd_bit b n
    have n0 := div2_bit b n
    rw [h] at bf n0
    simp only [bodd_zero, div2_zero] at bf n0
    subst bf n0
    rw [binaryRec_zero]
    intros
    rw [h']
    rfl
theorem 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) := by
  rw [binaryRec]
  by_cases h : bit b n = 0
  -- Note: this renames the original `h : f false 0 z = z` to `h'` and leaves `h : bit b n = 0`
  

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
h' : f false 0 z = z
b : Bool
n : ℕ
h : bit b n = 0
⊢ (if n0 : bit b n = 0 then Eq.mpr (_ : C (bit b n) = C 0) z
    else
      let n' := div2 (bit b n);
      let_fun _x := (_ : bit (bodd (bit b n)) (div2 (bit b n)) = bit b n);
      Eq.mpr (_ : C (bit b n) = C (bit (bodd (bit b n)) n')) (f (bodd (bit b n)) n' (binaryRec z f n'))) =
    f b n (binaryRec z f n)

Next tactic:
case pos h' =>
    simp only [dif_pos h]
    generalize binaryRec z f (bit b n) = e
    revert e
    have bf := bodd_bit b n
    have n0 := div2_bit b n
    rw [h] at bf n0
    simp only [bodd_zero, div2_zero] at bf n0
    subst bf n0
    rw [binaryRec_zero]
    intros
    rw [h']
    rfl
theorem 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) := by
  rw [binaryRec]
  by_cases h : bit b n = 0
  -- Note: this renames the original `h : f false 0 z = z` to `h'` and leaves `h : bit b n = 0`
  case pos h' =>
    

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
h' : f false 0 z = z
b : Bool
n : ℕ
h : bit b n = 0
⊢ (if n0 : bit b n = 0 then Eq.mpr (_ : C (bit b n) = C 0) z
    else
      let n' := div2 (bit b n);
      let_fun _x := (_ : bit (bodd (bit b n)) (div2 (bit b n)) = bit b n);
      Eq.mpr (_ : C (bit b n) = C (bit (bodd (bit b n)) n')) (f (bodd (bit b n)) n' (binaryRec z f n'))) =
    f b n (binaryRec z f n)

Next tactic:
simp only [dif_pos h]
theorem 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) := by
  rw [binaryRec]
  by_cases h : bit b n = 0
  -- Note: this renames the original `h : f false 0 z = z` to `h'` and leaves `h : bit b n = 0`
  case pos h' =>
    simp only [dif_pos h]
    

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
h' : f false 0 z = z
b : Bool
n : ℕ
h : bit b n = 0
⊢ Eq.mpr (_ : C (bit b n) = C 0) z = f b n (binaryRec z f n)

Next tactic:
generalize binaryRec z f (bit b n) = e
theorem 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) := by
  rw [binaryRec]
  by_cases h : bit b n = 0
  -- Note: this renames the original `h : f false 0 z = z` to `h'` and leaves `h : bit b n = 0`
  case pos h' =>
    simp only [dif_pos h]
    generalize binaryRec z f (bit b n) = e
    

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
h' : f false 0 z = z
b : Bool
n : ℕ
h : bit b n = 0
e : C (bit b n)
⊢ Eq.mpr (_ : C (bit b n) = C 0) z = f b n (binaryRec z f n)

Next tactic:
revert e
theorem 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) := by
  rw [binaryRec]
  by_cases h : bit b n = 0
  -- Note: this renames the original `h : f false 0 z = z` to `h'` and leaves `h : bit b n = 0`
  case pos h' =>
    simp only [dif_pos h]
    generalize binaryRec z f (bit b n) = e
    revert e
    

Proof state:
C : ℕ → Sort u
z : C 0
f : (b : Bool) → (n : ℕ) → C n → C (bit b n)
h' : f false 0 z = z
b : Bool
n : ℕ
h : bit b n = 0
⊢ C (bit b n) → Eq.mpr (_ : C (bit b n) = C 0) z = f b n (binaryRec z f n)

Next tactic:
have bf := bodd_bit b n