0% found this document useful (0 votes)
10 views

The Theory of Computation Part II

The document discusses deterministic finite automata (DFAs). It defines a DFA as a 5-tuple with states, an alphabet, transition functions, an initial state, and accepting states. It provides examples of DFAs, including how to design a DFA to recognize a given language. It also discusses using code to represent DFA concepts and provides an exercise to design a DFA to recognize a language.

Uploaded by

mjn0107
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

The Theory of Computation Part II

The document discusses deterministic finite automata (DFAs). It defines a DFA as a 5-tuple with states, an alphabet, transition functions, an initial state, and accepting states. It provides examples of DFAs, including how to design a DFA to recognize a given language. It also discusses using code to represent DFA concepts and provides an exercise to design a DFA to recognize a language.

Uploaded by

mjn0107
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 113

The Theory of Computation

Part II
CONTENTS
Introduction
1. Sets, Relations, and Functions
2. Finite Automata
3. Context-free Languages
4. Turing Machines
5. Undecidablity

Authors of Elements of the theory of


computation
Harry R. Lewis
Christos H. Papadimitriou
Typos of Elements of the theory of
computation
PART II

Finite Automata
Part II. Finite Automata
 2.1 Deterministic Finite Automata
 2.2 Nondeterministic Finite Automata
 2.3 Finite Automata and Regular Expressions
 2.4 Languages that are and are not regular
 2.5 State Minimization
 2.6 Algorithms for Finite Automata*
2.1 Deterministic Finite Automata(DFA)
 Why Deterministic

 Automata reads one symbol from the input tape and then enters a new state that
depends only on the current state and the symbol just read.
2.1 Deterministic Finite Automata(DFA)
 The simplest computational model, with very limited memory, but highly useful
 Example: a finite automaton modeling an on/off switch

push

Start
off on

push
2.1 Deterministic Finite Automata(DFA)
 The simplest computational model, with very limited memory, but highly useful
 Example: a finite automaton modeling an train schedule

207 208
189 190

Chengdu Chongqin

Kunmin Guiyang
2.1 Deterministic Finite Automata(DFA)
 The simplest computational model, with very limited memory, but highly useful
 Example: a finite automaton modeling for Linux kernel process control
2.1 Deterministic Finite Automata(DFA)
 Beginning from an example 0 1 0
 State diagram: a directed graph
q1 q2 q3
 States : q1, q2, q3
1 0,1
Initial state: with an arrow not labeled
Final states: with double circles
 Transition : the arrows labeled
 Input
A string 1101
 Output
A state: if the state is one of the final states, accepting , else no accepting.
on input “0110”, the machine goes:q1q1q2q2q3 = “reject”
 Process
Start from the initial state
Read the input string from left to right
2.1 Deterministic Finite Automata (DFA)
 Definition of a deterministic finite automata
A quintuple
M=(K, , , s, F)
K : a finite set of states;
: an alphabet;
s K : the initial state;
F  K : the set of final states;
 : the transition function from K to K,
a  , q K, (q,a)K .
For example
M1=(K, , , q1, F)
K = {q1, q2, q3}; ={0,1} ; s= q1; F={q2} 0 1 0
: 0 1
q1 q1 q2 q1 q2 q3
q2 q3 q2 1 0,1
q3 q2 q2
2.1 Deterministic Finite Automata (DFA)
 Configuration
 The status of M at successive moments
 Any element of K* : (q,w).
 Computing
 One step yield  :
if and only if a, w=aw’ and (q,a)=q’
(q,w)  (q’,w’ )
 Yield * :
the reflexive transitive closure of .
(q,w) * (q’,w’ )
A string w* is said to be accepted by M if and only if qF such
that (s,w) * (q,e).
The language accepted by M, L(M), is the set of all strings accepted by
M.
Extension of  to Strings

 Intuitively, an FA accepts a string w = a1a2…an if there


is a path in the state diagram that:
1. Begins at the start state,
2. Ends at an accept state, and
3. Has sequence of labels a1, a2, …, an.

 Formally, the transition function  can be extended to


*(q, w), where w is any string of input symbols.
 Basis: *(q, ) = q
 Induction: *(q, wa) =  (*(q, w), a)
Language of an FA
 An FA M = (Q, Σ, , q0, F) accepts a string w if
*(q0, w) F.
 The language recognized by an FA M= (Q, Σ, , q0,
F) is
L(M) = {w | *(q0, w) F}.
 A language is called a regular language if some
finite automaton recognizes it.
Designing Finite Automata
 Given some language, design a FA that recognizes
