-- Mathlib/.lake/packages/lean4/src/lean/Init/Data/List/Lex.lean
theorem lex_eq_true_iff_exists [BEq α] (lt : α → α → Bool) :
    lex l₁ l₂ lt = true ↔
      (l₁.isEqv (l₂.take l₁.length) (· == ·) ∧ l₁.length < l₂.length) ∨
        (∃ (i : Nat) (h₁ : i < l₁.length) (h₂ : i < l₂.length),
          (∀ j, (hj : j < i) →
            l₁[j]'(Nat.lt_trans hj h₁) == l₂[j]'(Nat.lt_trans hj h₂)) ∧ lt l₁[i] l₂[i])

Proof state:
case cons.cons.mpr
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
a : α
l₁ : List α
ih :
  ∀ {l₂ : List α},
    l₁.lex l₂ lt = true ↔
      (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true
b : α
l₂ : List α
⊢ (((a == b) = true ∧ (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true) ∧ l₁.length < l₂.length ∨
      ∃ i h h₂,
        (∀ (j : Nat) (hj : j < i), ((a :: l₁)[j] == (b :: l₂)[j]) = true) ∧ lt (a :: l₁)[i] (b :: l₂)[i] = true) →
    lt a b = true ∨
      (a == b) = true ∧
        ((l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
          ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true)

Tactic:
rintro (⟨⟨h₁, h₂⟩, h₃⟩ | ⟨i, h₁, h₂, w₁, w₂⟩)

Result:
case cons.cons.mpr.inl.intro.intro
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
a : α
l₁ : List α
ih :
  ∀ {l₂ : List α},
    l₁.lex l₂ lt = true ↔
      (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true
b : α
l₂ : List α
h₃ : l₁.length < l₂.length
h₁ : (a == b) = true
h₂ : (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true
⊢ lt a b = true ∨
    (a == b) = true ∧
      ((l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true)

case cons.cons.mpr.inr.intro.intro.intro.intro
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
a : α
l₁ : List α
ih :
  ∀ {l₂ : List α},
    l₁.lex l₂ lt = true ↔
      (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true
b : α
l₂ : List α
i : Nat
h₁ : i < l₁.length + 1
h₂ : i < l₂.length + 1
w₁ : ∀ (j : Nat) (hj : j < i), ((a :: l₁)[j] == (b :: l₂)[j]) = true
w₂ : lt (a :: l₁)[i] (b :: l₂)[i] = true
⊢ lt a b = true ∨
    (a == b) = true ∧
      ((l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true)

Proof state:
case cons.cons.mpr.inr.intro.intro.intro.intro.succ.h.h.refine_1
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
a : α
l₁ : List α
ih :
  ∀ {l₂ : List α},
    l₁.lex l₂ lt = true ↔
      (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true
b : α
l₂ : List α
i : Nat
h₁ : i + 1 < l₁.length + 1
h₂ : i + 1 < l₂.length + 1
w₁ : ∀ (j : Nat) (hj : j < i + 1), ((a :: l₁)[j] == (b :: l₂)[j]) = true
w₂ : lt (a :: l₁)[i + 1] (b :: l₂)[i + 1] = true
⊢ ∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true

Tactic:
intro j hj

Result:
case cons.cons.mpr.inr.intro.intro.intro.intro.succ.h.h.refine_1
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
a : α
l₁ : List α
ih :
  ∀ {l₂ : List α},
    l₁.lex l₂ lt = true ↔
      (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true
b : α
l₂ : List α
i : Nat
h₁ : i + 1 < l₁.length + 1
h₂ : i + 1 < l₂.length + 1
w₁ : ∀ (j : Nat) (hj : j < i + 1), ((a :: l₁)[j] == (b :: l₂)[j]) = true
w₂ : lt (a :: l₁)[i + 1] (b :: l₂)[i + 1] = true
j : Nat
hj : j < i
⊢ (l₁[j] == l₂[j]) = true

Proof state:
case cons.cons.mp.inr.intro.inr.intro.intro.intro.intro
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
a : α
l₁ : List α
ih :
  ∀ {l₂ : List α},
    l₁.lex l₂ lt = true ↔
      (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true
b : α
l₂ : List α
hab : (a == b) = true
i : Nat
h₁ : i < l₁.length
h₂ : i < l₂.length
w₁ : ∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true
w₂ : lt l₁[i] l₂[i] = true
⊢ ((a == b) = true ∧ (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true) ∧ l₁.length < l₂.length ∨
    ∃ i h h₂, (∀ (j : Nat) (hj : j < i), ((a :: l₁)[j] == (b :: l₂)[j]) = true) ∧ lt (a :: l₁)[i] (b :: l₂)[i] = true

Tactic:
refine .inr ⟨i + 1, by simp [h₁],
  by simp [h₂], ?_, ?_⟩

Result:
case cons.cons.mp.inr.intro.inr.intro.intro.intro.intro.refine_1
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
a : α
l₁ : List α
ih :
  ∀ {l₂ : List α},
    l₁.lex l₂ lt = true ↔
      (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true
b : α
l₂ : List α
hab : (a == b) = true
i : Nat
h₁ : i < l₁.length
h₂ : i < l₂.length
w₁ : ∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true
w₂ : lt l₁[i] l₂[i] = true
⊢ ∀ (j : Nat) (hj : j < i + 1), ((a :: l₁)[j] == (b :: l₂)[j]) = true

case cons.cons.mp.inr.intro.inr.intro.intro.intro.intro.refine_2
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
a : α
l₁ : List α
ih :
  ∀ {l₂ : List α},
    l₁.lex l₂ lt = true ↔
      (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true
b : α
l₂ : List α
hab : (a == b) = true
i : Nat
h₁ : i < l₁.length
h₂ : i < l₂.length
w₁ : ∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true
w₂ : lt l₁[i] l₂[i] = true
⊢ lt (a :: l₁)[i + 1] (b :: l₂)[i + 1] = true

Proof state:
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
a : α
l₁ : List α
ih :
  ∀ {l₂ : List α},
    l₁.lex l₂ lt = true ↔
      (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true
b : α
l₂ : List α
hab : (a == b) = true
i : Nat
h₁ : i < l₁.length
h₂ : i < l₂.length
w₁ : ∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true
w₂ : lt l₁[i] l₂[i] = true
⊢ i + 1 < l₂.length + 1

Tactic:
simp [h₂]

Result:
no goals

Proof state:
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
a : α
l₁ : List α
ih :
  ∀ {l₂ : List α},
    l₁.lex l₂ lt = true ↔
      (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true
b : α
l₂ : List α
i : Nat
h₁ : i + 1 < l₁.length + 1
h₂ : i + 1 < l₂.length + 1
w₁ : ∀ (j : Nat) (hj : j < i + 1), ((a :: l₁)[j] == (b :: l₂)[j]) = true
w₂ : lt (a :: l₁)[i + 1] (b :: l₂)[i + 1] = true
⊢ 0 < i + 1

Tactic:
simp

Result:
no goals

Proof state:
case cons.cons.mp.inr.intro.inr.intro.intro.intro.intro.refine_1
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
a : α
l₁ : List α
ih :
  ∀ {l₂ : List α},
    l₁.lex l₂ lt = true ↔
      (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true ∧ l₁.length < l₂.length ∨
        ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true) ∧ lt l₁[i] l₂[i] = true
b : α
l₂ : List α
hab : (a == b) = true
i : Nat
h₁ : i < l₁.length
h₂ : i < l₂.length
w₁ : ∀ (j : Nat) (hj : j < i), (l₁[j] == l₂[j]) = true
w₂ : lt l₁[i] l₂[i] = true
j : Nat
hj : j < i + 1
⊢ ((a :: l₁)[j] == (b :: l₂)[j]) = true

Tactic:
cases j with
| zero => simp [hab]
| succ j =>
  simp only [getElem_cons_succ]
  rw [w₁]
  simpa using hj

Result:
no goals