automata theory bcbcvbcbvcbbbbbbvcbcbvcbcbcbcvbcvbvcbcvbcvbcvbcvbcvbcvbcvbcvbcvbcbcb

manishatapale 15 views 80 slides Jun 02, 2024
Slide 1
Slide 1 of 80
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80

About This Presentation

elaine rich ppts bccv ...


Slide Content

Finite State Machines
Chapter 5

Languages and Machines

Regular Languages
Regular
Language
Regular Expression
Finite State
Machine
L
Accepts

There are two types of FSM
•Deterministic FSM (DFSM): in these machines there is
always exactly one move that can be made from each step;
this is determined by the current state and the next input
character.
•Nondeterministic FSM (NDFSM): in these machines there
may be at various points in the computation more than one
move from which the machine has to decide.

Definition of a DFSM
Mis a quintuple = (K, , , s, A), where:
Kis a finite set of states
is an alphabet
sKis the initial state
AKis the set of accepting states, and
is the transition function from
(K) to K
state input symbol state

Accepting by a DFSM
Informally, Maccepts a string wiff Mwinds up in some
element of Awhen it has finished reading w.
The language accepted by M, denoted L(M), is the set
of all strings accepted by M.

Configurations of DFSMs
A configurationof a DFSM Mis an element of:
K*
It captures the two things that can make a difference to
M’s future behavior:
• its current state
• the input that is still left to read.
The initial configurationof a DFSM M, on input w, is:
(s
M, w)

The Yields Relations
The yields-in-one-steprelation |-
M:
(q, w) |-
M(q', w') iff
• w= aw'for some symbol a, and
• (q, a) = q'
|-
M*is the reflexive, transitive closure of |-
M.

Computations Using FSMs
A computationby Mis a finite sequence of
configurations C
0, C
1, …, C
nfor some n0 such
that:
• C
0is an initial configuration,
• C
nis of the form (q, ), for some state qK
M,
• C
0|-
MC
1|-
MC
2|-
M… |-
MC
n.

Accepting and Rejecting
A DFSM Macceptsa string wiff:
(s, w) |-
M* (q, ), for some qA.
A DFSM Mrejectsa string wiff:
(s, w) |-
M* (q, ), for some qA
M.
The language accepted byM, denoted L(M), is the
set of all strings accepted by M.
Theorem:Every DFSM M, on input s, halts in |s|
steps.

An Example Computation
An FSM to accept odd integers:
even odd
even
q
0 q
1
odd
On input 235, the configurations are:
(q
0, 235) |-
M (q
0, 35)
|-
M
|-
M
Thus (q
0, 235) |-
M* (q
1, )

Regular Languages
A language is regulariff it is accepted by some
FSM.

A Very Simple Example
L= {w{a, b}* :
every ais immediately followed by a b}.

A Very Simple Example
L= {w{a, b}* :
every ais immediately followed by a b}.

Parity Checking
L= {w{0, 1}* : whas odd parity}.

Parity Checking
L= {w{0, 1}* : whas odd parity}.

No More Than One b
L= {w{a, b}* : every aregion in wis of even length}.

No More Than One b
L= {w{a, b}* : every aregion in wis of even length}.

Checking Consecutive Characters
L= {w{a, b}* :
no two consecutive characters are the same}.

Checking Consecutive Characters
L= {w{a, b}* :
no two consecutive characters are the same}.

Dead States
L=
{w{a, b}* : every aregion in wis of even length}

Dead States
L=
{w{a, b}* : every aregion in wis of even length}

Dead States
L=
{w{a, b}* : every bin wis surrounded by a’s}

The Language of Floating Point
Numbers is Regular
Example strings:
+3.0, 3.0, 0.3E1, 0.3E+1, -0.3E+1, -3E8
The language is accepted by the DFSM:

A Simple Communication Protocol

Controlling a Soccer-Playing Robot

A Simple Controller

Programming FSMs
Cluster strings that share a “future”.
Let L= {w{a, b}* : wcontains an even
number of a’s and an odd number of b’s}

Even a’s Odd b’s

Vowels in Alphabetical Order
L= {w{a-z}* : all five vowels, a, e, i, o, and u,
occur in win alphabetical order}.

Vowels in Alphabetical Order
L= {w{a-z}* : all five vowels, a, e, i, o, and u,
occur in win alphabetical order}.

Programming FSMs
L= {w{a, b}* : wdoes not contain the
substring aab}.