it.
 Pretending to be a FA,
You see the input symbols one by one
You have finite memory, i.e. finite set of states, so
remember only the crucial information (finite set of
possibilities) about the string seen so far.
Example

 Σ ={0,1}, L = {w | w has odd number


of 1s}, design a FA to recognize L.
 What is the necessary information to
remember? --- Is the number of 1s seen so
far even or odd? Two possibilities.
Example

 Σ ={0,1}, L = {w | w has odd number


of 1s}, design a FA to recognize L.
 What is the necessary information to
remember? --- Is the number of 1s seen so
far even or odd? Two possibilities.
 Assign a state to each possibility.
qeven qodd
Example

 Σ ={0,1}, L = {w | w has odd number


of 1s}, design a FA to recognize L.
 What is the necessary information to 0 0
remember? --- Is the number of 1s seen so
far even or odd? Two possibilities. 1
 Assign a state to each possibility.
qeven qodd
 Assign the transitions from one possibility
to another upon reading a symbol.
1
Example

 Σ ={0,1}, L = {w | w has odd number


of 1s}, design a FA to recognize L.
 What is the necessary information to 0 0
remember? --- Is the number of 1s seen so
far even or odd? Two possibilities. 1
 Assign a state to each possibility.
qeven qodd
 Assign the transitions from one possibility
to another upon reading a symbol.
1
 Set the start and accept states.
2.1 Deterministic Finite Automata (DFA)
 Example 2.1.1
Let M be the DFA M=(K, , , s, F)
K = {q0, q1}
={a,b} a b a
s= q0
q0 q1
F={q0} b
: q  (q,)

q0 a q0
q0 b q1
q1 a q1
q1 b q0
2.1 Deterministic Finite Automata (DFA)
 Example 2.1.1
Input aabba a b a
Initial configuration (q0, aabba)
q0 q1
(q0, aabba)  (q0, abba) b
 (q0, bba)
 (q1, ba)
 (q0, a)
 (q0, e)
So there is (q0, aabba) * (q0, e), the aabba is accepted by M.
2.1 Deterministic Finite Automata (DFA)
 Example 2.1.2
Design a DFA M that accepts the language
L(M)={w{a,b}*: w does not contain the bbb substrings}
Let M=(K, , , s, F)
K = {q0, q1 , q2 , q3}
={a,b}
q   (q,)
s= q0 q0 a q0
q0 b q1
F={q0 , q1 , q2} q1 a q0
: q1 b q2
q2 a q0
q2 b q3
q3 a q3
q3 b q3
2.1 Deterministic Finite Automata (DFA)
 Example 2.1.2

a
a b
b b b
q0 q1 q2 q3
a a
2.1 Deterministic Finite Automata (DFA)
2.1 Deterministic Finite Automata (DFA)
 用 C 语言描述 DFA 思想
