intro to theory of computation
DESCRIPTION
L ECTURE 6 Theory of Computation Proving that a language is not regular Pushdown automaton (PDA) Context-free grammar (CFG). Intro to Theory of Computation. CS 464. Sofya Raskhodnikova. THE PUMPING LEMMA. Let L be a regular language with |L| = . - PowerPoint PPT PresentationTRANSCRIPT
04/19/2023
Sofya Raskhodnikova
Intro to Theory of Computation
LECTURE 6 Theory of Computation• Proving that a language is
not regular• Pushdown automaton
(PDA)• Context-free grammar
(CFG)
Sofya Raskhodnikova; based on slides by Nick Hopper 6.1
THE PUMPING LEMMA
Let L be a regular language with |L| =
Then there exists a length p such that
1. |y| > 0
2. |xy| ≤ p
3. xyiz L for all i ≥ 0
if w L and |w| ≥ p thenw can be split into three parts w=xyz where:
Sofya Raskhodnikova; based on slides by Nick Hopper04/19/2023 6.2
GENERAL STRATEGY
Proof by contradiction – assume L is regular
Find a string w 2 L with |w| ¸ p
Show that no matter how an adversarychooses xyz, your w cannot be pumped!
Conclude that L is not regular
Then there is a pumping length p
Sofya Raskhodnikova; based on slides by Nick Hopper L6.304/19/2023
PUMPING DOWNProve C = { 0i1j | i > j ¸ 0} is not regular.Proof: Assume … pumping length p
Find a w 2 C longer than p
Show that … w cannot be pumped:0P+11P
00…0011…11
p+1 p
w=
y
xyyz = 00…00011…11
> p+1P
xz = 0…0011…11
· p PSofya Raskhodnikova; based on slides by Nick Hopper L6.4
USING THE PUMPING LEMMA:
04/19/2023
PUMPING DOWN
Prove C = { 0i1j | i > j ¸ 0} is not regular.Proof: Assume … pumping length p
Find a w 2 C longer than p
If w = xyz with |xy| · p theny = 0J for some J¸ 1.Then xy0z = xz = 0P+1-J1P C
0P+11P
xz = 0…0011…11
Sofya Raskhodnikova; based on slides by Nick Hopper L6.5
Contradiction!
04/19/2023
For every p, w L with |w| ≥ p
1. |y| > 0there exist xyz=w, where
3. xyiz L for all i ≥ 0
2. |xy| ≤ p
WHAT THE PUMPING LEMMADOESN’T SAY - I
Let L = 1*. L is regular.The string 10 cannot be pumped with p=1.
You need to show that no matter what p is chosen,L has a string w, |w| ≥ p, that cannot be pumped.
Sofya Raskhodnikova; based on slides by Nick Hopper L6.604/19/2023
WHAT THE PUMPING LEMMADOESN’T SAY - II
For every xyz=w, where:
Example: Let L = 10*1*. Pickingw = 10P1P; x=ε; y=10P; z=1P
does not contradict pumping lemma!
(You can pick x=1, y=0, z=0P-11P.)
1. |y| > 0
3. xyiz L for all i ≥ 0
2. |xy| ≤ p
Sofya Raskhodnikova; based on slides by Nick Hopper L6.704/19/2023
CHOOSING WISELY
Let BALANCED = { w | w has an equal # of 1sand 0s }
Assume … there is a p
Find a w 2 BALANCED longer than p
(01)P
Show that w cannot be pumped:
If w = xyz with |xy| · p theny = 0J for some J>0.
Then xyyz = 0P+J1P BALANCED
0P1P
Sofya Raskhodnikova; based on slides by Nick Hopper04/19/2023 6.8
REUSING A PROOF
Pumping a language can be lots of work…
Let’s try to reuse that work!
{0n1n : n ¸ 0} = BALANCED ∩ 0*1*
If BALANCED is regular then so is {0n1n: n ¸ 0}
Sofya Raskhodnikova; based on slides by Nick Hopper04/19/2023 6.9
USING CLOSURE
A C B∩ =
(Not regular)
Prove: A is not regular
or any of {¢, [, ∩, :, R, *}
If A is regular, then A ∩ C (= B) is regular.
(regular)
But B is not regular so neither is A.
Sofya Raskhodnikova; based on slides by Nick Hopper04/19/2023 6.10
Prove A = {0i1j : i j} is not regular using B = {0n1n : n¸0}
B [ { strings that mix 0s and 1s }
:A ∩ 0*1* = B
:A =
USING CLOSURE: example
Sofya Raskhodnikova; based on slides by Nick Hopper04/19/2023 6.11
PUMPINGNON-REGULAR LANGUAGES
Let F = {aibjck | i, j, k ¸ 0 and i=1 ) j=k}
F has pumping length 2!
HW3: prove that F is not regular.
i = 0i = 1i = 2
A non-regular language may still satisfy the pumping lemma.
Sofya Raskhodnikova; based on slides by Nick Hopper04/19/2023 6.12
464 so far
MODEL OF A PROGRAM: DFA
MODEL OF A PROBLEM: LANGUAGE
EQUIVALENT MODELS: NFA, REGEXP
PROBLEMS THAT A DFA CAN’T SOLVE
ARE WE DONE?
Sofya Raskhodnikova; based on slides by Nick Hopper04/19/2023 6.13
• Σ = {0, 1}, L = { 0n1n | n ≥ 0 }
• Σ = {a, b, c, …, z}, L = { w | w = wR }
• Σ = { (, ) }, L = { balanced strings of parens }
NONE OF THESE ARE REGULAR
We can write a SCHEME or JAVA program for any of them!
Sofya Raskhodnikova; based on slides by Nick Hopper04/19/2023 6.14
PUSHDOWN AUTOMATA (PDA)
FINITE STATE CONTROL
STACK(Last in, first out)
INPUT
Sofya Raskhodnikova; based on slides by Nick Hopper04/19/2023 6.15
ε,ε → $0,ε → 0
1,0 → ε
1,0 → εε,$ → ε
string pop push
0011
STACK $
0011011
$0
11
$0
1
ε,ε → $0,ε → 0
1,0 → ε
1,0 → εε,$ → ε
string pop push
001
STACK $ $0 $0
101001
PDA to recognize L = { 0n1n | n ≥ 0 }
Formal Definition
04/19/2023
Q is a finite set of statesΣ is the alphabet
q0 Q is the start stateF Q is the set of accept states
A PDA is a 6-tuple P = (Q, Σ, Γ, , q0, F)
Sofya Raskhodnikova; based on slides by Nick Hopper
: Q Σε Γε → P(Q Γε) is the transition function
P(Q Γε) is the set of subsets of Q Γε and Σε = Σ {ε}
Γ is the stack alphabet
Note: A PDA is defined to be nondeterministic.
6.18
Formal Definition
04/19/2023
Q is a finite set of statesΣ is the alphabet
q0 Q is the start stateF Q is the set of accept states
A PDA is a 6-tuple P = (Q, Σ, Γ, , q0, F)
Sofya Raskhodnikova; based on slides by Nick Hopper
: Q Σε Γε → P(Q Γε) is the transition function
Γ is the stack alphabet
A PDA starts with an empty stack. It accepts a string if at least one of its computational branches reads all the input and gets into an accept state at the end of it.
6.19
ε,ε → $0,ε → 0
1,0 → ε
1,0 → εε,$ → ε
q0 q1
q2q3
Q = {q0, q1, q2, q3} Γ =Σ =
: Q Σε Γε → P(Q Γε)
{0,1} {$,0}
(q1,1,0) = { (q2,ε) } (q2,1,1) =
EVEN-LENGTH PALINDROMES
Σ = {a, b, c, …, z}
ε,ε → $
ε,ε → ε
, → εε,$ → ε
q0 q1
q2q3
,ε →
Build a PDA to recognize L = { aibjck | i, j, k ≥ 0 and (i = j or i = k) }
ε,ε → $
b,a → ε
ε,$ → εq0
q5q1
q3
a,ε → a
q2
q4
ε,ε →
ε
q6ε,ε → ε ε,ε → ε ε,$ → ε
b,ε → ε c,a → ε
c,ε → ε
A → 0A1A → BB → #
CONTEXT-FREE GRAMMARS (CFGs)
A
variablesterminals
productionrulesstart variable
0A1 00A11 00B11 00#11
04/19/2023 Sofya Raskhodnikova; based on slides by Nick Hopper 6.23
<PHRASE> → <START><END>
<PHRASE> → <FILLER><PHRASE>
<FILLER> → LIKE
<FILLER> → UMM
<START> → YOU KNOW
<END> → GAG ME WITH A SPOON
<START> → ε
<END> → AS IF
<END> → WHATEVER
VALLEY GIRL GRAMMAR
<END> → LOSER
04/19/2023 Sofya Raskhodnikova; based on slides by Nick Hopper 6.24