230 likes | 254 Views
Learn methods to identify nonregular languages using finite automata, regular expressions, and pumping lemma in theory of computing.
E N D
CSCI 2670Introduction to Theory of Computing September 9, 2004
Agenda • Yesterday • Proved correspondence between DFA’s and RE’s • Began an example converting a DFA to an RE • Today • Complete example • Learn how to prove languages are not regular
Next week • New method for describing languages • Context-free grammars • Read Section 2.1 (pages 91 – 101)
Converting a GNFA to a RE • If the GNFA has two states, then the label connecting the states is the RE • Otherwise, remove one state at a time without changing the language accepted by the machine until the GNFA has two states
a12 q2 q1 a32 a13 q3 a33 Removing one state from a GNFA a12a13a33*a32 q1’ q2’
a12 a22 a11 q2 q1 a21 a13 a32 a23 a31 q3 a33 Accounting for loops a22a23a33*a32 a11a13a33*a31 a12a13a33*a32 q1’ q2’ a21a23a33*a31
1 1 0 q1 q2 0 Example
qs qt Example 1 1 0 q1 q2 0 ε ε Step 1: Add two new states
qs qt Example 1 101*0 1 0 q1 q2 0 ε ε 1*0 Step 2: Remove q1
qs qt Example 101*0 q2 ε 1*0 1*0(101*0)* Step 3: Remove q2
1 1 0 q1 q2 0 Example So this DFA Is equivalent to the regular expression 1*0(101*0)*
Nonregular languages • So far, we have explored several ways to identify regular languages • DFA’s, NFA’s, GNFA’s, RE’s • There are many nonregular languages • {0n1n | n 0} • {101,101001,1010010001,…} • {w | w has the same number of 0s and 1s} • How can we tell if a language is not regular?
Property of regular languages • All regular languages can be generated by finite automata • States must be reused if the length of a string is greater than the number of states • If states are reused, there will be repetition
The pumping lemma Theorem: If A is a regular language, then there is a number p where, if s is any string in A of length at least p, then s may be divided into three pieces, s = xyz, satisfying the following conditions • for each i 0, xyizis in A • |y| > 0, and • |xy| p p is called the pumping length
Proof idea • Pumping length is equal to the number of states in the DFA whose language is A • p = |Q| • If A accepts a word w with |w| > p, then some state must be entered twice while processing w • Pigeonhole principle
y x z Proof idea • for each i 0, xyizis in A • |y| > 0, and • |xy| p
Using the pumping lemma • We can use the pumping lemma to prove a language B is not regular • Assume B is regular • Show that the pumping lemma is not satisfied • Proof by contradiction
Example • B={101,101001,1010010001,…} • The jth and (j+1)th 1’s are separated by j 0’s • Assume B is regular and let w be any string in B • Let w=xyz, where |y|>0 • We cannot make any assumptions on the value of p • We want to show that no matter what y is, there is some i for which xyizB
Example (cont.) • There are 3 possibilities for y • y has no 1’s • y = 0b for some b > 0 • y has one 1 • y = 0b10c for some b,c 0 • y has two or more 1’s • y = 0b10c1v for some b,c 0 and some v* • If y=0b then xy2z B • The number of 1’s between the last 1 in x and the fist 1 in z has increased
Example (cont.) • There are 3 possibilities for y • y has no 1’s • y = 0b for some b > 0 • y has one 1 • y = 0b10c for some b,c 0 • y has two or more 1’s • y = 0b10c1v for some b,c 0 and some v* • If y = 0b10c then xy3z B • There are two consecutive 1’s with b+c 0’s between them
Example (cont.) • There are 3 possibilities for y • y has no 1’s • y = 0b for some b > 0 • y has one 1 • y = 0b10c for some b,c 0 • y has two or more 1’s • y = 0b10c1v for some b,c 0 and some v* • If y=0b10c1v then xy2z B • There are c 0’s between a pair of consecutive 1’s twice
Example (cont.) • Therefore, the pumping lemma is not satisfied so B is not a regular language • For every p and every y with |y| > 0, we can show that xyiz B for some i