Top Banner
1 Introduction to Turing Machines 0 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 0 0 0 1 0
102

1 Introduction to Turing Machines 011011111101101100010.

Mar 28, 2015

Download

Documents

Miguel Holt
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Introduction to Turing Machines 011011111101101100010.

1

Introduction toTuring Machines

0 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 0 0 010

Page 2: 1 Introduction to Turing Machines 011011111101101100010.

Alan Turing -- 1912 – 1954 • Mathematician, a computer scientis

• Influantial • Development of computer sciences• provided an influential formalisation

• of the concept of the algorithm • and computation with the• Turing Machine • Turing Test contribute to the debate of AI

• Can machines think?

• One of the 100 more imp. People in 20th century• 21st on BBC nation wide poll of the 100 Greatest britons• http://www.turing.org.uk/turing/• http://en.wikipedia.org/wiki/Alan_Turing/

2

Page 3: 1 Introduction to Turing Machines 011011111101101100010.

3

The Turing Machine

0 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 0 0 0101

A TM consists of an infinite length tape, on which input is provided as a finite sequence of symbols.

A head reads the input tape. The TM starts at start state s0. On reading an input symbol it optionally replaces it with another symbol, changes its internal state and moves one cell to the right or left.

Page 4: 1 Introduction to Turing Machines 011011111101101100010.

4

The Turing Machine

A TM is defined as: TM = <S, T, s0, , H> where,

S is a set of TM states T is a set of tape symbols s0 is the start state H S is a set of halting states : S x T S x T x {L,R}

is the transition function

Page 5: 1 Introduction to Turing Machines 011011111101101100010.

5

A Turing Machine

............Tape

Read-Write head

Control Unit

Page 6: 1 Introduction to Turing Machines 011011111101101100010.

6

The Tape

............

Read-Write head

No boundaries -- infinite length

The head moves Left or Right

Page 7: 1 Introduction to Turing Machines 011011111101101100010.

7

............

Read-Write head

The head at each time step:

1. Reads a symbol 2. Writes a symbol 3. Moves Left or Right

Page 8: 1 Introduction to Turing Machines 011011111101101100010.

8

............

Example:Time 0

Time 1

1. Reads

2. Writes

a a cb

a

3. Moves Left

............ a b cd

d

Page 9: 1 Introduction to Turing Machines 011011111101101100010.

9

............Time 1

a c

............Time 2

a c

1. Reads

2. Writes

3. Moves Right

b

s

s

b

f

f

Page 10: 1 Introduction to Turing Machines 011011111101101100010.

10

The Input String

............

Blank symbol

head

a b ca

•Head starts at the leftmost position of the input string.•The input string is never empty

Input string

# # # # #

Page 11: 1 Introduction to Turing Machines 011011111101101100010.

11

States & Transitions

1q 2qLba ,

Read Write Move Left

1q 2qRba ,

Move Right

Page 12: 1 Introduction to Turing Machines 011011111101101100010.

12

............ a b cTime 1

1q 2q

............ a b cTime 2

1q

2q

Example:

current state

a

d

Rda ,

Page 13: 1 Introduction to Turing Machines 011011111101101100010.

13

............ a b cTime 1

1q 2qLba ,

............ a b cTime 2

1q

2q

Example:

a

b

Page 14: 1 Introduction to Turing Machines 011011111101101100010.

14

............ a b caTime 1

1q 2q

............ ga b cbTime 2

1q

2q

Example:

Lg,

# # # #

# # #

Page 15: 1 Introduction to Turing Machines 011011111101101100010.

15

Determinism

1q

2qRba ,

Allowed Not Allowed

3qLdb ,

1q

2qRba ,

3qLda ,

No lambda transitions allowed

Turing Machines are deterministic

Page 16: 1 Introduction to Turing Machines 011011111101101100010.

16

Partial Transition Function

1q

2qRba ,

3qLdb ,

Example:

No transitionfor input symbol c

Allowed:

# #

1q

............ a b ca # # #

Page 17: 1 Introduction to Turing Machines 011011111101101100010.

17

Halting

The machine halts if there areno possible transitions to follow

# #

1q

............ a b c # # #

1q

2qRba ,

3qLdb ,

c

No possible transition

HALT!!!

Page 18: 1 Introduction to Turing Machines 011011111101101100010.

18

Final States

1q 2q Allowed

1q 2q Not Allowed

• Final states have no outgoing transitions• In a final state the machine halts

Page 19: 1 Introduction to Turing Machines 011011111101101100010.

19

Acceptance

Accept Input If machine halts in a final state

Reject Input

If machine halts in a non-final state or If machine enters an infinite loop

