Presentation is loading. Please wait.

Presentation is loading. Please wait.

Complexity and Computability Theory I

Similar presentations


Presentation on theme: "Complexity and Computability Theory I"— Presentation transcript:

1 Complexity and Computability Theory I
Lecture #7 Instructor: Rina Zviel-Girshin Leah Epstein

2 Rina Zviel-Girshin @ASC
Overview Nonregular languages The pumping lemma Examples Rina Zviel-Girshin @ASC

3 Are all languages regular?
No. Most of the languages are not regular. Why? A finite automaton has limited memory. Rina Zviel-Girshin @ASC

4 Rina Zviel-Girshin @ASC
Example The language L = {0n1n | n>0} is not regular. Two sequences of same length: first of 0's and second of 1's. 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 0's substring can be any number. A finite automaton has a finite number of states. So it can not remember the length of 0’s substring. Rina Zviel-Girshin @ASC

5 Rina Zviel-Girshin @ASC
The pumping lemma The central theorem concerning regular languages is the pumping lemma. It determines the basic nature of regular languages. A basic property of a regular language is in each word (except for a small finite set of words) there is a part which can be repeated and the resulting word - "pumped" word - is still in the language. The lemma that allows the "pumping" is called the pumping lemma. Rina Zviel-Girshin @ASC

6 Examples of automata and finite languages
If L(A) is finite, and number of states in A is n, then the longest word in L is less than n in length.  Example: A: A has 3 states. The language of A is all words of length 2 or less. Rina Zviel-Girshin @ASC

7 Rina Zviel-Girshin @ASC
Finite Languages If L is finite then L is regular. Proof idea: Build an automaton for every word w in L: A(w). Add qstart with -transitions to each q0 of A(w) The resulting automaton recognizes L. Rina Zviel-Girshin @ASC

8 Examples of automata and infinite languages
L= ab*c A: Each word in L has a path q0any number of loops on q1q2. Denote the path from q0 to q1 by x Denote the path from q1 to q1 by y Denote the path from q1 to q2 by z Rina Zviel-Girshin @ASC

9 Rina Zviel-Girshin @ASC
Examples (cont.) Each word in L has the following three parts: x – a substring on which A goes from q0 to q1 y – a substring on which A goes from q1 to q1 z – a substring on which A goes from q1 to q2  We can say that each word wL is xyz. Rina Zviel-Girshin @ASC

10 Rina Zviel-Girshin @ASC
Examples (cont.) All the strings over the * We see that x and z can be . y is never . Rina Zviel-Girshin @ASC

11 Rina Zviel-Girshin @ASC
Pumping lemma If L is a regular language then there is a number n such that any string w  L of length at least n may be divided into three parts w=xyz such that: |y|>0 |xy| n for each i0 xyiz L Rina Zviel-Girshin @ASC

12 Rina Zviel-Girshin @ASC
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 is obviously should not be of length 0 (at least one letter). The parts before and after the "pumpable" part could be . The part we may pump is inside a prefix of length at most n. Rina Zviel-Girshin @ASC

13 Rina Zviel-Girshin @ASC
Proof idea Any finite automaton without cycles can recognize only a finite language. An infinite language is created by automaton with loops. The infinite number of words is the result of repeating the loop any number of times. Each word in language L of length more than the number of states includes a path in a cycle (by the pigeonhole principle). Rina Zviel-Girshin @ASC

14 Rina Zviel-Girshin @ASC
Proof idea The part before the cycle is x. The cycle is y. The part after is z. The z part ends with an accepting state as the word is in L. 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 cycle any number of times and still proceed through z to accepting state. Rina Zviel-Girshin @ASC

15 Rina Zviel-Girshin @ASC
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 went through while processing the prefix is q0 and one state for each letter read. After reading this prefix we have a sequence of n+1 length. Rina Zviel-Girshin @ASC

16 Rina Zviel-Girshin @ASC
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. The substring read before first appearance of r : x. The substring between first and second appearance: y. And the substring after second appearance of r till the end of the string: z. Rina Zviel-Girshin @ASC

17 Rina Zviel-Girshin @ASC
Formal Proof (cont.) z ends with an accepting state f because the string is in L. y is the cycle in the automaton. y has at least length 1 because we move from state to state in the DFA only upon reading a letter. Rina Zviel-Girshin @ASC

18 Rina Zviel-Girshin @ASC
Formal Proof (cont.) As there is a path from r to an accepting state f (z) there is a direct path q0 - r - f without going through the r cycle even once (xy0z=xz). On the other hand we can go through the cycle more than once and still get out from r to I (xyiz). There is no limit on a number of times we can do through the cycle. Q.E.D. Rina Zviel-Girshin @ASC

19 Rina Zviel-Girshin @ASC
Usage of the lemma The main usage of pumping lemma is to prove that some language is not regular. The technique: Assume that the language is regular. Find a string w that has a length greater than n. Find a partition of w into x,y,z such that properties 1 and 2 of pumping lemma hold. Find an i such that xyiz is not in the language. Rina Zviel-Girshin @ASC

20 Rina Zviel-Girshin @ASC
L = {0m1m | m>0} Is L = {0m1m | m>0} regular? We will use pumping lemma to show that L is not regular. Assume to the contrary that L is regular. Let n be the pumping length given by the pumping lemma. We choose w= 0n1n . w is in L, |w|>n so by pumping lemma w can be divided into three parts w=xyz. Rina Zviel-Girshin @ASC

21 Rina Zviel-Girshin @ASC
L = {0n1n | n>0} x and y are both in prefix of length n and so are build of 0's. Denote the length of x by s and the length of y by t. Then : x=0s s0 y=0t t1,s+tn z=0n-s-t1n By pumping lemma if the language is regular then xyiz is in L for any i. Rina Zviel-Girshin @ASC

22 Rina Zviel-Girshin @ASC
L = {0n1n | n>0} Take i=2. The resulting word is xy2z = 0s02t0n-s-t1n = 0n+t1n . 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 regular language. Rina Zviel-Girshin @ASC

23 Rina Zviel-Girshin @ASC
L={an! | n0} Is L={an! | n0} regular? We will use pumping lemma to show that L is not regular. Assume to the contrary that L is regular. Let n’ be the pumping length given by the pumping lemma. We choose w= an! where n=max(n’,2) . w is in L, |w|>n’ so by pumping lemma w can be divided into three parts w=xyz. Rina Zviel-Girshin @ASC

24 Rina Zviel-Girshin @ASC
L={an! | n0} x and y are both in the prefix of length n and consist of a's only. Denote the length of x by s and the length of y by t. Then : x=as s>=0 y=at t>0,s+t<=n z=an!-t-s By pumping lemma if the language is regular then xyiz is in L for any i. Rina Zviel-Girshin @ASC

25 L={an! | n0} Take i=2. The resulting word is xy2z = an!+t .
Now we proove that an!+t is not in L. We know that t>0 and n>=t that means n!+t <= n!+n < n!+(n+1) < n!*(n+1) = (n+1)! Thus we have a contradiction to the pumping lemma. That means: our assumption that L is regular is wrong. L is not regular language. Rina Zviel-Girshin @ASC

26 Rina Zviel-Girshin @ASC
Any Questions? Rina Zviel-Girshin @ASC


Download ppt "Complexity and Computability Theory I"

Similar presentations


Ads by Google