CSCI 3130: Formal languages and automata theory Tutorial 5

Slides:



Advertisements
Similar presentations
The Pumping Lemma for CFL’s
Advertisements

INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
CS21 Decidability and Tractability
Examples for Context-free Language and Pumping Lemma CSC3130 Tutorial 5 Xiao Linfu Department of Computer Science & Engineering.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
Chap 2 Context-Free Languages. Context-free Grammars is not regular Context-free grammar : eg. G 1 : A  0A1substitution rules A  Bproduction rules B.
127 The Chomsky Hierarchy(review) Recursively Enumerable Sets Turing Machines Post System Markov Algorithms,  -recursive Functions Regular Expression.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 9, 2006.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.
CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)
Homework 4 Solutions.
1 CSCI 3130: Formal Languages and Automata Theory Tutorial 4 Hung Chun Ho Office: SHB 1026 Department of Computer Science & Engineering.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
1 Background Information for the Pumping Lemma for Context-Free Languages Definition: Let G = (V, T, P, S) be a CFL. If every production in P is of the.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
CS5371 Theory of Computation Lecture 12: Computability III (Decidable Languages relating to DFA, NFA, and CFG)
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Chapter 12: Context-Free Languages and Pushdown Automata
Tutorial CSC3130 : Formal Languages and Automata Theory Haifeng Wan ( )
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
The Pumping Lemma for Context Free Grammars. Chomsky Normal Form Chomsky Normal Form (CNF) is a simple and useful form of a CFG Every rule of a CNF grammar.
Pushdown Automata CS 130: Theory of Computation HMU textbook, Chap 6.
Context-free Languages Chapter 2. Ambiguity.
Section 12.4 Context-Free Language Topics
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
CS 203: Introduction to Formal Languages and Automata
Pumping Lemma for CFLs. Theorem 7.17: Let G be a CFG in CNF and w a string in L(G). Suppose we have a parse tree for w. If the length of the longest path.
CSCI 3130: Formal languages and automata theory Tutorial 3 Chin.
1 Applications of pumping lemma(Dr. Torng) Applications of Pumping Lemma –General proof template What is the same in every proof What changes in every.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
CSCI 3130: Formal languages and automata theory Tutorial 1 Lee Chin Ho.
1 Alphabets: An Alphabet is a finite set of symbols. We will usually use  to denote the alphabet of input symbols or “terminal characters.” String: A.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Limitations.
Lecture 14 Push Down Automata (PDA) Topics:  Definition  Moves of the PDA  Languages of the PDA  Deterministic PDA’s June 18, 2015 CSCE 355 Foundations.
Lecture #5 Advanced Computation Theory Finite Automata.
CSCI 2670 Introduction to Theory of Computing September 22, 2004.
Lecture # 21.
Formal Languages, Automata and Models of Computation
7. Properties of Context-Free Languages
Lecture 22 Pumping Lemma for Context Free Languages
PDA’s - A new format for FAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Pushdown Automata PDAs
Non-Context-Free Languages Sections: 2.3 page 123 October 17, 2008
Intro to Theory of Computation
CSCI 3130: Formal languages and automata theory Tutorial 6
Definition: Let G = (V, T, P, S) be a CFL
7. Properties of Context-Free Languages
فصل دوم Context-Free Languages
Properties of Context-Free Languages
Department of Computer Science & Engineering
Definition Moves of the PDA Languages of the PDA Deterministic PDA’s
Midterm #2 — Review problems
Limitations of pushdown automata
Pushdown automata The Chinese University of Hong Kong Fall 2011
Limitations of context-free languages
Presentation transcript:

CSCI 3130: Formal languages and automata theory Tutorial 5 Chin

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

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.

Homework 2 To show a language is not regular You only have to choose one string. The chosen string should be in terms of n. 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. You only have to choose one value for i.

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

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

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

Homework 2 Problem 1 (d) A few students did the following Let L1 = {anb: n ≥ 0}, L2 = {an: n ≥ 0} Then L1L2 = {anban : n ≥ 0}. wrong! The n in L1 and the n in L2 are independent. L1L2 = {anbam : n, m ≥ 0}.

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

Homework 2 Problem 2 (c) L3 = {w : w does not have the same number of as, bs, and cs} A few students got L3 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.

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.

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”.

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 a, b/c q0 q1

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

