The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V32. Logic, model theory and computability

Mathlib.Computability.EpsilonNFA

60 declarations and 2 deprecated aliases. Mathlib docs · Source

Epsilon Nondeterministic Finite Automata

This file contains the definition of an epsilon Nondeterministic Finite Automaton (εNFA), a state machine which determines whether a string (implemented as a list over an arbitrary alphabet) is in a regular set by evaluating the string over every possible path, also having access to ε-transitions, which can be followed without reading a character. Since this definition allows for automata with infinite states, a Fintype instance must be supplied for true εNFA's.

Conversions between εNFA and NFA

Regex-like operations

ctor εNFA.IsPath.below.cons E0 #

∀ {α : Type u} {σ : Type v} {M : εNFA α σ} {motive : (a a_1 : σ) → (a_2 : List (Option α)) → M.IsPath a a_1 a_2 → Prop}
  (t s u : σ) (a : Option α) (x : List (Option α)) (a_1 : t ∈ M.step s a) (a_2 : M.IsPath t u x),
  εNFA.IsPath.below a_2 → motive t u x a_2 → εNFA.IsPath.below ⋯

ctor εNFA.IsPath.below.nil E0 #

∀ {α : Type u} {σ : Type v} {M : εNFA α σ} {motive : (a a_1 : σ) → (a_2 : List (Option α)) → M.IsPath a a_1 a_2 → Prop}
  (s : σ), εNFA.IsPath.below ⋯

theorem εNFA.mk.injEq E0 #

∀ {α : Type u} {σ : Type v} (step : σ → Option α → Set σ) (start accept : Set σ) (step_1 : σ → Option α → Set σ)
  (start_1 accept_1 : Set σ),
  ({ step := step, start := start, accept := accept } = { step := step_1, start := start_1, accept := accept_1 }) =
    (step = step_1 ∧ start = start_1 ∧ accept = accept_1)

def εNFA.ctorIdx E1 #

{α : Type u} → {σ : Type v} → εNFA α σ → ℕ

theorem εNFA.mk.inj E1 #

∀ {α : Type u} {σ : Type v} {step : σ → Option α → Set σ} {start accept : Set σ} {step_1 : σ → Option α → Set σ}
  {start_1 accept_1 : Set σ},
  { step := step, start := start, accept := accept } = { step := step_1, start := start_1, accept := accept_1 } →
    step = step_1 ∧ start = start_1 ∧ accept = accept_1

structure εNFA E1 #

Type u → Type v → Type (max u v)

An εNFA is a set of states (σ), a transition function from state to state labelled by the alphabet (step), a starting state (start) and a set of acceptance states (accept). Note the transition function sends a state to a Set of states and can make ε-transitions by inputting none. Since this definition allows for Automata with infinite states, a Fintype instance must be supplied for true εNFA's.

ctor εNFA.mk E0 #

{α : Type u} → {σ : Type v} → (σ → Option α → Set σ) → Set σ → Set σ → εNFA α σ

abbrev εNFA.step E1 #

{α : Type u} → {σ : Type v} → εNFA α σ → σ → Option α → Set σ

Transition function. The automaton is rendered non-deterministic by this transition function returning Set σ (rather than σ), and ε-transitions are made possible by taking Option α (rather than α).

abbrev εNFA.start E1 #

{α : Type u} → {σ : Type v} → εNFA α σ → Set σ

Starting states.

abbrev εNFA.accept E1 #

{α : Type u} → {σ : Type v} → εNFA α σ → Set σ

Set of acceptance states.

def εNFA.εClosure E1 #

{α : Type u} → {σ : Type v} → εNFA α σ → Set σ → Set σ

The εClosure of a set is the set of states which can be reached by taking a finite string of ε-transitions from an element of the set.

theorem εNFA.subset_εClosure E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) (S : Set σ), S ⊆ M.εClosure S

theorem εNFA.mem_εClosure_of_mem_step E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {S : Set σ} {s t : σ},
  t ∈ M.step s none → s ∈ M.εClosure S → t ∈ M.εClosure S

theorem εNFA.εClosure_induction E1 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {S : Set σ} {motive : (x : σ) → x ∈ M.εClosure S → Prop},
  (∀ (x : σ) (hx : x ∈ S), motive x ⋯) →
    (∀ (x y : σ) (hyx : y ∈ M.step x none) (hx : x ∈ M.εClosure S), motive x hx → motive y ⋯) →
      ∀ {x : σ} (hx : x ∈ M.εClosure S), motive x hx