Char *input ,*pCurr // 全局量
Bool FA_func( ) 0 1
{ start:
q1:if (*pCurr==0) PCurr++; goto q1;
else if (*pCurr==1) PCurr++; goto q2; 1 0
Else if ( (*pCurr==NULL) return False
q2: if (*pCurr==0) PCurr++; goto q3;
else if (*pCurr==1) PCurr++; goto q2
Else if ( (*pCurr==NULL) return true q1 q2 q3
q3: if (*pCurr==0 || *pCurr==1)
PCurr++; goto q2;
Else if ( (*pCurr==NULL) return False:

} 0,1
自动机对应于只有 if,goto ,无数组,无内部变量的程序,
程序不如图形直观,程序容易使用超标的资源(内存,栈,数组
Exercise
 Σ ={0,1}, L = {w | w has even number of 0s and
even number of 1s}, design a FA to recognize L.
What to remember?
How many possibilities?
Exercise

q00 q01

1
0 0 0 0
1

q10 q11

1
Example 1.9
 Σ ={0,1}, L = {w | w contains 001 as a substring},
design a FA to recognize L.
 four possibilities:
1. haven’t just seen any symbols of 001 --- q
2. have just seen a 0 --- q0
3. have just seen a 00 --- q00
4. have seen the entire pattern 001 --- q001
Example 1.9

0
1 0, 1
0
0
1
q q0 q00 q001

1
2.2 Nondeterministic Finite Automata
(NFA)
 Definition of a deterministic finite automata
A quintuple
M=(K, , , s, F)
K : a finite set of states;
: an alphabet;
s K : the initial state;
F  K : the set of final states;
 : the transition relation, a subset of K({e})K,
(q, u, p)  .
Note:
 need not be a function. If M is in state q and the next input symbol is a,
then M may next follow any transition of the form (q,a,p) or (q,e,p); if a
transition (q,e,p) is followed, then no input symbol is read.
2.2 Nondeterministic Finite Automata
(NFA)
 Configuration
 The status of M at successive moments
 Any element of K* : (q,w).
 Computing
 One step yield  :
if and only if u{e}, such that w=uw’ and ( q, u, q’ )  
(q,w)  (q’,w’ )
 Yield * :
the reflexive transitive closure of .
(q,w) * (q’,w’ )
A string w* is said to be accepted by M if and only if qF such
that (s,w) * (q,e).
The language accepted by M, L(M), is the set of all strings accepted by
M.
2.2 Nondeterministic Finite Automata
(NFA)
 Example a
For language: L=(ababa)*
a b a
DFA: q0 q1 q2 q3
NFA: a b
b b
q4
a b
b
q0 q1
a a q1
a b q0
e b
q2 a
q2
2.2 Nondeterministic Finite Automata
(NFA)
 Example 2.2.1 L(M)=(bbbab)*
M=(K, , , s, F) a,b
K = {q0, q1 , q2 , q3 , q4}
b b
={a,b} q0 q1 q2
s= q0
F={q4}
a e
 : {(q0, a, q0), (q0, b, q0), (q0, b, q1),
(q1, b, q2), (q1, a, q3), (q2, e, q4), q3 q4 a,b
(q3, b, q4), (q4, a, q4), (q4, b, q4)}
b
For bababab
(q0, bababab)  (q0, ababab) (q0, bababab)  (q1,ababab)
 (q0, babab)  (q3,
babab)
 (q0, abab)
 (q4,

abab)
 (q0, e)
 (q4,
bab)
2.2 Nondeterministic Finite Automata
(NFA)
 Example 2.2.2
Let ={a1, …, an}, n2, the language is
L={w: there is a symbol ai not appearing in w}
Design a NFA M for n=3.
q1 a2, a3
K={q0, q1, …, qn}
e
F=K e
q0 q2 a1, a3
s= q0
e
q3 a1, a2
2.2 Nondeterministic Finite Automata (NFA)
2.2 Nondeterministic Finite Automata (NFA)
2.2 Nondeterministic Finite Automata
(NFA)
 Equivalence between NFA M and DFA M’
L(M)= L(M’)
 Theorem 2.2.1
For each NFA, there is an equivalent DFA.
Proof.
 Key ideas:
1. the NFA’s states at any moment is a set of states but not a
single one.
2. Construct a DFA to simulate the NFA.
2.2 Nondeterministic Finite Automata
(NFA)
 Theorem 2.2.1
Proof.
NFA: M=(K, , , s, F),
DFA: M’=(K’, , ’, s’, F’)
K’=2K
I. Construct M’ without the symbol e
1. K’=P(K): P(K) is the set of all subsets of K .
2. For RK’ and a, let
’(R,a)={qK : rR, such that q  (r,a)}
 R, a    r , a 
rR
2.2 Nondeterministic Finite Automata
(NFA)
 Theorem 2.2.1
Proof.
I. Construct M’ without the symbol e
3. s’={s}
4. F’={RK’ : R contains an accepted state of M}
II. Construct M’ with the symbol e
For RK’ , Let
E(R)={pK : (q,e) *(p,e)} (contain R itself )
’(R,a) may be modified by
’(R,a)={qK : rR, such that q E( (r,a))}
s’ may be modified by
s’ =E({s})
2.2 Nondeterministic Finite Automata (NFA)
2.2 Nondeterministic Finite Automata (NFA)
2.2 Nondeterministic Finite Automata
(NFA)
 Example
Design a DFA M2 from the NFA M1 q1
M1 = ({q1, q2, q3}, {a,b}, , q1, {q1})
b a
M2 =(K’, {a,b}, ’, s’, F’) e
a
K’={{e}, {q1}, {q2}, {q3}, {q1, q2}, q2 q3
a,b
{q1, q3}, {q2, q3}, {q1, q2, q3}}
s’=E({q1})= {q1, q3}
F’= {{q1}, {q1, q2}, {q1, q3}, {q1, q2, q3}}
2.2 Nondeterministic Finite Automata
(NFA)
(q1, a)={e}, E({e})={e}
q1
(q1, b)={q2}, E({q2})={q2}
(q2, a)={q2, q3}, E({q2, q3})={q2, q3} b a
e
(q2, b)={q3}, E({q3})={q3} a
(q3, a)={q1}, E({q1})={q1, q3} q2 a,b q3
(q3, b)={e}
a,b
a {q1}
b {q2}
{e} {q1,q2}

b a a,b
b b
a
{q3} {q1,q3} a {q2,q3} {q1,q2,q3} a
a
b
b
2.2 Nondeterministic Finite Automata
(NFA)

a b
a {q1,q3} {q3} {e}

a,b
b
b b
a
{q2} {q2,q3} {q1,q2,q3}
a b
a
Exercises
 P.69 (P37): 2.1.2, 2.1.3
 P.73 (P45) : 2.2.1
 P.74 (P36) : 2.2.2, 2.2.3
 P.75 (P36) : 2.2.9
2.3 Finite automata and regular expressions
 Note: the class of regular languages is closure of certain
finite languages under the language operation of union,
concatenation, and Kleene star. Is the class of language
accepted by finite automata similar?
 Theorem 2.3.1:
 The class of languages accepted by finite automata is closed under
Union;
Concatenation;
Kleene star;
Complementation;
Intersection.
2.3 Finite automata and regular expressions
 Theorem 2.3.1 (Proof )
Union
Let M1=(K1, , 1, s1, F1) and M2=(K2, , 2, s2, F2) be NFA.
Construct a NFA M such that L(M)= L(M1)L(M2).
Idea: using non-determinism to “guess” whether the input is in
L(M1) or in L(M2).
Definition of M accepted L(M1)L(M2):
• Assume K1 and K2 are disjoint sets;
• M = (K, , , s, F)
• K = K1K2{s};
• F = F1F2;
  = 1 2  {(s,e,s1), (s,e,s2)}.
2.3 Finite automata and regular expressions
 Theorem 2.3.1 (Proof )
Union

s1 s2 es e
s1 s2
 F
F1 F2

M1 M2 M
2.3 Finite automata and regular expressions
 Theorem 2.3.1 (Proof )
Concatenation
Let M1=(K1, , 1, s1, F1) and M2=(K2, , 2, s2, F2) be NFA.
Construct a NFA M such that L(M)= L(M1)L(M2).
Idea: using non-determinism to “guess” which final state in M1
“jumping” to M2 .
Definition of M accepted L(M1)L(M2):
• Assume K1 and K2 are disjoint sets;
• M = (K, , , s1, F2)
• K = K1K2; (q, a, p )1 if q  K1 and q  F1
• F = F2 ; (q, a, p ) if q  F1 and a  e
 1
( q, a, p )  
 : (q, a, p )1  (q, a, s2 ) if q  F1 and a  e
(q, a, p ) 2 if q  K 2
2.3 Finite automata and regular expressions
 Theorem 2.3.1 (Proof )
s1
Concatenation
F1
s1 s2
 e e
F1 F2 s2

M1 M2
F=F2

M
2.3 Finite automata and regular expressions
 Theorem 2.3.1 (Proof )
Kleene star
Let M1=(K1, , 1, s1, F1) be a NFA.
Construct a NFA M such that L(M)= L(M1)*.
Idea: using non-determinism to “guess” that each
concatenation (contain {e}) between all elements in L(M1) can
be accepted.
Definition of M accepted L(M1)*:
• M = (K, , , s, F)
• K = K1{s}; (q, a, p )1 if q  K1 and q  F1
 if q  F1 and a  e
• F = F1{s}; (q, a, p )1

 : (q, a, p )  (q, a, p )1  (q, a, s1 ) if q  F1 and a  e
(q, a, s ) if q  s and a  e
 1

(q, a, {e}) if q  s and a  e


2.3 Finite automata and regular expressions
 Theorem 2.3.1 (Proof )
Kleene star
s
* e
s1
s1
F1 e e

M1 F1

M
2.3 Finite automata and regular expressions
 Theorem 2.3.1 (Proof )
Complementation
Let M1=(K, , , s, F1) be a DFA.
Construct a DFA M=(K, , , s, F) such that L(M)=*L(M1).
Definition of M accepted L(M) :
• M = (K, , , s, F)
• F = K  F1.
2.3 Finite automata and regular expressions
 Theorem 2.3.1 (Proof )
Intersection
By De Morgan Low, there is
L1L2 = *((*  L1)  (*  L2))
So closedness under intersection follows from closedness
under union and complementation.
2.3 Finite automata and regular expressions
 Theorem 2.3.2:
A language is regular if and only if it is accepted by a
finite automaton.
 Proof
Only if :
Class of regular languages : the smallest class of language
(containing the empty set, and the singletons {a}) closed under
union, concatenation, and Kleene star.
By the theorem 2.3.1 : the finite automaton languages are
closed under union, concatenation, and Kleene star.
Hence, every regular language is accepted by some finite
automata.
2.3 Finite automata and regular expressions
 Theorem 2.3.2 (Proof):
Only if : (each regular expression can be transferred to a
finite automaton.)
Let R be a regular expression, there are the cases following:
a
R=a, a, so L(R)={a}
R=e, so L(R)={e}
R=, so L(R)=
R=R1R2, R=R1R2, and R=R1* : show as the theorem 2.3.1.
2.3 Finite automata and regular expressions
 Transition from any regular expression to some
a
finite automata
For example:(aba)*  NFA b,e
a
a:
b
b:
a e b
ab :
e a e b
aba :
e a
e
(aba)* : e a e b
e
a
e
e
2.3 Finite automata and regular expressions
 Theorem 2.3.2 (Proof ):
 if : (each finite automaton can be transferred to a regular
expression.) Omitting the proof.
 Generalized NFA (GNFA)
Mg=(K, , , qstart, qaccept)
 : (K{qstart})(K{qaccept})R
R: the set of all regular expressions on ;
qstart : start state;
qaccept : accept state.
(1)The start state has the transitions to each of K{qstart}, but any one from the
K{qstart}; (2)There are only one accept state which has all transitions from
each of K{qaccept}, but one to any others, and qstart  qaccept; (3)Except qstart and
qaccept , all states have the transitions to each other and to themselves.
2.3 Finite automata and regular expressions
 GNFA: example
ab*
qstart aa
a*
 (aa)* abba

b qaccept
b*
ab
2.3 Finite automata and regular expressions
 DFAGNFA


e a
s q1
q1 a
  b 
b
a,b f q2
e
q2 ab
DFA
GNFA
2.3 Finite automata and regular expressions
 GNFA  Regular Expression
Let the GNFAk have k states, and so k2;
Construct a new GNFAk1 with k1 states;
Continue the construction until k=2: GNFA2;
The  of GNFA2 : (qstart , qaccept)R.

3 states 5 states 4 states 3 states 2 states


DFA GNFA GNFA GNFA GNFA

R
2.3 Finite automata and regular expressions
 GNFA  Regular Expression
From GNFAk to GNFAk1 , a state qrip should be deleted.
The qrip is not the qstart and qaccept .
For each deleting (qrip) step, modify the  of GNFAk
between any qi and qj, (also qi=qj)
Rule: R4
qi qj (R1)(R2)*(R3)(R4)
qi qj
R1 R3
qrip
R2
2.3 Finite automata and regular expressions
 DFA  Regular Expression example

a e a e a
q1 s q1 s q1

b b b(ab)*
a,b
q2 f e q2 f
ab
DFA GNFA4 GNFA3

R a*b(ab)*
s f
2.3 Finite automata and regular expressions
b b
a a
q1 q2 q1 q2
a a
b e b a e
a b f
b s e
q3 q3
aab
a(aab)*
a s f
q2
s ab a(aab)*abb
e (baa)(aab)*e
b baa f
e q3
q3
bb (baa)(aab)*abbb

(a(aab)*abb)((baa)
s f
(aab)*abbb)*((baa)
Exercises
 P.83 (P51) : 2.3.4, 2.3.5
 P.84 (P52) : 2.3.7
2.4 Languages that are and are not regular
 “Is a language regular ?” how to answer it?
If a language is regular, show why?
By a variety of techniques:
Regular expressions;
DFA;
NFA;
If a language is not regular, show why?
By what?
2.4 Languages that are and are not regular
 Example 2.4.1
Let ={0,1,…,9} and let L* be the set of decimal
representations for nonnegative integers(without redundant
leading 0’s) divisible by 2 or 3. For example, 0,3,6,244  L, but
1,03,00  L. Then L is regular.
 Let L1 be the set of decimal representations of nonnegative
integers. Then
L1=0{1,2,…,9}*, evident, it’s a regular expression.
 Let L2 be the set of decimal representations of nonnegative
integers divisible by 2. Then L2 is
L2= L1*{0,2,4,6,8}, L2 is a regular expression.
 Let L3 be the set of decimal representations of nonnegative
integers divisible by 3. (a number is divisible by 3 if and only if
the sum of its digits is divisible by 3.)
2.4 Languages that are and are not regular
 Example 2.4.1 (continued)
Construct a finite automaton M 0,3,6,9
L3=L’(M)
q2
So,
L= L2  L3. 1,4,7 1,4,7
L is a regular language. 2,5,8

q1 q3

0,3,6,9 1,4,7 0,3,6,9


2.4 Languages that are and are not regular
 All regular languages share 2 properties
“Bound”
{0n1n : n0} and {w : same number of 0’s and 1’s in w} are not
regular.
“Repetitive structure”
{an : n1 is a prime} is not regular.
2.4 Languages that are and are not regular
 Pumping lemma
 Theorem 2.4.1
Let L be a regular language. There is an integer n1 such that any
string w L with |w|n can be rewritten as w=xyz such that for
each i0, ye, |xy|n, and xyizL.
Note:
n is called the pumping length. So, the pumping lemma provides
a property of the regular language class: any string in the
language can be “pumped” if its length is not less than the
pumping length n. In other words, each such string w contains a
substring which can be repetitive any times such that the new
string w’L.
2.4 Languages that are and are not regular
 Pumping lemma
Idea:
Let M be a DFA accepts L(M);
Let the pumping length n be the number of M’s states;
For any w in L, the w can be divided 3 segments xyz.
In L, if there are not any w, such that |w|<n, how?
It’s easy. The theorem is tenable however.
Consider a sequence q of computation for w, an example as:
w = w1 w2 w3 w4 w5 w6 … wn

q =q1 q3 q20 q9 q17 q9 q6 …q35 q13


2.4 Languages that are and are not regular
 Pumping lemma (idea)
 q13 is the accept state. y
 Let |w|=n , |q| = n+1
the number of M’s states is n. q9
By the Pigeonhole Principle,
there are the same states in the q x
as q9 z
 Now, let w=xyz,
x: the part of w before q9; q1 q13
y: the part of w between the two q9;
z: the rest part of w after the last q9;
 So this xyz satisfies the 3 conditions:
 for each i0, ye (|y|>0), |xy|n, and xyizL.
2.4 Languages that are and are not regular
 Pumping lemma
Proof : see P88 of the book.
2.4 Languages that are and are not regular
 Example 2.4.2:
The language L={aibi:i0} is not regular.
If L is regular, consider then the string w=anbn  L for
some n.
Let w=xyz, such that |xy|n and  ye, that is,
y=ai for some i>0.
But then  xz = an-ibnL.
contradicting the theorem.
2.4 Languages that are and are not regular
 Example 2.4.3:
The language L={an : n is prime} is not regular.
If L is regular, let w=xyz, and x=ap, y=aq, z=ar, where
p,r0 and q>0.
By the theorem, xynzL for each n0;
That is, p+nq+r is prime for each n0.
But this is impossible, if let n=p+2q+r+2, then
p+nq+r =(q+1)(p+2q+r), p+nq+r is not prime.
2.4 Languages that are and are not regular
 Example 2.4.4
Use closure properties to show that a language is not
regular.
L={w{a,b}* : w has an equal number of a’s and b’s} is
not regular.
If L were indeed regular, then so would be La*b* , by
closure under intersection.
However, the language La*b* = {anbn : n0}, such that
L is not regular.
2.4 Languages that are and are not regular
 Example 2.4.4
 Use pumping lemma to show that L={w{a,b}* : w has an equal
number of a’s and b’s} is not regular.
Assume L is regular, let w=xyz, and w=(ab)n, n is the pumping
length. Trying the 3 “pumping” conditions:
Let x=e, y=ab, and z=(ab)n-1, so for each i, xyizL.
Here, L is regular!
2.4 Languages that are and are not regular
 Example 2.4.4
Use pumping lemma to show that L={w{a,b}* : w has
an equal number of a’s and b’s} is not regular.
Assume L is regular, let w=xyz, and w=anbn, n is the
pumping length. Trying the 3 “pumping” conditions:
Let x=e, y=anbn, and z=e, so for each i, xyizL.
But if |xy|n, such that y should consist only of a, and
xyyzL.
contradicting the assumption.
2.4 Languages that are and are not regular
 Example: show that L={uu:u{0,1}*} is not
regular.
Assume L is regular, n is the pumping length. let w=xyz,
and w=0n10n1.
Although xyizL for each i, if x=e and z=e.
But if |xy|n, y should be 0 such that xyyzL.
Note: w=0n10n1 is one of strings that show the non
regular of L, but w=0n0n can not show the non regular.
The w=0n0n L , but it can be “pumped”.
2.4 Languages that are and are not regular
 n2

 Example: show that L  1 : n  0 is not regular.
Assume L is regular, p is the pumping length and w=1p2.
|w|=p2>p, so w=xyz.
For any i0, xyizL . Note |xyiz| and |xyi+1z| are perfect
square.
Let m=n2 is a perfect square, consider the difference of two
perfect squares: (n+1)2-n2=2m½ +1.
Let m=|xyiz|, count |y|: |y||w|=p2, let i=p4,
|y|p2=(p4)½ <2(p4)½ +1 2(|xyiz|)½ +1.
So, |xyiz| and |xyi+1z| are not perfect square simultaneously.
2.4 Languages that are and are not regular
 Example: show that L={aibj : i>j} is not regular.
Assume L is regular, p is the pumping length. Let
w=ap+1bp, so w=xyz.
By |xy|p, such that y contains only a.
By xyizL for any i0, consider i=0:
xy0z=xz, the number of a’s in w is only more 1 than b’s, so the
number of a’s in xz can not be more than b’s, such that xy0zL.
Exercises
 P.90 (P56): 2.4.4, 2.4.5
2.5 State minimization
 The number of states of a DFA
L(M)=(abba)*
8 states:
a b b
q1 q2 q3 q8
a
b a a b a a b

q4 q5 q6 q7
b b a
a,b
2.5 State minimization
 The number of states of a DFA
L(M)=(abba)*
6 states: a b
q1 q2 q3
a
b a a b a

q4 q5 q6
b b
a,b
2.5 State minimization
 The number of states of a DFA
L(M)=(abba)*
6 states:
Attention: q4, q6.

a b
q1 q2 q3
a
b a a b a

q4 q5 q6
b b
a,b
2.5 State minimization
 The number of states of a DFA
L(M)=(abba)*
6 states: a b
q1 q2 q3
Attention: q4, q6. a
b a a b a

q4 q5 q6
b b
a,b
2.5 State minimization
 Equivalence class
Definition 2.5.1
Let L* be a language, and let x,y*. x and y are
equivalent with respect to L, denote x L y, if for all
z*, the following is true : xzL if and only if yzL.
Notice that L is an equivalence relation.
Equivalence class [x]
[x]: x is a string.
2.5 State minimization
 Equivalence class of L
Example: for L=(abba)*
(1) [e]=L
(2) [a]=La
(3) [b]=Lb
(4) [aa]= L(aabb)*
2.5 State minimization
 Definition 2.5.2
Let M=(K,,,s,F) be a DFA. Two strings x,y* are
equivalent with respect to M, denoted x M y , if they both
drive M from s to the same state.
Formally, x M y if there is a state q such that
(s,x) *M (q,e) and (s,y) *M (q,e).
 M is an equivalence relation.
The equivalence class of M is identified by the states of
M:
denoted by Eq
2.5 State minimization
 Equivalence class of M
Example for the DFA M
a b
L(M)=(abba)* q1 q2 q3
(1) Eq1= (ba)* a
(2) Eq2= abLaa b a a b a
(3) Eq3= (ba)*abL
q4 q
5 q6
(4) Eq4= b(ab)* b b
a,b
(5) Eq5= L(aabb)*
(6) Eq6= (ba)*abLb
The equivalence class forms a partition of *.
2.5 State minimization
 Theorem 2.5.1
For any DFA M=(K,,,s,F) and any strings x,y*, if
x M y , then x L(M) y .
 M is a refinement of L(M) ;
The each equivalence class of  is contained in some
equivalence class of  ; that is , each equivalence of  is
the union of one or more equivalence classes of .
For example:
For the DFA M,
[aa]= L(aabb)* =Eq5
[e]= Eq1Eq3 = (ba)*(ba)*abL=L
2.5 State minimization
2.5 State minimization
 Form the theorem 2.5.1:
The number of equivalence classes of L(M) is a
natural lower bound on the number of states of any
automaton equivalent.
2.5 State minimization
 Theorem 2.5.2 (The Myhill-Nerode Theorem)
Let L* be a regular language, then there is a DFA
with precisely as many states as there are equivalence
classes in L that accepts L.
 Standard automaton
Definition : M=(K,,,s,F)
K={[x] : x*}, the set of equivalence classes under L;
s=[e], the equivalence class of e under L;
F={[x] : xL};
For any [x]K and a, ([x],a)=[xa]
2.5 State minimization
 Standard automaton
Example: L=(abba)* a
(1) [e]=L [e] [a]
(2) [a]=La b
(3) [b]=Lb b a a
(4) [aa]= L(aabb)*
[b] [aa]
b
a,b
2.5 State minimization
 Corollary
A language L is regular if and only if L has finitely
many equivalence classes.
Another useful way for proving that a language is not
regular. For example,
L={anbn : n  1} is not regular.
Proof: No two strings ai and aj , with ij , are equivalent under
L , so L has infinitely many equivalence classes [e], [a], [aa],
[aaa], … ; by the corollary, L is not regular.
2.5 State minimization
 The equivalence class of the states of DFA
Definition:
For a DFA M=(K,,,s,F) , the relation AMK* : (q,w)AM
if and only if some fF, (q,w) *M (f,e).
For all z*, (q,z)AM if and only if (p,z)AM , denote q  p.
For all z* and a number n, |z|n, (q,z)AM if and only if
(p,z)AM , denote q n p.
Each equivalence relation in 0, 1, 2, … is a refinement
of the previous one.
q 0 p holds if q and p are either both accepting, or both
non-accepting.Two equivalence classes of 0: F and K–F
2.5 State minimization
 Lemma 2.5.1
For any two states q,pK and any integer n1, qn p if and
only if (1) q n-1 p and (2) a, (q,a) n-1 (p,a).
Algorithm for compute  :
initially the equivalence classes of 0 are F and K–F;
repeat for n:=1,2,…
compute the equivalence classes of n from those n-1;
until n is the same as n-1.
Each iteration can be carried out by applying Lemma 2.5.1: For each
pair of states of M, we test whether the conditions of the lemma
hold, and if so we put the two states in the same equivalence class of
n.
2.5 State minimization

11:04:59
2.5 State minimization

11:04:59
2.5 State minimization

11:05:00
2.5 State minimization
 Example 2.5.3
Compute  of the M.

a b
q1 q2 q3
a
b a a b a

q4 q5 q6
b b
a,b
2.5 State minimization
 Example 2.5.3
 0 : {q1, q3} and {q2, q4 , q5 , q6}
 1 : {q1, q3}, {q2}, {q4, q6}, {q5}

a b a
q1 q2 q3
{q1, q3} {q2}
a b
b a a b a b a a

q4 q5 q6
b b {q4, q6} {q5}
b
a,b a,b
2.6 Algorithms for Finite Automata*
 Many of the results in this chapter were concerned with
different ways of representing a regular language: as a
language accepted by a finite automaton, deterministic or
nondeterministic, and as a language generated by a
regular expression.
 All these results are constructive, in that their proofs
immediately suggest algorithms which, given a
representation of one kind, produce a representation of
any one of the others. In this subsection we shall make
such algorithms more explicit, and we shall analyze
roughly their complexity.
2.6 Algorithms for Finite Automata*
2.6 Algorithms for Finite Automata*
2.6 Algorithms for Finite Automata*
2.6 Algorithms for Finite Automata*
 There are, however, three important questions that r
emain unresolved in Theorem 2.6.1:
 A) Is there a polynomial algorithm for determining whether two given
nondeterministic finite automata are equivalent, or is the exponential
complexity in (f) inherent?
 B) Can we find in polynomial time the nondeterministic automaton wi
th the fewest states that is equivalent to a given nondeterministic auto
maton? We can certainly do so in exponential time: Try all possible no
ndeterministic automata with fewer states than the given one, testing e
quivalence in each case using the exponential algorithm in (f).
2.6 Algorithms for Finite Automata*
 C ) More intriguingly, suppose that we are given a nondeterministic
finite automaton and we wish to find the equivalent deterministic finit
e automaton with the fewest states. This can be accomplished by com
bining the algorithms for (a) and (d) above. However, the number of st
eps may be expoexponential in the size of the given nondeterministic
automaton, even though the end result may be small —simply becaus
e the intermediate result, the unoptimized deterministic automaton pro
duced by the subset construction, may have exponentially more states
than necessary. Is there an algorithm that produces directly the minim
um-state equivalent deterministic automa- automaton in time which is
bounded by a polynomial in the input and the final output?
2.6 Algorithms for Finite Automata*
 Finite Automata as Algorithms
 A deterministic finite automaton M is an efficient algorithm for decidi
ng whether a given string is in L ( M ) .
2.6 Algorithms for Finite Automata*
 2.6.1 FA as algorithms
2.6 Algorithms for Finite Automata*
 suppose that M = (K, E, A, s, F) is a nondeterministi
c finite automaton, and consider the following algori
thm:
2.6 Algorithms for Finite Automata*
Exercises
 P.100 (P63) : 2.5.1 (a): (i)(ii)(iii)(iv)(v)
 P.101 (P63) : 2.5.3 (2.1.2 (a)(b)(c))

You might also like