Programming FSMs
L= {w{a, b}* : wdoes not contain the substring
aab}.
Start with a machine for L:
How must it be changed?

A Building Security System
L= {event sequences such that the alarm
should sound}

FSMs Predate Computers
The Prague Orloj, originally built in 1410.

The Abacus

The Jacquard Loom
Invented in 1801.

Finite State Representations in
Software Engineering
A high-level state chart model of a digital watch.

Making the Model Hierarchical

The Missing Letter Language
Let = {a, b, c, d}.
Let L
Missing=
{w: there is a symbol a
inot appearing in w}.
Try to make a DFSM for L
Missing:

Definition of an NDFSM
M= (K, , , s, A), where:
Kis a finite set of states
is an alphabet
sKis the initial state
AKis the set of accepting states, and
is the transition relation. It is a finite subset of
(K({})) K

Accepting by an NDFSM
Maccepts a string wiff there exists some pathalong
which wdrives Mto some element of A.
The language accepted by M, denoted L(M), is the set
of all strings accepted by M.

Sources of Nondeterminism

Two approaches:
• Explore a search tree:
• Follow all paths in parallel
Analyzing Nondeterministic FSMs

Optional Substrings
L= {w{a, b}* : wis made up of an optional a
followed by aafollowed by zero or more b’s}.

Multiple Sublanguages
L= {w{a, b}* : w= abaor |w| is even}.

The Missing Letter Language
Let = {a, b, c, d}. Let L
Missing= {w: there is a
symbol a
inot appearing in w}

The Missing Letter Language

Pattern Matching
L= {w{a, b, c}* : x, y{a, b, c}* (w= xabcabby)}.
A DFSM:

Pattern Matching
L= {w{a, b, c}* : x, y{a, b, c}* (w= xabcabby)}.
An NDFSM:

Pattern Matching with NDFSMs
L= {w{a, b}* :
x, y{a, b}* : w= xaabbbyor
w= xabbaby}

Multiple Keywords
L= {w{a, b}* : x, y{a, b}*
((w= xabbaay) (w= xbabay))}.

Checking from the End
L= {w{a, b}* :
the fourth to the last character is a}

Checking from the End
L= {w{a, b}* :
the fourth to the last character is a}

Another Pattern Matching Example
L= {w{0, 1}* : wis the binary encoding of a
positive integer that is divisible by 16 or is
odd}

Another NDFSM
L
1= {w{a, b}*: aaoccurs in w}
L
2= {x{a, b}*: bboccurs in x}
L
3= {y: L
1or L
2}
M
1=
M
2=
M
3=

A “Real” Example

English Morphology

Analyzing Nondeterministic FSMs
Does this FSM accept:
baaba
Remember: we just have to find one accepting path.

Two approaches:
• Explore a search tree:
• Follow all paths in parallel
Analyzing Nondeterministic FSMs

Another Nondeterministic Example
b* (b(ac)cb(ab) (c))* b

Dealing with Transitions
eps(q) = {pK: (q, w) |-*
M(p, w)}.
eps(q) is the closure of {q} under the relation
{(p, r) : there is a transition (p, , r) }.
How shall we compute eps(q)?

An Algorithm to Compute eps(q)
result= {q}.
While there exists some presultand
some rresultand
some transition (p, , r) do:
Insert r into result.
Return result.
eps(q: state) =

An Example of eps
eps(q
0) =
eps(q
1) =
eps(q
2) =
eps(q
3) =

Simulating a NDFSM
ndfsmsimulate(M: NDFSM, w: string) =
1.current-state= eps(s).
2.While any input symbols in wremain to be read do:
1.c= get-next-symbol(w).
2.next-state= .
3.For each state qin current-statedo:
For each state psuch that (q, c, p) do:
next-state= next-stateeps(p).
4.current-state= next-state.
3.If current-statecontains any states in A, accept. Else
reject.

Nondeterministic and
Deterministic FSMs
Clearly: {Languages accepted by a DFSM} 
{Languages accepted by a NDFSM}
More interestingly:
Theorem:
For each NDFSM, there is an equivalent DFSM.

Nondeterministic and
Deterministic FSMs
Theorem:For each NDFSM, there is an
equivalent DFSM.
Proof:By construction:
Given a NDFSM M= (K, , , s, A),
we construct M' = (K', , ', s', A'), where
K'= P(K)
s'= eps(s)
A'= {QK: QA}
'(Q, a) = {eps(p): pKand
(q, a, p) for some qQ}

