Formal Definition of Computation Formal Definition of Computation - - PowerPoint PPT Presentation

formal definition of computation
SMART_READER_LITE
LIVE PREVIEW

Formal Definition of Computation Formal Definition of Computation - - PowerPoint PPT Presentation

Formal Definition of Computation Formal Definition of Computation p.1/28 Computation model The model of computation considered so far is the work performed by a finite automaton Formal Definition of Computation p.2/28


slide-1
SLIDE 1

Formal Definition of Computation

Formal Definition of Computation – p.1/28

slide-2
SLIDE 2

Computation model

  • The model of computation considered so far is the

work performed by a finite automaton

Formal Definition of Computation – p.2/28

slide-3
SLIDE 3

Computation model

  • The model of computation considered so far is the

work performed by a finite automaton

  • Finite automata were described informally, using state

diagrams, and formally, as a 5-tuple

Formal Definition of Computation – p.2/28

slide-4
SLIDE 4

Computation model

  • The model of computation considered so far is the

work performed by a finite automaton

  • Finite automata were described informally, using state

diagrams, and formally, as a 5-tuple

  • Informal description is easier to grasp first, but the

formal definition is useful for making this notion precise, resolving any ambiguities that may occur in formal description

Formal Definition of Computation – p.2/28

slide-5
SLIDE 5

Formal definition of computation

Let

✂ ✄ ☎ ✄ ✆ ✄ ✝✟✞ ✄ ✠ ✡

be a finite automaton and

  • ☛✟☞
☛✟✌✎✍ ✍ ✍ ☛✑✏

be a string over

Formal Definition of Computation – p.3/28

slide-6
SLIDE 6

Formal definition of computation

Let

✂ ✄ ☎ ✄ ✆ ✄ ✝✟✞ ✄ ✠ ✡

be a finite automaton and

  • ☛✟☞
☛✟✌✎✍ ✍ ✍ ☛✑✏

be a string over

Then accepts

if a sequence of states

✄ ✍ ✍ ✍ ✄

exist in

such that the following hold:

Formal Definition of Computation – p.3/28

slide-7
SLIDE 7

Formal definition of computation

Let

✂ ✄ ☎ ✄ ✆ ✄ ✝✟✞ ✄ ✠ ✡

be a finite automaton and

  • ☛✟☞
☛✟✌✎✍ ✍ ✍ ☛✑✏

be a string over

Then accepts

if a sequence of states

✄ ✍ ✍ ✍ ✄

exist in

such that the following hold:

1.

✂✁ ✄ ☎ ✁

Formal Definition of Computation – p.3/28

slide-8
SLIDE 8

Formal definition of computation

Let

✂ ✄ ☎ ✄ ✆ ✄ ✝✟✞ ✄ ✠ ✡

be a finite automaton and

  • ☛✟☞
☛✟✌✎✍ ✍ ✍ ☛✑✏

be a string over

Then accepts

if a sequence of states

✄ ✍ ✍ ✍ ✄

exist in

such that the following hold:

1.

✂✁ ✄ ☎ ✁

2.

✄✂ ☎ ✆ ✂ ✝ ✞ ✟ ✄
✝ ✞

for

✠ ✄ ✡ ☎ ☛ ☎☞ ☞ ☞ ☎ ✌ ✍ ☛

Formal Definition of Computation – p.3/28

slide-9
SLIDE 9

Formal definition of computation

Let

✂ ✄ ☎ ✄ ✆ ✄ ✝✟✞ ✄ ✠ ✡

be a finite automaton and

  • ☛✟☞
☛✟✌✎✍ ✍ ✍ ☛✑✏

be a string over

Then accepts

if a sequence of states

✄ ✍ ✍ ✍ ✄

exist in

such that the following hold:

1.

✂✁ ✄ ☎ ✁

2.

✄✂ ☎ ✆ ✂ ✝ ✞ ✟ ✄
✝ ✞

for

✠ ✄ ✡ ☎ ☛ ☎☞ ☞ ☞ ☎ ✌ ✍ ☛

3.

✁ ✂ ✄

Formal Definition of Computation – p.3/28

