1 / 17

Decision problems for classes of languages

Decision problems for classes of languages. We sometimes need to know whether a language of a given class has a given property, e.g. is it empty? is it finite? is it regular? does it contain a particular string? In some cases, the answer is always yes or always no

Download Presentation

Decision problems for classes of languages

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. Decision problems for classes of languages • We sometimes need to know whether a language of a given class has a given property, e.g. • is it empty? is it finite? is it regular? • does it contain a particular string? • In some cases, the answer is always yes or always no • e.g., is a given finite language regular? • In other cases, there’s an algorithm for deciding the question

  2. Closure properties of regular languages • In some cases, applying a particular operation to languages of a given class always gives a result of that same class. • In these cases the language is said to be closed under that operation. • It's easy to see that regular languages are closed under the ⋃, ∙, and * operations • since the set of regular expressions is also closed under these operations

  3. Closure under complementation • The set of regular languages is closed under complementation. • If L is L(M), then an NFA for its complement L' can be obtained from M by complementing M's set of final states

  4. Closure under intersection • The set of regular languages is also closed under intersection. • suppose L1 and L2 are regular languages • then L1⋂ L2 = (L1' ⋃ L2')', which is regular • Linz gives a constructive proof on p. 101 • the set of states is Q1x Q2 • the set of final states is F1x F2 • d((q1, q2),a) = (d1(q1,a), d2(q2,a))

  5. New examples of regular languages • The set of binary representations of multiples of 3 greater than 10 • The set of strings of even length beginning and ending with 0

  6. Other closure properties • The set of regular languages is also closed under set difference • L1 - L2 = L1 ⋂ L2', the intersection of two regular languages • Linz describes several other less important operations under which the regular languages are closed • you’re responsible for his Sec. 4.1 only through the statement of Theorem 4.2

  7. Taking subsets and supersets • We can see that the class of regular languages is not closed under the taking of subsets or supersets • i.e., neither a subset nor a superset of a regular language is necessarily regular • L = { x ∊ {0,1}* | x has the same number of 0's as 1's} is not a regular language • 0m and 0n are distinguishable (by 1m) when m ≠ n • So L is a nonregular subset of {0,1}* • and anonregular superset of ∅

  8. Decision algorithms for regular languages • How do we represent an input language? • For regular languages, we can use a DFA, or NFA, or regular expression • we can convert from any of these representations to any other one if necessary • Some decision algorithms for regular languages may seem trivial • for other language classes, they’re much less so • in some cases, no algorithm is possible!

  9. Algorithms for decision problems • We already have algorithms for testing: • membership of a string in a regular language • find a DFA representation for the language if necessary • then run the DFA on the string • equality of two regular languages • find DFA representations for the languages if necessary • minimize both DFAs and compare them

  10. Other decision algorithms • emptiness of a regular language • find a DFA representation • see if any final state is accessible from q0 • whether a regular language equals S* • find a DFA representation • see if any nonfinal state is accessible from q0 • whether L is a subset of M • find a DFA for L-M and see if it accepts the empty language

  11. Finite and infinite languages • To test whether regular language L is infinite: • see if there’s a (directed) cycle that’s accessible • and from which a final state is accessible • If the DFA has n states, and L has a string w of length at least n, there will be such a cycle • an infinite language must have such a string • if y labels the cycle and w = xyz, then xyiz ∊ L for all i ≥ 0. • we have |y| > 0, and may assume that |xy| ≤ n

  12. Pumping strings • If L has a long string that can’t be “pumped” as described above, then L can’t be regular • One problem: we don’t know what n is. • We can say that if L is regular, every sufficiently long string can be pumped. • And thus if some sufficiently long string can’t be pumped, then L is not regular • More precisely, …

  13. The pumping lemma • …if L is regular, then • there’s an n such that • for every w ∊ L with |w| ≥ n, • there exist x, y, z with w = xyz, |y|>0, and |xy| ≤ n • and for all i ≥ 0, xyiz ∊ L • (Pumping lemma) L can’t be regular if • for every n, • there’s a w ∊ L with |w| ≥ n such that • for every x, y, z with w = xyz , |y|>0, and |xy| ≤ n • there’s an i ≥ 0 with xyiz ∉ L

  14. Using the pumping lemma • To show that a set is nonregular using the pumping lemma • we need to choose w and i • our “enemy” picks n, x, y, and z (cf. Linz, p. 117) • The less variation in w’s first n symbols, the less complicated the proof • in terms of needing separate cases

  15. A pumping lemma example • Consider L = { 0m1m | m ≥ 0 } • Given n, let w = 0n1n • We must have x = 0j and y = 0k, so z = 0n-j-k1n • So xyiz = 0j+ki+n-j-k1n = 0n+k(i-1)1n • Since k ≠ 0, this string is in L iff i = 1 • So any i other than 1 will work, completing the proof

  16. Generalizing our pumping lemma example • A similar proof works for {0r1s0r+s | r,s ≥ 0} • And for the set of balanced parentheses, defined as the set of strings in {(,)}* with • the same number of )’s as (’s, and • for which no prefix has more )’s than (’s • Note that for any reasonable language L for algebraic expressions, L ⋂ {(,)}* will be the language above • So such an L cannot be regular • We could have used this argument for { 0m1m | m ≥ 0 } • {0**r)(1**s)(0**(r+s)} • for palindromes (defined early in Ch 5) • can't just let w = 0**n • let w = (0**n)(1**n)(0**n) • 1{0**m)(1**m) • let w = 1{0**n)(1**n) • note that y may be 1 or 10**k or 0**k • in each case we get a contradiction • other nonregular sets are mentioned in exercises

  17. More general pumping lemma arguments • For { 0p1q | q > p ≥ 0 } • the original proof works, as long as i > 0 • For the set L of palindromes over {0,1} • choosing w = 0n won’t work; pumping stays in L • instead let w = 0n1n0n • For L = { 10m1m | m ≥ 0 } • we may let w = 10n 1n • but note that y may or may not contain 1 • these two cases need to be handled separately

More Related