Вы находитесь на странице: 1из 7

A function

Domain:

Computing Functions
with
Turing Machines

f (w)

has:
Result Region:

D
f (w)

w D

f ( w) S

A function may have many parameters:


Example:

Integer Domain

Addition function

f ( x, y ) = x + y

Decimal:

Binary:

101

Unary:

11111

We prefer unary representation:


easier to manipulate with Turing machines
3

Definition:

In other words:

A function
f
is computable if
there is a Turing Machine M such that:

A function
f
is computable if
there is a Turing Machine M such that:

Initial configuration

q0 initial state
For all

w D

q0 w q f f ( w)

Final configuration

f (w)
q f final state

Domain

Initial
Configuration

For all

Final
Configuration

w D

Domain

1
PDF created with pdfFactory Pro trial version www.pdffactory.com

Example
The function

f ( x, y ) = x + y
x, y

is computable

Start

1 1

are integers

1 0 1

q0
initial state

Turing Machine:
Input string:

x0 y

unary

Output string:

xy0

unary

The 0 is the delimiter that


separates the two numbers
7

x
Start

1 1

1 0 1

The 0 helps when we use


the result for other operations

q0 initial state

x+ y
Finish

1 1

x+ y

q f final state

Turing machine for function

1 1, R

Finish

1 1 0

1 1

1 1, R

10

Execution Example:

x = 11

(2)

y = 11

(2)

1 1, L

Time 0

1 1 0 1 1

q0
Final Result

q0 0 1, R q1 , L q2 1 0, L q3

x+ y

, R
q4

1 1 0

q f final state

f ( x, y ) = x + y

11

1 1 1 1 0

q4

12

2
PDF created with pdfFactory Pro trial version www.pdffactory.com

Time 0

1 1 0 1 1

Time 1

1 1 0 1 1

q0

q0
1 1, R

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R
q4

Time 2

, R
q4

13

1 1 0 1 1

Time 3

1 1 1 1 1

q0
1 1, R

q1

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R
q4

Time 4

, R
q4

15

1 1 1 1 1

Time 5

16

1 1 1 1 1

q1
1 1, R

14

q1

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R
q4

17

, R
q4

18

3
PDF created with pdfFactory Pro trial version www.pdffactory.com

Time 6

1 1 1 1 1

Time 7

1 1 1 1 0

q3

q2
1 1, R

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R
q4

Time 8

, R
q4

19

1 1 1 1 0

Time 9

1 1 1 1 0

q3
1 1, R

q3

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R
q4

Time 10

, R
q4

21

1 1 1 1 0

Time 11

q3
1 1, R

20

22

1 1 1 1 0

q3

1 1, R

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

1 1, R

1 1, L

q0 0 1, R q1 , L q2 1 0, L q3

, R
q4

23

, R
q4

24

4
PDF created with pdfFactory Pro trial version www.pdffactory.com

Another Example

1 1 1 1 0

Time 12

f ( x) = 2 x

The function

q4
1 1, R

1 1, R

1 1, L

Turing Machine:
Input string:

, R

HALT & accept

q4

Output string:

unary

xx

unary

25

x
1 1

is integer

q0 0 1, R q1 , L q2 1 0, L q3

Start

is computable

26

f ( x) = 2 x

Turing Machine Pseudocode for

Replace every 1 with $

q0 initial state

Repeat:
Find rightmost $, replace it with 1

2x
Finish

Go to right end, insert 1

1 1

1 1 1

q f final state

Turing Machine for

Until no more $ remain


27

28

Start

f ( x) = 2 x

Example

1 1

1 1 1 1

q0
1 $, R

1 1, L

1 1, R

q0 , L q1 $ 1, R
, R
q3

q3

1 $, R

q2

Finish

1 1, L

1 1, R

q0 , L q1 $ 1, R

1, L
29

, R
q3

q2

1, L
30

5
PDF created with pdfFactory Pro trial version www.pdffactory.com

Another Example

f ( x, y ) =

The function
is computable

Turing Machine for

if

if

x>y

f ( x, y ) =

x y
Input:
Output:

if

x>y

if

x y

x0 y
1

or

31

32

Turing Machine Pseudocode:


Repeat
Match a 1 from
Until all of

x with a 1 from y

Combining Turing Machines

x or y is matched

If a 1 from x is not matched


erase tape, write 1
else
erase tape, write 0

( x > y)
( x y)

33

34

Example:

f ( x, y ) =

Block Diagram

input

Turing
Machine

x + y if x > y

x, y
output

x, y

Comparer

Adder

x+ y

Eraser

x> y
x y

35

if x y

36

6
PDF created with pdfFactory Pro trial version www.pdffactory.com

Question: Do Turing machines have


the same power with
a digital computer?

Turings Thesis
Intuitive answer: Yes

There is no formal answer!!!

37

38

Computer Science Law:

Turings thesis:
Any computation carried out
by mechanical means
can be performed by a Turing Machine

A computation is mechanical
if and only if
it can be performed by a Turing Machine

There is no known model of computation


more powerful than Turing Machines

(1930)
39

Definition of Algorithm:

40

Algorithms are Turing Machines

An algorithm for function f (w)


is a
Turing Machine which computes f (w)

When we say:
There exists an algorithm
We mean:
There exists a Turing Machine
that executes the algorithm
41

42

7
PDF created with pdfFactory Pro trial version www.pdffactory.com

Вам также может понравиться