0% found this document useful (0 votes)
7 views

Lecture 3 Final

Uploaded by

Mado Saeed
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Lecture 3 Final

Uploaded by

Mado Saeed
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, 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, posted on homepage.


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 as an example

Today’s Theorem: If is regular then for some regular expr


Proof: Give conversion DFA
WAIT! Need new concept
first.
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.
GNFA Regular Expressions
Lemma: Every GNFA has an equivalent regular expression
Proof: By induction on the number of states of
Basis :
𝐺=¿ 𝑟 Remember: is in special form

Let

Induction step : Assume Lemma true for states and prove for states
IDEA: Convert -state GNFA to equivalent -state GNFA

GNFA GNFA
states states
-state GNFA (—1)-state GNFA

Check-in 3.1
𝑥 𝑟2 𝑥
𝑟 1 showed
We just 𝑟 how
3 to convert GNFAs to regular expressions 1. Pick any state except
but
𝑞our goal was 𝑞 to show that how𝑞to𝑖 convert DFAs 𝑞to𝑗 the start and accept states.
𝑖 𝑟4 𝑗 ∗
𝑟 (𝑟 2) 𝑟 3 ∪ 𝑟 4
regular expressions. How do we finish 1our 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 typestates
states of GNFAs. went through .
4. Make the indicated change
Thus DFAs and regular expressions are equivalent. for each pair of states .
Check-in 3.1
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 .


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.
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

}
2)
3) 𝑖
Informally: is regular → every long string in can be
Check-in 3.2pumped and the result stays in .
Proof: Let DFA recognize . Let be the number of states in . Pick where .
The Pumping Lemma depends on the fact that
𝑥 𝑦 𝑧 if has 𝑀 states and it runs
𝑦 for more than steps then
𝑠=¿ will enter some state at least twice.
𝑞𝑗 𝑞𝑗
We call that fact:
𝑥 𝑞𝑗 The path that follows
will repeat a state when reading 𝑧 when reading .
because is so long. (a) The Pigeonhole Principle
𝑥 𝑦 𝑦 𝑧 (b) Burnside's Counting Theorem
𝑞𝑗 𝑞𝑗 𝑞 is also(c)
𝑗
The Coronavirus Calculation
accepted Check-in 3.2
Example 1 of Proving Non-regularity
Pumping Lemma: For every regular language , there is a
such that if and then where
1) for all
2)
3)

Let
Show: is not regular
Proof by Contradiction:
Assume (to get a contradiction) that is regular.
The pumping lemma gives as above. Let . 𝑠=¿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.
Example 2 of Proving Non-regularity
Pumping Lemma: For every regular language , there is a
such that if and then where
1) for all
2)
3)

Let Say .
Show: is not regular 𝑠=¿000 ⋯ 000000 ⋯ 000
Proof by Contradiction:
𝑥𝑦 𝑧
≤𝑝 𝑦 =00
Assume (for contradiction) that is regular.
The pumping lemma gives as above. Need to choose . Which ?
Try . But that can be pumped and stay inside . Bad choice. 𝑠=¿000 ⋯ 001000 ⋯ 001
Try . Show cannot be pumped satisfying the 3 conditions.
𝑥𝑦 𝑧
≤𝑝
Contradiction! Therefore is not regular.
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 is regular so is regular (closure under intersection).
But and we already showed is not regular. Contradiction!
Therefore our assumption is false, so is not regular.
Context Free Grammars
𝐺1
S 0S1
S R
R } (Substitution) Rules

In :
3Check-in 3.3
Rule: Variable string of variables and terminals rules 𝐺 2 S RR
Variables: Symbols appearing on left-hand side of rule R,S
Example of generating a string
Terminals: Symbols appearing only on right-hand s 0,1 R 0R1
Start Variable: Top left symbol S Tree of R
S S Resulting
substitutions string
Grammars generate strings Check all of the strings 0that
S 1are 0inS1
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∈ 𝐿 ( 𝐺1)
4. is the language of all generated strings.
(d) 𝐿 ( 𝐺 ) ={ 0 𝑘 1 𝑘|𝑘 ≥ 0 }
1
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

You might also like