-- Mathlib/.lake/packages/batteries/Batteries/Data/List/Lemmas.lean
theorem dropInfix?_go_eq_some_iff [BEq α] {i l acc p s : List α} :
    dropInfix?.go i l acc = some (p, s) ↔ ∃ p',
      p = acc.reverse ++ p' ∧
      -- `i` is an infix up to `==`
      (∃ i', l = p' ++ i' ++ s ∧ i' == i) ∧
        -- and there is no shorter prefix for which that is the case
        (∀ p'' i'' s'', l = p'' ++ i'' ++ s'' → i'' == i → p''.length ≥ p'.length)

Proof state:
case h_2.h_1.mpr.intro.intro.intro.intro.intro.inr.intro.intro.inr.intro.intro
α : Type u_1
inst✝ : BEq α
i acc s x✝² x✝¹ : List α
a : α
x✝ : Option (List α)
i' : List α
h₂ : (i' == i) = true
p' : List α
h : (a :: (p' ++ i' ++ s)).dropPrefix? i = none
w :
  ∀ (p'' i'' s'' : List α), a :: (p' ++ i' ++ s) = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ (a :: p').length
⊢ acc.reverse ++ a :: p' = (a :: acc).reverse ++ p' ∧
    (∃ i'_1, p' ++ i' ++ s = p' ++ i'_1 ++ s ∧ (i'_1 == i) = true) ∧
      ∀ (p'' i'' s'' : List α), p' ++ i' ++ s = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length

Tactic:
simp only [reverse_cons, append_assoc, singleton_append, append_cancel_left_eq,
  append_cancel_right_eq, exists_eq_left', ge_iff_le, true_and]

Result:
case h_2.h_1.mpr.intro.intro.intro.intro.intro.inr.intro.intro.inr.intro.intro
α : Type u_1
inst✝ : BEq α
i acc s x✝² x✝¹ : List α
a : α
x✝ : Option (List α)
i' : List α
h₂ : (i' == i) = true
p' : List α
h : (a :: (p' ++ i' ++ s)).dropPrefix? i = none
w :
  ∀ (p'' i'' s'' : List α), a :: (p' ++ i' ++ s) = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ (a :: p').length
⊢ (i' == i) = true ∧
    ∀ (p'' i'' s'' : List α), p' ++ (i' ++ s) = p'' ++ (i'' ++ s'') → (i'' == i) = true → p'.length ≤ p''.length

Proof state:
case h_2.h_1.mpr
α : Type u_1
inst✝ : BEq α
i acc p s x✝² x✝¹ : List α
a : α
t : List α
x✝ : Option (List α)
h : (a :: t).dropPrefix? i = none
⊢ (∃ p',
      p = acc.reverse ++ p' ∧
        (∃ i', a :: t = p' ++ i' ++ s ∧ (i' == i) = true) ∧
          ∀ (p'' i'' s'' : List α), a :: t = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length) →
    ∃ p',
      p = (a :: acc).reverse ++ p' ∧
        (∃ i', t = p' ++ i' ++ s ∧ (i' == i) = true) ∧
          ∀ (p'' i'' s'' : List α), t = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length

Tactic:
rintro ⟨p', rfl, ⟨i', h₁, h₂⟩, w⟩

Result:
case h_2.h_1.mpr.intro.intro.intro.intro.intro
α : Type u_1
inst✝ : BEq α
i acc s x✝² x✝¹ : List α
a : α
t : List α
x✝ : Option (List α)
h : (a :: t).dropPrefix? i = none
p' : List α
w : ∀ (p'' i'' s'' : List α), a :: t = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length
i' : List α
h₁ : a :: t = p' ++ i' ++ s
h₂ : (i' == i) = true
⊢ ∃ p'_1,
    acc.reverse ++ p' = (a :: acc).reverse ++ p'_1 ∧
      (∃ i', t = p'_1 ++ i' ++ s ∧ (i' == i) = true) ∧
        ∀ (p'' i'' s'' : List α), t = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'_1.length

Proof state:
case h_2
α : Type u_1
inst✝ : BEq α
i acc p s x✝¹ x✝ : List α
a : α
t : List α
⊢ (match (a :: t).dropPrefix? i with
      | none => dropInfix?.go i t (a :: acc)
      | some s => some (acc.reverse, s)) =
      some (p, s) ↔
    ∃ p',
      p = acc.reverse ++ p' ∧
        (∃ i', a :: t = p' ++ i' ++ s ∧ (i' == i) = true) ∧
          ∀ (p'' i'' s'' : List α), a :: t = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length

Tactic:
split <;> rename_i h

Result:
case h_2.h_1
α : Type u_1
inst✝ : BEq α
i acc p s x✝² x✝¹ : List α
a : α
t : List α
x✝ : Option (List α)
h : (a :: t).dropPrefix? i = none
⊢ dropInfix?.go i t (a :: acc) = some (p, s) ↔
    ∃ p',
      p = acc.reverse ++ p' ∧
        (∃ i', a :: t = p' ++ i' ++ s ∧ (i' == i) = true) ∧
          ∀ (p'' i'' s'' : List α), a :: t = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length

case h_2.h_2
α : Type u_1
inst✝ : BEq α
i acc p s x✝² x✝¹ : List α
a : α
t : List α
x✝ : Option (List α)
s✝ : List α
h : (a :: t).dropPrefix? i = some s✝
⊢ some (acc.reverse, s✝) = some (p, s) ↔
    ∃ p',
      p = acc.reverse ++ p' ∧
        (∃ i', a :: t = p' ++ i' ++ s ∧ (i' == i) = true) ∧
          ∀ (p'' i'' s'' : List α), a :: t = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length

