Download presentation

Presentation is loading. Please wait.

Published byCael Podd Modified about 1 year ago

1
CSCI 3130: Formal languages and automata theory Tutorial 5 Chin

2
Reminder Homework 3 is due tomorrow. Midterm is on next Monday. Review session tomorrow. You can get back homework 2 after this tutorial.

3
Homework 2 We only say a language is regular or non-regular. We do not say a string is regular or non-regular Never write x is regular We only say a string is in a language or not.

4
Homework 2 To show a language is not regular (a)You only have to choose one string. (b)The chosen string should be in terms of n. (c)You cannot choose what u, v, w are. e.g. u = (ab) n-1, v = (ab) n, w = (bc) n. wrong! You have to consider every possible partitions of uvw. (d)You only have to choose one value for i.

5
Homework 2 Problem 1 (a)Most answers are incorrect. Some of you used the following arguments: Replace with What if: q0 NFA a q0 NFA q0 NFA a q1 b

6
Homework 2 Problem 1 (a)There can be multiple accepting states in the DFA Many states can reach an accepting state on ‘b’

7
Homework 2 Problem 1 (c) Many students drew the following x and y are not fixed. NFA q0 x y

8
Homework 2 Problem 1 (d) A few students did the following Let L 1 = {a n b: n ≥ 0}, L 2 = {a n : n ≥ 0} Then L 1 L 2 = {a n ba n : n ≥ 0}. wrong! The n in L 1 and the n in L 2 are independent. L 1 L 2 = {a n ba m : n, m ≥ 0}.

9
Homework 2 Problem 2 (a)Some of you chose the strings (a+b) n (b+c) n The proof fails if I take b n b n, which is of the above form. Choose one string is okay. e.g. a n c n

10
Homework 2 Problem 2 (c) L 3 = {w : w does not have the same number of as, bs, and cs} A few students got L 3 wrong. (b) Many students let u = (ac) n-1, v = (ac), w = (abc) n. You cannot choose what u, v, w are! v can be any nonempty substring of the first n characters of the string. e.g. v can be the first ‘a’ of the string.

11
Homework 2 Problem 3 (b) To show two states are distinguishable Write down on what inputs one of them goes to an accepting state but the other does not.

12
Homework 2 Problem 4 (b) Some of you did not handle names without any ‘a’. (c) A few of you did not handle the names “crystal”. (d) A few of you missed the case “rin”.

13
Pushdown Automata NFA with a stack Read a, pop b, and push c Push c to the stack after popping b a, b, c can be Use $ to mark stack bottom q0 a, b/c q1

14
Pushdown Automata PDA = CFG Languages that can be represented by PDA/CFG are context-free.

15
Pushdown Automata Design a PDA for the following. = {a, b, c} L 1 = {x : x has fewer a’s than b’s and c’s together} L 2 = {a i b j c k : i = j or j = k}

16
Pushdown Automata L 1 = {x : x has fewer a’s than b’s and c’s together} Lecture: L = {w: w has same number 0s and 1s} First, treat a as a, b and c as x q0 0, / 0 , / $ 1, / 1 , $ / 0, 1 / 1, 0 / q1 q2 q0 a, / a , / $ b, / x , $ / a, x / b, a / q1 q3 c, / x c, a /

17
Pushdown Automata L 1 = {x : x has fewer a’s than b’s and c’s together} First, treat a as a, b and c as x Accept if there are still x’s in the stack q0 a, / a , / $ b, / x , $ / a, x / b, a / q1 q3 c, / x c, a / q0 a, / a , / $ b, / x a, x / b, a / q1 q3 c, / x c, a / q2 , x / , $ /

18
Pushdown Automata L 2 = {a i b j c k : i = j or j = k} Separate it into two cases {a i b j c k : i = j } U {a i b j c k : j = k} 1.{a i b j c k : i = j } Lecture: L = {w: w has same number 0s and 1s} q0 0, / 0 , / $ 1, / 1 , $ / 0, 1 / 1, 0 / q1 q2

19
Pushdown Automata L 2 = {a i b j c k : i = j or j = k} 1.{a i b j c k : i = j } Lecture: L = {w: w has same number 0s and 1s} add c’s q0 0, / 0 , / $ 1, / 1 , $ / 0, 1 / 1, 0 / q1 q2 q0 a, / a , / $ b, / b , / a, b / b, a / q1 q3 q2 , $ / c, /

20
Pushdown Automata L 2 = {a i b j c k : i = j or j = k} 2. {a i b j c k : j = k} Lecture: L = {w: w has same number 0s and 1s} add a’s q0 0, / 0 , / $ 1, / 1 , $ / 0, 1 / 1, 0 / q1 q2 q0 c, / c , / $ b, / b , / c, b / b, c / q1 q3 q2 , $ / a, /

21
Pushdown Automata L 2 = {a i b j c k : i = j or j = k} Take union c, / c , / $ b, / b , / c, b / b, c / q5 q6 q4 , $ / a, / q0 a, / a , / $ b, / b , / a, b / b, a / q1 q3 q2 , $ / c, /

