-- 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 nil
α : Type u_1
inst✝ : BEq α
lt : α → α → Bool
l₂ : List α
⊢ [].lex l₂ lt = true ↔
    ([].isEqv (take [].length l₂) fun x1 x2 => x1 == x2) = true ∧ [].length < l₂.length ∨
      ∃ i h₁ h₂, (∀ (j : Nat) (hj : j < i), ([][j] == l₂[j]) = true) ∧ lt [][i] l₂[i] = true

Tactic:
cases l₂ with
| nil => simp [lex]
| cons b bs => simp [lex]

Result:
no goals

Proof state:
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)

Tactic:
exact .inr ⟨h₁, .inl ⟨h₂, by simpa using h₃⟩⟩

Result:
no goals

Proof state:
case cons.cons.mpr.inr.intro.intro.intro.intro.zero
α : 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₁ : 0 < l₁.length + 1
h₂ : 0 < l₂.length + 1
w₁ : ∀ (j : Nat) (hj : j < 0), ((a :: l₁)[j] == (b :: l₂)[j]) = true
w₂ : lt (a :: l₁)[0] (b :: l₂)[0] = 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:
left

Result:
case cons.cons.mpr.inr.intro.intro.intro.intro.zero.h
α : 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₁ : 0 < l₁.length + 1
h₂ : 0 < l₂.length + 1
w₁ : ∀ (j : Nat) (hj : j < 0), ((a :: l₁)[j] == (b :: l₂)[j]) = true
w₂ : lt (a :: l₁)[0] (b :: l₂)[0] = true
⊢ lt a b = true

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

Tactic:
simp [lex]

Result:
no goals

Proof state:
case cons.cons.mp.inr.intro.inr.intro.intro.intro.intro.refine_1.succ
α : 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 + 1 < i + 1
⊢ ((a :: l₁)[j + 1] == (b :: l₂)[j + 1]) = true

Tactic:
simp only [getElem_cons_succ]

Result:
case cons.cons.mp.inr.intro.inr.intro.intro.intro.intro.refine_1.succ
α : 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 + 1 < i + 1
⊢ (l₁[j] == l₂[j]) = 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
h₁ : (l₁.isEqv (take l₁.length l₂) fun x1 x2 => x1 == x2) = true
h₂ : l₁.length < l₂.length
⊢ l₁.length < l₂.length

Tactic:
simpa using h₂

Result:
no goals

Proof state:
case cons.cons.mp.inr.intro.inr.intro.intro.intro.intro.refine_1.succ
α : 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 + 1 < i + 1
⊢ (l₁[j] == l₂[j]) = true

Tactic:
rw [w₁]

Result:
case cons.cons.mp.inr.intro.inr.intro.intro.intro.intro.refine_1.succ.hj
α : 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 + 1 < i + 1
⊢ j < i

Proof state:
case cons.cons
α : 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 :: l₁).lex (b :: l₂) lt = true ↔
    ((a :: l₁).isEqv (take (a :: l₁).length (b :: l₂)) fun x1 x2 => x1 == x2) = true ∧
        (a :: l₁).length < (b :: 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:
simp [lex_cons_cons, Bool.or_eq_true, Bool.and_eq_true, ih, isEqv, length_cons]

Result:
case cons.cons
α : 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 α
⊢ 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) ↔
    ((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