Epsilon-NFA

Extended NFA with Free Moves — Same Power, More Convenience

ε
Free Moves
No input consumed
CL(q)
ε-Closure
Reachable via ε*
RE
Thompson’s
Regex → ε-NFA

CS305 — Formal Language Theory

Arrow keys to navigate

Big Picture: Where Does ε-NFA Fit?

All three models recognize exactly the same class of languages: the regular languages.

Key Idea

Adding ε-transitions does NOT increase the machine’s power. It only makes designing automata easier and more modular.

Analogy: Assembly vs Python

A DFA is like assembly — precise but tedious. An ε-NFA is like Python — higher-level, more expressive, but compiles down to the same computation.

Every conversion is possible:

RegEx ⟶ ε-NFA ⟶ NFA ⟶ DFA ⟶ RegEx

Motivation: Why Add ε-Transitions?

The Problem

Sometimes designing an NFA for a complex language is painful. We want to:

  • Build small machines for simple sub-languages
  • Glue them together without re-engineering
  • Translate regular expressions to automata mechanically

Analogy: LEGO Bricks

ε-transitions are LEGO connectors: snap small, tested components together into bigger machines without redesigning anything.

What is an ε-Transition?

Definition

An ε-transition allows the machine to change state without reading any input symbol. The machine “spontaneously” moves.

Key Properties

  • No input consumed — the read head stays put
  • Nondeterministic choice — the machine may or may not take the ε-move
  • Can chain — multiple ε-transitions can fire in sequence
  • Drawn as dashed arrows labeled “ε”

Common Mistake

ε is not a symbol in the alphabet Σ. It’s a special marker meaning “no input.”

Formal Definition: The 5-Tuple

An ε-NFA is E = (Q, Σ, δ, q0, F) where:

ComponentMeaning
QFinite set of states
ΣInput alphabet (ε ∉ Σ)
δQ × (Σ ∪ {ε}) → P(Q)
q0Start state (q0 ∈ Q)
FAccept states (F ⊆ Q)

The ONE Difference from NFA

NFA: δ : Q × Σ → P(Q)

ε-NFA: δ : Q × (Σ ∪ {ε}) → P(Q)

The transition function now also accepts ε as input. The transition table gets an extra column for ε.

Example Transition Table

abε
→ q0{q1}
q1{q2}
*q2

The ε column is new — it tells us where the machine can go for free.

Don’t Add ε to Σ

ε is never in the alphabet. The transition function’s domain is extended to include ε, but Σ stays the same.

Example: An ε-NFA

Build an ε-NFA for L = { strings over {a,b} that start with ‘a’ or end with ‘b’ or are empty }.

Transition Table

abε
→ *q0{q1, q3}
*q1{q2}
*q2{q2}{q2}
q3{q3}{q3, q4}
*q4

Modular Design

q1-q2 handles “starts with a”. q3-q4 handles “ends with b”. q0 uses ε to choose which sub-machine to enter.

ε-Closure: CL(q)

The ε-closure of state q is the set of all states reachable from q by following zero or more ε-transitions.

Formal Definition

CL(q) is the smallest set such that:

  • Base: q ∈ CL(q) — always reachable from yourself via zero ε-moves
  • Induction: If p ∈ CL(q) and r ∈ δ(p, ε), then r ∈ CL(q)

Analogy: Wormhole Network

Each ε-transition is a wormhole. CL(q) is everywhere you can reach from q using only wormholes (no fuel needed). You always include your starting location!

Don’t Forget!

A state is always in its own ε-closure. CL(q) always contains q itself.

Interactive ε-Closure Explorer

Click a state to watch BFS discover its ε-closure step by step.

BFS Algorithm

ECLOSE(q):
  result = {q}
  queue = [q]
  while queue not empty:
    p = dequeue()
    for r in δ(p, ε):
      if r not in result:
        result ∪= {r}
        enqueue(r)
  return result

Key Insight

ε-closure is just graph reachability. The ε-transitions form a directed graph; CL(q) = all nodes reachable from q.

ε-Closure for Sets: CL(S)

We often need the ε-closure of a set of states, not just one state.

Definition

For a set of states S ⊆ Q:

CL(S) = ⋃q ∈ S CL(q)

Just take the union of every individual ε-closure.

Analogy

After each “real” step (reading a symbol), all your tokens teleport through every wormhole they can reach. You always “expand” via ε before and after reading input.

Extended Transition Function: δ̂

Tells us the set of states reachable from q after reading string w, with ε-closures baked in.

Recursive Definition

Base case:

δ̂(q, ε) = CL(q)

On empty input, reach anything via ε.

Inductive case: For w = xa:

δ̂(q, xa) = CL( ⋃p ∈ δ̂(q,x) δ(p, a) )

Process x to get states, follow ‘a’ from each, then ε-close the result.

Difference from NFA

In a plain NFA: δ̂(q, ε) = {q}.
In ε-NFA: δ̂(q, ε) = CL(q), which may include many states!

Interactive ε-NFA Simulator

ε-NFA for L = {“ab”} ∪ {“b”}: type a string and step through processing.

ε: q0→{q1,q4} | a: q1→q2 | b: q2→q3, q4→q5 | F={q3,q5}

Active: --
Input: --

Challenge: Predict the ε-Closure

ε-edges: p→q, p→s, q→r, s→t, t→r | Regular: r—a→u

Loading...
Question 1 / 3

