-- 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_1
α : Type u_1
inst✝ : BEq α
i acc p s x✝¹ x✝ : List α
⊢ (if i.isEmpty = true then some (acc.reverse, []) else none) = some (p, s) ↔
    ∃ p',
      p = acc.reverse ++ p' ∧
        (∃ i', [] = p' ++ i' ++ s ∧ (i' == i) = true) ∧
          ∀ (p'' i'' s'' : List α), [] = p'' ++ i'' ++ s'' → (i'' == i) = true → p''.length ≥ p'.length

Tactic:
simp only [isEmpty_eq_true, ite_none_right_eq_some, some.injEq, Prod.mk.injEq, nil_eq,
  append_assoc, append_eq_nil_iff, ge_iff_le, and_imp]

Result:
case h_1
α : Type u_1
inst✝ : BEq α
i acc p s x✝¹ x✝ : List α
⊢ i = [] ∧ acc.reverse = p ∧ s = [] ↔
    ∃ p',
      p = acc.reverse ++ p' ∧
        (∃ i', (p' = [] ∧ i' = [] ∧ s = []) ∧ (i' == i) = true) ∧
          ∀ (p'' i'' s'' : List α), p'' = [] → i'' = [] → s'' = [] → (i'' == i) = true → p'.length ≤ p''.length

Proof state:
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 : ∃ p', a :: t = p' ++ s' ∧ (p' == i) = true
⊢ acc.reverse = p ∧ s' = 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:
obtain ⟨p', h, w⟩ := h

Result:
case h_2.h_2.intro.intro
α : Type u_1
inst✝ : BEq α
i acc p s x✝² x✝¹ : List α
a : α
t : List α
x✝ : Option (List α)
s' p' : List α
h : a :: t = p' ++ s'
w : (p' == i) = true
⊢ acc.reverse = p ∧ s' = 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_1.mp.intro.intro
α : Type u_1
inst✝ : BEq α
acc x✝¹ x✝ : List α
⊢ ∃ p',
    acc.reverse = acc.reverse ++ p' ∧
      (∃ i', (p' = [] ∧ i' = [] ∧ [] = []) ∧ (i' == []) = true) ∧
        ∀ (p'' i'' s'' : List α), p'' = [] → i'' = [] → s'' = [] → (i'' == []) = true → p'.length ≤ p''.length

Tactic:
simp

Result:
no goals

Proof state:
case h_2.h_2.intro.intro.mpr.intro.intro.intro.intro.intro
α : 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'' i' : List α
h₁ : a :: t = p'' ++ (i' ++ s)
h₂ : (i' == i) = true
w' : p'' = []
⊢ acc.reverse = acc.reverse ++ p'' ∧ s' = s

Tactic:
simp [w'] at h₁ ⊢

Result:
case h_2.h_2.intro.intro.mpr.intro.intro.intro.intro.intro
α : 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'' i' : List α
h₂ : (i' == i) = true
w' : p'' = []
h₁ : a :: t = i' ++ s
⊢ s' = s

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
⊢ ∀ (p'' i'' s'' : List α), p' ++ (i' ++ s) = p'' ++ (i'' ++ s'') → (i'' == i) = true → p'.length ≤ p''.length

Tactic:
intro p'' i'' s'' h₃ h₄

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
p'' i'' s'' : List α
h₃ : p' ++ (i' ++ s) = p'' ++ (i'' ++ s'')
h₄ : (i'' == i) = true
⊢ p'.length ≤ p''.length

Proof state:
case h_1.mpr
α : Type u_1
inst✝ : BEq α
i acc p s x✝¹ x✝ : List α
⊢ (∃ p',
      p = acc.reverse ++ p' ∧
        (∃ i', (p' = [] ∧ i' = [] ∧ s = []) ∧ (i' == i) = true) ∧
          ∀ (p'' i'' s'' : List α), p'' = [] → i'' = [] → s'' = [] → (i'' == i) = true → p'.length ≤ p''.length) →
    i = [] ∧ acc.reverse = p ∧ s = []

Tactic:
rintro ⟨p', rfl, ⟨_, ⟨rfl, rfl, rfl⟩, h⟩, w⟩

Result:
case h_1.mpr.intro.intro.intro.intro.intro.intro.intro
α : Type u_1
inst✝ : BEq α
i acc x✝¹ x✝ : List α
w : ∀ (p'' i'' s'' : List α), p'' = [] → i'' = [] → s'' = [] → (i'' == i) = true → [].length ≤ p''.length
h : ([] == i) = true
⊢ i = [] ∧ acc.reverse = acc.reverse ++ [] ∧ [] = []

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

Tactic:
intro p'' i'' s'' h₁ h₂

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

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

Tactic:
rw [cons_eq_append_iff] at h₁

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