Formal Definition of a Finite Automaton Formal Definition of a - - PowerPoint PPT Presentation

formal definition of a finite automaton
SMART_READER_LITE
LIVE PREVIEW

Formal Definition of a Finite Automaton Formal Definition of a - - PowerPoint PPT Presentation

Formal Definition of a Finite Automaton Formal Definition of a Finite Automaton p.1/23 Why a formal definition? A formal definition is precise: Formal Definition of a Finite Automaton p.2/23 Why a formal definition? A formal


slide-1
SLIDE 1

Formal Definition

  • f a Finite Automaton

Formal Definition of a Finite Automaton – p.1/23

slide-2
SLIDE 2

Why a formal definition?

  • A formal definition is precise:

Formal Definition of a Finite Automaton – p.2/23

slide-3
SLIDE 3

Why a formal definition?

  • A formal definition is precise:
  • It resolves any uncertainties about what is allowed in a finite

automaton such as the number of accept states and number of transitions exiting from a state

Formal Definition of a Finite Automaton – p.2/23

slide-4
SLIDE 4

Why a formal definition?

  • A formal definition is precise:
  • It resolves any uncertainties about what is allowed in a finite

automaton such as the number of accept states and number of transitions exiting from a state

  • A formal definition provides a notation:

Formal Definition of a Finite Automaton – p.2/23

slide-5
SLIDE 5

Why a formal definition?

  • A formal definition is precise:
  • It resolves any uncertainties about what is allowed in a finite

automaton such as the number of accept states and number of transitions exiting from a state

  • A formal definition provides a notation:
  • Good notation helps think and express thoughts clearly

Formal Definition of a Finite Automaton – p.2/23

slide-6
SLIDE 6

Parts of a finite automaton

  • A finite set of states

Formal Definition of a Finite Automaton – p.3/23

slide-7
SLIDE 7

Parts of a finite automaton

  • A finite set of states
  • Rules for going from one state to another

depending upon the input symbol

Formal Definition of a Finite Automaton – p.3/23

slide-8
SLIDE 8

Parts of a finite automaton

  • A finite set of states
  • Rules for going from one state to another

depending upon the input symbol

  • A finite input alphabet that indicates the

allowed symbols

Formal Definition of a Finite Automaton – p.3/23

slide-9
SLIDE 9

Parts of a finite automaton

  • A finite set of states
  • Rules for going from one state to another

depending upon the input symbol

  • A finite input alphabet that indicates the

allowed symbols

  • A start state

Formal Definition of a Finite Automaton – p.3/23

slide-10
SLIDE 10

Parts of a finite automaton

  • A finite set of states
  • Rules for going from one state to another

depending upon the input symbol

  • A finite input alphabet that indicates the

allowed symbols

  • A start state
  • A finite set of accept states

Formal Definition of a Finite Automaton – p.3/23

slide-11
SLIDE 11

Observation

  • In mathematical language a list of five

elements is called a 5-tuple, hence a finite automaton can be defined as a 5-tuple

Formal Definition of a Finite Automaton – p.4/23

slide-12
SLIDE 12

Observation

  • In mathematical language a list of five

elements is called a 5-tuple, hence a finite automaton can be defined as a 5-tuple

  • We can denote the transition rules by a

function called the transition function, δ : States × Alphabet → States

Formal Definition of a Finite Automaton – p.4/23

slide-13
SLIDE 13

Observation

  • In mathematical language a list of five

elements is called a 5-tuple, hence a finite automaton can be defined as a 5-tuple

  • We can denote the transition rules by a

function called the transition function, δ : States × Alphabet → States

  • Example: δ(q0, x) = q1

Formal Definition of a Finite Automaton – p.4/23

slide-14
SLIDE 14

Formal definition

A finite automaton is a 5-tuple (Q, Σ, δ, q0, F):

Formal Definition of a Finite Automaton – p.5/23

slide-15
SLIDE 15

Formal definition

A finite automaton is a 5-tuple (Q, Σ, δ, q0, F):

  • 1. Q is a finite set called the set of states

Formal Definition of a Finite Automaton – p.5/23

slide-16
SLIDE 16

Formal definition

A finite automaton is a 5-tuple (Q, Σ, δ, q0, F):

  • 1. Q is a finite set called the set of states
  • 2. Σ is a finite set called the alphabet

Formal Definition of a Finite Automaton – p.5/23

slide-17
SLIDE 17

Formal definition

