270 likes | 369 Views
CSci 4011. INHERENT LIMITATIONS OF COMPUTER PROGAMS. A PDA transition function takes as input a state, an input symbol, and:. QUIZ 2. a stack symbol. If P is a PDA then L(P) is the set:. { w | P accepts w }. Let G = (V,Σ,R,S) be a CFG then R is the set of:. Production rules.
E N D
CSci 4011 INHERENT LIMITATIONS OF COMPUTER PROGAMS
A PDA transition function takes as input a state, an input symbol, and: QUIZ 2 a stack symbol If P is a PDA then L(P) is the set: { w | P accepts w } Let G = (V,Σ,R,S) be a CFG then R is the set of: Production rules The regular pumping lemma says that… if w L and |w| ≥ P, then Ǝx,y,z so w = xyz and: (1) |xy| ≤ P (2) |y| > 0 (3) For every i ≥ 0, xyiz L. Give a CFG for the language {anb2n : n ≥ 0 }: S → aSbb | ε
What are practical uses for PDAs? Why are pumping lemmas annoying? Buddhist temple, CFG, levitating during meditation? What will be on the upcoming midterm? WTF Implementation of PL? Context-Free Pumping Lemma? Why do I care about CNF? Where are we going with this? What does it mean for something to be context free? How does a CFG relate to a computer? What is your favorite topic in this class? Is there a rule for the CF pumping lemma like |xy|≤P? Is there a multi-stack PDA? How many more types of languages are there? PDA/CFG conversions? CNF Unit rule redundancy? Do we need to prove every case for the pumping lemma? Is this class graded on a curve?
I will be in my office: Today 4-5:30pm and Thurs. 9:00am-11:00am HW4 SOLUTIONS POSTED TOMORROW AT NOON.
NOTATION An alphabetΣ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x a string, |x| is the length of x The unique string of length 0 will be denoted by ε and will be called the empty or null string A language over Σ is a set of strings over Σ
q1 1 0 0,1 1 M q0 q2 0 0 1 q3 M = (Q, Σ, , q0, F) where Q = {q0, q1, q2, q3} are states Σ = {0,1} is the alphabet : Q Σ→ Q transition function* q0 Q is start state F = {q1, q2} Q accept states * NFAs have “choices” -- : Q ΣP (Q), and accept on input w if there is a path from q0 to a qa∈ F.
NFA DFA DEF Regular Language Regular Expression
SOME LANGUAGES ARE NOT REGULAR! B = {0n1n | n ≥ 0} is NOT regular! Suppose B is regular and let P be the pumping length. The string 0P1P B and has length at least P. So by the pumping lemma, there should be xyz = 0P1P so that |xy| ≤ P, |y| > 0, and xyyzB. But y must be only 0s (otherwise |xy| > P), so xyyz has at least P+1 “0”s (because |y| > 0) but only P “1”s. So xyyz B, contradicting the pumping lemma. Therefore B is not regular.
string pop push ε,ε → $ 0,ε→ 0 1,0→ε ε,$ → ε 1,0→ε A PDA accepts the string x if there is a path on input x and empty stack from q0 to some qa2 F. Following transition “a,bc” reads “a” from the input, pops “b” off the stack, and pushes “c” onto it.
CONTEXT-FREE GRAMMARS production rules start variable A → 0A1 A → B B → # variables terminals A 0A1 00A11 00B11 00#11 uVw yields uvw if (V → v) 2 R. A derives 00#11 in 4 steps.
PARSE TREES A A A B 0 0 # 1 1 A 0A1 00A11 00B11 00#11 Each node corresponds to a rule in the derivation. A string is derived ambiguously if it has ≥ 2 parse trees. A grammar is ambiguous if it derives a string ambiguously.
THE CHOMSKY NORMAL FORM A context-free grammar is in Chomsky normal form if every rule is of the form: A → BC B and C are not start variable A → a a is a terminal S → ε S is the start variable Any variable A that is not the start variable can only generate strings of length > 0 Theorem: If G is in CNF, w L(G) and |w| > 0, then any derivation of w in G has length ≤ 2|w| - 1
THE CONTEXT-FREE PUMPING LEMMA Let L be a context-free language Then there exists P such that For every w L with |w| ≥ P there exist uvxyz=w, where: 1. |vy| > 0 2. |vxy| ≤ P 3. uvixyiz L for any i ≥ 0 { ww | w ∈Σ* } is not regular!
USING THE PUMPING LEMMA Prove L = {w#wR | w ∈ {0,1}* and #1s = #0s} is not context-free Assume L is context-free. Then there is a pumping length P. No matter what P is, the string s = 0P1P#1P0P has |s| ≥ P and s∈L. So there should be uvxyz=s with: 1) |vy| > 0, 2) |vxy| ≤ P, 3)∀i, uvixyiz ∈ L. P P P P s = 00…0011…11#11…1100…00
USING THE PUMPING LEMMA Prove L = {w#wR | w ∈ {0,1}* and #1s = #0s} is not context-free Assume L is context-free. Then there is a pumping length P. vxy cannot be only in either half, since pumping would make one side of # longer than the other. since # is in x and |vxy| · P, neither v nor y can have 0s, and at least one must have a 1. Then uv2xy2z has more 1s than 0s and is not in L. No matter what P is, the string s = 0P1P#1P0P has |s| ¸ P and s 2 L. # cannot be in v or y since pumping would add too many #s. So it must be in x. So there should be uvxyz=s with: 1) |vy| > 0, 2) |vxy| ≤ P, 3) ∀i, uvixyiz ∈ L. P P P P s = 00…0011…11#11…1100…00 vxy
NON-REGULAR NON-CFL REGULAR LANGUAGES CONTEXT-FREE LANGUAGES 100 100 100 200 200 200 300 300 300 FINAL JEOPARDY
A regular expression for the set of strings accepted by the NFA: 1 0,1
A proof that the language { w Σ*| w ≠ wR } is not regular.
The language accepted by the following PDA: 0,ε→ 0 1,0→ε ε,ε → $ 1,0→ε ε,0 → ε
DAILY DOUBLE Regular operations that the Context-Free Languages are closed under.
A class of strings in the language L = { 1n#1n | n ≥ 0} that contradicts the regular pumping lemma for each pumping length p.
A class of strings in the language {an#an#an | n ≥ 0 } that contradicts the context-free pumping lemma for each pumping length p.
A proof that the language { an#bm | m = n2, n ≥ 0 } is not context-free.