Pushdown Automata Design a PDA for the following. S = {a, b, c} L1 = {x : x has fewer a’s than b’s and c’s together} L2 = {aibjck : i = j or j = k}

Pushdown Automata L1 = {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 e, e / $ e, $ / e q0 q1 q2 0, e / 0 1, e / 1 0, 1 / e 1, 0 / e e, e / $ e, $ / e q0 q1 q3 a, e / a b, e / x a, x / e b, a / e c, e / x c, a / e

Pushdown Automata L1 = {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 e, e / $ e, $ / e q0 q1 q3 a, e / a b, e / x b, a / e a, x / e c, e / x c, a / e e, e / $ e, x / e e, $ / e q0 q1 q2 q3 a, e / a b, e / x b, a / e e, x / e a, x / e c, e / x c, a / e

Pushdown Automata L2 = {aibjck : i = j or j = k} Separate it into two cases {aibjck : i = j } U {aibjck : j = k} {aibjck : i = j } Lecture: L = {w: w has same number 0s and 1s} e, e / $ e, $ / e q0 q1 q2 0, e / 0 1, e / 1 0, 1 / e 1, 0 / e

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

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

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

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 uviwxiy is not in L for some i ≥ 0. z depends on n u, w, y can be empty string v, x can also be empty string, but not both. i can be 0 (very useful) You only have to choose one z Unlike the regular language version, vwx can be anywhere in z.

Pumping lemma for Context-free languages 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 CFG Show that the following languages are not context-free L1 = {anbmanbm : m, n ≥ 0}. S = {a, b}. L2 = {x#y#z : yR is a substring of xz; x, y, z ∈ {a,b}*}. S = {a, b, #}.

Pumping lemma for CFG L1 = {anbmanbm : m, n ≥ 0}. S = {a, b}. Suppose L is context-free. Let n be the pumping length. Then z = _anbnanbn_ (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?

Pumping lemma for CFG L1 = {anbmanbm : m, n ≥ 0}. S = {a, b}. Then z = _anbnanbn_ (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… part of the first an part of the first anbn part of the first bn part of the middle bnan part of the second an part of the second anbn part of the last bn a……ab……ba……ab……b

Pumping lemma for CFG L1 = {anbmanbm : m, n ≥ 0}. S = {a, b}. Then z = _anbnanbn_ (z should contain n somewhere) is in L. Write z = uvwxy, where |vwx| ≤ n and |vx|≥ 1. If vwx is part of the first an uv2wx2y has less a’s in the first group than the second group If vwx is part of the first anbn v and x cannot be both empty If v is not empty, v must contain some a, uv0wx0y has less a’s in the first group than the second group If x is not empty, x must contain some b, uv0wx0y 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

Pumping lemma for CFG L2 = {x#y#z : yR is a substring of xz; x, y, z ∈ {a,b}*}. Suppose L is context-free. Let n be the pumping length. Then z = _an#bnan#bn_ (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?

Pumping lemma for CFG a……a#b……ba……a#b……b L2 = {x#y#z : yR is a substring of xz; x, y, z ∈ {a,b}*}. Then z = _an#bnan#bn_ (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. part of the first an part of the first an#bn part of the first bn part of the middle bnan part of the second an vwx is part of the last an#bn vwx is part of the last bn a……a#b……ba……a#b……b

Pumping lemma for CFG L2 = {x#y#z : yR is a substring of xz; x, y, z ∈ {a,b}*}. Then z = _an#bnan#bn_ (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 L2. If vwx is part of the first an, uv0wx0y = X#Y#Z contains less a’s in X than in Y. thus the YR cannot be a substring of XZ. a……a#b……ba……a#b……b

Pumping lemma for CFG a……a#b……ba……a#b……b L2 = {x#y#z : yR is a substring of xz; x, y, z ∈ {a,b}*}. Then z = _an#bnan#bn_ (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 L2. If vwx is part of the first an#bn, v and x cannot be both empty If v is not empty, v must contain some a, uv0wx0y = X#Y#Z contains less a’s in X than in Y. thus the YR cannot be a substring of XZ. If x is not empty, x must contain some b, uv2wx2y = X#Y#Z contains less b’s in X than in Y. The rest are similar, do explain them in the homework/exam. a……a#b……ba……a#b……b

End Questions?