slide-10
SLIDE 10

Interpretation

  • Condition (1) says that the machine starts its

computation in the start state

Formal Definition of Computation – p.4/28

slide-11
SLIDE 11

Interpretation

  • Condition (1) says that the machine starts its

computation in the start state

  • Condition (2) says that as long as input is available the

machine goes from state to state according to its transition function

Formal Definition of Computation – p.4/28

slide-12
SLIDE 12

Interpretation

  • Condition (1) says that the machine starts its

computation in the start state

  • Condition (2) says that as long as input is available the

machine goes from state to state according to its transition function

  • Condition (3) says that the machine accepts its input if

it ends up in an accept state

Formal Definition of Computation – p.4/28

slide-13
SLIDE 13

Interpretation

  • Condition (1) says that the machine starts its

computation in the start state

  • Condition (2) says that as long as input is available the

machine goes from state to state according to its transition function

  • Condition (3) says that the machine accepts its input if

it ends up in an accept state

  • Can you translate this interpretation into the

computation performed by a program?

Formal Definition of Computation – p.4/28

slide-14
SLIDE 14

Translation

A program behaves like a fi nite automaton:

Formal Definition of Computation – p.5/28

slide-15
SLIDE 15

Translation

A program behaves like a fi nite automaton:

  • Its start state is a function mapping program variables

to their initial values

Formal Definition of Computation – p.5/28

slide-16
SLIDE 16

Translation

A program behaves like a fi nite automaton:

  • Its start state is a function mapping program variables

to their initial values

  • Program execution goes from state to state by

transitions performed according to program control flow

Formal Definition of Computation – p.5/28

slide-17
SLIDE 17

Translation

A program behaves like a fi nite automaton:

  • Its start state is a function mapping program variables

to their initial values

  • Program execution goes from state to state by

transitions performed according to program control flow

  • The language of this machine is the class of problems

solved by program execution

Formal Definition of Computation – p.5/28

slide-18
SLIDE 18

Difference

A program computation differs from FA computation because:

Formal Definition of Computation – p.6/28

slide-19
SLIDE 19

Difference

A program computation differs from FA computation because:

  • A program may have a potential infinite set of states

and can run forever

Formal Definition of Computation – p.6/28

slide-20
SLIDE 20

Difference

A program computation differs from FA computation because:

  • A program may have a potential infinite set of states

and can run forever

  • During execution a program may interact with its

environment

Formal Definition of Computation – p.6/28

slide-21
SLIDE 21

Difference

A program computation differs from FA computation because:

  • A program may have a potential infinite set of states

and can run forever

  • During execution a program may interact with its

environment

  • The accepting state of the program has a larger

interpretation

Formal Definition of Computation – p.6/28

slide-22
SLIDE 22

Note

We say that a machine recognizes the language

  • if
☛ ✂ ✄☎ ☎ ✆✝ ✞✠✟ ☛ ✡

How is this interpreted in terms of a program execution?

Formal Definition of Computation – p.7/28

slide-23
SLIDE 23

Regular language

Definition 1.7 A language is called a regular language if some finite automaton recognizes it

Formal Definition of Computation – p.8/28

slide-24
SLIDE 24

Example computation

Take the machine

  • from Example 1.5 and
✆ ✄ ☛ ✡ ✁ ✂✄ ☎ ✄ ✆ ✝ ✞ ✞ ✁ ✂ ✄ ☎ ✄ ✆ ✝ ✡ ☛ ✞ ✟ ✠ ✡ ✞ ✟ ☛ ☞ ✌ ✞✎✍ ✏ ✑ ✒ ✓ ✒ ✔ ✕ ✖ ✌ ✍ ✏ ✑ ✒ ✓ ✒ ✔ ✕ ✗ ☞ ☞ ✌ ✘ ☞ ✍ ✏ ✑ ✒ ✓ ✒ ✔ ✕ ✟ ✙ ✚ ☞ ✛ ✌ ✖ ✞

Figure 1: Finite automaton

Formal Definition of Computation – p.9/28

slide-25
SLIDE 25

Running

  • accepts