A finite automaton is a 5-tuple (Q, Σ, δ, q0, F):

  • 1. Q is a finite set called the set of states
  • 2. Σ is a finite set called the alphabet
  • 3. δ : Q × Σ → Q is the transition function

Formal Definition of a Finite Automaton – p.5/23

slide-18
SLIDE 18

Formal definition

A finite automaton is a 5-tuple (Q, Σ, δ, q0, F):

  • 1. Q is a finite set called the set of states
  • 2. Σ is a finite set called the alphabet
  • 3. δ : Q × Σ → Q is the transition function
  • 4. q0 ∈ Q is the start (or initial) state

Formal Definition of a Finite Automaton – p.5/23

slide-19
SLIDE 19

Formal definition

A finite automaton is a 5-tuple (Q, Σ, δ, q0, F):

  • 1. Q is a finite set called the set of states
  • 2. Σ is a finite set called the alphabet
  • 3. δ : Q × Σ → Q is the transition function
  • 4. q0 ∈ Q is the start (or initial) state
  • 5. F ⊆ Q is the set of accept (or final) states

Formal Definition of a Finite Automaton – p.5/23

slide-20
SLIDE 20

Note

  • Since the set F can be emptyset ∅ a finite

automaton may have zero accept states

Formal Definition of a Finite Automaton – p.6/23

slide-21
SLIDE 21

Note

  • Since the set F can be emptyset ∅ a finite

automaton may have zero accept states

  • Since transitions are described by a function,

the function δ specifies exactly one next state for each possible combination of state and input symbol

Formal Definition of a Finite Automaton – p.6/23

slide-22
SLIDE 22

Example finite automaton

The automaton M1 have been defined by the transition diagram in Figure 1

✲ ✖✕ ✗✔

q1

❯ ❯

1

✖✕ ✗✔

q2

✒✑ ✓✏ ❯

1

❯ ■

0, 1 ✖✕

✗✔

q3

Figure 1: The finite automaton M1

Formal Definition of a Finite Automaton – p.7/23

slide-23
SLIDE 23

Formalizing M1

M1 = (Q, Σ, δ, q1, F) where

  • 1. Q = {q1, q2, q3}
  • 2. Σ = {0, 1}
  • 3. δ is described by the table:

δ 1 q1 q1 q2 q2 q3 q2 q3 q2 q2

  • 4. q1 is the start state, and 5. F = {q2}.

Formal Definition of a Finite Automaton – p.8/23

slide-24
SLIDE 24

Language of a machine

  • Since a finite automaton is used here as the

model of a computer we also refer to a finite automaton as a “machine"

Formal Definition of a Finite Automaton – p.9/23

slide-25
SLIDE 25

Language of a machine

  • Since a finite automaton is used here as the

model of a computer we also refer to a finite automaton as a “machine"

  • If A is the set of all strings that a machine M

accepts, we say that A is the language of the machine M and write L(M) = A.

Formal Definition of a Finite Automaton – p.9/23

slide-26
SLIDE 26

Terminology

  • The term accept has a different meaning

when we refer to machines accepting strings and machines accepting languages. In order to avoid confusion:

Formal Definition of a Finite Automaton – p.10/23

slide-27
SLIDE 27

Terminology

  • The term accept has a different meaning

when we refer to machines accepting strings and machines accepting languages. In order to avoid confusion:

  • Use accept when we refer to strings

Formal Definition of a Finite Automaton – p.10/23

slide-28
SLIDE 28

Terminology

  • The term accept has a different meaning

when we refer to machines accepting strings and machines accepting languages. In order to avoid confusion:

  • Use accept when we refer to strings
  • Use recognize when we refer to languages

Formal Definition of a Finite Automaton – p.10/23

slide-29
SLIDE 29

Consequences

  • A machine may accept several strings, but it

always recognizes only one language

Formal Definition of a Finite Automaton – p.11/23

slide-30
SLIDE 30

Consequences

  • A machine may accept several strings, but it

always recognizes only one language

  • If a machine accepts no strings, it still

recognizes one language, namely the empty language ∅

Formal Definition of a Finite Automaton – p.11/23

slide-31
SLIDE 31

Consequences

  • A machine may accept several strings, but it

always recognizes only one language

  • If a machine accepts no strings, it still

recognizes one language, namely the empty language ∅

  • Language recognized by machine M1 is:

Formal Definition of a Finite Automaton – p.11/23

slide-32
SLIDE 32

Consequences

  • A machine may accept several strings, but it

