Lecture 3
Lecture 3
Adnane Saoud
1
Summary of lecture 2
Lecture 2
§ Nondeterministic finite automatas (NFAs)
§ Closure under ∘ and ∗
§ How to convert regular expressions to finite automata
Lecture 3
§ From finite automata to regular expressions
§ Proving some languages are not regular
§ Context free grammars
2
From finite automata
to regular expressions
3
DFAs → Regular Expressions
Recall Theorem: If a language is described by a regular expression then it
is regular
Proof: Conversion 𝑅 → NFA 𝑀 → DFA 𝑀′
𝑀
Regular Finite
expression 𝑅 automaton
5
GNFA → Regular Expressions
Lemma: Every GNFA 𝐺 has an equivalent regular expression 𝑅
Proof: By induction on the number of states 𝑘 of 𝐺
Basis (𝑘 = 2):
𝑟 𝐺 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
6
𝑘-state GNFA → (𝑘—1)-state GNFA
𝑥 𝑟) 𝑥
𝑟( 𝑟*
𝑘 states 𝑘 − 1 states
8
Non-Regular Languages
How do we show a language is not regular?
- 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.
But 𝑥𝑦𝑦𝑧 has excess 0s and thus 𝑥𝑦𝑦𝑧 ∉ 𝐷 contradicting the pumping lemma.
Therefore our assumption (𝐷 is regular) is false. We conclude that 𝐷 is not regular.
11
Example 2 of Proving Non-regularity
12
Example 3 of Proving Non-regularity
13
Converting NFAs to DFAs
Theorem: If an NFA recognizes 𝐴 then 𝐴 is regular
Proof: Let NFA 𝑀 = (𝑄, Σ, 𝛿, 𝑞% , 𝐹) recognize 𝐴
Construct DFA 𝑀′ = (𝑄′, Σ, 𝛿′, 𝑞%& , 𝐹′) recognizing 𝐴
(Ignore the ε-transitions, can easily modify to handle them)
IDEA: DFA 𝑀′ keeps track of the subset of possible states in NFA 𝑀. ε-
Context-free
transitions, can easily modify to handle them)
Languages
Construction of 𝑴′:
𝑄′ = 𝓟 𝑄
𝛿 & 𝑅, 𝑎 = 𝑞 𝑞 ∈ 𝛿(𝑟, 𝑎) for some 𝑟 ∈ 𝑅}
𝑞%& = {q % }
𝐹′ = 𝑅 ∈ 𝑄& 𝑅 intersects 𝐹}
6 14
Context Free Grammars
𝐺0
}
S → 0S1
S→R ((Substitution) Rules
R→ε
In 𝐺0:
Rule: Variable → string of variables and terminals 3 rules
Variables: Symbols appearing on left-hand side of rule R,S
Terminals: Symbols appearing only on right-hand side 0,1
Start Variable: Top left symbol S
𝐺0
}
S → 0S1
S→R ((Substitution) Rules
R→ε
0 S1 00S11
R 00R11
ε 0011 ∈ 𝐿 𝐺'
𝐿 𝐺0 = 0+ 1+ 𝑘 ≥ 0}
16
Summary
17
Summary
18