deterministic finite state machines chapter 5. languages and machines 2
TRANSCRIPT
![Page 1: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/1.jpg)
Deterministic Finite State Machines
Chapter 5
![Page 2: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/2.jpg)
Languages and Machines
2
![Page 3: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/3.jpg)
Regular Languages
Regular Language
Regular Expression
Finite State Machine
L
Accepts
3
![Page 4: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/4.jpg)
Finite State Machines
Vending Machine: An FSM to accept $.50 in change
Drink is 25 centsNo more than 50 cents can be deposited
X
Other FSM examples?4
![Page 5: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/5.jpg)
Definition of a DFSM
M = (K, , , s, A), where:
K is a finite set of states is an alphabet s K is the initial state A K is the set of accepting states, and is the transition function from
(K ) to Kstate input symbol state
Quintuple
Cartesian product
5
![Page 6: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/6.jpg)
Accepting by a DFSM
Informally, M accepts a string w iff M winds up in some element of A when it has finished reading w.
The language accepted by M, denoted L(M), is the set of all strings accepted by M.
6
![Page 7: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/7.jpg)
Configurations of DFSMs
A configuration of a DFSM M is 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 configuration of a DFSM M, on input w, is:
(sM, w), where sM is the start state of M 7
![Page 8: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/8.jpg)
The Yields Relations
The yields-in-one-step relation |-M :
(q, w) |-M (q', w') iff
• w = a w' for some symbol a , and • (q, a) = q'
The relation yields, |-M*, is the reflexive, transitive closure of |-M.
C1 |-M* C2 : M can go from C1 to C2 in 0 or more steps.
8
![Page 9: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/9.jpg)
Computations Using FSMs
A computation by M is a finite sequence of configurations C0, C1, …, Cn for some n 0 such that:
• C0 is an initial configuration,
• Cn is of the form (q, ), for some state q KM,
• C0 |-M C1 |-M C2 |-M … |-M Cn.
9
![Page 10: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/10.jpg)
Accepting and Rejecting
A DFSM M accepts a string w iff:
(s, w) |-M * (q, ), for some q A.
A DFSM M rejects a string w iff:
(s, w) |-M* (q, ), for some q AM.
The language accepted by M, denoted L(M), is the set of all strings accepted by M.
Theorem: Every DFSM M, on input s, halts in |s| steps.
10
![Page 11: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/11.jpg)
An Example Computation
An FSM to accept odd integers: even odd
even
q0 q1
odd
On input 235, the configurations are:
(q0, 235) |-M (q0, 35)|-M
|-M
Thus (q0, 235) |-M* (q1, ) 11
![Page 12: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/12.jpg)
Regular Languages
A language is regular iff it is accepted by some FSM.
12
![Page 13: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/13.jpg)
A Very Simple Example
L = {w {a, b}* : every a is immediately followed by a b}.
13
![Page 14: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/14.jpg)
A Very Simple Example
L = {w {a, b}* : every a is immediately followed by a b}.
14
![Page 15: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/15.jpg)
A Very Simple Example
L = {w {a, b}* : every a is immediately followed by a b}.
M = (K, , , s, A) = ({q0, q1, q2}, {a, b}, , q0, {q0}), where
= {((q0, a), q1), ((q0, b), q0),
((q1, a), q2), ((q1, b), q0),
((q2, a), q2), ((q2, b), q2)}15
![Page 16: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/16.jpg)
Parity Checking
L = {w {0, 1}* : w has odd parity}.
16
![Page 17: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/17.jpg)
Parity Checking
L = {w {0, 1}* : w has odd parity}.
M = (K, , , s, A) = ({q0, q1}, {0, 1}, , q0, {q1}), where
= {((q0, 0), q0), ((q0, 1), q1),
((q1, 0), q1), ((q1, 1), q0)}
17
![Page 18: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/18.jpg)
No More Than One b
L = {w {a, b}* : w contains no more than one b}.
18
![Page 19: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/19.jpg)
No More Than One b
L = {w {a, b}* : w contains no more than one b}.
M = (K, , , s, A)
19
![Page 20: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/20.jpg)
Checking Consecutive Characters
L = {w {a, b}* :
no two consecutive characters are the same}.
20
![Page 21: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/21.jpg)
Checking Consecutive Characters
L = {w {a, b}* :
no two consecutive characters are the same}.
21
![Page 22: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/22.jpg)
Dead States
L = {w {a, b}* : every a region in w is of even length}
22
![Page 23: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/23.jpg)
Dead States
L = {w {a, b}* : every a region in w is of even length}
M = (K, , , s, A)
23
![Page 24: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/24.jpg)
Dead States
L = {w {a, b}* : every b in w is surrounded by a’s}
24
![Page 25: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/25.jpg)
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:
25
![Page 26: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/26.jpg)
A Simple Communication Protocol
26
![Page 27: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/27.jpg)
Controlling a Soccer-Playing Robot
27
![Page 28: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/28.jpg)
A Simple Controller
28
![Page 29: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/29.jpg)
Programming FSMs
Cluster strings that share a “future”.
Let L = {w {a, b}* : w contains an even number of a’s and an odd number of b’s}
What states are needed? How many states are there?
29
![Page 30: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/30.jpg)
Even a’s Odd b’s
30
![Page 31: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/31.jpg)
Vowels in Alphabetical Order
L = {w {a - z}* : all five vowels, a, e, i, o, and u,
occur in w in alphabetical order}.
31
![Page 32: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/32.jpg)
Vowels in Alphabetical Order
L = {w {a - z}* : all five vowels, a, e, i, o, and u,
occur in w in alphabetical order}.
O
u
32
![Page 33: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/33.jpg)
Programming FSMs
L = {w {a, b}* : w does not contain the substring aab}.
33
![Page 34: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/34.jpg)
Programming FSMs
L = {w {a, b}* : w does not contain the substring aab}.
Start with a machine for L:
How must it be changed?
34
![Page 35: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/35.jpg)
Programming FSMs
L = {w {a, b}* : w does not contain the substring aab}.
Start with a machine for L:
How must it be changed?
35
![Page 36: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/36.jpg)
A Building Security System
L = {event sequences such that the alarm should sound}
36
![Page 37: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/37.jpg)
FSMs Predate Computers
The Prague Orloj, originally built in 1410
The Chinese Abacus,14 century AD
The Jacquard Loom, invented in 1801
37
![Page 38: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/38.jpg)
Finite State Representations in Software Engineering
A high-level state chart model of a digital watch.
38
![Page 39: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/39.jpg)
Making the Model Hierarchical
39
![Page 40: Deterministic Finite State Machines Chapter 5. Languages and Machines 2](https://reader035.vdocuments.site/reader035/viewer/2022062301/56649e955503460f94b999f0/html5/thumbnails/40.jpg)
The Missing Letter Language
Let = {a, b, c, d}.
Let LMissing = {w : there is a symbol ai not appearing in w}.
Try to make a DFSM for LMissing:
40