0% found this document useful (0 votes)
70 views13 pages

MIT18 404f20 Lec3

Uploaded by

Zuci Dark
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views13 pages

MIT18 404f20 Lec3

Uploaded by

Zuci Dark
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

18.404/6.

840 Lecture 3

Last time:
- Nondeterminism
- NFA → DFA
- Closure under ∘ and ∗
- Regular expressions → finite automata

Today: (Sipser §1.4 – §2.1)


- Finite automata → regular expressions
- Proving languages aren’t regular
- Context free grammars

We start counting Check-ins today.


Review your email from Canvas.

Homework due Thursday.


1
DFAs → Regular Expressions
Recall Theorem: If " is a regular expressipn and # = % " then # is regular
Proof: Conversion " → NFA & → DFA &′

&
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

We can easily modify a GNFA to have this special form.

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.

Two examples: Here Σ = {0,1}.


1. Let ( = ) ) has equal numbers of 0s and 1s}
Intuition: ( is not regular because DFAs cannot count unboundedly.
2. Let * = ) ) has equal numbers of 01 and 10 substrings}
]
]

0101 ∉ * 0110 ∈ *
]

Intuition: * is not regular because DFAs cannot count unboundedly.


However * is regular! Sometimes intuition works, but it can also be wrong.
Moral: You need to give a proof.

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) '( ≤ " +

Informally: ! is regular → every long string in ! can


Check-in 3.2be pumped and the result stays in !.
Proof: Let DFA 0 recognize !. Let " be thePumping
The number ofLemma
states in depends
0. Pick # on where
∈ !the # ≥ ".
fact that
' ( ) if 0 has0" states and it
( runs for more than " steps
#=
12 12
then 0 will enter some state at least twice.
0 will repeat a state 12 when reading #We call that fact:
12 The path that 0 foll
' ) when reading #.
because # is so long. (a) The Pigeonhole Principle
' ( ( ) (b) Burnside's Counting Theorem
12 12 12 is also(c) The Coronavirus Calculation
accepted Check-in 3.2

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) $% ≤ "

Let & = (( ( ∈ Σ ∗ } . Say Σ ∗ = {0,1}.


Show: & is not regular 2 = 000 ⋯ 000000 ⋯ 000
$ % #
Proof by Contradiction: ≤"
% = 00
Assume (for contradiction) that & is regular.
The pumping lemma gives " as above. Need to choose 2 ∈ &. Which 2?
Try 2 = 03 03 ∈ &. But that 2 can be pumped and stay inside &. Bad choice. 2 = 000 ⋯ 001000 ⋯ 001
$ % #
Try 2 = 03 103 1 ∈ &. Show cannot be pumped 2 = $%# satisfying the 3 conditions. ≤"
$%%# ∉ & Contradiction! Therefore & is not regular.

9
Example 3 of Proving Non-regularity
Variant: Combine closure properties with the Pumping Lemma.

Let ! = # # has equal numbers of 0s and 1s}


Show: ! is not regular
Proof by Contradiction:
Assume (for contradiction) that ! is regular.
We know that 0∗1∗ is regular so ! ∩ 0∗1∗ is regular (closure under intersection).
But ) = ! ∩ 0∗1∗ and we already showed ) is not regular. Contradiction!
Therefore our assumption is false, so ! is not regular.

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

1. Conversion of DFAs to regular expressions


Summary: DFAs, NFAs, regular expressions are all equivalent
2. Proving languages not regular by using the pumping lemma
and closure properties
3. Context Free Grammars

12
MIT OpenCourseWare
https://ocw.mit.edu

18.404J / 18.4041J / 6.840J Theory of Computation


Fall 2020

For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.

You might also like