Page 20: 1 Introduction to Turing Machines 011011111101101100010.

20

Turing Machine Example

A Turing machine that accepts the language:

*aa

0q

Raa ,

L,1q

Page 21: 1 Introduction to Turing Machines 011011111101101100010.

21

aaTime 0

0q

a

0q

Raa ,

L,1q

Page 22: 1 Introduction to Turing Machines 011011111101101100010.

22

aaTime 1

0q

a

0q

Raa ,

L,1q

Page 23: 1 Introduction to Turing Machines 011011111101101100010.

23

aaTime 2

0q

a

0q

Raa ,

L,1q

Page 24: 1 Introduction to Turing Machines 011011111101101100010.

24

aaTime 3

0q

a

0q

Raa ,

L,1q

Page 25: 1 Introduction to Turing Machines 011011111101101100010.

25

aaTime 4

1q

a

0q

Raa ,

L,1q

Halt & Accept

Page 26: 1 Introduction to Turing Machines 011011111101101100010.

26

Rejection Example

0q

Raa ,

L,1q

baTime 0

0q

a

Page 27: 1 Introduction to Turing Machines 011011111101101100010.

27

0q

Raa ,

L,1q

baTime 1

0q

a

No possible Transition

Halt & Reject

Page 28: 1 Introduction to Turing Machines 011011111101101100010.

28

Infinite Loop Example

0q

Raa ,

L,1q

Lbb ,