according to the formal definition of computation because the sequence of states it enters when computing on

is

✝ ✞ ✄ ✝ ☞ ✄ ✝ ☞ ✄ ✝✟✞ ✄ ✝ ✌ ✄ ✝ ☞ ✄ ✝✟✞ ✄ ✝✟✞ ✄ ✝ ☞ ✄ ✝✟✞

:

Formal Definition of Computation – p.10/28

slide-26
SLIDE 26

Running

  • accepts

according to the formal definition of computation because the sequence of states it enters when computing on

is

✝ ✞ ✄ ✝ ☞ ✄ ✝ ☞ ✄ ✝✟✞ ✄ ✝ ✌ ✄ ✝ ☞ ✄ ✝✟✞ ✄ ✝✟✞ ✄ ✝ ☞ ✄ ✝✟✞

:

  • ✝✟✞

is the first state by definition

Formal Definition of Computation – p.10/28

slide-27
SLIDE 27

Running

  • accepts

according to the formal definition of computation because the sequence of states it enters when computing on

is

✝ ✞ ✄ ✝ ☞ ✄ ✝ ☞ ✄ ✝✟✞ ✄ ✝ ✌ ✄ ✝ ☞ ✄ ✝✟✞ ✄ ✝✟✞ ✄ ✝ ☞ ✄ ✝✟✞

:

  • ✝✟✞

is the first state by definition

✁ ✝✟✞ ✄

,

✆ ✁ ✝ ☞ ✄ ✁ ✡
☞ ✡

,

✆ ✁ ✝ ☞ ✄ ✂ ✄☎ ✆ ☎ ✝ ✞ ✡
  • ✝✟✞

Formal Definition of Computation – p.10/28

slide-28
SLIDE 28

Running

  • accepts

according to the formal definition of computation because the sequence of states it enters when computing on

is

✝ ✞ ✄ ✝ ☞ ✄ ✝ ☞ ✄ ✝✟✞ ✄ ✝ ✌ ✄ ✝ ☞ ✄ ✝✟✞ ✄ ✝✟✞ ✄ ✝ ☞ ✄ ✝✟✞

:

  • ✝✟✞

is the first state by definition

✁ ✝✟✞ ✄

,

✆ ✁ ✝ ☞ ✄ ✁ ✡
☞ ✡

,

✆ ✁ ✝ ☞ ✄ ✂ ✄☎ ✆ ☎ ✝ ✞ ✡
  • ✝✟✞
✁ ✝✟✞ ✄

,

✆ ✁ ✝ ✌ ✄

,

✆ ✁ ✝ ☞ ✄ ✂ ✄ ☎ ✆ ☎ ✝ ✞ ✡
  • ✝✟✞

Formal Definition of Computation – p.10/28

slide-29
SLIDE 29

Running

  • accepts

according to the formal definition of computation because the sequence of states it enters when computing on

is

✝ ✞ ✄ ✝ ☞ ✄ ✝ ☞ ✄ ✝✟✞ ✄ ✝ ✌ ✄ ✝ ☞ ✄ ✝✟✞ ✄ ✝✟✞ ✄ ✝ ☞ ✄ ✝✟✞

:

  • ✝✟✞

is the first state by definition

✁ ✝✟✞ ✄

,

✆ ✁ ✝ ☞ ✄ ✁ ✡
☞ ✡

,

✆ ✁ ✝ ☞ ✄ ✂ ✄☎ ✆ ☎ ✝ ✞ ✡
  • ✝✟✞
✁ ✝✟✞ ✄

,

✆ ✁ ✝ ✌ ✄

,

✆ ✁ ✝ ☞ ✄ ✂ ✄ ☎ ✆ ☎ ✝ ✞ ✡
  • ✝✟✞
✁ ✝ ✞ ✄ ✁ ✡

,

✆ ✁ ✝ ✞ ✄

,

✆ ✁ ✝ ☞ ✄

Formal Definition of Computation – p.10/28

slide-30
SLIDE 30

The language

☛ ✂

the sum of the symbols in

is 0 modulo 3, except that