An Algorithm for Constructing the
Deterministic FSM
1. Compute the eps(q)’s.
2. Compute s'= eps(s).
3. Compute ‘.
4. Compute K'= a subset of P(K).
5. Compute A'= {QK': QA}.

The Algorithm ndfsmtodfsm
ndfsmtodfsm(M: NDFSM) =
1. For each state qin K
Mdo:
1.1 Compute eps(q).
2. s'= eps(s)
3. Compute ':
3.1 active-states= {s'}.
3.2 ' = .
3.3 While there exists some element Qof active-statesfor
which 'has not yet been computed do:
For each character cin 
Mdo:
new-state= .
For each state qin Q do:
For each state psuch that (q, c, p) do:
new-state= new-stateeps(p).
Add the transition (Q, c, new-state) to '.
If new-stateactive-statesthen insert it.
4. K'= active-states.
5. A'= {QK' : QA}.

An Example

The Number of States May Grow
Exponentially
No. of states after 0 chars: = 1
No. of new states after 1 char: = n
No. of new states after 2 chars: = n(n-1)/2
No. of new states after 3 chars: = n(n-1)(n-2)/6
Total number of states after nchars: 2
nn
n






1 n
n






2 n
n






3
|| = n

Another Hard Example
L= {w{a, b}* :
the fourth to the last character is a}

If the Original FSM is Deterministic
1. Compute the eps(q)s:
2. s'= eps(q0) =
3. Compute '
({q0}, odd, {q1}) ({q0}, even, {q0})
({q1}, odd, {q1}) ({q1}, even, {q0})
4.K'= {{q0}, {q1}}
5. A'= { {q1} }
M'= M
M

The Real Meaning of “Determinism”
Is Mdeterministic?
An FSM is deterministic, in the most general definition of
determinism, if, for each input and state, there is at most one
possible transition.
•DFSMs are always deterministic. Why?
•NDFSMs can be deterministic (even with -transitions and implicit
dead states), but the formalism allows nondeterminism, in general.
•Determinism implies uniquely defined machine behavior.
Let M=

Deterministic FSMs as Algorithms
L= {w{a, b}* : wcontains no more than one b}:

Deterministic FSMs as Algorithms
until accept or reject do:
S:s= get-next-symbol
if s= end-of-file then accept
else if s= a then go to S
else if s= b then go to T
T: s= get-next-symbol
if s= end-of-file then accept
else if s= a then go to T
else if s= b then reject
end

Deterministic FSMs as Algorithms
until accept or reject do:
S:s= get-next-symbol
if s= end-of-file then accept
else if s= a then go to S
else if s= b then go to T
T: s= get-next-symbol
if s= end-of-file then accept
else if s= a then go to T
else if s= b then reject
end
Length of Program: |K| (|| + 2)
Time required to analyze string w: O(|w| ||)
We have to write new code for every new FSM.

A Deterministic FSM Interpreter
dfsmsimulate(M: DFSM, w: string) =
1. st= s.
2. Repeat
2.1 c= get-next-symbol(w).
2.2 If cend-of-file then
2.2.1 st= (st, c).
until c= end-of-file.
3. If stAthen accept else reject.
Input: aabaa

Nondeterministic FSMs as
Algorithms
Real computers are deterministic, so we have three choices
if we want to execute a NDFSM:
1. Convert the NDFSM to a deterministic one:
•Conversion can take time and space 2
|K|
.
•Time to analyze string w: O(|w|)
2. Simulate the behavior of the nondeterministic one by
constructing sets of states "on the fly" during execution
•No conversion cost
•Time to analyze string w: O(|w| |K|
2
)
3. Do a depth-first search of all paths through the
nondeterministic machine.

A NDFSM Interpreter
ndfsmsimulate(M = (K, , , s, A): NDFSM, w: string) =
1. Declare the set st.
2. Declare the set st1.
3.st= eps(s).
4. Repeat
4.1c= get-next-symbol(w).
4.2 If c end-of-file then do
4.2.1st1= .
4.2.2 For all qstdo
4.2.2.1 For all r(q, c) do
4.2.2.1.1 st1= st1eps(r).
4.2.3st= st1.
4.2.4 If st= then exit.
until c= end-of-file.
6. If stAthen accept else reject.
Tags