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

Proof steps:
state_before: a b c : ℕ
h : a ≠ b ^^^ c
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
state_after: a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
tactic: set v := a ^^^ (b ^^^ c) with hv
state_before: a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
state_after: a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
tactic: have hab : a ^^^ b = c ^^^ v := by
    rw [hv]
    conv_rhs =>
      rw [Nat.xor_comm]
      simp [Nat.xor_assoc]
state_before: a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
state_after: a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
tactic: have hac : a ^^^ c = b ^^^ v := by
    rw [hv]
    conv_rhs =>
      right
      rw [← Nat.xor_comm]
    rw [← Nat.xor_assoc, ← Nat.xor_assoc, xor_self, zero_xor, Nat.xor_comm]
state_before: a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
state_after: a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
tactic: have hbc : b ^^^ c = a ^^^ v := by simp [hv, ← Nat.xor_assoc]
state_before: a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
state_after: case intro.intro
a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
tactic: obtain ⟨i, ⟨hi, hi'⟩⟩ := exists_most_significant_bit (xor_ne_zero.2 h)
state_before: case intro.intro
a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
state_after: case intro.intro
a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
this : a.testBit i = true ∨ b.testBit i = true ∨ c.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
tactic: have : testBit a i = true ∨ testBit b i = true ∨ testBit c i = true := by
    contrapose! hi
    simp only [Bool.eq_false_eq_not_eq_true, Ne, testBit_xor, Bool.bne_eq_xor] at hi ⊢
    rw [hi.1, hi.2.1, hi.2.2, Bool.xor_false, Bool.xor_false]
state_before: case intro.intro
a b c : ℕ
h : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
this : a.testBit i = true ∨ b.testBit i = true ∨ c.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
state_after: case intro.intro.inl
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : a.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c

case intro.intro.inr.inl
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : b.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c

case intro.intro.inr.inr
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : c.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
tactic: rcases this with (h | h | h)
state_before: case intro.intro.inl
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : a.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c

case intro.intro.inr.inl
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : b.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c

case intro.intro.inr.inr
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : c.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
state_after: case intro.intro.inl.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : a.testBit i = true
⊢ a ^^^ v < a

case intro.intro.inr.inl
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : b.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c

case intro.intro.inr.inr
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : c.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
tactic: on_goal 1 => left; rw [hbc]
state_before: case intro.intro.inl.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : a.testBit i = true
⊢ a ^^^ v < a

case intro.intro.inr.inl
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : b.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c

case intro.intro.inr.inr
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : c.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
state_after: case intro.intro.inl.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : a.testBit i = true
⊢ a ^^^ v < a

case intro.intro.inr.inl.h.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : b.testBit i = true
⊢ b ^^^ v < b

case intro.intro.inr.inr
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : c.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
tactic: on_goal 2 => right; left; rw [hac]
state_before: case intro.intro.inl.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : a.testBit i = true
⊢ a ^^^ v < a

case intro.intro.inr.inl.h.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : b.testBit i = true
⊢ b ^^^ v < b

case intro.intro.inr.inr
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : c.testBit i = true
⊢ b ^^^ c < a ∨ a ^^^ c < b ∨ a ^^^ b < c
state_after: case intro.intro.inl.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : a.testBit i = true
⊢ a ^^^ v < a

case intro.intro.inr.inl.h.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : b.testBit i = true
⊢ b ^^^ v < b

case intro.intro.inr.inr.h.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : c.testBit i = true
⊢ c ^^^ v < c
tactic: on_goal 3 => right; right; rw [hab]
state_before: case intro.intro.inl.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : a.testBit i = true
⊢ a ^^^ v < a

case intro.intro.inr.inl.h.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : b.testBit i = true
⊢ b ^^^ v < b

case intro.intro.inr.inr.h.h
a b c : ℕ
h✝ : a ≠ b ^^^ c
v : ℕ := a ^^^ (b ^^^ c)
hv : v = a ^^^ (b ^^^ c)
hab : a ^^^ b = c ^^^ v
hac : a ^^^ c = b ^^^ v
hbc : b ^^^ c = a ^^^ v
i : ℕ
hi : (a ^^^ (b ^^^ c)).testBit i = true
hi' : ∀ (j : ℕ), i < j → (a ^^^ (b ^^^ c)).testBit j = false
h : c.testBit i = true
⊢ c ^^^ v < c
state_after: no goals
tactic: all_goals
    exact lt_of_testBit i (by simp [h, hi]) h fun j hj => by simp [hi' _ hj]