✂ ✄ ☎ ✆ ☎ ✝ ✞

resets the count to 0

Since

  • is a finite automaton

is a regular language

Formal Definition of Computation – p.11/28

slide-31
SLIDE 31

Designing finite automata

  • Whether it be of automata or artwork, design is a

creative process

Formal Definition of Computation – p.12/28

slide-32
SLIDE 32

Designing finite automata

  • Whether it be of automata or artwork, design is a

creative process

  • Consequently it cannot be reduced to a simple recipe
  • r formula

Formal Definition of Computation – p.12/28

slide-33
SLIDE 33

Designing finite automata

  • Whether it be of automata or artwork, design is a

creative process

  • Consequently it cannot be reduced to a simple recipe
  • r formula
  • However, for a given design task one can find a

particular approach useful; here we consider a useful approach for designing various types of automata

Formal Definition of Computation – p.12/28

slide-34
SLIDE 34

The approach

Be yourself the machine you are trying to design!

Formal Definition of Computation – p.13/28

slide-35
SLIDE 35

The approach

Be yourself the machine you are trying to design!

  • As the machine you try to design, answer the question:

how would you go about performing the machine’s task?

Formal Definition of Computation – p.13/28

slide-36
SLIDE 36

The approach

Be yourself the machine you are trying to design!

  • As the machine you try to design, answer the question:

how would you go about performing the machine’s task?

  • Pretending that you are the machine is a psychological

trick that helps engage your whole mind in the design process

Formal Definition of Computation – p.13/28

slide-37
SLIDE 37

Using the approach

Suppose that you are given some language and want to design a finite automaton that recognizes it Remember: a language is a set of strings over a given al- phabet!

Formal Definition of Computation – p.14/28

slide-38
SLIDE 38

Pretending to be the automaton

  • Pretending that you are the automaton, you receive an

input string and must determine whether it belongs to the language

Formal Definition of Computation – p.15/28

slide-39
SLIDE 39

Pretending to be the automaton

  • Pretending that you are the automaton, you receive an

input string and must determine whether it belongs to the language

  • You got to see the symbols in the string one by one.

After each symbols you must decide whether the string seen so far is in the language.

Formal Definition of Computation – p.15/28

slide-40
SLIDE 40

Pretending to be the automaton

  • Pretending that you are the automaton, you receive an

input string and must determine whether it belongs to the language

  • You got to see the symbols in the string one by one.

After each symbols you must decide whether the string seen so far is in the language.

  • The reason is that you, like the machine, don’t know

when the end of the string is coming; so you must always be ready with the answer.

Formal Definition of Computation – p.15/28

slide-41
SLIDE 41

Making decisions

  • In order to make decisions, you have to figure out what

you need to remember about the input string as you are reading it

Formal Definition of Computation – p.16/28

slide-42
SLIDE 42

Making decisions

  • In order to make decisions, you have to figure out what

you need to remember about the input string as you are reading it

  • Bear in mind that as you are pretending to be a finite

automaton, you have a finite number of states and thus a finite memory, say a single sheet of paper

Formal Definition of Computation – p.16/28

slide-43
SLIDE 43

Making decisions

  • In order to make decisions, you have to figure out what

you need to remember about the input string as you are reading it

  • Bear in mind that as you are pretending to be a finite

automaton, you have a finite number of states and thus a finite memory, say a single sheet of paper

  • Fortunately, you don’t need to remember entire input,

you only need to remember certain crucial information

Formal Definition of Computation – p.16/28

slide-44
SLIDE 44

Note

Which information is crucial depends on the particular lan- guage considered

Formal Definition of Computation – p.17/28

slide-45
SLIDE 45

Example design

Suppose

✁ ✄

and the language consists of all strings with an odd number of 1s. You want to construct a finite automaton

☎ ☞

to recognize this language

Formal Definition of Computation – p.18/28

slide-46
SLIDE 46

Constructing the states

  • Start getting an input string of 0s and 1s symbol by

symbol

Formal Definition of Computation – p.19/28

slide-47
SLIDE 47

Constructing the states

  • Start getting an input string of 0s and 1s symbol by