An induction principle for membership of M.εClosure S. If motive holds of all elements of S and is preserved under ε-transitions, then it holds of all elements of M.εClosure S.

theorem εNFA.εClosure_min E1 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {S T : Set σ},
  S ⊆ T → (∀ x ∈ T, ∀ y ∈ M.step x none, y ∈ T) → M.εClosure S ⊆ T

M.εClosure S is the smallest set containing S which is closed under ε-transitions of M.

theorem εNFA.εClosure_empty E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ), M.εClosure ∅ = ∅

theorem εNFA.εClosure_univ E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ), M.εClosure Set.univ = Set.univ

theorem εNFA.mem_εClosure_iff_exists E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {S : Set σ} {s : σ}, s ∈ M.εClosure S ↔ ∃ t ∈ S, s ∈ M.εClosure {t}

def εNFA.stepSet E1 #

{α : Type u} → {σ : Type v} → εNFA α σ → Set σ → α → Set σ

M.stepSet S a is the union of the ε-closure of M.step s a for all s ∈ S.

theorem εNFA.mem_stepSet_iff E0 #

∀ {α : Type u} {σ : Type v} {M : εNFA α σ} {S : Set σ} {s : σ} {a : α},
  s ∈ M.stepSet S a ↔ ∃ t ∈ S, s ∈ M.εClosure (M.step t (some a))

theorem εNFA.stepSet_empty E0 #

∀ {α : Type u} {σ : Type v} {M : εNFA α σ} (a : α), M.stepSet ∅ a = ∅

def εNFA.evalFrom E1 #

{α : Type u} → {σ : Type v} → εNFA α σ → Set σ → List α → Set σ

M.evalFrom S x computes all possible paths through M with input x starting at an element of S.

theorem εNFA.evalFrom_nil E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) (S : Set σ), M.evalFrom S [] = M.εClosure S

theorem εNFA.evalFrom_singleton E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) (S : Set σ) (a : α), M.evalFrom S [a] = M.stepSet (M.εClosure S) a

theorem εNFA.evalFrom_append_singleton E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) (S : Set σ) (x : List α) (a : α),
  M.evalFrom S (x ++ [a]) = M.stepSet (M.evalFrom S x) a

theorem εNFA.evalFrom_empty E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) (x : List α), M.evalFrom ∅ x = ∅

theorem εNFA.mem_evalFrom_iff_exists E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {s : σ} {S : Set σ} {x : List α},
  s ∈ M.evalFrom S x ↔ ∃ t ∈ S, s ∈ M.evalFrom {t} x

def εNFA.eval E1 #

{α : Type u} → {σ : Type v} → εNFA α σ → List α → Set σ

M.eval x computes all possible paths through M with input x starting at an element of M.start.

theorem εNFA.eval_nil E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ), M.eval [] = M.εClosure M.start

theorem εNFA.eval_singleton E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) (a : α), M.eval [a] = M.stepSet (M.εClosure M.start) a

theorem εNFA.eval_append_singleton E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) (x : List α) (a : α), M.eval (x ++ [a]) = M.stepSet (M.eval x) a

def εNFA.accepts E1 #

{α : Type u} → {σ : Type v} → εNFA α σ → Language α

M.accepts is the language of x such that there is an accept state in M.eval x.

inductive εNFA.IsPath E1 #

{α : Type u} → {σ : Type v} → εNFA α σ → σ → σ → List (Option α) → Prop

M.IsPath represents a traversal in M from a start state to an end state by following a list of transitions in order.

theorem εNFA.isPath_iff E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) (a a_1 : σ) (a_2 : List (Option α)),
  M.IsPath a a_1 a_2 ↔ a_1 = a ∧ a_2 = [] ∨ ∃ t a_3 x, t ∈ M.step a a_3 ∧ M.IsPath t a_1 x ∧ a_2 = a_3 :: x

ctor εNFA.IsPath.nil E0 #

∀ {α : Type u} {σ : Type v} {M : εNFA α σ} (s : σ), M.IsPath s s []

ctor εNFA.IsPath.cons E0 #

∀ {α : Type u} {σ : Type v} {M : εNFA α σ} (t s u : σ) (a : Option α) (x : List (Option α)),
  t ∈ M.step s a → M.IsPath t u x → M.IsPath s u (a :: x)

theorem εNFA.isPath_nil E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {s t : σ}, M.IsPath s t [] ↔ s = t