always recognizes only one language

  • If a machine accepts no strings, it still

recognizes one language, namely the empty language ∅

  • Language recognized by machine M1 is:

A = {w| w contains at least one 1 and an even number of 0s follow the last 1}

Formal Definition of a Finite Automaton – p.11/23

slide-33
SLIDE 33

Consequences

  • A machine may accept several strings, but it

always recognizes only one language

  • If a machine accepts no strings, it still

recognizes one language, namely the empty language ∅

  • Language recognized by machine M1 is:

A = {w| w contains at least one 1 and an even number of 0s follow the last 1}

  • Conclusion: L(M1) = A, or equivalently, M1

recognizes A

Formal Definition of a Finite Automaton – p.11/23

slide-34
SLIDE 34

Machine M2

The state diagram in Figure 2 describes a machine M2

✲ ✖✕ ✗✔

q1

❄ ❯

1

❑ ✖✕ ✗✔ ✒✑ ✓✏

q2

1

Figure 2: State diagram of the finite automaton M2

Formal Definition of a Finite Automaton – p.12/23

slide-35
SLIDE 35

Machine M2

The state diagram in Figure 2 describes a machine M2

✲ ✖✕ ✗✔

q1

❄ ❯

1

❑ ✖✕ ✗✔ ✒✑ ✓✏

q2

1

Figure 2: State diagram of the finite automaton M2

Formally,

Formal Definition of a Finite Automaton – p.12/23

slide-36
SLIDE 36

Machine M2

The state diagram in Figure 2 describes a machine M2

✲ ✖✕ ✗✔

q1

❄ ❯

1

❑ ✖✕ ✗✔ ✒✑ ✓✏

q2

1

Figure 2: State diagram of the finite automaton M2

Formally, M2 = ({q1, q2}, {0, 1}, δ, q1, {q2}) where

Formal Definition of a Finite Automaton – p.12/23

slide-37
SLIDE 37

Machine M2

The state diagram in Figure 2 describes a machine M2

✲ ✖✕ ✗✔

q1

❄ ❯

1

❑ ✖✕ ✗✔ ✒✑ ✓✏

q2

1

Figure 2: State diagram of the finite automaton M2

Formally, M2 = ({q1, q2}, {0, 1}, δ, q1, {q2}) where δ(q1, 0) = q1, δ(q1, 1) = q2, δ(q2, 0) = q1, δ(q2, 1) = q2

Formal Definition of a Finite Automaton – p.12/23

slide-38
SLIDE 38

Note

  • State diagram of M2 and its formal description

contain the same information, in different form

Formal Definition of a Finite Automaton – p.13/23

slide-39
SLIDE 39

Note

  • State diagram of M2 and its formal description

contain the same information, in different form

  • A good way of understanding any machine is

to try it on some sample input string

Formal Definition of a Finite Automaton – p.13/23

slide-40
SLIDE 40

Note

  • State diagram of M2 and its formal description

contain the same information, in different form

  • A good way of understanding any machine is

to try it on some sample input string

  • Example: Discover the language of M2,

Formal Definition of a Finite Automaton – p.13/23

slide-41
SLIDE 41

Note

  • State diagram of M2 and its formal description

contain the same information, in different form

  • A good way of understanding any machine is

to try it on some sample input string

  • Example: Discover the language of M2,

L(M2) = {w| w ends in a 1}

Formal Definition of a Finite Automaton – p.13/23

slide-42
SLIDE 42

Another example

Consider the finite automaton M3 in Figure 3

✲ ✖✕ ✗✔ ✒✑ ✓✏

q1

❄ ❯

1

❑ ✖✕ ✗✔

q2

1

Figure 3: State diagram of the finite automaton M3

Formal Definition of a Finite Automaton – p.14/23

slide-43
SLIDE 43

Another example

Consider the finite automaton M3 in Figure 3

✲ ✖✕ ✗✔ ✒✑ ✓✏

q1

❄ ❯

1

❑ ✖✕ ✗✔

q2

1

Figure 3: State diagram of the finite automaton M3

Note: M3 is similar to M2, except for the location of the accept state

Formal Definition of a Finite Automaton – p.14/23

slide-44
SLIDE 44

Observations

  • As usual, M3 accepts all strings that leave it in an

accept state when it has consumed the input.

Formal Definition of a Finite Automaton – p.15/23

slide-45
SLIDE 45

Observations

  • As usual, M3 accepts all strings that leave it in an

accept state when it has consumed the input.

  • Because M3’s start state is also accept state, M3

