1 / 15

Introduction to CS Theory

Introduction to CS Theory. Lecture 6 – Kleene’s Theorem, Pumping Lemma Piotr Faliszewski pf@cs.rit.edu. NFAs Formal definition δ * function, acceptance by an NFA Converting an FA to an NFA Converting an NFA to an FA NFA- ε ε -closures. Previous Class. NFA

grist
Télécharger la présentation

Introduction to CS Theory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to CS Theory Lecture 6 – Kleene’s Theorem, Pumping Lemma Piotr Faliszewski pf@cs.rit.edu

  2. NFAs Formal definition δ* function, acceptance by an NFA Converting an FA to an NFA Converting an NFA to an FA NFA-ε ε-closures Previous Class

  3. NFA We allow multiple transitions with the same label We allow missing transitions… NFA-ε We additionally allow transitions labeled with ε We can follow an ε-transition at any time, without consuming another symbol of input Consider the NFA-ε below. Does it accept aba abab aaabbb Exercise: Give NFA-ε’s for the following languages a*b*c* 0*(01)*0* Can we get NFAs for them as well? NFA’s With ε-Transitions a b a a,b ε a ε b

  4. Def. NFA-ε M is a quintuple M = (Q, Σ, q0, A, δ) where: Q – set of states Σ – input alphabet q0 – initial state (q0 Q) A – set of accepting states (A  Q) δ – transition function δ: Q  (Σ  {ε})  2Q We want: δ*(q,x) = set of states that M can reach if it starts from state q and sees string x But we need to handle ε-transitions first. S – set of states ε(S) – the ε closure of S (i.e., all states reachable from S via ε-transitions). Define ε(S) properly. Now define δ*(q,x) properly. NFA-ε – Formal Definition Def.We say that a finite automaton M = (Q, Σ, q0, A, δ) accepts a string x  Σ* iff δ*(q0, x) A. L(M) = set of strings accepted by M

  5. NFA-ε’s are no weaker than NFAs Almost immediate! NFA “is” an NFA-ε with no ε-transitions Can we use NFA-ε’s instead of NFAs for free? How can we simulate the ε-transitions. NFAs versus NFA-ε’s Yes! Show how! Conclusion: NFAs, NFA-ε, and FAs are all equvialent!

  6. Example: Conversions • Conversion to an NFA • Start state? • Transitions? • Convert • To NFA • Then to FA C 0 0 0 1 ε ε B A D

  7. Kleene’s Theorem • Theorem • A language L is regular if and only if there is finite automaton M such that L = L(M) • Proof • Two parts • For each regular expression r there is an FA M such that L(M) = L(r) (L(r) – the set of strings described by the regular expression) • For each FA M, L(M) is regular • Proof: Mostly on the board

  8. Kleene’s Theorem: Part 1 • Theorem • For each regular expression r there is an FA M such that L(M) = L(r) (L(r) – the set of strings described by the regular expression) • Proof • Given: Regular expression r, r is either • ε, , aΣ, or • r1r2 • r1+r2 • (r1)* • where r1 and r2 are two (smaller) regular expressions (structural induction) • In each case we can convert! • Example: Convert • (0+1)*0 • (00+1)*(10)*

  9. Kleene’s Theorem: Part 2 • Theorem • For each FA M, L(M) is regular • Proof • Wow, this is nontrivial! Need some insight! • We will focus on the construction • Correctness: Implicit and natural. M = (Q, Σ, q0, δ, A) be an FA L(p,q) = {x | δ*(p,x) = q } L(p,q,k) = {x | δ*(p,x) = q without ever going through state with a number > k} L(p,q,||Q||) = L(p,q) How to use these definitions in an inductive proof? (Board!)

  10. Kleene’s Theorem: Part 2 (Example) • Convert the following FA to a regular expression • That’s a LOT of work! 2 b a a b b 1 a 3

  11. Kleene’s Theorem: Part 2 (Example) • Convert the following NFA to a regular expression • Generalized NFA method! D a,b a b b B A a C

  12. How can we prove that a language is not regular? If a language is finite, it is regular All infinite regular languages share a certain property… Consider a regular language L and an FA M such that L = L(M) Assume M has n states. Consider a sequence of states that M goes through on an input of length n… What can you say about strings in L? Example FA Proving Languages Nonregular 2 b a a b b 1 a 3

  13. Theorem (The Pumping Lemma) Let L be a regular language. There is an integer n such that for any x  L with |x|  n there are strings u, v, w such that x = uvw |uv| ≤ n |v| > 0 For each m  0, uvmw  L Applications of the pumping lemma Showing that some language is not regular Prove that for this language the pumping lemma does not hold Just because the pumping lemma holds does not mean that the language is regular! The Pumping Lemma

  14. Proving a Language Nonregular Set L = {aibi | i  N }. Goal: Show that L is not regular. Proof. (by contradiction) Suppose that L is regular. Thus, pumping lemma holds for L and there exists an n such that for each string x in L, |x| > n, there are strings u, v, w such that • x = uvm, • |uv| ≤ n • |v| > 0 • For each m  0, uvmw  L Pick x = anbn. The pumping lemma implies however that for some j  1 it holds that an+jbn is in L! But this is false. A contradiction..

  15. Nonmechanical elements of a “pumping lemma”-based nonregularity proof Choose x of length at least n. Choose m (often 0 or 2, never 1) Derive the contradiction Some examples: L1 = {ai | i is a square} L2 = {ai | i is prime} L3 = {ww | w  Σ*} L4 = {w | w has an equal number of a’s and b’s} Steps of a “Pumping Lemma” Proof

More Related