MIT18 404f20 Lec3
MIT18 404f20 Lec3
840 Lecture 3
Last time:
- Nondeterminism
- NFA → DFA
- Closure under ∘ and ∗
- Regular expressions → finite automata
&
Regular Finite
expression " automaton
Recall: we did a ∪ ab ∗ as an example
Today’s Theorem: If # is regular then # = % " for some regular expr "
Proof: Give conversion DFA & → "
WAIT! Need new concept first.
2
Generalized NFA
Defn: A Generalized Nondeterministic Finite Automaton (GNFA) is
similar to an NFA, but allows regular expressions as transition labels
a a∗ b ∗
!1 ab
#1 #2
b For convenience we will assume:
ε - One accept state, separate from the start state
∅
- One arrow from each state to each state, except
a∪b aab
a) only exiting the start state
#3
ε #4 b) only entering the accept state
3
GNFA → Regular Expressions
Lemma: Every GNFA ! has an equivalent regular expression "
Proof: By induction on the number of states # of !
Basis (# = 2):
(
!= Remember: ! is in special form
Let " = (
Induction step (# > 2): Assume Lemma true for # − 1 states and prove for # states
IDEA: Convert #-state GNFA to equivalent # − 1 -state GNFA
GNFA GNFA
# states # − 1 states
4
!-state GNFA → (!—1)-state GNFA
Check-in 3.1
$ (* $
() showed(+how to convert GNFAs to regular expressions
We just 1. Pick any state $ except
but%&our goal was to%' show that how to
%& convert DFAs%to
'
the start and accept states.
(, () (* ∗ (+ ∪ (,
regular expressions. How do we finish our goal? 2. Remove $.
(a) Show how to convert DFAs to GNFAs 3. Repair the damage by
(b) Show how to convert GNFAs to DFAs recovering all paths that
(c) We are already done. DFAs are a type
! states ! − of GNFAs.
1 states went through $.
4. Make the indicated change
Thus DFAs and regular expressions are equivalent. for each pair of states %& , %' .
Check-in 3.1
5
Non-Regular Languages
How do we show a language is not regular?
- Remember, to show a language is regular, we give a DFA.
- To show a language is not regular, we must give a proof.
- It is not enough to say that you couldn’t find a DFA for it,
therefore the language isn’t regular.
0101 ∉ * 0110 ∈ *
]
6
Method for Proving Non-regularity
Pumping Lemma: For every regular language !,
there is a number " (the “pumping length”) such that
if # ∈ ! and # ≥ " then # = '() where
1) '( * ) ∈ ! for all + ≥ 0 ( * = (( ⋯ (
}
2) ( ≠ ε
3) '( ≤ " +
7
Example 1 of Proving Non-regularity
Pumping Lemma: For every regular language 1, there is a )
such that if * ∈ 1 and * ≥ ) then * = -./ where
1) -. 2 / ∈ 1 for all 3 ≥ 0 . 2 = .. ⋯ .
2) . ≠ ε
3) -. ≤ )
Let ! = 0$ 1$ & ≥ 0}
Show: ! is not regular
Proof by Contradiction:
Assume (to get a contradiction) that ! is regular.
The pumping lemma gives ) as above. Let * = 0+ 1+ ∈ !. * = 000 ⋯ 000111 ⋯ 111
Pumping lemma says that can divide * = -./ satisfying the 3 conditions. - . /
≤)
But -../ has excess 0s and thus -../ ∉ ! contradicting the pumping lemma.
Therefore our assumption (! is regular) is false. We conclude that ! is not regular.
8
Example 2 of Proving Non-regularity
Pumping Lemma: For every regular language 6, there is a "
such that if 2 ∈ 6 and 2 ≥ " then 2 = $%# where
1) $% 8 # ∈ 6 for all 9 ≥ 0 % 8 = %% ⋯ %
2) % ≠ ε
3) $% ≤ "
9
Example 3 of Proving Non-regularity
Variant: Combine closure properties with the Pumping Lemma.
10
Context Free Grammars
')
S → 0S 1
S→R
R→ε } (Substitution) Rules
In ') :
Rule: Variable → string of variables and terminals 3Check-in
rules 3.3 '3
Variables: Symbols appearing on left-hand side of rule R,S
S → RR
Example of ') generating a string
Terminals: Symbols appearing only on right-hand side 0,1 R → 0R 1
Start Variable: Top left symbol S Tree of RS → ε S Resulting
substitutions string
Grammars generate strings Check all of the strings 0that
S 1 are 0inS1%('3 ):
1. Write down start variable (a) 001101 0 S 1 00S11
2. Replace any variable according to a rule
Repeat until only terminals remain
(b) 000111
R 00R11
3. Result is the generated string (c) 1010 ε 0011 ∈ % ')
4. %(') is the language of all generated strings.
(d) ε % ' = 0- 1- / ≥ 0}
)
11 Check-in 3.3
Quick review of today
12
MIT OpenCourseWare
https://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.