accepts the empty string ǫ.

Formal Definition of a Finite Automaton – p.15/23

slide-46
SLIDE 46

Observations

  • As usual, M3 accepts all strings that leave it in an

accept state when it has consumed the input.

  • Because M3’s start state is also accept state, M3

accepts the empty string ǫ.

  • Note: as soon as M3 begins the reading of ǫ it is at the end,

so it accepts it

Formal Definition of a Finite Automaton – p.15/23

slide-47
SLIDE 47

Observations

  • As usual, M3 accepts all strings that leave it in an

accept state when it has consumed the input.

  • Because M3’s start state is also accept state, M3

accepts the empty string ǫ.

  • Note: as soon as M3 begins the reading of ǫ it is at the end,

so it accepts it

  • In addition to ǫ, M3 accepts any string that ends in 0

Formal Definition of a Finite Automaton – p.15/23

slide-48
SLIDE 48

Observations

  • As usual, M3 accepts all strings that leave it in an

accept state when it has consumed the input.

  • Because M3’s start state is also accept state, M3

accepts the empty string ǫ.

  • Note: as soon as M3 begins the reading of ǫ it is at the end,

so it accepts it

  • In addition to ǫ, M3 accepts any string that ends in 0

L(M3) = {w|w is the empty string ǫ or ends in 0}

Formal Definition of a Finite Automaton – p.15/23

slide-49
SLIDE 49

Example 1.4

Consider the five-state machine M4, Figure 4

❄ ✖✕ ✗✔

s

a

❅ ❅ ❅ ❘

b

✖✕ ✗✔ ✒✑ ✓✏

q1

✲ ✖✕ ✗✔ ✒✑ ✓✏

r1 ✛ a b

b

a

✖✕ ✗✔

q2

b

a

b

✖✕ ✗✔

r2 ✛ a

Figure 4: Finite automaton M4

Formal Definition of a Finite Automaton – p.16/23

slide-50
SLIDE 50

Observations

  • M4 has two accept states, q1 and r1

Formal Definition of a Finite Automaton – p.17/23

slide-51
SLIDE 51

Observations

  • M4 has two accept states, q1 and r1
  • M4 operates over the alphabet Σ = {a, b}

Formal Definition of a Finite Automaton – p.17/23

slide-52
SLIDE 52

Observations

  • M4 has two accept states, q1 and r1
  • M4 operates over the alphabet Σ = {a, b}
  • Some experimentation with M4 shows that it

accepts strings as a, b, aa, bb, bab and does not accept strings as ab, ba, bbba

Formal Definition of a Finite Automaton – p.17/23

slide-53
SLIDE 53

Observations

  • M4 has two accept states, q1 and r1
  • M4 operates over the alphabet Σ = {a, b}
  • Some experimentation with M4 shows that it

accepts strings as a, b, aa, bb, bab and does not accept strings as ab, ba, bbba

  • M4 begins in state s and after it reads the first

symbol in the input it either goes to the left to q states or to the right to r states

Formal Definition of a Finite Automaton – p.17/23

slide-54
SLIDE 54

More observations

  • Once M4 goes to the left or to the right it can never

return to the start state

Formal Definition of a Finite Automaton – p.18/23

slide-55
SLIDE 55

More observations

  • Once M4 goes to the left or to the right it can never

return to the start state

  • If the first symbol in the string is a then it goes to the

left and accepts when the strings ends with an a

Formal Definition of a Finite Automaton – p.18/23

slide-56
SLIDE 56

More observations

  • Once M4 goes to the left or to the right it can never

return to the start state

  • If the first symbol in the string is a then it goes to the

left and accepts when the strings ends with an a

  • If the first symbol in the string is b then it goes to the

right and accept when the strings ends with a b

Formal Definition of a Finite Automaton – p.18/23

slide-57
SLIDE 57

More observations

  • Once M4 goes to the left or to the right it can never

return to the start state

  • If the first symbol in the string is a then it goes to the

left and accepts when the strings ends with an a

  • If the first symbol in the string is b then it goes to the

right and accept when the strings ends with a b

  • Conclusion: L(M4) = {w|w = axa} ∪ {w|w = byb} for x, y ∈ Σ∗

Formal Definition of a Finite Automaton – p.18/23

slide-58
SLIDE 58

Example 1.5

The state diagram in Figure 5 shows the machine M5 which has a four-symbol input alphabet, Σ = {RESET, 0, 1, 2} where RESET is treated as a single symbol