symbol

  • Remember whether the number of 1s seen so far is

even or odd;

Formal Definition of Computation – p.19/28

slide-48
SLIDE 48

Constructing the states

  • Start getting an input string of 0s and 1s symbol by

symbol

  • Remember whether the number of 1s seen so far is

even or odd;

  • Represent the information you need as a finite list: (1)

even so far, (2) odd so far

Formal Definition of Computation – p.19/28

slide-49
SLIDE 49

Constructing the states

  • Start getting an input string of 0s and 1s symbol by

symbol

  • Remember whether the number of 1s seen so far is

even or odd;

  • Represent the information you need as a finite list: (1)

even so far, (2) odd so far

  • Assign a state to each possibility, Figure 2

Formal Definition of Computation – p.19/28

slide-50
SLIDE 50

Constructing transitions

To construct transitions you need to observe the way of going between possibilities while reading the input Example: the transition to flip state on a 1 and stay put on 0 is shown in Figure 3

✟✁ ✂
☎ ✞ ✆ ☞ ✟✞✝ ✟ ✟ ☎ ✞ ✠ ☞

Figure 3: Adding the start and accept state

Formal Definition of Computation – p.20/28

slide-51
SLIDE 51

Start state and final states

  • Set the start state to the state corresponding to the

possibility associated with having seen

symbols so far (i.e., the empty string

  • )

Formal Definition of Computation – p.21/28

slide-52
SLIDE 52

Start state and final states

  • Set the start state to the state corresponding to the

possibility associated with having seen

symbols so far (i.e., the empty string

  • )
  • In our example this correspond to
☎✁ ✂
  • Formal Definition of Computation – p.21/28
slide-53
SLIDE 53

Start state and final states

  • Set the start state to the state corresponding to the

possibility associated with having seen

symbols so far (i.e., the empty string

  • )
  • In our example this correspond to
☎✁ ✂
  • Set the accept states to be those corresponding to

possibilities where you want to accept the input

Formal Definition of Computation – p.21/28

slide-54
SLIDE 54

Start state and final states

  • Set the start state to the state corresponding to the

possibility associated with having seen

symbols so far (i.e., the empty string

  • )
  • In our example this correspond to
☎✁ ✂
  • Set the accept states to be those corresponding to

possibilities where you want to accept the input

  • In our example this is the set
✁ ✝✁ ✂ ✂ ✡

Formal Definition of Computation – p.21/28

slide-55
SLIDE 55

The result

The result of the example considered above is in Figure 4

☞ ✟
☎ ✞ ✆ ☞ ✟✞✝ ✟ ✟ ☎ ✞ ✠ ☞

Figure 4: Adding the start and accept state

Formal Definition of Computation – p.22/28

slide-56
SLIDE 56

Example 1.9

This example shows how to design a finite automaton

☎ ✌

to recognize the regular language of all strings over the alphabet

✁ ✄

that contain the string

✁ ✁
  • as a

substring

Example:

  • strings 0010, 1001, 001, 11111110011111 are in

that language

Formal Definition of Computation – p.23/28

slide-57
SLIDE 57

Pretending to be

  • As symbols come in, you would initially skip over all 1s

Formal Definition of Computation – p.24/28

slide-58
SLIDE 58

Pretending to be

  • As symbols come in, you would initially skip over all 1s
  • If you come to a

, you note that you may have just seen the first of the three symbols in the pattern

✁ ✁
  • Formal Definition of Computation – p.24/28
slide-59
SLIDE 59

Pretending to be

  • As symbols come in, you would initially skip over all 1s
  • If you come to a

, you note that you may have just seen the first of the three symbols in the pattern

✁ ✁
  • If after the first 0 you see a 1, then there were too few

0s so you back to skipping over 1s

Formal Definition of Computation – p.24/28

slide-60
SLIDE 60

Pretending to be

  • As symbols come in, you would initially skip over all 1s
  • If you come to a

, you note that you may have just seen the first of the three symbols in the pattern

✁ ✁
  • If after the first 0 you see a 1, then there were too few

0s so you back to skipping over 1s

  • If after the first 0 you see another 0 then you should

