Download Regular Operations

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Transcript
Introduction to Computability
Theory
Lecture2: Non Deterministic
Finite Automata
Prof. Amos Israeli
1
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 .
2
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.
3
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 ,...
*
4
Motivation for Nondeterminism
The Regular Operations give us a way to
construct all regular languages systematically.
In the previous lecture, we showed that the
union operation preserves regularity:
Given two regular languages L1 and L2 and their
recognizing automata, M1 and M2 ,we
constructed an automaton that recognizes
L1  L2 .
5
Motivation for Nondeterminism
This approach fails when trying to prove that
concatenation and star preserve regularity.
To overcome this problem we introduce
nondeterminism.
6
Roadmap for Lecture
In this lecture we:
• (Already) Present the three regular
operations.
• Present Non-Deterministic Finite Automata.
• Prove that NFA-s and DFA-s are equivalent.
• Use NFA-s to show that when each of the
regular operation is applied on regular
languages yields yet another regular language.
7
Example of an NFA
NFA – Nondeterministic Finite Automaton
q0
0,1
1
q2
 ,0
q3
1
q4
0,1
1. A state nay have 0-many transitions labeled with the
same symbol.
2.  transitions are possible.
8
Computation of an NFA
• When several transitions with the same label
exist, an input word may induce several paths.
• When 0 transition is possible a computation
may get “stuck”.
Q:Which words are accepted and which are not?
A: If word w induces (at least) a single accepting
computation, the automaton “chooses” this
accepting path and w is accepted.
9
Computation of an NFA - Example
1
q1
0,1
q2
 ,0
q3
1
q4
0,1
On the input word w=010110 there exist an
accepting path and w is accepted.
Can we characterize (find) the language
recognized by this automaton?
Words containing 101 or 11 as substrings
10
Why do we Care About NFAs?
• NFA-s and DFA-s are equivalent (Meaning:
They recognize the same set of languages). In
other words: Each NFA recognizing language L
has an equivalent DFA recognizing L.
(Note: This statement must be proved.)
• But usually, the NFA is much simpler.
• Enables the proof of theorems. (e.g. about
regular operations)
11
What is the language of this DFA?
12
13
Bit Strings that have 1 in position third from the end
14
Can you verify it now?
15
DFA – A Formal Definition(Rerun)
A finite automaton is a 5-tupple Q, ,  , q0 , F 
where:
1. Qis a finite set called the states.
2. is a finite set called the alphabet.
3.  : Q    Q is the transition function.
4. q0  Q is the start state, and
,
5. F  Q is the set of accepting states.
,
16
NFA – A Formal Definition
A finite automaton is a 5-tupple Q, ,  , q0 , F 
where:
1. Qis a finite set called the states.
2. is a finite set called the alphabet.
3.  : Q  * PQ  is the transition function.
4. q0  Q is the start state, and
,
5. F  Q is the set of accept states.
,
*      
17
Differences between NFA-s and DFA-s
There are two differences:
1. The range of the transition function  is now
PQ  . (The set of subsets of the state set Q )
2. The transition function allows  transitions.
18
Possible Computations
DFA
q0
.
.
.
NFA
At each step of the computation:
DFA - A single state is occupied.
NFA - Several states may be
occupied.
qc
qd
qf
qi
19
qg
qh
....
qa
qb
qe
qj
qk
ql
Computations of NFA-s
In general a computation of an NFA, N, on input
w, induces a computation tree.
Each path of the computation tree represents a
possible computation of N.
The NFA N accepts w, if its computation tree
includes at least one path ending with an
accepting state.
20
Computations of NFA-s
There are two ways to look at computations of
an NFA:
• The first is to say that the NFA N “chooses”
the right path on its tree of possible
computations.
• The second is to say that the NFA N traverses
its computation tree “in parallel”.
21
Equivalence Between DFAs and NFAs
Now we prove that the class of NFAs is
Equivalent to the class of DFA:
Theorem: For every NFA N , there exists a DFA
M  M N , such that LN   LM N  .
Proof Idea: The proof is Constructive: We
assume that we know N , and construct a
simulating DFA, M .
22
Proof
Let N  Q, ,  , q0 , F  recognizing some
language A. the state set of the simulating
DFA M, should reflect the fact that at each
step of the computation, N may occupy
several sates.
Thus we define the state set of M as PQ 
the power-set of the state set of N.
23
Proof (cont.)
Let N  Q, ,  , q0 , F  recognizing some
language A. First we assume that N has no
 - transitions.
Define M  Q' , ,  ' , q0 ' , F  where Q'  PQ .
24
Proof (cont.)
Our next task is to define the M’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 process an input symbol
a, M goes to the set of states to which N will
go in any of the branches of its computation.
25
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 M accepts if N reaches at least one
accepting state.
The reader can verify for her/his self that N
indeed simulates N .
26
Proof (cont.)
It remains to consider  - transitions.
For any state R of M 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
27
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 M satisfies all requirements.
28
Corollary
A language L is regular if and only if there exists
an NFA recognizing L .
29
The Regular Operations (Rerun)
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 .
30
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 ,...
*
31
Theorem (rerun)
The class of Regular languages is closed under the
all three regular operations.
.
32
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 .
33
A Pictorial proof
34
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 ,
35
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.
.
36
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 .
37
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.
38
A Pictorial proof
39
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   
1 q, a   q2 q  F1 and a  
 1 q, a 
q  Q2
40
Theorem
The class of Regular languages is closed under the
star operation.
.
41
A Pictorial proof
42
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



43
 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:
• Motivated and defined the three Regular
Operations.
• Introduced NonDeterministic Finite
Automatons.
• Proved equivalence between DFA-s and NFA-s.
• Proved that the regular operations preserve
regularity.
44