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

Lecture 3

1. Finite automata, regular expressions, and context-free grammars were discussed. Finite automata and regular expressions are equivalent in the languages they can recognize. 2. The pumping lemma can be used to prove that a language is not regular by showing that any string in the language cannot be pumped while remaining in the language. Closure properties can also be used when combined with the pumping lemma. 3. Context-free grammars generate languages using substitution rules on variables and terminals, allowing variables on the left side and strings on the right side. They are more powerful than regular languages.

Uploaded by

Mohieddine Farid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Lecture 3

1. Finite automata, regular expressions, and context-free grammars were discussed. Finite automata and regular expressions are equivalent in the languages they can recognize. 2. The pumping lemma can be used to prove that a language is not regular by showing that any string in the language cannot be pumped while remaining in the language. Closure properties can also be used when combined with the pumping lemma. 3. Context-free grammars generate languages using substitution rules on variables and terminals, allowing variables on the left side and strings on the right side. They are more powerful than regular languages.

Uploaded by

Mohieddine Farid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Theory of computation

Lecture 3: Automata and Regular languages

Adnane Saoud

Tuesday, September 19, 2023

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

Today’s Theorem: If a language 𝐴 is regular then it can described as regular


expression
Proof: Give conversion DFA 𝑀 → 𝑅

We need a new concept. 4


Generalized NFAs
Definition: A Generalized Nondeterministic Finite Automaton (GNFA) is similar to an NFA, but allows
regular expressions as transition labels

For simplicity we will assume:


- One accept state, separate from the start state
- One arrow from each state to each state, except
a) only exiting the start state
b) only entering the accept state

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


𝐺1
𝑞1 𝑞2
b
ε

a∪b aab
𝑞3 𝑞4
ε

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

1. Pick any state 𝑥 except the start and accept states.


2. Remove 𝑥.
3. Repair the damage by recovering all paths that went through 𝑥.
4. Make the indicated change for each pair of states 𝑞! , 𝑞" . 7
Pumping Lemma

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.

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


Let 𝐵 = 𝑤 𝑤 has equal numbers of 0s and 1s}
Intuition: 𝐵 is not regular because DFAs cannot count unboundedly.
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.
9
Method for Proving Non-regularity
Pumping Lemma: For every regular language 𝐴, there is a number 𝑝 (the
“pumping length”) such that for any string 𝑠 ∈ 𝐴 satisfying 𝑠 ≥ 𝑝 there
exist 𝑥, 𝑦 and 𝑧 such that 𝑠 = 𝑥𝑦𝑧 where
1) 𝑥𝑦 ! 𝑧 ∈ 𝐴 for all 𝑖 ≥ 0 𝑦 ! = 𝑦𝑦 ⋯ 𝑦
2) 𝑦 ≠ ε 𝑖
3) 𝑥𝑦 ≤ 𝑝
Informally: 𝐴 is regular → every long string in 𝐴 can be pumped and the result
stays in 𝐴.
Proof: Let DFA 𝑀 recognize 𝐴. Let 𝑝 be the number of states in 𝑀. Pick 𝑠 ∈
𝐴 where 𝑠 ≥ 𝑝.
𝑥 𝑦 𝑧 𝑀 𝑦
𝑠=
𝑞! 𝑞!
𝑞!
𝑀 will repeat a state 𝑞' when reading 𝑠 𝑥 𝑧
because 𝑠 is so long.
𝑥 𝑦 𝑦 𝑧
𝑞! 𝑞! 𝑞! is also accepted The path that 𝑀 follows
when reading 𝑠. 10
Example 1 of Proving Non-regularity

Pumping Lemma: For every regular language 𝐴, there is a 𝑝


such that for any string 𝑠 ∈ 𝐴 satisfying 𝑠 ≥ 𝑝 there exist 𝑥, 𝑦
and 𝑧 such that 𝑠 = 𝑥𝑦𝑧 where
1) 𝑥𝑦 ! 𝑧 ∈ 𝐴 for all 𝑖 ≥ 0 𝑦 ! = 𝑦𝑦 ⋯ 𝑦
2) 𝑦 ≠ ε
3) 𝑥𝑦 ≤ 𝑝
Let 𝐷 = 0+ 1+ 𝑘 ≥ 0}
𝑠 = 000 ⋯ 000111 ⋯ 111
Show: 𝐷 is not regular
𝑥 𝑦 𝑧
≤𝑝
Proof by Contradiction:
Assume (to get a contradiction) that 𝐷 is regular.
The pumping lemma gives 𝑝 as above. Let 𝑠 = 0# 1# ∈ 𝐷.
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.

11
Example 2 of Proving Non-regularity

Let 𝐹 = 𝑤𝑤 𝑤 ∈ Σ ∗ } . Say Σ ∗ = {0,1}.

Show: 𝐹 is not regular


Proof by Contradiction:
Assume (for contradiction) that 𝐹 is regular.
The pumping lemma gives 𝑝 as above. Need to choose 𝑠 ∈ 𝐹. Which 𝑠?
Try 𝑠 = 0# 0# ∈ 𝐹. But that 𝑠 can be pumped and stay inside 𝐹. Bad choice.
Try 𝑠 = 0# 10# 1 ∈ 𝐹. Show cannot be pumped 𝑠 = 𝑥𝑦𝑧 satisfying the 3 conditions.
𝑥𝑦𝑦𝑧 ∉ 𝐹 Contradiction! Therefore 𝐹 is not regular.

𝑠 = 000 ⋯ 001000 ⋯ 001


𝑥 𝑦 𝑧
≤𝑝

12
Example 3 of Proving Non-regularity

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.

Variant: Combine closure properties with the


Pumping Lemma.

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

Grammars generate strings


1. Write down start variable
2. Replace any variable according to a rule
Repeat until only terminals remain
3. Result is the generated string
4. 𝐿(𝐺) is the language of all generated strings.
15
Context Free Grammars

𝐺0

}
S → 0S1
S→R ((Substitution) Rules
R→ε

Example of 𝐺' generating a string


Tree of S S Resulting
substitutions string
0 S1 0S1

0 S1 00S11

R 00R11
ε 0011 ∈ 𝐿 𝐺'
𝐿 𝐺0 = 0+ 1+ 𝑘 ≥ 0}
16
Summary

17
Summary

1. DFAs, NFAs, regular expressions are all equivalent


2. Proving languages not regular by using the pumping lemma and
closure properties
3. Context Free Grammars

18

You might also like