Unit 6. Non Regular Languages The Pumping Lemma. Reading: Sipser, chapter 1

Similar documents
Computer Sciences Department

Finite Automata and Regular languages

CSE 105 THEORY OF COMPUTATION

Properties of Regular Languages. BBM Automata Theory and Formal Languages 1

CS 455/555: Finite automata

CSE 105 THEORY OF COMPUTATION

TDDD65 Introduction to the Theory of Computation

Sri vidya college of engineering and technology

CSE 105 THEORY OF COMPUTATION

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

Closure under the Regular Operations

More Properties of Regular Languages

CS5371 Theory of Computation. Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)

CS 154. Finite Automata, Nondeterminism, Regular Expressions

The Pumping Lemma and Closure Properties

Theory of Computation (I) Yijia Chen Fudan University

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CS 530: Theory of Computation Based on Sipser (second edition): Notes on regular languages(version 1.1)

Computational Models - Lecture 3 1

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

CSE 105 THEORY OF COMPUTATION

Formal Languages, Automata and Models of Computation

Theory of Computation p.1/?? Theory of Computation p.2/?? Unknown: Implicitly a Boolean variable: true if a word is

Closure Properties of Context-Free Languages. Foundations of Computer Science Theory

Automata: a short introduction

Computational Theory

Finite Automata and Regular Languages

Lecture 4: More on Regexps, Non-Regular Languages

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

CSci 311, Models of Computation Chapter 4 Properties of Regular Languages

Inf2A: Converting from NFAs to DFAs and Closure Properties

MA/CSSE 474 Theory of Computation

Incorrect reasoning about RL. Equivalence of NFA, DFA. Epsilon Closure. Proving equivalence. One direction is easy:

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

3515ICT: Theory of Computation. Regular languages

CPS 220 Theory of Computation REGULAR LANGUAGES

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

Before we show how languages can be proven not regular, first, how would we show a language is regular?

CSE 105 THEORY OF COMPUTATION

Languages. A language is a set of strings. String: A sequence of letters. Examples: cat, dog, house, Defined over an alphabet:

More on Finite Automata and Regular Languages. (NTU EE) Regular Languages Fall / 41

CS 154, Lecture 3: DFA NFA, Regular Expressions

Theory of Computation (II) Yijia Chen Fudan University

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 9 : Myhill-Nerode Theorem and applications

We define the multi-step transition function T : S Σ S as follows. 1. For any s S, T (s,λ) = s. 2. For any s S, x Σ and a Σ,

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Great Theoretical Ideas in Computer Science. Lecture 4: Deterministic Finite Automaton (DFA), Part 2

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Formal Languages. We ll use the English language as a running example.

Proving languages to be nonregular

Exam 1 CSU 390 Theory of Computation Fall 2007

Computational Models - Lecture 4

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Properties of Regular Languages. Wen-Guey Tzeng Department of Computer Science National Chiao Tung University

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 5 : DFA minimization

Theory of Computation

MA/CSSE 474 Theory of Computation. Your Questions? Previous class days' material Reading Assignments

CSE 105 THEORY OF COMPUTATION

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

Part 3 out of 5. Automata & languages. A primer on the Theory of Computation. Last week, we learned about closure and equivalence of regular languages

Harvard CS 121 and CSCI E-207 Lecture 4: NFAs vs. DFAs, Closure Properties

COMP4141 Theory of Computation

Uses of finite automata

Computational Models: Class 3

Equivalence of DFAs and NFAs

CSE 105 Homework 5 Due: Monday November 13, Instructions. should be on each page of the submission.

UNIT-III REGULAR LANGUAGES

CSE 105 THEORY OF COMPUTATION

MA/CSSE 474 Theory of Computation

Finite Automata (contd)

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

What we have done so far

Theory of Computation Lecture 1. Dr. Nahla Belal

CS 275 Automata and Formal Language Theory

Finite Automata Part Two

CSE 105 THEORY OF COMPUTATION

V Honors Theory of Computation

Computational Models #1

CSE 105 THEORY OF COMPUTATION

CMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata

Lecture 7 Properties of regular languages

Lecture 3: Nondeterministic Finite Automata

Closure under the Regular Operations

CSE 105 THEORY OF COMPUTATION

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

FS Properties and FSTs

Notes for Comp 497 (Comp 454) Week 5 2/22/05. Today we will look at some of the rest of the material in Part 1 of the book.

Regular Expressions and Language Properties

We have seen many ways to specify Regular languages. Are all languages Regular languages?

Büchi Automata and their closure properties. - Ajith S and Ankit Kumar

