cs3102: theory of computation class 8: non-context-free languages spring 2010 university of virginia...
TRANSCRIPT
![Page 1: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/1.jpg)
cs3102: Theory of Computation
Class 8: Non-Context-Free Languages
Spring 2010University of VirginiaDavid Evans
![Page 2: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/2.jpg)
Menu
• Computing Model for CFGs• Non-CFLs: languages that cannot be
recognized by NDPDA or CFG
![Page 3: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/3.jpg)
s
All Languages
RegularLanguages
Can be recognized by some DFA
Finite Languages
Context-Free Languages
![Page 4: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/4.jpg)
Computing Model for CFG
There can be multiple rules for one variable:
S 0S0S 1S1S ε
![Page 5: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/5.jpg)
Computing Model for CFG
There can be multiple rules for one variable:
Can we define an extended transition function for a CFG?
![Page 6: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/6.jpg)
CFG Extended Transition Function
Should we have really called this *?
Unlike the other * functions we have defined, this one cannot (typically) actually be calculated!
![Page 7: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/7.jpg)
Acceptance Rule for CFG
![Page 8: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/8.jpg)
s
All Languages
RegularLanguages
Can be recognized by some DFA
Finite Languages
Context-Free Languages
What can’t a CFG/NPDA do?
![Page 9: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/9.jpg)
Recall: Non-Regular Languages
q0
qz
x
y
z
qi
Finite number of configurations (only the state).If string is long enough, some state must repeatIf configuration repeats, can repeat any number of times.
Does this work for NPDAs?
![Page 10: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/10.jpg)
How many PDA configurations?
For a nondeterministic PDA how many different machine configurations are possible?
q2
ε, ε +
![Page 11: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/11.jpg)
Are NPDAs/CFGs all powerful!?
![Page 12: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/12.jpg)
Limits of NPDA/CFGs
Pushdown Automata• Finite number of states and
stack symbols• Can only read top symbol
on stack
Context-Free Grammar• Finite number of variables
and rules• Left side of rule is a single
variable
Pumping Lemma for Context-Free Languages: we will prove it for CFGs
Because we proved L(NPDA) = L(CFG), this pumping lemma applies to NPDAs also – but its much tougher to see why. A convincing proof of the CFL pumping lemma that does not use CFG-equivalence is worth a challenge bonus (exemption from Exam 1).
![Page 13: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/13.jpg)
Pumping Lemma for CFLs
S AbcDA Sab…
G has a finite number of variables and rules.
If A is a CFL, there exists some CFG G that generates A.
b = maximum number of symbols on right side of any rule
What is the longest string G could produce in h replacement steps?
![Page 14: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/14.jpg)
S SSSSS 0
S
SSSS
SSSSSSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
0000000000000000000000000000000000000000000000000000000000000000
…
b
b0
b1
b2
h
For parse tree height h, maximum length string is bh.
![Page 15: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/15.jpg)
CFG Repetition
• If A is a CFL, there exists some CFG G that generates A where b is the maximum number of symbols on the right side of a rule.
• There is some string s A with length
How do we know such a string exists?
Because of the maximum length property, we know it takes at least |V| steps to derive s.
![Page 16: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/16.jpg)
S
X
Because of the maximum length property, we know it takes at least |V| steps to derive s: for some X V, X must be on the left side of a chosen rule more than once!
X
s = u v x y z
![Page 17: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/17.jpg)
S
X
X
s = u v x y z
G is context-free.Wherever variable A appears, it can be replaced the same way.
X
yv
s’ = uvvxyyz
![Page 18: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/18.jpg)
A more powerful language class needs a more powerful pumping lemma!
![Page 19: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/19.jpg)
Pumping Lemma for CFLs
Player 1: picks h (maximum number of variables) and b (maximum number of symbols on right side of rule). Let p = bh+1.
Player 2: picks s A, |s| pPlayer 1: picks u,v,x,y,z such that s = uvxyz and
|vy| > 0 and |vxy| p.Player 2: picks i 0.
Player 2 wins if uvixyiz A.If Player 2 can always win, A is not context free!
![Page 20: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/20.jpg)
Pumping Lemma for CFLs
Player 1: picks h (maximum number of variables) and b (maximum number of symbols on right side of rule). Let p = bh+1.
Player 2: picks s A, |s| pPlayer 1: picks u,v,x,y,z such that s = uvxyz and
|vy| > 0 and |vxy| p.Player 2: picks i 0.
Player 2 wins if uvixyiz A.If Player 2 can always win, A is not context free!
Simple way to prove non-context-free languages are non-regular:
Pick u = ε, v = ε and we have the PL for regular languages!
![Page 21: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/21.jpg)
Example:
![Page 22: Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans](https://reader036.vdocuments.us/reader036/viewer/2022062305/56649f4d5503460f94c6e904/html5/thumbnails/22.jpg)
Charge
• PS3: only one week (but shorter than PS2)• Exam 1: March 2 (two weeks from today)• Thursday– Closure properties for CFLs– DFAs, CFGs, and Compilers