File: Mathlib/Computability/NFA.lean

full_name: NFA.accept
code: /-- An NFA is a set of states (`σ`), a transition function from state to state labelled by the
  alphabet (`step`), a set of starting states (`start`) and a set of acceptance states (`accept`).
  Note the transition function sends a state to a `Set` of states. These are the states that it
  may be sent to. -/
structure NFA (α : Type u) (σ : Type v) where
  step : σ → α → Set σ
  start : Set σ
  accept : Set σ
goal: Set σ

full_name: NFA.start
code: /-- An NFA is a set of states (`σ`), a transition function from state to state labelled by the
  alphabet (`step`), a set of starting states (`start`) and a set of acceptance states (`accept`).
  Note the transition function sends a state to a `Set` of states. These are the states that it
  may be sent to. -/
structure NFA (α : Type u) (σ : Type v) where
  step : σ → α → Set σ
  start : Set σ
  accept : Set σ
goal: Set σ

full_name: NFA.step
code: /-- An NFA is a set of states (`σ`), a transition function from state to state labelled by the
  alphabet (`step`), a set of starting states (`start`) and a set of acceptance states (`accept`).
  Note the transition function sends a state to a `Set` of states. These are the states that it
  may be sent to. -/
structure NFA (α : Type u) (σ : Type v) where
  step : σ → α → Set σ
  start : Set σ
  accept : Set σ
goal: σ → α → Set σ

full_name: NFA
code: /-- An NFA is a set of states (`σ`), a transition function from state to state labelled by the
  alphabet (`step`), a set of starting states (`start`) and a set of acceptance states (`accept`).
  Note the transition function sends a state to a `Set` of states. These are the states that it
  may be sent to. -/
structure NFA (α : Type u) (σ : Type v) where
  step : σ → α → Set σ
  start : Set σ
  accept : Set σ
goal: Type (max u v)

full_name: NFA.instInhabited
code: instance : Inhabited (NFA α σ) 
goal: Inhabited (NFA α σ)

full_name: NFA.stepSet
code: /-- `M.stepSet S a` is the union of `M.step s a` for all `s ∈ S`. -/
def stepSet (S : Set σ) (a : α) : Set σ 
goal: Set σ

full_name: NFA.mem_stepSet
code: theorem mem_stepSet (s : σ) (S : Set σ) (a : α) : s ∈ M.stepSet S a ↔ ∃ t ∈ S, s ∈ M.step t a 
goal: s ∈ M.stepSet S a ↔ ∃ t ∈ S, s ∈ M.step t a

full_name: NFA.stepSet_empty
code: @[simp]
theorem stepSet_empty (a : α) : M.stepSet ∅ a = ∅ 
goal: M.stepSet ∅ a = ∅

full_name: NFA.evalFrom
code: /-- `M.evalFrom S x` computes all possible paths though `M` with input `x` starting at an element
  of `S`. -/
def evalFrom (start : Set σ) : List α → Set σ 
goal: List α → Set σ

full_name: NFA.evalFrom_nil
code: @[simp]
theorem evalFrom_nil (S : Set σ) : M.evalFrom S [] = S 
goal: M.evalFrom S [] = S

full_name: NFA.evalFrom_singleton
code: @[simp]
theorem evalFrom_singleton (S : Set σ) (a : α) : M.evalFrom S [a] = M.stepSet S a 
goal: M.evalFrom S [a] = M.stepSet S a

full_name: NFA.evalFrom_append_singleton
code: @[simp]
theorem evalFrom_append_singleton (S : Set σ) (x : List α) (a : α) :
    M.evalFrom S (x ++ [a]) = M.stepSet (M.evalFrom S x) a 
goal: M.evalFrom S (x ++ [a]) = M.stepSet (M.evalFrom S x) a

full_name: NFA.eval
code: /-- `M.eval x` computes all possible paths though `M` with input `x` starting at an element of
  `M.start`. -/
def eval : List α → Set σ 
goal: List α → Set σ

full_name: NFA.eval_nil
code: @[simp]
theorem eval_nil : M.eval [] = M.start 
goal: M.eval [] = M.start