Finite Automata and Languages

CHAPTER 1 Regular Languages. Contents

Warshall s algorithm

10. The GNFA method is used to show that

Transcription:

Unit 6 Non Regular Languages The Pumping Lemma Reading: Sipser, chapter 1 1

Are all languages regular? No! Most of the languages are not regular! Why? A finite automaton has limited memory. How can we show that a language is regular? How can we show that a language is not-regular? 2

Finite Languages Theorem: If L is finite then L is regular. Proof idea: Build an automaton for every word w in L: A(w). Add q start with -transitions to every initial state of A(w) The resulting automaton recognizes L. 3

What About Infinite Languages? Infinite language could be regular or non-regular Example of an infinite regular language: L={0 n 1 m n,m>0} Example of a non-regular language: L = {0 n 1 m m>n} 4

Example of an infinite non-regular language The language L = {0 n 1 m m>n} is not regular. It is not regular because when we reach substring of 1 s we have to remember the length of the 0 s substring. The length is remembered by states - one state for each letter. The length of the 0's prefix can be any number. A finite automaton has a finite number of states. So it can not remember the length of 0 s prefix. 5

The Pumping Lemma The central theorem concerning regular languages. It determines the basic nature of regular languages. Any regular language satisfies the Lemma. A language that does not satisfy the Lemma must be non-regular. 6

The Pumping Idea Assume an automaton with n states. Any word w, w n must include a loop. Denote the part before the loop by x. The loop is y. The part after the loop is z. The z part ends with an accepting state as the word is in L. q 0 x r z f y 7

The Pumping Idea (cont.) The loop can be repeated any number of times and still go through z to an accepting state. Hence the y part can be pumped. We can repeat the loop any number of times and still proceed through z to accepting state. q 0 x r z f y 8

The Pumping Lemma Lemma: If L is a regular language then there is a number n such that any string w L, where w n, can be divided into three parts w=xyz such that: 1. y >0 2. xy n 3. For each i 0 xy i z L q 0 x r z f y 9

Informally For each regular language there is a constant number n, such that any string of length more than n can be pumped. The pumped part (y) should not be of length 0 (at least one letter). The parts before and after the "pumpable" part (x,z) could be. The part we may pump is inside a prefix (xy) of length at most n. 10

Formal Proof Let M be a DFA that recognizes L. Let n be the number of states of M. Let w be a string in L of length at least n. It has a prefix of length n. The sequence of states in automaton M that we go through while processing the prefix is q 0 and one state for each letter read. After reading this prefix we have a sequence of n+1 states. 11

Formal Proof (cont.) As there are only n different states in automaton M at least one state has to be repeated while reading the prefix. Denote one of them r. Let x be the prefix of w read before first appearance of r. Let y be the substring of y read between first and second appearance of r. And let z be the substring of w read after second appearance of r till the end w. 12

Formal Proof (cont.) z ends with an accepting state f because the string is in L. y is a loop in the automaton. y has at least length 1 because we move from state to state in the DFA only upon reading a letter. q 0 x r z f y 13

Formal Proof (cont.) As there is a path from r to an accepting state f there is a direct path q 0 r f without going through the r loop even once (xy 0 z=xz). On the other hand we can go through the loop more than once and still get out from r to f (xy i z). There is no limit on a number of times we can go through the loop. Q.E.D. 14

Example of an infinite languages automaton L= ab*c b q a 0 q c 1 q 2 Each word in L consists of a path q 0 q 1 followed by any number of loops on q 1, followed by a path q 1 q 2. Denote the path from q 0 to q 1 by x Denote the path from q 1 to q 1 by y Denote the path from q 1 to q 2 by z We can say that each word w L is xy i z. 15

Another example q 2 a,b All the strings over * In this case x and z can be. For any word of length 1, y is not. 16

Finite Languages Let s consider the following automaton: 0,1 0,1 0,1 q 0 q 1 q 2 q 3 0,1 A has 4 states. L(A) is all words of length 2 or less. L(A) is regular, however, does the pumping lemma work here??? Theorem: For a DFA A, if L(A) is finite, and the number of states in A is n, then the longest word in L has length < n Proof: if (w L and w n) then (w=xyz) s.t. 1+2+3 exists, thus L is infinite. 17

Usage of the Pumping Lemma The main usage of pumping lemma is to prove that some language is not regular. The technique: 1. Assume that the language is regular. 2. Assume some n, and find a string w that has a length greater than n. 3. Show that for any partition of w into x,y,z such that properties 1 and 2 of pumping lemma hold, there exists an i such that xy i z is not in the language. 18

