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

tactic: induction' n using Nat.binaryRec with b n hn' generalizing i m
state_before: n m i : ℕ
hn : testBit n i = false
hm : testBit m i = true
hnm : ∀ (j : ℕ), i < j → testBit n j = testBit m j
⊢ n < m

tactic: induction' m using Nat.binaryRec with b' m hm' generalizing i
state_before: case f
n✝ m✝ i✝ : ℕ
hn✝ : testBit n✝ i✝ = false
hm✝ : testBit m✝ i✝ = true
hnm✝ : ∀ (j : ℕ), i✝ < j → testBit n✝ j = testBit m✝ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m i : ℕ
hn : testBit (bit b n) i = false
hm : testBit m i = true
hnm : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j
⊢ bit b n < m

tactic: by_cases hi : i = 0
state_before: case f.f
n✝ m✝¹ i✝¹ : ℕ
hn✝¹ : testBit n✝ i✝¹ = false
hm✝¹ : testBit m✝¹ i✝¹ = true
hnm✝¹ : ∀ (j : ℕ), i✝¹ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i✝ : ℕ
hn✝ : testBit (bit b n) i✝ = false
hm✝ : testBit m✝ i✝ = true
hnm✝ : ∀ (j : ℕ), i✝ < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
i : ℕ
hn : testBit (bit b n) i = false
hm : testBit (bit b' m) i = true
hnm : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit (bit b' m) j
⊢ bit b n < bit b' m

tactic: contrapose! hm
state_before: case z
n m✝ i✝ : ℕ
hn✝ : testBit n i✝ = false
hm✝ : testBit m✝ i✝ = true
hnm✝ : ∀ (j : ℕ), i✝ < j → testBit n j = testBit m✝ j
m i : ℕ
hn : testBit 0 i = false
hm : testBit m i = true
hnm : ∀ (j : ℕ), i < j → testBit 0 j = testBit m j
⊢ 0 < m

tactic: rw [le_zero_iff] at hm
state_before: case z
n m✝ i✝ : ℕ
hn✝ : testBit n i✝ = false
hm✝ : testBit m✝ i✝ = true
hnm✝ : ∀ (j : ℕ), i✝ < j → testBit n j = testBit m✝ j
m i : ℕ
hn : testBit 0 i = false
hnm : ∀ (j : ℕ), i < j → testBit 0 j = testBit m j
hm : m ≤ 0
⊢ testBit m i ≠ true

tactic: simp [hm]
state_before: case z
n m✝ i✝ : ℕ
hn✝ : testBit n i✝ = false
hm✝ : testBit m✝ i✝ = true
hnm✝ : ∀ (j : ℕ), i✝ < j → testBit n j = testBit m✝ j
m i : ℕ
hn : testBit 0 i = false
hnm : ∀ (j : ℕ), i < j → testBit 0 j = testBit m j
hm : m = 0
⊢ testBit m i ≠ true

tactic: exact False.elim (Bool.ff_ne_tt ((zero_testBit i).symm.trans hm))
state_before: case f.z
n✝ m✝ i✝¹ : ℕ
hn✝¹ : testBit n✝ i✝¹ = false
hm✝¹ : testBit m✝ i✝¹ = true
hnm✝¹ : ∀ (j : ℕ), i✝¹ < j → testBit n✝ j = testBit m✝ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m i✝ : ℕ
hn✝ : testBit (bit b n) i✝ = false
hm✝ : testBit m i✝ = true
hnm✝ : ∀ (j : ℕ), i✝ < j → testBit (bit b n) j = testBit m j
i : ℕ
hn : testBit (bit b n) i = false
hm : testBit 0 i = true
hnm : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit 0 j
⊢ bit b n < 0

tactic: subst hi
state_before: case pos
n✝ m✝¹ i✝¹ : ℕ
hn✝¹ : testBit n✝ i✝¹ = false
hm✝¹ : testBit m✝¹ i✝¹ = true
hnm✝¹ : ∀ (j : ℕ), i✝¹ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i✝ : ℕ
hn✝ : testBit (bit b n) i✝ = false
hm✝ : testBit m✝ i✝ = true
hnm✝ : ∀ (j : ℕ), i✝ < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
i : ℕ
hn : testBit (bit b n) i = false
hm : testBit (bit b' m) i = true
hnm : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit (bit b' m) j
hi : i = 0
⊢ bit b n < bit b' m

tactic: simp only [testBit_zero] at hn hm
state_before: case pos
n✝ m✝¹ i✝ : ℕ
hn✝¹ : testBit n✝ i✝ = false
hm✝¹ : testBit m✝¹ i✝ = true
hnm✝¹ : ∀ (j : ℕ), i✝ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i : ℕ
hn✝ : testBit (bit b n) i = false
hm✝ : testBit m✝ i = true
hnm✝ : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
hn : testBit (bit b n) 0 = false
hm : testBit (bit b' m) 0 = true
hnm : ∀ (j : ℕ), 0 < j → testBit (bit b n) j = testBit (bit b' m) j
⊢ bit b n < bit b' m

tactic: have : n = m :=
  eq_of_testBit_eq fun i => by convert hnm (i + 1) (Nat.zero_lt_succ _) using 1
  <;> rw [testBit_succ]
state_before: case pos
n✝ m✝¹ i✝ : ℕ
hn✝¹ : testBit n✝ i✝ = false
hm✝¹ : testBit m✝¹ i✝ = true
hnm✝¹ : ∀ (j : ℕ), i✝ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i : ℕ
hn✝ : testBit (bit b n) i = false
hm✝ : testBit m✝ i = true
hnm✝ : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
hnm : ∀ (j : ℕ), 0 < j → testBit (bit b n) j = testBit (bit b' m) j
hn : b = false
hm : b' = true
⊢ bit b n < bit b' m

tactic: rw [hn, hm, this, bit_false, bit_true, bit0_val, bit1_val]
state_before: case pos
n✝ m✝¹ i✝ : ℕ
hn✝¹ : testBit n✝ i✝ = false
hm✝¹ : testBit m✝¹ i✝ = true
hnm✝¹ : ∀ (j : ℕ), i✝ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i : ℕ
hn✝ : testBit (bit b n) i = false
hm✝ : testBit m✝ i = true
hnm✝ : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
hnm : ∀ (j : ℕ), 0 < j → testBit (bit b n) j = testBit (bit b' m) j
hn : b = false
hm : b' = true
this : n = m
⊢ bit b n < bit b' m

tactic: exact lt_add_one _
state_before: case pos
n✝ m✝¹ i✝ : ℕ
hn✝¹ : testBit n✝ i✝ = false
hm✝¹ : testBit m✝¹ i✝ = true
hnm✝¹ : ∀ (j : ℕ), i✝ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i : ℕ
hn✝ : testBit (bit b n) i = false
hm✝ : testBit m✝ i = true
hnm✝ : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
hnm : ∀ (j : ℕ), 0 < j → testBit (bit b n) j = testBit (bit b' m) j
hn : b = false
hm : b' = true
this : n = m
⊢ 2 * m < 2 * m + 1

tactic: convert hnm (i + 1) (Nat.zero_lt_succ _) using 1
<;> rw [testBit_succ]
state_before: n✝ m✝¹ i✝¹ : ℕ
hn✝¹ : testBit n✝ i✝¹ = false
hm✝¹ : testBit m✝¹ i✝¹ = true
hnm✝¹ : ∀ (j : ℕ), i✝¹ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i✝ : ℕ
hn✝ : testBit (bit b n) i✝ = false
hm✝ : testBit m✝ i✝ = true
hnm✝ : ∀ (j : ℕ), i✝ < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
hnm : ∀ (j : ℕ), 0 < j → testBit (bit b n) j = testBit (bit b' m) j
hn : b = false
hm : b' = true
i : ℕ
⊢ testBit n i = testBit m i

tactic: obtain ⟨i', rfl⟩ := exists_eq_succ_of_ne_zero hi
state_before: case neg
n✝ m✝¹ i✝¹ : ℕ
hn✝¹ : testBit n✝ i✝¹ = false
hm✝¹ : testBit m✝¹ i✝¹ = true
hnm✝¹ : ∀ (j : ℕ), i✝¹ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i✝ : ℕ
hn✝ : testBit (bit b n) i✝ = false
hm✝ : testBit m✝ i✝ = true
hnm✝ : ∀ (j : ℕ), i✝ < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
i : ℕ
hn : testBit (bit b n) i = false
hm : testBit (bit b' m) i = true
hnm : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit (bit b' m) j
hi : ¬i = 0
⊢ bit b n < bit b' m

tactic: simp only [testBit_succ] at hn hm
state_before: case neg.intro
n✝ m✝¹ i✝ : ℕ
hn✝¹ : testBit n✝ i✝ = false
hm✝¹ : testBit m✝¹ i✝ = true
hnm✝¹ : ∀ (j : ℕ), i✝ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i : ℕ
hn✝ : testBit (bit b n) i = false
hm✝ : testBit m✝ i = true
hnm✝ : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
i' : ℕ
hn : testBit (bit b n) (succ i') = false
hm : testBit (bit b' m) (succ i') = true
hnm : ∀ (j : ℕ), succ i' < j → testBit (bit b n) j = testBit (bit b' m) j
hi : ¬succ i' = 0
⊢ bit b n < bit b' m

tactic: have :=
  hn' _ hn hm fun j hj => by convert hnm j.succ (succ_lt_succ hj) using 1 <;> rw [testBit_succ]
state_before: case neg.intro
n✝ m✝¹ i✝ : ℕ
hn✝¹ : testBit n✝ i✝ = false
hm✝¹ : testBit m✝¹ i✝ = true
hnm✝¹ : ∀ (j : ℕ), i✝ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i : ℕ
hn✝ : testBit (bit b n) i = false
hm✝ : testBit m✝ i = true
hnm✝ : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
i' : ℕ
hnm : ∀ (j : ℕ), succ i' < j → testBit (bit b n) j = testBit (bit b' m) j
hi : ¬succ i' = 0
hn : testBit n i' = false
hm : testBit m i' = true
⊢ bit b n < bit b' m

tactic: cases b <;> cases b'
<;> simp only [bit_false, bit_true, bit0_val n, bit1_val n, bit0_val m, bit1_val m]
<;> linarith only [this]
state_before: case neg.intro
n✝ m✝¹ i✝ : ℕ
hn✝¹ : testBit n✝ i✝ = false
hm✝¹ : testBit m✝¹ i✝ = true
hnm✝¹ : ∀ (j : ℕ), i✝ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i : ℕ
hn✝ : testBit (bit b n) i = false
hm✝ : testBit m✝ i = true
hnm✝ : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
i' : ℕ
hnm : ∀ (j : ℕ), succ i' < j → testBit (bit b n) j = testBit (bit b' m) j
hi : ¬succ i' = 0
hn : testBit n i' = false
hm : testBit m i' = true
this : n < m
⊢ bit b n < bit b' m

tactic: convert hnm j.succ (succ_lt_succ hj) using 1 <;> rw [testBit_succ]
state_before: n✝ m✝¹ i✝ : ℕ
hn✝¹ : testBit n✝ i✝ = false
hm✝¹ : testBit m✝¹ i✝ = true
hnm✝¹ : ∀ (j : ℕ), i✝ < j → testBit n✝ j = testBit m✝¹ j
b : Bool
n : ℕ
hn' :
  ∀ {m : ℕ} (i : ℕ), testBit n i = false → testBit m i = true → (∀ (j : ℕ), i < j → testBit n j = testBit m j) → n < m
m✝ i : ℕ
hn✝ : testBit (bit b n) i = false
hm✝ : testBit m✝ i = true
hnm✝ : ∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m✝ j
b' : Bool
m : ℕ
hm' :
  ∀ (i : ℕ),
    testBit (bit b n) i = false →
      testBit m i = true → (∀ (j : ℕ), i < j → testBit (bit b n) j = testBit m j) → bit b n < m
i' : ℕ
hnm : ∀ (j : ℕ), succ i' < j → testBit (bit b n) j = testBit (bit b' m) j
hi : ¬succ i' = 0
hn : testBit n i' = false
hm : testBit m i' = true
j : ℕ
hj : i' < j
⊢ testBit n j = testBit m j