Lecture3

advertisement
Introduction to Computability
Theory
Lecture2: Non Deterministic
Finite Automata (cont.)
1
Roadmap for Lecture
In this lecture we:
• Prove that NFA-s and DFA-s are equivalent.
• Present the three regular operations.
• Prove that each of the regular operations
preserves regularity.
2
Equivalence Between DFAs and NFAs
Every DFA is (A special case of) an NFA, hence
DFA  s  NFA  s , but NFA  s  DFA  s .
Nevertheless, these classes are Equivalent.
This means that for any NFA N there exists a DFA
D satisfying: LD  LN  .
3
Equivalence Between DFAs and NFAs
Thus, to prove equivalence of the classes we
prove:
Theorem: For every NFA N there exists a DFA D
satisfying LD  LN  :
Proof Idea: The proof is Constructive: We
assume that we know N , and construct a
simulating DFA, D .
4
Proof
Let N  Q, ,  , q0 , F  recognizing some
language A. The state set of the simulating
DFA D, should reflect the fact that at each
step of the computation, N may occupy
several sates.
Thus we define the state set of D as PQ 
the power-set of the state set of N.
5
Proof (cont.)
Let N  Q, ,  , q0 , F  recognizing some
language A. First we assume that N has no
 - transitions.
Define D  Q' , ,  ' , q0 ' , F  where Q'  PQ .
6
Proof (cont.)
Our next task is to define D’s transition function,
':
For any R  Q ' and a   define
 ' R, a   q  Q | q  r, a  for some r  R
If R is a state of M, then it is a set of states of N.
When M in state R processes an input symbol
a, M goes to the set of states to which N will
go in any of the branches of its computation.
7
Proof (cont.)
An alternative way to write the definition of M’s
transition function, ' is:
For any R  Q ' and a   define
 ' R, a    rR  r, a 
And the explanation is just the same.
Note: if  rR  r, a    than  ' R, a   
Which is OK since   PQ  .
8
Proof (cont.)
The initial state of M is:
q0 '  q0  .
Finally, the final state of M is:
F '  R  Q' | R contains a finite state of N 
Since D accepts if N reaches at least one
accepting state.
The reader can verify for her/him self that D
indeed simulates N .
9
Proof (cont.)
It remains to consider  - transitions.
For any state R of D define E R to be the
collection of states of R unified with the
states reachable from R by  - transitions.
The old definition of  ' R, a  is:
 ' R, a   q  Q | q  r, a  for some r  R
And the new definition is:
 ' R, a   q  Q | q  E  r, a  for some r  R
10
Proof (end)
In addition, we have to change the definition of
q0 ' , the initial state of M . The previous
definition, q0 '  q0  , is replaced with
q0 '  E q0  .
Once again the reader can verify that the new
definition of D satisfies all requirements.
11
Corollary
A language L is regular if and only if there exists
an NFA recognizing L .
12
The Regular Operations
Let A and B be 2 regular languages above the
same alphabet,  . We define the 3 Regular
Operations:
• Union: A  B  x | x  A or x  B .
• Concatenation: A  B  xy | x  A and y  B .
• Star: A*  x1 , x2 ,..., xk | k  0 and xk  A .
13
Elaboration
• Union is straight forward.
• Concatenation is the operation in which each
word in A is concatenated with every word in
B.
• Star is a unary operation in which each word
in A is concatenated with every other word in
A and this happens any finite number of
times.
14
The Regular Operations - Examples
A  good , bad  B  girl, boy
• A  B  good , bad , girl , boy
• A  B  goodgirl , goodboy, badgirl
. , badboy
 , good , bad , goodgood , goodbad ,

• A 

 goodgoodgoodbad , badbadgoodbad ,...
*
15
Motivation for Nondeterminism
We want to use the regular operations for a
systematic construction of all regular
expressions.
Given a two DFA-s, their product DFA can
recognizes their union, but we do not know
how to construct a DFA recognizing either
concatenation or star.
This can be proved by using NFA-s.
16
Theorem
The class of Regular languages is closed under the
all three regular operations.
.
17
Proof for union Using NFA-s
If A1 and A2 are regular, each has its own
recognizing automaton N1 and N 2 ,
respectively.
In order to prove that the language A1  A2 is
regular we have to construct an FA that
accepts exactly the words in A1  A2 .
18
A Pictorial proof
q0

19
N1
q1
f1
f2

N2
f3
q2
f4
f5
F
Proof for union Using NFA-s
Let N1  Q1, , 1, q1, F1  recognizing A1 , and
N2  Q2 , , 2 , q2 , F2  recognizing A2 .
Construct N  Q, ,  , q, F  to recognize A1  A2 ,
Where Q  q0  Q1  Q2 ,
20
1 q, a 
 q, a 
 2
 q, a   
 q1 , q2 
 
F  F1  F2
q  Q1
q  Q2
q  Q1 and a  
q  Q1 and a  
,
Theorem
The class of Regular languages is closed under the
concatenation operation.
.
21
Proof idea
Given an input word to be checked whether it
belongs to A1  A2 , we may want to run N1
until it reaches an accepting state and then to
move to N 2 .
22
Proof idea
The problem: Whenever an accepting state is
reached, we cannot be sure whether the word
of A1 is finished yet.
The idea: Use non-determinism to choose the
right point in which the word of A1 is finished
and the word of A2 starts.
23
A Pictorial proof
q0
F
N1
q0  q1
f1
f2
24


N2
q2
f3
f4
Proof using NFAs
Let N1  Q1, ,  , q1, F1  recognizing A1 , and
N2  Q2 , ,  , q2 , F2  recognizing A2 .
Construct N  Q, ,  , q1, F  to recognize A1  A2 ,
Where Q  Q1  Q2 , F  F2 ,
q  Q1 and q  F1
 1 q, a 
  q, a 
q  F1 and a  
 1
 q, a   



q
,
a
 q2 q  F1 and a  
1

 1 q, a 
q  Q2
25
Theorem
The class of Regular languages is closed under the
star operation.
.
26
A Pictorial proof
q0
q0


N1
q1

27
f2
f3
F
Proof using NFAs
Let N1  Q1, ,  , q1, F1  recognizing A1 .
Construct N  Q, ,  , q0 , F  to recognize A
*
1
Where Q  q0  Q1, F
 1 q, a 
  q, a 
1

 q, a   1 q, a   q1

q1



28
 q0  F1 , and
q  Q1 and q  F1
q  F1 and a  
q  F1 and a  
q  q0 and a  
q  q0 and a  
Wrap Up
In this lecture we:
• Proved equivalence between DFA-s and NFA-s.
• Motivated and defined the three Regular
Operations.
• Proved that the regular operations preserve
regularity.
29
Download