22
Pumping lemma for Context-free languages To show a language L is not context free: For every n, choose one z of length ≥ n in L, such that for every way of writing z = uvwxy where |vwx| ≤ n and |vx| ≥ 1, the string uv i wx i y is not in L for some i ≥ 0. 1. z depends on n 2. u, w, y can be empty string 3. v, x can also be empty string, but not both. 4. i can be 0 (very useful) 5.You only have to choose one z 6.Unlike the regular language version, vwx can be anywhere in z.

23
Template Suppose L is context-free. Let n be the pumping length. Then z = _______ (z should contain n somewhere) is in L. Write z = uvwxy, where |vwx| ≤ n and |vx|≥ 1. Argue! no matter how we write z = uvwxy, the string uv _ wx _ y is not in L (choose one i in _, i can be 0) Therefore L is not regular. Pumping lemma for Context-free languages

24
Pumping lemma for CFG Show that the following languages are not context-free L 1 = {a n b m a n b m : m, n ≥ 0}. = {a, b}. L 2 = {x#y#z : y R is a substring of xz; x, y, z ∈ {a,b}*}. = {a, b, #}.

25
Pumping lemma for CFG L 1 = {a n b m a n b m : m, n ≥ 0}. = {a, b}. Suppose L is context-free. Let n be the pumping length. Then z = _a n b n a n b n _ (z should contain n somewhere) is in L. Write z = uvwxy, where |vwx| ≤ n and |vx|≥ 1. Argue! no matter how we write z = uvwxy, the string uv _ wx _ y is not in L (choose one i in _, i can be 0) How to argue?

26
Pumping lemma for CFG L 1 = {a n b m a n b m : m, n ≥ 0}. = {a, b}. Then z = _a n b n a n b n _ (z should contain n somewhere) is in L. Write z = uvwxy, where |vwx| ≤ n and |vx|≥ 1. What can vwx be if |vwx| ≤ n? vwx can be… 1.part of the first a n 2.part of the first a n b n 3.part of the first b n 4.part of the middle b n a n 5.part of the second a n 6.part of the second a n b n 7.part of the last b n a……ab……ba……ab……b

27
Pumping lemma for CFG L 1 = {a n b m a n b m : m, n ≥ 0}. = {a, b}. Then z = _a n b n a n b n _ (z should contain n somewhere) is in L. Write z = uvwxy, where |vwx| ≤ n and |vx|≥ 1. 1.If vwx is part of the first a n uv 2 wx 2 y has less a’s in the first group than the second group 2.If vwx is part of the first a n b n v and x cannot be both empty If v is not empty, v must contain some a, uv 0 wx 0 y has less a’s in the first group than the second group If x is not empty, x must contain some b, uv 0 wx 0 y has less b’s in the first group than the second group The rest are similar, do explain them in the homework/exam. a……ab……ba……ab……b

28
Pumping lemma for CFG L 2 = {x#y#z : y R is a substring of xz; x, y, z ∈ {a,b}*}. Suppose L is context-free. Let n be the pumping length. Then z = _a n #b n a n #b n _ (z should contain n somewhere) is in L. Write z = uvwxy, where |vwx| ≤ n and |vx|≥ 1. Argue! no matter how we write z = uvwxy, the string uv _ wx _ y is not in L (choose one i in _, i can be 0) How to argue?

29
Pumping lemma for CFG L 2 = {x#y#z : y R is a substring of xz; x, y, z ∈ {a,b}*}. Then z = _a n #b n a n #b n _ (z should contain n somewhere) is in L. Write z = uvwxy, where |vwx| ≤ n and |vx|≥ 1. What can vwx be if |vwx| ≤ n? vwx can be… 0. If v and x contain ‘#’, then we can always pump it and the string will contain more than 2 #s. 1.part of the first a n 2.part of the first a n #b n 3.part of the first b n 4.part of the middle b n a n 5.part of the second a n 6.vwx is part of the last a n #b n 7.vwx is part of the last b n a……a#b……ba……a#b……b

30
Pumping lemma for CFG L 2 = {x#y#z : y R is a substring of xz; x, y, z ∈ {a,b}*}. Then z = _a n #b n a n #b n _ (z should contain n somewhere) is in L. Write z = uvwxy, where |vwx| ≤ n and |vx|≥ 1. 0. If v and x contain ‘#’, then we can always pump it and the string will contain more than 2 #s, which is not in L 2. 1.If vwx is part of the first a n, uv 0 wx 0 y = X#Y#Z contains less a’s in X than in Y. thus the Y R cannot be a substring of XZ. a……a#b……ba……a#b……b

31
Pumping lemma for CFG L 2 = {x#y#z : y R is a substring of xz; x, y, z ∈ {a,b}*}. Then z = _a n #b n a n #b n _ (z should contain n somewhere) is in L. Write z = uvwxy, where |vwx| ≤ n and |vx|≥ 1. 0. If v and x contain ‘#’, then we can always pump it and the string will contain more than 2 #s, which is not in L 2. 2.If vwx is part of the first a n #b n, v and x cannot be both empty If v is not empty, v must contain some a, uv 0 wx 0 y = X#Y#Z contains less a’s in X than in Y. thus the Y R cannot be a substring of XZ. If x is not empty, x must contain some b, uv 2 wx 2 y = X#Y#Z contains less b’s in X than in Y. thus the Y R cannot be a substring of XZ. The rest are similar, do explain them in the homework/exam. a……a#b……ba……a#b……b

32
End Questions?

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google