Acceptance in ε-NFA

Definition

ε-NFA E accepts string w iff:

δ̂(q0, w) ∩ F ≠ ∅

After processing w (with all ε-closures), at least one final state is an accept state.

The language recognized by E:

L(E) = { w ∈ Σ* | δ̂(q0, w) ∩ F ≠ ∅ }

The Empty String Subtlety

Even if q0 is NOT an accept state, the ε-NFA might still accept ε! If any state in CL(q0) is an accept state, then ε ∈ L(E).

Converting ε-NFA to Ordinary NFA

We can eliminate all ε-transitions to get an equivalent ordinary NFA.

The Algorithm

Given ε-NFA E = (Q, Σ, δE, q0, F), build NFA N = (Q, Σ, δN, q0, F′):

  1. New transitions: For each q, a:
    δN(q, a) = CL( δE( CL(q), a ) )
    ε-close q → follow a → ε-close result
  2. New accept states:
    F′ = { q ∈ Q | CL(q) ∩ F ≠ ∅ }
    Any state whose ε-closure touches F
  3. Same start state: q0

Challenge: Fix the Bug in This Conversion

ε-NFA Reference

abε
→ q0{q1}
q1{q2}
q2{q3}
*q3{q4}
q4

Student’s NFA (has ONE bug)

ab
→ q0{q2,q3}
q1{q2,q3}
*q2{q4}
*q3{q4}
q4

Student also marked F′ = {q2, q3}.

Click the buggy cell in the table above.

Interactive: ε-NFA → NFA Conversion

ε-NFA: accepts “ab” or “b”

abε
→ q0{q1, q4}
q1{q2}
q2{q3}
*q3
q4{q5}
*q5

NFA Being Built

Step 0
ab
→ q0----
q1----
q2----
*q3----
q4----
*q5----

Converting ε-NFA Directly to DFA

Skip the intermediate NFA — go straight from ε-NFA to DFA using modified subset construction.

Modified Subset Construction

  1. Start state: CL(q0) — not just {q0}!
  2. For each DFA state S and symbol a:
    δDFA(S, a) = CL( ⋃q ∈ S δ(q, a) )
    Move on a, then ε-close
  3. Accept states: Any S where S ∩ F ≠ ∅
  4. Repeat until no new DFA states appear

Same Old Subset Construction

It’s the algorithm you already know from NFA → DFA, except you wrap every intermediate result in CL(). Think: “subset construction wearing ε-closure glasses.”

Interactive: ε-NFA → DFA Subset Construction

ε-NFA: accepts “ab”

abε
→ q0{q1}
q1{q2}
q2{q3}
*q3

DFA Being Built

Step 0
DFA Stateε-NFA StatesabAccept?

Why ε-NFA Matters: Thompson’s Construction

Every regex operator maps to an ε-NFA pattern. This is how grep, lex, and regex engines work.

The Three Patterns

Union: R1 | R2

New start ⟶ ε to both sub-machines. Both final states ⟶ ε to new accept.

Concatenation: R1 R2

Final of R1 ⟶ ε to start of R2. Chain them together.

Kleene Star: R*

New start (also accept) ⟶ ε to R. Final of R ⟶ ε back to start. Handles zero repetitions.

The Big Win

ε-transitions let us compose automata like functions. Build small, test small, combine freely. This is the foundation of practical regex engines.

Challenge: Which Conversion Path?

For each scenario, pick the best conversion approach.

Scenario 1

“I have an ε-NFA and need a DFA for a hardware implementation.”

Scenario 2

“I need to prove that (a|b)*a accepts the same strings as my DFA.”

Scenario 3

“I want to combine three separate NFAs for L1, L2, L3 into one machine for L1∪L2∪L3.”

Summary & Cheat Sheet

Core Concepts

ConceptDefinition
ε-transitionMove without consuming input
CL(q)All states reachable from q via ε*
CL(S)∪ CL(q) for all q in S
δ̂(q,ε)= CL(q)
δ̂(q,xa)= CL( δ( δ̂(q,x), a ) )
Accepts wδ̂(q0,w) ∩ F ≠ ∅

Conversion Cheat Sheet

ε-NFA → NFA:
  δ_N(q,a) = CL( δ_E( CL(q), a ) )
  F' = { q | CL(q) ∩ F ≠ ∅ }

ε-NFA → DFA (direct):
  Start = CL(q0)
  δ_DFA(S,a) = CL( ∪ δ(q,a) for q∈S )
  Accept if S ∩ F ≠ ∅

Quiz: Multiple Choice

Q1: Complexity

Converting an ε-NFA with n states to a DFA can produce at most how many states?

Q2: Acceptance

An ε-NFA has q0 ∉ F but CL(q0) ∩ F ≠ ∅. Does it accept ε?

Q3: ε-Closure

If δ(q, ε) = ∅ for all states q, what is every CL(q)?

Quiz: Trace δ̂(q0, “ab”)

ε-NFA

abε
→ q0{q1}
q1{q2}{q3}
q2{q3}
*q3

Fill in each step of δ̂(q0, “ab”):

Step 0: CL(q0) =
Step 1: Read “a” → δ(CL(q0), a) = → CL =
Step 2: Read “b” → δ(…, b) = → CL =
Accept?

Quiz: Does This ε-NFA Accept?

ε: q0→{q1,q4} | a: q1→q2 | b: q2→q3, q4→q5 | F={q3,q5}

Loading...