theorem εNFA.isPath_singleton E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {s t : σ} {a : Option α}, M.IsPath s t [a] ↔ t ∈ M.step s a

theorem εNFA.IsPath.singleton E1 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {s t : σ} {a : Option α}, t ∈ M.step s a → M.IsPath s t [a]

Alias of the reverse direction of εNFA.isPath_singleton.

theorem εNFA.isPath_append E1 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {s u : σ} {x y : List (Option α)},
  M.IsPath s u (x ++ y) ↔ ∃ t, M.IsPath s t x ∧ M.IsPath t u y

theorem εNFA.mem_εClosure_iff_exists_path E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {s₁ s₂ : σ},
  s₂ ∈ M.εClosure {s₁} ↔ ∃ n, M.IsPath s₁ s₂ (List.replicate n none)

theorem εNFA.mem_evalFrom_iff_exists_path E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {s₁ s₂ : σ} {x : List α},
  s₂ ∈ M.evalFrom {s₁} x ↔ ∃ x', x'.reduceOption = x ∧ M.IsPath s₁ s₂ x'

theorem εNFA.mem_accepts_iff_exists_path E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) {x : List α},
  x ∈ M.accepts ↔ ∃ s₁ s₂ x', s₁ ∈ M.start ∧ s₂ ∈ M.accept ∧ x'.reduceOption = x ∧ M.IsPath s₁ s₂ x'

def εNFA.toNFA E1 #

{α : Type u} → {σ : Type v} → εNFA α σ → NFA α σ

M.toNFA is an NFA constructed from an εNFA M.

theorem εNFA.toNFA_evalFrom_match E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) (start : Set σ), M.toNFA.evalFrom (M.εClosure start) = M.evalFrom start

theorem εNFA.toNFA_correct E0 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ), M.toNFA.accepts = M.accepts

theorem εNFA.pumping_lemma E1 #

∀ {α : Type u} {σ : Type v} (M : εNFA α σ) [inst : Fintype σ] {x : List α},
  x ∈ M.accepts →
    Fintype.card (Set σ) ≤ x.length →
      ∃ a b c,
        x = a ++ b ++ c ∧ a.length + b.length ≤ Fintype.card (Set σ) ∧ b ≠ [] ∧ {a} * KStar.kstar {b} * {c} ≤ M.accepts

def NFA.toεNFA E1 #

{α : Type u} → {σ : Type v} → NFA α σ → εNFA α σ

M.toεNFA is an εNFA constructed from an NFA M by using the same start and accept states and transition functions.

theorem NFA.toεNFA_εClosure E0 #

∀ {α : Type u} {σ : Type v} (M : NFA α σ) (S : Set σ), M.toεNFA.εClosure S = S

theorem NFA.toεNFA_evalFrom_match E0 #

∀ {α : Type u} {σ : Type v} (M : NFA α σ) (start : Set σ), M.toεNFA.evalFrom start = M.evalFrom start

theorem NFA.toεNFA_correct E0 #

∀ {α : Type u} {σ : Type v} (M : NFA α σ), M.toεNFA.accepts = M.accepts

instance εNFA.instZero E0 #

{α : Type u} → {σ : Type v} → Zero (εNFA α σ)

instance εNFA.instOne E0 #

{α : Type u} → {σ : Type v} → One (εNFA α σ)

instance εNFA.instInhabited E0 #

{α : Type u} → {σ : Type v} → Inhabited (εNFA α σ)

theorem εNFA.step_zero E0 #

∀ {α : Type u} {σ : Type v} (s : σ) (a : Option α), εNFA.step 0 s a = ∅

theorem εNFA.step_one E0 #

∀ {α : Type u} {σ : Type v} (s : σ) (a : Option α), εNFA.step 1 s a = ∅

theorem εNFA.start_zero E0 #

∀ {α : Type u} {σ : Type v}, εNFA.start 0 = ∅

theorem εNFA.start_one E0 #

∀ {α : Type u} {σ : Type v}, εNFA.start 1 = Set.univ

theorem εNFA.accept_zero E0 #

∀ {α : Type u} {σ : Type v}, εNFA.accept 0 = ∅

theorem εNFA.accept_one E0 #

∀ {α : Type u} {σ : Type v}, εNFA.accept 1 = Set.univ

Deprecated aliases

NameNew nameSince
εNFA.εClosure.baseεNFA.subset_εClosure2026-07-07
εNFA.εClosure.stepεNFA.mem_εClosure_of_mem_step2026-07-07