COMS W3261
Computer Science Theory
Lecture 7: September 30, 2009
Constructing an NFA from a Regular Expression
1. Outline
- Review
- From regular expressions to ε-NFA's
- Algebraic laws for regular expressions
- The pumping lemma for regular languages
2. Review
- From DFA's to regular expressions
3. From RE's to ε-NFA's
- Theorem: If L = L(R) for some regular expression R, then there is
an ε-NFA N such that L = L(N).
- Proof: See HMU, Sect. 3.2.1, pp. 93-97.
- The proof is in the form of an algorithm that takes as input
a regular expression R of length n and inductively constructs from
it an equivalent ε-NFA that has
- exactly one start state and one final state
- at most 2n states
- no arcs coming into its start state
- no arcs leaving its final state
- at most two arcs leaving any nonfinal state
4. Algebraic Laws for Regular Expressions
- Algebraic laws can be used to simplify regular expressions
- Here are some of the most important algebraic identities for regular expressions
- Union is commutative: L + M = M + L
- Union is associative: (L + M) + N = L + (M + N)
- Concatenation is associative: (LM)N = L(MN)
- ∅ is the identity for union: ∅ + L = L + ∅ = L
- ε is the identity for concatenation:
εL = Lε = L
- ∅ is the annihilator for concatenation:
∅L = L∅ = ∅
- Concatenation left distributes over union: L(M + N) = LM + LN
- Concatenation right distributes over union: (M + N)L = ML + NL
- Union is idempotent: L + L = L
- L** = L*
- ∅* = ε
- ε* = ε
5. The Pumping Lemma for Regular Languages
- The Pumping Lemma: For every nonfinite regular language L,
there exists a constant n that depends on L such that
for all w in L with |w| ≥ n, there exists a decomposition
of w into xyz such that
- y ≠ ε,
- |xy| ≤ n, and
- for all k ≥ 0, the string xykz is in L.
- Proof: See HMU, p. 129.
6. Applications of the Pumping Lemma
- One important use of the pumping lemma is to prove some
languages are not regular.
- Example: The language L consisting of all strings of a's and b's
of the form aibi, i ≥ 0, is not regular.
- The proof will be by contradiction. Assume L is regular.
Then by the pumping lemma there is a constant n associated with L
such that for all w in L with |w| ≥ n, w can be written as xyz
such that
- y ≠ ε,
- |xy| ≤ n, and
- for all k ≥ 0, the string xykz is in L.
- Since |xy| ≤ n, xy = am for some 0 < m ≤ n.
- Setting k = 0, condition (3) of the pumping lemma says xz must also be
in L.
- But xz is of the form apbn, where p < n.
- This contradicts the conclusion that xz must be in L.
7. Practice Problems
- Convert the regular expression a(a+b)*b into an equivalent ε-NFA.
- Convert your ε-NFA into an equivalent DFA.
- Show that the language consisting of strings of a's where
the number of a's is a perfect square is not regular.
- Show that the language consisting of strings of balanced
parentheses is not regular.
8. Reading Assignment
aho@cs.columbia.edu