next hemp =>
  simp at h
  have : stack.pop.size < stack.size := Array.lt_size_of_pop_of_not_empty _ (by assumption)
  split at h
  next _ target heq =>
    have inv' : LowerInvExploreεClosure nfa next target stack.pop := by
      intro i j hi hj
      cases inv i j hi hj with
      | inl hnext => exact .inl hnext
      | inr hstack =>
        cases Array.mem_pop_or_eq_of_mem _ _ hemp hstack with
        | inl hstack => exact .inr (.inr hstack)
        | inr heq' =>
          rw [heq] at heq'
          have : j = target := by
            simp at heq'
            exact heq'
          exact .inr (.inl this)
    exact lower_inv_exploreεClosure h inv'
  next _ _ heq =>
    have inv' : LowerInvεClosure nfa next stack.pop := by
      intro i j hi hj
      cases inv i j hi hj with
      | inl hnext => exact .inl hnext
      | inr hstack =>
        cases Array.mem_pop_or_eq_of_mem _ _ hemp hstack with
        | inl hstack => exact .inr hstack
        | inr heq' =>
          rw [heq] at heq'
          contradiction
    exact lower_inv_εClosure h inv'
case inr
nfa : NFA
pos : String.Pos
next : SparseSet nfa.nodes.size
currentSave : Array (Option String.Pos)
matched : Option (Array (Option String.Pos))
saveSlots : Data.Vec (Array (Option String.Pos)) nfa.nodes.size
stack : Array (StackEntry nfa.nodes.size)
matched' : Option (Array (Option String.Pos))
next' : SparseSet nfa.nodes.size
saveSlots' : Data.Vec (Array (Option String.Pos)) nfa.nodes.size
inv : LowerInvεClosure nfa next stack
h✝ : ¬stack.isEmpty = true
h :
  (let entry := stack.back' h✝;
    let stack' := stack.pop;
    let_fun this := ⋯;
    match entry with
    | StackEntry.explore target => exploreεClosure nfa pos next currentSave matched saveSlots target stack'
    | StackEntry.restore save => εClosure nfa pos next save matched saveSlots stack') =
    (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]
no goals