A Turing machine for language *)(* babaa

Page 29: 1 Introduction to Turing Machines 011011111101101100010.

29

baTime 0

0q

a

0q

Raa ,

L,1q

Lbb ,

Page 30: 1 Introduction to Turing Machines 011011111101101100010.

30

baTime 1

0q

a

0q

Raa ,

L,1q

Lbb ,

Page 31: 1 Introduction to Turing Machines 011011111101101100010.

31

baTime 2

0q

a

0q

Raa ,

L,1q

Lbb ,

Page 32: 1 Introduction to Turing Machines 011011111101101100010.

32

baTime 2

0q

a

baTime 3

0q

a

baTime 4

0q

a

baTime 5

0q

a

Infinite

loop

Page 33: 1 Introduction to Turing Machines 011011111101101100010.

33

Because of the infinite loop:

•The final state cannot be reached

•The machine never halts

•The input is not accepted

Page 34: 1 Introduction to Turing Machines 011011111101101100010.

34

Another Turing Machine Example

Turing machine for the language }{ nnba

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

Page 35: 1 Introduction to Turing Machines 011011111101101100010.

35

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

ba

0q

a bTime 0

Page 36: 1 Introduction to Turing Machines 011011111101101100010.

36

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

bx

1q

a b Time 1

Page 37: 1 Introduction to Turing Machines 011011111101101100010.

37

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

bx

1q

a b Time 2

Page 38: 1 Introduction to Turing Machines 011011111101101100010.

38

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

2q

a b Time 3

Page 39: 1 Introduction to Turing Machines 011011111101101100010.

39

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

2q

a b Time 4

Page 40: 1 Introduction to Turing Machines 011011111101101100010.

40

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

0q

a b Time 5

Page 41: 1 Introduction to Turing Machines 011011111101101100010.

41

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

1q

x b Time 6

Page 42: 1 Introduction to Turing Machines 011011111101101100010.

42

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

1q

x b Time 7

Page 43: 1 Introduction to Turing Machines 011011111101101100010.

43

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx x y

2q

Time 8

Page 44: 1 Introduction to Turing Machines 011011111101101100010.

44

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx x y

2q

Time 9

Page 45: 1 Introduction to Turing Machines 011011111101101100010.

45

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

0q

x y Time 10

Page 46: 1 Introduction to Turing Machines 011011111101101100010.

46

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

3q

x y Time 11

Page 47: 1 Introduction to Turing Machines 011011111101101100010.

47

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

3q

x y Time 12

Page 48: 1 Introduction to Turing Machines 011011111101101100010.

48

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

4q

x y

Halt & Accept

Time 13

Page 49: 1 Introduction to Turing Machines 011011111101101100010.

49

If we modify the machine for the language }{ nnba

we can easily construct a machine for the language }{ nnn cba

Observation:

Page 50: 1 Introduction to Turing Machines 011011111101101100010.

50

Formal Definitionsfor

Turing Machines

Page 51: 1 Introduction to Turing Machines 011011111101101100010.

51

Transition Function

1q 2qRba ,

),,(),( 21 Rbqaq

Page 52: 1 Introduction to Turing Machines 011011111101101100010.

52

1q 2qLdc ,

),,(),( 21 Ldqcq

Transition Function

Page 53: 1 Introduction to Turing Machines 011011111101101100010.

53

Turing Machine:

),,,,,,( 0 FqQM

States

Inputalphabet

Tapealphabet

Transitionfunction

Initialstate

blank

Finalstates

Page 54: 1 Introduction to Turing Machines 011011111101101100010.

54

Configuration

ba

1q

a

Instantaneous description:

c

baqca 1

Page 55: 1 Introduction to Turing Machines 011011111101101100010.

55

yx

2q

a b

Time 4

yx

0q

a b

Time 5

A Move: aybqxxaybq 02

Page 56: 1 Introduction to Turing Machines 011011111101101100010.

56

yx

2q

a b

Time 4

yx

0q

a b

Time 5

bqxxyybqxxaybqxxaybq 1102

yx

1q

x b

Time 6

yx

1q

x b

Time 7

Page 57: 1 Introduction to Turing Machines 011011111101101100010.

57

bqxxyybqxxaybqxxaybq 1102

bqxxyxaybq 12

Equivalent notation:

Page 58: 1 Introduction to Turing Machines 011011111101101100010.

58

Initial configuration: wq0

ba

0q

a b

w

Input string

Page 59: 1 Introduction to Turing Machines 011011111101101100010.

59

The Accepted Language

For any Turing Machine M

}:{)( 210 xqxwqwML f

Initial state Final state

Page 60: 1 Introduction to Turing Machines 011011111101101100010.

60

Standard Turing Machine

• Deterministic

• Infinite tape in both directions

•Tape is the input/output file

The machine we described is the standard:

Page 61: 1 Introduction to Turing Machines 011011111101101100010.

61

Computing Functionswith

Turing Machines

Page 62: 1 Introduction to Turing Machines 011011111101101100010.

62

A function )(wf

Domain: Result Region:

has:

D

Dw

S

Swf )()(wf

Page 63: 1 Introduction to Turing Machines 011011111101101100010.

63

A function may have many parameters:

yxyxf ),(

Example: Addition function

Page 64: 1 Introduction to Turing Machines 011011111101101100010.

64

Integer Domain

Unary:

Binary:

Decimal:

11111

101

5

We prefer unary representation:

easier to manipulate with Turing machines

Page 65: 1 Introduction to Turing Machines 011011111101101100010.

65

Definition:

A function is computable ifthere is a Turing Machine such that:

fM

Initial configuration Final configuration

Dw Domain

0q

w

fq

)(wf

final stateinitial state

For all

Page 66: 1 Introduction to Turing Machines 011011111101101100010.

66

)(0 wfqwq f

Initial Configuration

FinalConfiguration

A function is computable ifthere is a Turing Machine such that:

fM

In other words:

Dw DomainFor all

Page 67: 1 Introduction to Turing Machines 011011111101101100010.

67

Example

The function yxyxf ),( is computable

Turing Machine:

Input string: yx0 unary

Output string: 0xy unary

yx, are integers

Page 68: 1 Introduction to Turing Machines 011011111101101100010.

68

0

0q

1 1 1 1

x y

1 Start

initial state

The 0 is the delimiter that separates the two numbers

Page 69: 1 Introduction to Turing Machines 011011111101101100010.

69

0

0q

1 1 1 1

x y

1

0

fq

1 1

yx

11

Start

Finish

final state

initial state

Page 70: 1 Introduction to Turing Machines 011011111101101100010.

70

0

fq

1 1

yx

11Finish

final state

The 0 helps when we usethe result for other operations

Page 71: 1 Introduction to Turing Machines 011011111101101100010.

71

0q

Turing machine for function

1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

yxyxf ),(

Page 72: 1 Introduction to Turing Machines 011011111101101100010.

72

Execution Example:

11x

11y 0

0q

1 1 1 1

Time 0

x y

Final Result

0

4q

1 1 1 1

yx

(2)

(2)

Page 73: 1 Introduction to Turing Machines 011011111101101100010.

73

0

0q

1 1Time 0

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

1 1

Page 74: 1 Introduction to Turing Machines 011011111101101100010.

74

0q

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

01 11 1Time 1

Page 75: 1 Introduction to Turing Machines 011011111101101100010.

75

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

0

0q

1 1 1 1Time 2

Page 76: 1 Introduction to Turing Machines 011011111101101100010.

76

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

1q

1 11 11Time 3

Page 77: 1 Introduction to Turing Machines 011011111101101100010.

77

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

1q

1 1 1 11Time 4

Page 78: 1 Introduction to Turing Machines 011011111101101100010.

78

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

1q

1 11 11Time 5

Page 79: 1 Introduction to Turing Machines 011011111101101100010.

79

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

2q

1 1 1 11Time 6

Page 80: 1 Introduction to Turing Machines 011011111101101100010.

80

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

3q

1 11 01Time 7

Page 81: 1 Introduction to Turing Machines 011011111101101100010.

81

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

3q

1 1 1 01Time 8

Page 82: 1 Introduction to Turing Machines 011011111101101100010.

82

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

3q

1 11 01Time 9

Page 83: 1 Introduction to Turing Machines 011011111101101100010.

83

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

3q

1 1 1 01Time 10

Page 84: 1 Introduction to Turing Machines 011011111101101100010.

84

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

3q

1 11 01Time 11

Page 85: 1 Introduction to Turing Machines 011011111101101100010.

85

0q 1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

4q

1 1 1 01

HALT & accept

Time 12

Page 86: 1 Introduction to Turing Machines 011011111101101100010.

86

Another Example

The function xxf 2)( is computable

Turing Machine:

Input string: x unary

Output string: xx unary

x is integer

Page 87: 1 Introduction to Turing Machines 011011111101101100010.

87

0q

1 1

x

1

1

fq

1 1

x2

11

Start

Finish

final state

initial state

Page 88: 1 Introduction to Turing Machines 011011111101101100010.

88

Turing Machine Pseudocode for xxf 2)(

• Replace every 1 with $

• Repeat:

• Find rightmost $, replace it with 1

• Go to right end, insert 1

Until no more $ remain

Page 89: 1 Introduction to Turing Machines 011011111101101100010.

89

0q 1q 2q

3q

R,1$

L,1

L,

R$,1 L,11 R,11

R,

Turing Machine for xxf 2)(

Page 90: 1 Introduction to Turing Machines 011011111101101100010.

90

0q 1q 2q

3q

R,1$

L,1

L,

R$,1 L,11 R,11

R,

Example

0q

1 1

3q

1 11 1

Start Finish

Page 91: 1 Introduction to Turing Machines 011011111101101100010.

91

Simple TM Examples

Turing Machine U+1:

Given a string of 1s on a tape (followed by an infinite number of 0s), add one more 1 at the end of the string.

#111100000000……. #1111100000000……….

Page 92: 1 Introduction to Turing Machines 011011111101101100010.

92

Simple TM Examples

TM: U+1(s0, 1) |-- (s0, 1, R) (s0, 0) |-- (h, 1, STOP)

#s0111100000….. #1s011100000….. #11s01100000….. #111s0100000….. #1111s000000….. #11111h0000….. STOP

Page 93: 1 Introduction to Turing Machines 011011111101101100010.

93

Another Example

The function ),( yxf

is computable0

1 yx

yx

if

if

Page 94: 1 Introduction to Turing Machines 011011111101101100010.

94

Turing Machine for

Input: yx0

Output: 1 0or

),( yxf0

1 yx

yx

if

if

Page 95: 1 Introduction to Turing Machines 011011111101101100010.

95

Turing Machine Pseudocode:

Match a 1 from with a 1 from x y

• Repeat

Until all of or is matchedx y

• If a 1 from is not matched erase tape, write 1 else erase tape, write 0

x)( yx

)( yx

Page 96: 1 Introduction to Turing Machines 011011111101101100010.

96

Combining Turing Machines

Page 97: 1 Introduction to Turing Machines 011011111101101100010.

97

Block Diagram

TuringMachine

input output

Page 98: 1 Introduction to Turing Machines 011011111101101100010.

98

Example:

),( yxf0

yx yx

yx

if

if

Comparer

Adder

Eraser

yx,

yx,

yx

yx

yx

0

Page 99: 1 Introduction to Turing Machines 011011111101101100010.

99

Turing’s Thesis

Any mathematical problem solving that can be described by a mechanical procedure (algorithm) can be modeled by a Turing machine.

All computers today perform only mechanical problem solving. They are no more expressive than a Turing machine.

Page 100: 1 Introduction to Turing Machines 011011111101101100010.

100

Turing’s ThesisTuring’s thesis is not a “theorem” there is no

“proof” for the thesis.The theorem may be refuted by showing at

least one task that is performed by a digital computer which cannot be performed by a Turing machine.

Many contentions have been made to this end. However, till date there have not been any conclusive evidence to refute Turing’s thesis.

Page 101: 1 Introduction to Turing Machines 011011111101101100010.

101

ConclusionsTMs are at a level that is much below the

assembly language of any typical microprocessor.

So in the practical world, TMs are more useful in what they cannot do rather than in what they can.

Page 102: 1 Introduction to Turing Machines 011011111101101100010.

Lab2Write some simpleTuring machine

programs

QUESTIONS?

102