✖✕ ✗✔

q1

✎ ✖✕ ✗✔ ✒✑ ✓✏

q0

✲ ❘

0, RESET

2, RESET

1

2

1, RESET

✖✕ ✗✔

q2

1

2

Figure 5: Finite automaton M5

Formal Definition of a Finite Automaton – p.19/23

slide-59
SLIDE 59

Running M5

  • M5 keeps a running count of the sum of the

numerical input symbols it reads, modulo 3.

Formal Definition of a Finite Automaton – p.20/23

slide-60
SLIDE 60

Running M5

  • M5 keeps a running count of the sum of the

numerical input symbols it reads, modulo 3.

  • The three states of the automaton correspond

to the three numbers 0,1,2, the sum could ever be

Formal Definition of a Finite Automaton – p.20/23

slide-61
SLIDE 61

Running M5

  • M5 keeps a running count of the sum of the

numerical input symbols it reads, modulo 3.

  • The three states of the automaton correspond

to the three numbers 0,1,2, the sum could ever be

  • Every time the automaton receives the

RESET symbol it resets the count to 0 while

moving to state q0

Formal Definition of a Finite Automaton – p.20/23

slide-62
SLIDE 62

Limitation of state diagrams

  • It is not always possible to describe a finite

automaton using a state diagram

Formal Definition of a Finite Automaton – p.21/23

slide-63
SLIDE 63

Limitation of state diagrams

  • It is not always possible to describe a finite

automaton using a state diagram

  • That may occur when the diagram would be

too big to draw, or if, as in the Example 1.5, the description depends on some unspecified parameter

Formal Definition of a Finite Automaton – p.21/23

slide-64
SLIDE 64

Limitation of state diagrams

  • It is not always possible to describe a finite

automaton using a state diagram

  • That may occur when the diagram would be

too big to draw, or if, as in the Example 1.5, the description depends on some unspecified parameter

  • In these cases one needs to resort to a

formal description to specify the machine

Formal Definition of a Finite Automaton – p.21/23

slide-65
SLIDE 65

Example 1.6

Consider a generalization of the Example 1.5 using the same four symbol alphabet Σ

  • For each i ≥ 0 let Ai be the language of all

strings where the sum of the numbers making up the input is a multiple of i, except that the sum is reset to 0 whenever a symbol RESET appears

Formal Definition of a Finite Automaton – p.22/23

slide-66
SLIDE 66

Example 1.6

Consider a generalization of the Example 1.5 using the same four symbol alphabet Σ

  • For each i ≥ 0 let Ai be the language of all

strings where the sum of the numbers making up the input is a multiple of i, except that the sum is reset to 0 whenever a symbol RESET appears

  • For each Ai we construct a finite automaton

Bi recognizing Ai

Formal Definition of a Finite Automaton – p.22/23

slide-67
SLIDE 67

Example 1.6

Consider a generalization of the Example 1.5 using the same four symbol alphabet Σ

  • For each i ≥ 0 let Ai be the language of all

strings where the sum of the numbers making up the input is a multiple of i, except that the sum is reset to 0 whenever a symbol RESET appears

  • For each Ai we construct a finite automaton

Bi recognizing Ai

Formal Definition of a Finite Automaton – p.22/23

slide-68
SLIDE 68

The automaton Bi

The machine Bi is described formally as follows: Bi = (Qi, Σ, δi, q0, {q0}) where

  • Qi = {q0, q1, . . . , qi−1}

Formal Definition of a Finite Automaton – p.23/23

slide-69
SLIDE 69

The automaton Bi

The machine Bi is described formally as follows: Bi = (Qi, Σ, δi, q0, {q0}) where

  • Qi = {q0, q1, . . . , qi−1}
  • Σ = {0, 1, 2, RESET}

Formal Definition of a Finite Automaton – p.23/23

slide-70
SLIDE 70

The automaton Bi

The machine Bi is described formally as follows: Bi = (Qi, Σ, δi, q0, {q0}) where

  • Qi = {q0, q1, . . . , qi−1}
  • Σ = {0, 1, 2, RESET}
  • δi is designed so that for each j, 0 ≤ j ≤ i − 1, if Bi is in the state

qj then the running sum is j modulo i. For each qj we set: δi(qj, 0) = qj δi(qj, 1) = qk, k = j + 1 modulo i δi(qj, 2) = qk, k = j + 2 modulo i δi(qj, RESET) = q0

Formal Definition of a Finite Automaton – p.23/23