full_name: NFA.eval_singleton
code: @[simp]
theorem eval_singleton (a : α) : M.eval [a] = M.stepSet M.start a 
goal: M.eval [a] = M.stepSet M.start a

full_name: NFA.eval_append_singleton
code: @[simp]
theorem eval_append_singleton (x : List α) (a : α) : M.eval (x ++ [a]) = M.stepSet (M.eval x) a 
goal: M.eval (x ++ [a]) = M.stepSet (M.eval x) a

full_name: NFA.accepts
code: /-- `M.accepts` is the language of `x` such that there is an accept state in `M.eval x`. -/
def accepts : Language α 
goal: Language α

full_name: NFA.mem_accepts
code: theorem mem_accepts {x : List α} : x ∈ M.accepts ↔ ∃ S ∈ M.accept, S ∈ M.evalFrom M.start x 
goal: x ∈ M.accepts ↔ ∃ S ∈ M.accept, S ∈ M.evalFrom M.start x

full_name: NFA.toDFA
code: /-- `M.toDFA` is a `DFA` constructed from an `NFA` `M` using the subset construction. The
  states is the type of `Set`s of `M.state` and the step function is `M.stepSet`. -/
def toDFA : DFA α (Set σ) 
goal: DFA α (Set σ)

full_name: NFA.toDFA_correct
code: @[simp]
theorem toDFA_correct : M.toDFA.accepts = M.accepts 
goal: M.toDFA.accepts = M.accepts

full_name: NFA.pumping_lemma
code: theorem pumping_lemma [Fintype σ] {x : List α} (hx : x ∈ M.accepts)
    (hlen : Fintype.card (Set σ) ≤ List.length x) :
    ∃ a b c,
      x = a ++ b ++ c ∧
        a.length + b.length ≤ Fintype.card (Set σ) ∧ b ≠ [] ∧ {a} * {b}∗ * {c} ≤ M.accepts 
goal: ∃ a b c, x = a ++ b ++ c ∧ a.length + b.length ≤ Fintype.card (Set σ) ∧ b ≠ [] ∧ {a} * {b}∗ * {c} ≤ M.accepts

full_name: DFA.toNFA_step
code: /-- `M.toNFA` is an `NFA` constructed from a `DFA` `M` by using the same start and accept
  states and a transition function which sends `s` with input `a` to the singleton `M.step s a`. -/
@[simps] def toNFA (M : DFA α σ') : NFA α σ' 
goal: M.toNFA.step s a = {M.step s a}

full_name: DFA.toNFA_accept
code: /-- `M.toNFA` is an `NFA` constructed from a `DFA` `M` by using the same start and accept
  states and a transition function which sends `s` with input `a` to the singleton `M.step s a`. -/
@[simps] def toNFA (M : DFA α σ') : NFA α σ' 
goal: M.toNFA.accept = M.accept

full_name: DFA.toNFA
code: /-- `M.toNFA` is an `NFA` constructed from a `DFA` `M` by using the same start and accept
  states and a transition function which sends `s` with input `a` to the singleton `M.step s a`. -/
@[simps] def toNFA (M : DFA α σ') : NFA α σ' 
goal: NFA α σ'

full_name: DFA.toNFA_start
code: /-- `M.toNFA` is an `NFA` constructed from a `DFA` `M` by using the same start and accept
  states and a transition function which sends `s` with input `a` to the singleton `M.step s a`. -/
@[simps] def toNFA (M : DFA α σ') : NFA α σ' 
goal: M.toNFA.start = {M.start}

full_name: DFA.toNFA_evalFrom_match
code: @[simp]
theorem toNFA_evalFrom_match (M : DFA α σ) (start : σ) (s : List α) :
    M.toNFA.evalFrom {start} s = {M.evalFrom start s} 
goal: M.toNFA.evalFrom {start} s = {M.evalFrom start s}

full_name: DFA.toNFA_correct
code: @[simp]
theorem toNFA_correct (M : DFA α σ) : M.toNFA.accepts = M.accepts 
goal: M.toNFA.accepts = M.accepts