Plan for Today CFGs and pumping lemma for

  • Slides: 20
Download presentation
 • • • Plan for Today CFGs and pumping lemma for it A

• • • Plan for Today CFGs and pumping lemma for it A = {0 n#02 n#03 n | n ≥ 0} (Ex 2. 30. b in text) A = {w#t | w, t ∈{0, 1}*, w is a substring of t } (Ex 2. 30. c in text) A = {0 i 1 j | i = j 2} A = {w | w ∈{1, 2, 3, 4}*, #1 w = #2 w, #3 w = #4 w} (Ex 2. 32 in text) A = {wtw. R | w, t ∈{0, 1}* , |w| = |t|} (Ex 2. 45 in text)

Context Free Grammar 4 -tuple, (V, Σ, R, S) V: variables Σ: alphabet R:

Context Free Grammar 4 -tuple, (V, Σ, R, S) V: variables Σ: alphabet R: rules, V (V �Σ)* aka. A w for some w ∈ (V �Σ)* • S ∈ V: starting variable • • We say that x ∈ L if there is a sequence of variable substitutions that ends up

Examples of CFGs • Shorthand for rules: A w 1 | w 2 •

Examples of CFGs • Shorthand for rules: A w 1 | w 2 • Balanced parentheses: s ε | (s) | ss • Arithmetic expressions with add/multiply (without order of precedence): s ε | {0. . 9}| (s) | s + s | s × s • Binary strings that read the same backward (palindromes): s ε | 0 | 1 | 0 s 0 | 1 s 1

Examples of CFGs • A = {0 n#02 n| n ≥ 0} (aside: check

Examples of CFGs • A = {0 n#02 n| n ≥ 0} (aside: check this is not regular) • Heuristic for checking whether a language is context free (warning: this does not always work): it counts one numbers • s # | 0 s 00 Example of this rule generating a string: s 0 s 00 00 s 0000 000 s 000000 000#000000

Next Class (Thursday) • CFGs are precisely the languages recognized by PDAs • PDA

Next Class (Thursday) • CFGs are precisely the languages recognized by PDAs • PDA <-> NFA with a stack NOTE: both CFGs and PDAs are naturally non-deterministic: there are many ways to run the intermediate stages, and acceptance is always phrased as `there exists a sequence of substitutions / stack operations’

All languages Turing decidable (hw 6) Context free ? ? ? (hw 6) Regular

All languages Turing decidable (hw 6) Context free ? ? ? (hw 6) Regular

Pumping Lemma for CFGs Can only be used to show A is NOT context

Pumping Lemma for CFGs Can only be used to show A is NOT context free If A is context free, then there exists some p such that for any w ∈ A with |w| > p, there is a split of w = uvxyz with • |vxy|≤ p, • |vy| > 0 • such that for all i ≥ 0, • uvixyiz ∈ A • •

Using Pumping Lemma for CFGs Show: • For all p • We can find

Using Pumping Lemma for CFGs Show: • For all p • We can find some bad w ∈ A with |w| > p, • Such that for all splits of w = uvxyz with • |vxy|≤ p, • |vy| > 0 Finer details: • There is some i ≥ 0 s. t. • u, v, x, y, z can ALL be empty (for • uvixyiz ∉ A different splits) • But v and y cannot both be empty • Need to rule out ALL splits

Using Pumping Lemma for CFGs, the finer points YOU get to pick w But

Using Pumping Lemma for CFGs, the finer points YOU get to pick w But you have 0 control over uvxyz You need to rule out ALL uvxyz All you can work with is the fact that vxy is short, and vy is non-zero • The fact that you can pick i helps a little, but not as much as one would think • •

Using Pumping Lemma for CFGs, the finer points • You need to rule out

Using Pumping Lemma for CFGs, the finer points • You need to rule out ALL uvxyz • Proofs essentially need to consider all of them, but proofs have finite length • How to determine all cases: • Remember that you can choose w! • Choose w so that the different length <p substrings have few cases

Using Pumping Lemma for CFGs A = {0 n#02 n#03 n | n ≥

Using Pumping Lemma for CFGs A = {0 n#02 n#03 n | n ≥ 0} (Ex 2. 30. b in text)

Using Pumping Lemma for CFGs A = {0 n#02 n#03 n | n ≥

Using Pumping Lemma for CFGs A = {0 n#02 n#03 n | n ≥ 0} (Ex 2. 30. b in text) Pick n > p, then cannot simultaneously touch all 3 portions with the part pumped For any p, consider w = 010 p#020 p#030 p (w ∈ A with n = 10 p) Now consider any split of w = uvxyz with |vxy| < p

Using Pumping Lemma for CFGs A = {0 n#02 n#03 n | n ≥

Using Pumping Lemma for CFGs A = {0 n#02 n#03 n | n ≥ 0} (Ex 2. 30. b in text) • • • w = 010 p#020 p#030 p any split of w = uvxyz with |vxy| < p First and second # are 20 p apart So vxy cannot cover both of them So the string uv 2 xy 2 z (i<-2) has different total length (this is where I use |vy| > 0), but one of the blocks still has the same length as before. Thus it cannot be in A

Using Pumping Lemma for CFGs A = {0 n#02 n#03 n | n ≥

Using Pumping Lemma for CFGs A = {0 n#02 n#03 n | n ≥ 0} (Ex 2. 30. b in text) • w = 010 p#020 p#030 p • split of w = uvxyz where vxy touches <=2 of the blocks • To show that uv 2 xy 2 z ∉ A • Note that length of uv 2 xy 2 z is not the same as w • For all strings in s ∈ A, the length of s uniquely determines the string (and in turn the number of 0 s between the #s) • But we know that one of the blocks is unchanged from w

Admin Items • HW 5 now due Thu Apr 2 • Test 3 now

Admin Items • HW 5 now due Thu Apr 2 • Test 3 now Thu Apr 9, will likely be a 2. 5 hour window, 11: 00 am - 1: 30 pm • Will look into provide. tex source • Office hours via bluejeans, https: //gatech. bluejeans. com/55332 6610

Using Pumping Lemma for CFGs A = {w#t | w, t ∈{0, 1}*, w

Using Pumping Lemma for CFGs A = {w#t | w, t ∈{0, 1}*, w is a substring of t} (Ex 2. 30. c in text)

Using Pumping Lemma for CFGs A = {w#t | w, t ∈{0, 1}*, w

Using Pumping Lemma for CFGs A = {w#t | w, t ∈{0, 1}*, w is a substring of t} (Ex 2. 30. c in text) • • For any p Set w = t = 0 p 1 p, gives the string 0 p 1 p#0 p 1 p Once again, have to consider all splits 0 p 1 p#0 p 1 p = uvxyz with |vxy|<=p, |vy|>0 Three cases: vxy in first half, vxy in second half, and vxy crosses the middle

Using Pumping Lemma for CFGs A = {w#t | w, t ∈{0, 1}*, w

Using Pumping Lemma for CFGs A = {w#t | w, t ∈{0, 1}*, w is a substring of t} (Ex 2. 30. c in text) • • • 0 p 1 p#0 p 1 p = uvxyz with |vxy|<=p, |vy|>0 vxy in first half (before the #): pump up (i = 2), then the first half has length bigger than second half (w cannot be a substring of t if |w| > |t|) vxy in second half (after the #): pump down! (i = 0) because this makes the second half shorter Note: w is substring of t if t = awb (for some strings a and b), |t| = |a| + |w| + |b|

Using Pumping Lemma for CFGs A = {w#t | w, t ∈{0, 1}*, w

Using Pumping Lemma for CFGs A = {w#t | w, t ∈{0, 1}*, w is a substring of t} (Ex 2. 30. c in text) • • • 0 p 1 p#0 p 1 p = uvxyz with |vxy|<=p, |vy|>0 vxy crosses middle: v can only contain 1 s, y can only contain 0 s Two more cases due to one of v or y potentially being empty: will deal with this next time (Thursday)

Using Pumping Lemma for CFGs A = {w#t | w, t ∈{0, 1}*, w

Using Pumping Lemma for CFGs A = {w#t | w, t ∈{0, 1}*, w is a substring of t } (Ex 2. 30. c in text) • • Let w = t = 0 p 1 p uvxyz = 0 p 1 p# 0 p 1 p v and y cannot contain # 3 ( 4) possibilities: • all on left pump left with i =2 • all on right pump right with i = 0 • v contains 1 s, or y contains 0 s