1 / 24

CSCI 3130: Automata theory and formal languages

Explore non-regular languages and formal languages using automata theory. Learn methods to prove non-regularity, like the Pigeonhole principle and the Pumping lemma. Engage in strategic reasoning games to show the non-regularity of languages.

marsj
Download Presentation

CSCI 3130: Automata theory and formal 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. Fall 2011 The Chinese University of Hong Kong CSCI 3130: Automata theory and formal languages Non-regular languages Andrej Bogdanov http://www.cse.cuhk.edu.hk/~andrejb/csc3130

  2. A non-regular language • An example • We reason by contradiction: • Suppose we have managed to construct a DFA M for L • We argue something must be wrong with this DFA • In particular, M must accept some strings outsideL L = {0n1n: n ≥ 0} is not regular.

  3. A non-regular language imaginary DFA for L with n states • What happens when we run M on input x = 0n+11n+1? • M better accept, because xL M x

  4. A non-regular language • What happens when we run M on input x = 0n+11n+1? • M better accept, because xL • But since M has n states, it must revisit at least one of its states while reading 0n+1 0 M x 0 0 0 0 0r1n+1

  5. Pigeonhole principle • Here, balls are 0s, bins are states: Suppose you are tossing n+ 1 balls into n bins. Then two balls end up in the same bin. If you have a DFA with n states and it reads n + 1 consecutive 0s, then it must end up in the same state twice.

  6. A non-regular language • What happens when we run M on input x = 0n+11n+1? • M better accept, because xL2 • But since M has n states, it must revisitat least one of its states while reading 0n+1 • But then the DFA must contain a loop with 0s 0 M x 0 0 0 0 0r1n+1

  7. A non-regular language • The DFA will then also accept strings that go around the loop multiple times • But such strings have more 0s than 1s, so they are not in L2! 0 M 0 0 0 0 0r1n+1

  8. General method for showing non-regularity • Every regular language L has a property: • For every sufficiently long input z in L, there is a “middle part” in z that, even if repeated any number of times, keeps the input inside L an z an-1 a1 ak+1 ak … … an+1…am

  9. Pumping lemma for regular languages • Pumping lemma: For every regular language L There exists a number nsuch that for every string z in L, we can write z = u v w where |uv| ≤ n |v| ≥ 1 For every i≥ 0, the string u vi w is in L. v z … … w u

  10. Arguing non-regularity • If L is regular, then: • So to prove L is not regular, it is enough to show: There exists nsuch that for every z in L, we can write z = u v w where|uv| ≤ n, |v| ≥ 1 and  For every i≥ 0, the string u vi w is in L. For every nthere exists z in L, such that for every way of writing z = u v w where|uv| ≤ n and|v| ≥ 1, the string u vi w is not in L for some i≥ 0.

  11. Proving non regularity For every nthere exists z in L, such that for every way of writing z = u v w where|uv| ≤ n and|v| ≥ 1, the string u vi w is not in L for some i≥ 0. • This is a game between you and an imagined adversary (say Donald) Donald choose nwrite z = uvw (|uv| ≤ n,|v| ≥ 1) you choose zLchoose iyou win if uviwL 1 2

  12. Arguing non-regularity • You need to give a strategy that, regardless of what the adversary does, always wins you the game Donald choose nwrite z = uvw (|uv| ≤ n,|v| ≥ 1) you choose zLchoose iyou win if uviwL 1 2

  13. Example Donald choose nwrite z = uvw (|uv| ≤ n,|v| ≥ 1) you choose zLchoose iyou win if uviwL 1 2 L = {0n1n: n ≥ 0} Donald you choose n z= 0n1n 1 write z = uvw i = 2 2 uv2w = 0n+k1nL 000000000000000111111111111111 u v w 0000000000000000000111111111111111 u v w v

  14. Example LDUP = {0n10n1: n ≥ 0} Donald you choose n z= 0n10n1 1 write z = uvw i = 2 2 uv2w = 0n+k10n1 L 000000000000001000000000000001 u v w 0000000000000000001000000000000001 u v w v

  15. Which of these are regular? S = {0, 1} L1 = {x: x has same number of 0s and 1s} L2 = {x: x = 0n1m, n > m≥ 0} L3 = {x: x has same number of patterns 01 and 10} L4 = {x: x has same number of patterns 01 and 10} L5 = {x: x has different number of 0s and 1s}

  16. Example L1 = {x: x has same number of 0s and 1s} Donald you choose n z= 0n1n 1 write z = uvw i = 2 2 uv2w = 0n+k1nL3 000000000000000111111111111111 u v w 0000000000000000000111111111111111 u v w v

  17. Example L2 = {x: x = 0m1n, m > n≥ 0} Donald you choose n z= 0n+11n 1 write z = uvw i = 0 2 uv0w = 0j+l1n+1 L2 000000000000000111111111111111 u v w 00000000000111111111111111 u w

  18. Example L3 = {x: x has same number of 01s and 11s} Donald you choose n z= (01)n(11)n 1 n = 1 L4 z= 0111 has too many 11s What we have in mind: n = 1 z= 011 z= (01)n1n n = 2 z= 010111 has n01s and n11s n = 3 z= 010101111

  19. Example L3 = {x: x has same number of 01s and 11s} Donald you win! choose n z= (01)n1n 1 write z = uvw i = 0 2 Taking out v will kill at least one 01, but it does not kill any 11s or 010101010101010111111111 010101010101010111111111 010101010101010111111111 so uv0w L3 or u u u v v v w w w

  20. Example L4 = {x: x has same number of 01s and 01s} Donald you choose n z= (01)n(10)n 1 n = 1 z= 0110 n = 2 z= 01011010 n = 3 z= 010101101010

  21. Example L4 = {x: x has same number of 01s and 10s} is regular! Donald you choose n z= (01)n(10)n 1 write z = uvw i = 2 i = 0 2 5 01 patterns 5 10 patterns 010101101010 u v w 6 01 patterns 4 01 patterns 6 10 patterns 4 10 patterns 01010101101010 0101101010 u v u v w w

  22. Example one more 10 1 0 0 r1 r0 1 1 q0 one more 01 0 1 0 1 s1 s0 0 L4 = {x: x has same number of 01s and 10s}

  23. Example L4 = {x: x has different number of 0s than 1s} Donald you choose n z= ? 1 there is an easier way! L1 = {x: x has same number of 0s and 1s} = L4 If L4 is regular, then L1= L4is also regular But L1 is not regular, so L4 cannot be regular

  24. Extra example L5 = {1p: p is prime} Donald you choose n z= 1p: p > n is prime 1 = a + c = ? write z = uvw = 1a1b1c i 2 uviw = 1a1ib1c = 1(a+c)+ib = 1(a+c)+(a+c)b = 1(a+c)(b+1) = 1compositeL5 111111111111111111111111111111 u = 1a v = 1b w = 1c

More Related