Proof state:
case h_2.h_1.mpr.intro.intro.intro.intro.intro.inr.intro.intro
α : Type u_1
inst✝ : BEq α
i acc s x✝² x✝¹ : List α
a : α
x✝ : Option (List α)
p' i' : List α
h₂ : (i' == i) = true
a' : List α
h₁ : p' = [] ∧ i' = a :: a' ∨ ∃ a'_1, p' = a :: a'_1 ∧ a' = a'_1 ++ i'
h : (a :: (a' ++ s)).dropPrefix? i = none
w : ∀ (p'' i'' s'' : List α), a :: (a' ++ s) = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length
⊢ ∃ p'_1,
    acc.reverse ++ p' = (a :: acc).reverse ++ p'_1 ∧
      (∃ i', a' ++ s = p'_1 ++ i' ++ s ∧ (i' == i) = true) ∧
        ∀ (p'' i'' s'' : List α), a' ++ s = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'_1.length

Tactic:
obtain (⟨rfl, rfl⟩ | ⟨p', rfl, rfl⟩) := h₁

Result:
case h_2.h_1.mpr.intro.intro.intro.intro.intro.inr.intro.intro.inl.intro
α : Type u_1
inst✝ : BEq α
i acc s x✝² x✝¹ : List α
a : α
x✝ : Option (List α)
a' : List α
h : (a :: (a' ++ s)).dropPrefix? i = none
w : ∀ (p'' i'' s'' : List α), a :: (a' ++ s) = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ [].length
h₂ : (a :: a' == i) = true
⊢ ∃ p',
    acc.reverse ++ [] = (a :: acc).reverse ++ p' ∧
      (∃ i', a' ++ s = p' ++ i' ++ s ∧ (i' == i) = true) ∧
        ∀ (p'' i'' s'' : List α), a' ++ s = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length

case h_2.h_1.mpr.intro.intro.intro.intro.intro.inr.intro.intro.inr.intro.intro
α : Type u_1
inst✝ : BEq α
i acc s x✝² x✝¹ : List α
a : α
x✝ : Option (List α)
i' : List α
h₂ : (i' == i) = true
p' : List α
h : (a :: (p' ++ i' ++ s)).dropPrefix? i = none
w :
  ∀ (p'' i'' s'' : List α), a :: (p' ++ i' ++ s) = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ (a :: p').length
⊢ ∃ p'_1,
    acc.reverse ++ a :: p' = (a :: acc).reverse ++ p'_1 ∧
      (∃ i'_1, p' ++ i' ++ s = p'_1 ++ i'_1 ++ s ∧ (i'_1 == i) = true) ∧
        ∀ (p'' i'' s'' : List α), p' ++ i' ++ s = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'_1.length

Proof state:
α : Type u_1
inst✝ : BEq α
i acc s x✝² x✝¹ : List α
a : α
t : List α
x✝ : Option (List α)
s' p' : List α
h : a :: t = p' ++ s'
w : (p' == i) = true
p'' : List α
w' : ∀ (p''_1 i'' s'' : List α), a :: t = p''_1 ++ (i'' ++ s'') → (i'' == i) = true → p''.length ≤ p''_1.length
i' : List α
h₁ : a :: t = p'' ++ (i' ++ s)
h₂ : (i' == i) = true
⊢ a :: t = [] ++ (p' ++ s')

Tactic:
simpa using h

Result:
no goals

Proof state:
case h_2
α : Type u_1
inst✝ : BEq α
i acc p s x✝¹ x✝ : List α
a✝ : α
t✝ : List α
⊢ (match (a✝ :: t✝).dropPrefix? i with
      | none => dropInfix?.go i t✝ (a✝ :: acc)
      | some s => some (acc.reverse, s)) =
      some (p, s) ↔
    ∃ p',
      p = acc.reverse ++ p' ∧
        (∃ i', a✝ :: t✝ = p' ++ i' ++ s ∧ (i' == i) = true) ∧
          ∀ (p'' i'' s'' : List α), a✝ :: t✝ = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length

Tactic:
rename_i a t

Result:
case h_2
α : Type u_1
inst✝ : BEq α
i acc p s x✝¹ x✝ : List α
a : α
t : List α
⊢ (match (a :: t).dropPrefix? i with
      | none => dropInfix?.go i t (a :: acc)
      | some s => some (acc.reverse, s)) =
      some (p, s) ↔
    ∃ p',
      p = acc.reverse ++ p' ∧
        (∃ i', a :: t = p' ++ i' ++ s ∧ (i' == i) = true) ∧
          ∀ (p'' i'' s'' : List α), a :: t = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length

Proof state:
α : Type u_1
inst✝ : BEq α
i acc s x✝² x✝¹ : List α
a : α
x✝ : Option (List α)
i' : List α
h₂ : (i' == i) = true
p' : List α
h : (a :: (p' ++ i' ++ s)).dropPrefix? i = none
p'' i'' s'' : List α
w :
  ∀ (p''_1 i''_1 s''_1 : List α),
    a :: (p'' ++ (i'' ++ s'')) = p''_1 ++ i''_1 ++ s''_1 → (i''_1 == i) = true → p''_1.length ≥ (a :: p').length
h₃ : p' ++ i' ++ s = p'' ++ (i'' ++ s'')
h₄ : (i'' == i) = true
⊢ a :: (p'' ++ (i'' ++ s'')) = a :: p'' ++ i'' ++ s''

Tactic:
simp

Result:
no goals