The Lemma: Caveats If L is regular n, s.t. (w L and w n) (w=xyz) s.t. 1+2+3 exists. regular(l) lemma (L). lemma (L) / regular(l). ~lemma(l) ~regular(l). In order to show that L is non-regular, one has to show that n, (w L and w n) s.t. (w=xyz), ~1 or ~2 or ~3. 19

The Lemma: Caveats If L is regular n, s.t. (w L and w n) (w=xyz) s.t. 1+2+3 exists. regular(l) lemma (L). lemma (L) / regular(l). ~lemma(l) ~regular(l). In order to show that L is non-regular, one has to show that n, (w L and w n) s.t. (w=xyz), ~1 or ~2 or ~3 20

Common Mistakes w L s.t. lemma(w) regular(l) w L, lemma(w) regular(l) w L and (w=xyz ) s.t. xy i z L ~regular(l) (you must show for all possible decompositions) w L and (w=xyz) xy i z L ~regular(l) ( w might be smaller than n) 21

L = {0 m 1 m m>0} We will use the pumping lemma to show that L = {0 m 1 m m>0} is not regular. Assume to the contrary that L is regular. Let n be the number promised by the pumping lemma. Consider w= 0 n 1 n. w is in L, w >n so by the pumping lemma w can be divided into three parts w=xyz. 22

L = {0 m 1 m m>0} (cont.) x and y are both in prefix of length n and so are consist of 0's. Denote the length of x by s and the length of y by t. Then : x=0 s s 0 y=0 t t 1, s+t n z=0 n-s-t 1 n 000 0000111 111 s t By the pumping lemma if the language is regular then xy i z is in L for any i. 23

Take i=2. L = {0 m 1 m m>0} (cont.) The resulting word is xy 2 z = 0 s 0 2t 0 n-s-t 1 n = 0 n+t 1 n. It is not in L as t 1 and the number of 0 is greater than the number of 1. Thus we have a contradiction to the pumping lemma. That means: our assumption that L is regular is wrong. L is not a regular language. Q.E.D. 24

L={a k! k 0} Is L={a k! k 0} regular? We will use the pumping lemma to show that L is not regular. Assume to the contrary that L is regular. Let n be the number promised by the pumping lemma. We choose w= a n! where n=max(n,2). w is in L, w n so by the pumping lemma w can be divided into three parts w=xyz. 25

L={a k! k 0} x and y consist of a's. Denote the length of x by s and the length of y by t. Then : x=a s, s 0 y=a t, t>0, s+t n z=a n!-t-s By the pumping lemma if the language is regular then xy i z is in L for any i. 26

Take i=2. L={a k! k 0} The resulting word is xy 2 z = a n!+t. We know that t>0 and t n, which means n!+t n!+n < n!+(n+1) < n!*(n+1) = (n+1)! Thus we have a contradiction to the pumping lemma, contradicting our assumption that L is regular. 27

L={0 m 1 n m>n} Assume L is regular. Let p be the number promised by the Lemma. Let w=0 p+1 1 p w can be split w into xyz. Since xy p, y consists of only 0s, y >0. # 0 (xy 0 z) # 1 (xy 0 z) xy 0 z L contradicting the pumping lemma. L is non-regular. 28

L = {w # 1 (w) = # 0 (w)} Is L regular? (no!) Proof idea: Assume to the contrary that L is regular. By the pumping lemma we have n s.t. Choose w=0 n 1 n L Pump w towards w L Problem: if we choose y=0 n 1 n then w L?? 29

L = {w # 1 (w) = # 0 (w)} Is L regular? (no!) Proof : Regular languages are close under intersection. Assume to the contrary that L is regular. It gives L =(0*1* L ) is regular. But L =0 n 1 n is not regular! L is non-regular 30

Is L regular? (no.) L = {ww w {0,1}* } Proof idea: Assume to the contrary that L is regular. By the pumping lemma we have n s.t. Choose w=0 n 10 n 1 L Pump w towards w L 31

Regular Languages Regular Expression Regular Languages DFA NFA A language is NOT regular if it does not satisfy the Pumping Lemma A language is regular if it has a DFA/NFA/RE recognizing it Pumping Lemma 32

Regular Languages: Recap Finite Automata (Q,,,q 0,F) Regular languages Closures (union, intersection, complements, minus) Non deterministic automaton: : Qx 2 Q Equivalence DFA NFA Closures (concatenation, Kleene star). Regular Expressions Equivalence DFA RE Minimal DFA Pumping Lemma. 33