Theorem: Regex.VM.lower_inv_εClosure (RegexCorrectness/VM/Auxiliary.lean)

State before:
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
h : εClosure nfa pos next currentSave matched saveSlots stack = (matched', next', saveSlots')
inv : LowerInvεClosure nfa next stack
⊢ LowerInvεClosure nfa next' #[]
Tactic:
unfold εClosure at h
State after:
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 :
  (if hemp : stack.isEmpty = true then (matched, next, saveSlots)
    else
      let entry := stack.back' hemp;
      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' #[]

State before:
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 :
  (if hemp : stack.isEmpty = true then (matched, next, saveSlots)
    else
      let entry := stack.back' hemp;
      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' #[]
Tactic:
split at h
State after:
case inl
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 : (matched, next, saveSlots) = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]

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' #[]

State before:
case inl
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 : (matched, next, saveSlots) = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]

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' #[]
Tactic:
next hemp =>
  have : stack = #[] := Array.isEmpty_iff.mp hemp
  subst this
  have : next = next' := by
    simp at h
    simp only [h]
  subst this
  exact inv
State after:
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' #[]

State before:
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' #[]
Tactic:
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'
State after:
no goals

State before:
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
hemp : stack.isEmpty = true
h : (matched, next, saveSlots) = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]
Tactic:
have : stack = #[] := Array.isEmpty_iff.mp hemp
State after:
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
hemp : stack.isEmpty = true
h : (matched, next, saveSlots) = (matched', next', saveSlots')
this : stack = #[]
⊢ LowerInvεClosure nfa next' #[]

State before:
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
hemp : stack.isEmpty = true
h : (matched, next, saveSlots) = (matched', next', saveSlots')
this : stack = #[]
⊢ LowerInvεClosure nfa next' #[]
Tactic:
subst this
State after:
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
matched' : Option (Array (Option String.Pos))
next' : SparseSet nfa.nodes.size
saveSlots' : Data.Vec (Array (Option String.Pos)) nfa.nodes.size
h : (matched, next, saveSlots) = (matched', next', saveSlots')
inv : LowerInvεClosure nfa next #[]
hemp : #[].isEmpty = true
⊢ LowerInvεClosure nfa next' #[]

State before:
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
matched' : Option (Array (Option String.Pos))
next' : SparseSet nfa.nodes.size
saveSlots' : Data.Vec (Array (Option String.Pos)) nfa.nodes.size
h : (matched, next, saveSlots) = (matched', next', saveSlots')
inv : LowerInvεClosure nfa next #[]
hemp : #[].isEmpty = true
⊢ LowerInvεClosure nfa next' #[]
Tactic:
have : next = next' := by
  simp at h
  simp only [h]
State after:
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
matched' : Option (Array (Option String.Pos))
next' : SparseSet nfa.nodes.size
saveSlots' : Data.Vec (Array (Option String.Pos)) nfa.nodes.size
h : (matched, next, saveSlots) = (matched', next', saveSlots')
inv : LowerInvεClosure nfa next #[]
hemp : #[].isEmpty = true
this : next = next'
⊢ LowerInvεClosure nfa next' #[]

State before:
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
matched' : Option (Array (Option String.Pos))
next' : SparseSet nfa.nodes.size
saveSlots' : Data.Vec (Array (Option String.Pos)) nfa.nodes.size
h : (matched, next, saveSlots) = (matched', next', saveSlots')
inv : LowerInvεClosure nfa next #[]
hemp : #[].isEmpty = true
this : next = next'
⊢ LowerInvεClosure nfa next' #[]
Tactic:
subst this
State after:
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
matched' : Option (Array (Option String.Pos))
saveSlots' : Data.Vec (Array (Option String.Pos)) nfa.nodes.size
inv : LowerInvεClosure nfa next #[]
hemp : #[].isEmpty = true
h : (matched, next, saveSlots) = (matched', next, saveSlots')
⊢ LowerInvεClosure nfa next #[]

State before:
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
matched' : Option (Array (Option String.Pos))
saveSlots' : Data.Vec (Array (Option String.Pos)) nfa.nodes.size
inv : LowerInvεClosure nfa next #[]
hemp : #[].isEmpty = true
h : (matched, next, saveSlots) = (matched', next, saveSlots')
⊢ LowerInvεClosure nfa next #[]
Tactic:
exact inv
State after:
no goals

State before:
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
matched' : Option (Array (Option String.Pos))
next' : SparseSet nfa.nodes.size
saveSlots' : Data.Vec (Array (Option String.Pos)) nfa.nodes.size
h : (matched, next, saveSlots) = (matched', next', saveSlots')
inv : LowerInvεClosure nfa next #[]
hemp : #[].isEmpty = true
⊢ next = next'
Tactic:
simp at h
State after:
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
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 #[]
hemp : #[].isEmpty = true
h : matched = matched' ∧ next = next' ∧ saveSlots = saveSlots'
⊢ next = next'

State before:
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
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 #[]
hemp : #[].isEmpty = true
h : matched = matched' ∧ next = next' ∧ saveSlots = saveSlots'
⊢ next = next'
Tactic:
simp only [h]
State after:
no goals

State before:
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
hemp : ¬stack.isEmpty = true
h :
  (let entry := stack.back' hemp;
    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' #[]
Tactic:
simp at h
State after:
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
hemp : ¬stack.isEmpty = true
h :
  (match stack.back' hemp with
    | StackEntry.explore target => exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop
    | StackEntry.restore save => εClosure nfa pos next save matched saveSlots stack.pop) =
    (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]

State before:
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
hemp : ¬stack.isEmpty = true
h :
  (match stack.back' hemp with
    | StackEntry.explore target => exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop
    | StackEntry.restore save => εClosure nfa pos next save matched saveSlots stack.pop) =
    (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]
Tactic:
have : stack.pop.size < stack.size := Array.lt_size_of_pop_of_not_empty _ (by assumption)
State after:
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
hemp : ¬stack.isEmpty = true
h :
  (match stack.back' hemp with
    | StackEntry.explore target => exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop
    | StackEntry.restore save => εClosure nfa pos next save matched saveSlots stack.pop) =
    (matched', next', saveSlots')
this : stack.pop.size < stack.size
⊢ LowerInvεClosure nfa next' #[]

State before:
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
hemp : ¬stack.isEmpty = true
h :
  (match stack.back' hemp with
    | StackEntry.explore target => exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop
    | StackEntry.restore save => εClosure nfa pos next save matched saveSlots stack.pop) =
    (matched', next', saveSlots')
this : stack.pop.size < stack.size
⊢ LowerInvεClosure nfa next' #[]
Tactic:
split at h
State after:
case h_1
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target✝ : Fin nfa.nodes.size
heq✝ : stack.back' hemp = StackEntry.explore target✝
h : exploreεClosure nfa pos next currentSave matched saveSlots target✝ stack.pop = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]

case h_2
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq✝ : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]

State before:
case h_1
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target✝ : Fin nfa.nodes.size
heq✝ : stack.back' hemp = StackEntry.explore target✝
h : exploreεClosure nfa pos next currentSave matched saveSlots target✝ stack.pop = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]

case h_2
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq✝ : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]
Tactic:
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'
State after:
case h_2
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq✝ : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]

State before:
case h_2
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq✝ : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]
Tactic:
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'
State after:
no goals

State before:
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
hemp : ¬stack.isEmpty = true
h :
  (match stack.back' hemp with
    | StackEntry.explore target => exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop
    | StackEntry.restore save => εClosure nfa pos next save matched saveSlots stack.pop) =
    (matched', next', saveSlots')
⊢ ¬stack.isEmpty = true
Tactic:
assumption
State after:
no goals

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]
Tactic:
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)
State after:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
inv' : LowerInvExploreεClosure nfa next target stack.pop
⊢ LowerInvεClosure nfa next' #[]

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
inv' : LowerInvExploreεClosure nfa next target stack.pop
⊢ LowerInvεClosure nfa next' #[]
Tactic:
exact lower_inv_exploreεClosure h inv'
State after:
no goals

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
⊢ LowerInvExploreεClosure nfa next target stack.pop
Tactic:
intro i j hi hj
State after:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
⊢ j ∈ next ∨ j = target ∨ StackEntry.explore j ∈ stack.pop

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
⊢ j ∈ next ∨ j = target ∨ StackEntry.explore j ∈ stack.pop
Tactic:
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)
State after:
no goals

State before:
case inl
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hnext : j ∈ next
⊢ j ∈ next ∨ j = target ∨ StackEntry.explore j ∈ stack.pop
Tactic:
exact .inl hnext
State after:
no goals

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
⊢ j ∈ next ∨ j = target ∨ StackEntry.explore j ∈ stack.pop
Tactic:
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)
State after:
no goals

State before:
case inr.inl
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack✝ : StackEntry.explore j ∈ stack
hstack : StackEntry.explore j ∈ stack.pop
⊢ j ∈ next ∨ j = target ∨ StackEntry.explore j ∈ stack.pop
Tactic:
exact .inr (.inr hstack)
State after:
no goals

State before:
case inr.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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
heq' : StackEntry.explore j = stack.back' hemp
⊢ j ∈ next ∨ j = target ∨ StackEntry.explore j ∈ stack.pop
Tactic:
rw [heq] at heq'
State after:
case inr.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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
heq' : StackEntry.explore j = StackEntry.explore target
⊢ j ∈ next ∨ j = target ∨ StackEntry.explore j ∈ stack.pop

State before:
case inr.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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
heq' : StackEntry.explore j = StackEntry.explore target
⊢ j ∈ next ∨ j = target ∨ StackEntry.explore j ∈ stack.pop
Tactic:
have : j = target := by
  simp at heq'
  exact heq'
State after:
case inr.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
hemp : ¬stack.isEmpty = true
this✝ : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
heq' : StackEntry.explore j = StackEntry.explore target
this : j = target
⊢ j ∈ next ∨ j = target ∨ StackEntry.explore j ∈ stack.pop

State before:
case inr.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
hemp : ¬stack.isEmpty = true
this✝ : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
heq' : StackEntry.explore j = StackEntry.explore target
this : j = target
⊢ j ∈ next ∨ j = target ∨ StackEntry.explore j ∈ stack.pop
Tactic:
exact .inr (.inl this)
State after:
no goals

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
heq' : StackEntry.explore j = StackEntry.explore target
⊢ j = target
Tactic:
simp at heq'
State after:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
heq' : j = target
⊢ j = target

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
target : Fin nfa.nodes.size
heq : stack.back' hemp = StackEntry.explore target
h : exploreεClosure nfa pos next currentSave matched saveSlots target stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
heq' : j = target
⊢ j = target
Tactic:
exact heq'
State after:
no goals

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next' #[]
Tactic:
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
State after:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
inv' : LowerInvεClosure nfa next stack.pop
⊢ LowerInvεClosure nfa next' #[]

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
inv' : LowerInvεClosure nfa next stack.pop
⊢ LowerInvεClosure nfa next' #[]
Tactic:
exact lower_inv_εClosure h inv'
State after:
no goals

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
⊢ LowerInvεClosure nfa next stack.pop
Tactic:
intro i j hi hj
State after:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
⊢ j ∈ next ∨ StackEntry.explore j ∈ stack.pop

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
⊢ j ∈ next ∨ StackEntry.explore j ∈ stack.pop
Tactic:
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
State after:
no goals

State before:
case inl
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hnext : j ∈ next
⊢ j ∈ next ∨ StackEntry.explore j ∈ stack.pop
Tactic:
exact .inl hnext
State after:
no goals

State before:
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
⊢ j ∈ next ∨ StackEntry.explore j ∈ stack.pop
Tactic:
cases Array.mem_pop_or_eq_of_mem _ _ hemp hstack with
| inl hstack => exact .inr hstack
| inr heq' =>
  rw [heq] at heq'
  contradiction
State after:
no goals

State before:
case inr.inl
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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack✝ : StackEntry.explore j ∈ stack
hstack : StackEntry.explore j ∈ stack.pop
⊢ j ∈ next ∨ StackEntry.explore j ∈ stack.pop
Tactic:
exact .inr hstack
State after:
no goals

State before:
case inr.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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
heq' : StackEntry.explore j = stack.back' hemp
⊢ j ∈ next ∨ StackEntry.explore j ∈ stack.pop
Tactic:
rw [heq] at heq'
State after:
case inr.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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
heq' : StackEntry.explore j = StackEntry.restore save✝
⊢ j ∈ next ∨ StackEntry.explore j ∈ stack.pop

State before:
case inr.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
hemp : ¬stack.isEmpty = true
this : stack.pop.size < stack.size
entry✝ : StackEntry nfa.nodes.size
save✝ : Array (Option String.Pos)
heq : stack.back' hemp = StackEntry.restore save✝
h : εClosure nfa pos next save✝ matched saveSlots stack.pop = (matched', next', saveSlots')
i j : Fin nfa.nodes.size
hi : i ∈ next
hj : ↑j ∈ nfa.εStep ↑i
hstack : StackEntry.explore j ∈ stack
heq' : StackEntry.explore j = StackEntry.restore save✝
⊢ j ∈ next ∨ StackEntry.explore j ∈ stack.pop
Tactic:
contradiction
State after:
no goals