Documente Academic
Documente Profesional
Documente Cultură
! Regular Languages
! Deterministic Finite Automata ! Nondeterministic Finite Automata
! Today:
! Equivalence of NFA and DFA ! Regular Expressions ! Equivalence to Regular Languages
Equivalence of Machines
Machine ifL(M1 ) =
q1
0
q0
M2
1
0,1
q1
0
q2
a
q0
M
q0
a a a
q1
b
q2
q1
b
q2
M!
{q0 }
DFA
M!
{q1, q2 }
{q0 }
From the NFA start states, where could we get on a? List the set of all possible states you can reach using just an a.
NFA
NFA
q1
b
q2
a a
q1
b
q2
a
DFA
M!
{q0 }
b
{q1, q2 }
How did we get from q0 to q2 using only a? (think ! )
DFA
M!
{q0 }
b
{q1, q2 }
From new set, where could we get on a?
From the NFA start states, where could we get on b? The set of all possible states you can reach may be empty!
NFA
a a
b
M
q0
a a
b
q1
b
q2
a
DFA
q1
b
q2
a
DFA
M!
{q0 }
b
M!
{q1, q2 }
From new set, where could we get on b?
{q0 }
b
{q1, q2 }
a, b
From empty set, we can only get back to empyt set.
M
q0
q1
b b
q2
a
q0 , q1, q2 ,...
There are a finite number of NFA states by definition
DFA
M!
{q0 }
b
{q1, q2 }
a, b
If a node has any NFA Final state, mark the node as Final in the DFA.
q0
{q0 }
! * (qi , a ), ! *( q j , a) ,
Add transition to DFA
...
Proof
Theorem
Take NFA
M
M!
L(M ) = L(M !)
and
M!
are equivalent :
AND
L(M ) = L(M !)
First we show:
w ! L( M )
w
w = ! 1! 2 !! k
qf
w " L( M !)
M:
q0
!1
!2
!k
qf
w ! L( M )
!k
M:
w = ! 1! 2 !! k
v = a1a2 ! an
a2
M:
q0
!1
!2
qf
M:
q0
a1
qi
qj
ql
an
qm
M!:
!1
!2
!k
{q0 }
w " L( M !)
{q f ,}
M!:
a1
{q0 }
a2
{qi ,} {q j ,}
an
{ql ,} {qm ,}
|v|
Induction hypothesis:
v = a1
q0
a1
1 !| v |! k
v = a1a2 ! ak
M:
q0
a1
M:
qi
qi
a2
qj
qc
ak
qd
M!:
a1
{q0 }
{qi ,}
M!:
a1
{q0 }
a2
{qi ,} {q j ,}
ak
{qc ,} {qd ,}
Induction Step:
| v |= k + 1
v!
Induction Step:
| v |= k + 1
v!
qi
a2
qj
qc
ak
qd
qi
a2
qj
qc
ak
qd ak +1 qe
v! M!:
a1
{q0 }
v!
ak
{qc ,} {qd ,}
a2
{qi ,} {q j ,}
M!:
a1
{q0 }
a2
{qi ,} {q j ,}
ak
ak +1
{qe ,}
{qc ,} {qd ,}
v!
v!
Therefore if
w ! L( M )
w = ! 1! 2 !! k
!2
!k
We have shown:
M:
q0
!1
qf
We also need to show:
M!:
!1
!2
!k
(proof is similar)
{q f ,}
{q0 }
w " L( M !)
Regular Languages
Languages accepted by DFAs
Step 2
Regular Languages
Regular Languages
Proof: Every DFA is trivially an NFA Any language L accepted by a DFA is also accepted by an NFA
Proof: Any NFA can be converted to an equivalent DFA Any language L accepted by an NFA is also accepted by a DFA
Regular Expressions
! Regular expressions describe regular languages
Recursive Definition
#, " , ! Given regular expressions r 1 and r2
Primitive regular expressions:
! Example:
(a + b ! c) *
r1 + r2 r1 ! r2 r1 *
Are regular expressions
(r1 )
Examples
A regular expression:
!
(a + b " c )* "(c + !)
! Example
(a + b + )
Formal Definition
! For primitive regular expressions:
Definition (continued)
! For regular expressions r 1 and r2
L(r1 + r2 ) = L(r1 ) ! L(r2 ) L(r1 ! r2 ) = L(r1 ) L(r2 ) L(r1 *) = (L(r1 ))* L((r1 )) = L(r1 )
Example
L((a + b )! a *) = L((a + b )) L(a *) = L(a + b ) L(a *)
Example
! Regular expression
= (L(a ) ! L(b )) (L(a ))* = ({a}! { b}) ({a})* = {a, b}{! , a, aa, aaa,...}
= {a, aa, aaa,..., b, ba, baa,...}
10
Whats Next
! Read
! Linz Chapter 1, 2.1, 2.2, 2.3, (skip 2.4), Chapter 3 ! JFLAP Startup, Chapter 1, 2.1, (skip 2.2) 3, 4
! Homework
! Homework 2 is Due Thursday
11