Non-regular languages

Slides:



Advertisements
Similar presentations
CSCI 3130: Formal languages and automata theory Tutorial 5
Advertisements

Lecture 10 Pumping Lemma A property of regular sets.
Fall 2006Costas Busch - RPI1 Non-regular languages (Pumping Lemma)
CSCI 2670 Introduction to Theory of Computing September 13, 2005.
Nonregular languages Sipser 1.4 (pages 77-82). CS 311 Mount Holyoke College 2 Nonregular languages? We now know: –Regular languages may be specified either.
Nonregular languages Sipser 1.4 (pages 77-82). CS 311 Fall Nonregular languages? We now know: –Regular languages may be specified either by regular.
CS 310 – Fall 2006 Pacific University CS310 Pumping Lemma Sections:1.4 page 77 September 27, 2006.
Formal languages and automata theory Li Fan. Pumping Lemma Let L be a regular set. Then there is a constant n such that if z is any word in L, and |z|>=n,
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Limitations.
Courtesy Costas Busch - RPI1 Non-regular languages.
Homework 4 Solutions.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
Prof. Busch - LSU1 Non-regular languages (Pumping Lemma)
1 Non-regular languages. 2 Regular languages Non-regular languages.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
Tutorial CSC3130 : Formal Languages and Automata Theory Haifeng Wan ( )
CSCI 3130: Formal languages and automata theory Tutorial 2 Chin.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Text search.
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
Class Discussion Can you draw a DFA that accepts the language {a k b k | k = 0,1,2,…} over the alphabet  ={a,b}?
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to.
CSCI 3130: Formal languages and automata theory Tutorial 3 Chin.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
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.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
1 Find as many examples as you can of w, x, y, z so that w is accepted by this DFA, w = x y z, y ≠ ε, | x y | ≤ 7, and x y n z is in L for all n ≥ 0.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Limitations.
Cs466(Prasad)L11PLEG1 Examples Applying Pumping Lemma.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Undecidable.
Nondeterminism The Chinese University of Hong Kong Fall 2011
CSE 105 theory of computation
Complexity and Computability Theory I
Formal Language & Automata Theory
Non-regular languages
Standard Representations of Regular Languages
CSE322 PUMPING LEMMA FOR REGULAR SETS AND ITS APPLICATIONS
LR(k) grammars The Chinese University of Hong Kong Fall 2009
PROPERTIES OF REGULAR LANGUAGES
Nonregular Languages Section 2.4 Wed, Oct 5, 2005.
Reducibility The Chinese University of Hong Kong Fall 2010
Intro to Theory of Computation
Pumping Lemma for Regular Languages some languages are not regular!
Properties of Regular Languages
More on DFA minimization and DFA equivalence
Hopcroft, Motawi, Ullman, Chap 4, sections 4.1 and 4.2
Properties of Regular Languages
NFAs, DFAs, and regular expressions
Elementary Questions about Regular Languages
Non-regular languages
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Chapter 4 Properties of Regular Languages
Nonregular languages & the pumping lemma
Are all Languages Regular
Non-Regular Languages
More undecidable languages
NFA to DFA conversion and regular expressions
Limitations of pushdown automata
Non-regular languages
Pushdown automata The Chinese University of Hong Kong Fall 2011
LR(k) grammars The Chinese University of Hong Kong Fall 2008
Text search and closure properties
DFA minimization The Chinese University of Hong Kong Fall 2011
CHAPTER 1 Regular Languages
Limitations of context-free languages
CSCI 2670 Introduction to Theory of Computing
Nondeterminism The Chinese University of Hong Kong Fall 2010
Presentation transcript:

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

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 outside L L = {0n1n: n ≥ 0} is not regular.

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

A non-regular language M x 0r1n+1 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

Pigeonhole principle Suppose you are tossing n + 1 balls into n bins. Then two balls end up in the same bin. Here, balls are 0s, bins are states: 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.

A non-regular language M x 0r1n+1 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 revisit at least one of its states while reading 0n+1 But then the DFA must contain a loop with 0s

A non-regular language M 0r1n+1 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!

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 a1 ak ak+1 an-1 … … an+1…am

Pumping lemma for regular languages Pumping lemma: For every regular language L There exists a number n such 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 … … u w

Arguing non-regularity If L is regular, then: So to prove L is not regular, it is enough to show: There exists n such 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 n there 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.

Proving non regularity For every n there 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 n write z = uvw (|uv| ≤ n,|v| ≥ 1) you choose z  L choose i you win if uviw  L 1 2

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

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

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

Which of these are regular? 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} S = {0, 1}

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

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

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

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

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

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

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

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

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