remember that you have seen two symbols of the pattern

Formal Definition of Computation – p.24/28

slide-61
SLIDE 61

Pretending to be

  • As symbols come in, you would initially skip over all 1s
  • If you come to a

, you note that you may have just seen the first of the three symbols in the pattern

✁ ✁
  • If after the first 0 you see a 1, then there were too few

0s so you back to skipping over 1s

  • If after the first 0 you see another 0 then you should

remember that you have seen two symbols of the pattern

  • Once you have seen two symbols of the pattern you

need to scan the input until you see a 1; if you find it, remember that you succeeded to find the pattern and continue skipping all symbols to the end

Formal Definition of Computation – p.24/28

slide-62
SLIDE 62

The list of possibilities

  • 1. Haven’t see any symbol of the pattern
  • 2. Have just seen a 0
  • 3. Have just seen 00
  • 4. Have seen the entire pattern 001

Formal Definition of Computation – p.25/28

slide-63
SLIDE 63

Designing states and transitions

  • Assign the states
✝ ✄ ✝ ✞ ✄ ✝✟✞ ✞ ✄ ✝✟✞ ✞ ☞

to the four possibilities

Formal Definition of Computation – p.26/28

slide-64
SLIDE 64

Designing states and transitions

  • Assign the states
✝ ✄ ✝ ✞ ✄ ✝✟✞ ✞ ✄ ✝✟✞ ✞ ☞

to the four possibilities

  • In state

: while reading 1 remain in

, but reading 0 you move to

✝ ✞

Formal Definition of Computation – p.26/28

slide-65
SLIDE 65

Designing states and transitions

  • Assign the states
✝ ✄ ✝ ✞ ✄ ✝✟✞ ✞ ✄ ✝✟✞ ✞ ☞

to the four possibilities

  • In state

: while reading 1 remain in

, but reading 0 you move to

✝ ✞
  • In state
✝ ✞

: reading 0 you transit to

✝ ✞ ✞

but reading 1 you transit to

Formal Definition of Computation – p.26/28

slide-66
SLIDE 66

Designing states and transitions

  • Assign the states
✝ ✄ ✝ ✞ ✄ ✝✟✞ ✞ ✄ ✝✟✞ ✞ ☞

to the four possibilities

  • In state

: while reading 1 remain in

, but reading 0 you move to

✝ ✞
  • In state
✝ ✞

: reading 0 you transit to

✝ ✞ ✞

but reading 1 you transit to

  • In state
✝ ✞ ✞

: reading 1 you move to

✝ ✞ ✞ ☞

while reading 0 you remain in state

✝ ✞ ✞

Formal Definition of Computation – p.26/28

slide-67
SLIDE 67

Designing states and transitions

  • Assign the states
✝ ✄ ✝ ✞ ✄ ✝✟✞ ✞ ✄ ✝✟✞ ✞ ☞

to the four possibilities

  • In state

: while reading 1 remain in

, but reading 0 you move to

✝ ✞
  • In state
✝ ✞

: reading 0 you transit to

✝ ✞ ✞

but reading 1 you transit to

  • In state
✝ ✞ ✞

: reading 1 you move to

✝ ✞ ✞ ☞

while reading 0 you remain in state

✝ ✞ ✞
  • In state
✝ ✞ ✞ ☞

: whatever you read remain in

✝ ✞ ✞ ☞

.

Formal Definition of Computation – p.26/28

slide-68
SLIDE 68

Start and final states

  • Start state is

The result is in Figure 5

☞ ✟ ☎ ☞ ✆ ✞ ✟ ☛ ✠ ☞ ☞ ✟ ☛ ☛ ☎ ✞ ☞ ☞ ✟ ☛ ☛ ✠ ☎ ✞✎✍ ☞

Figure 5: Accepting strings containing 001

Formal Definition of Computation – p.27/28

slide-69
SLIDE 69

Another example

Design a DFA that recognizes the languages:

☛ ✂ ☛

begins with 1 and ends with 0

☛ ✂ ☛

is any string except a and b

Formal Definition of Computation – p.28/28