Transcript
Page 1: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

1

Turing Machines (13.5) Longin Jan LateckiTemple University

Based on slides by Costas Busch from the coursehttp://www.cs.rpi.edu/courses/spring05/modcomp/and …

Page 2: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

2

DFA - regular languages

Push down automata - Context-free

Bounded Turing M’s - Context sensitive

Turing machines - Phrase-structure

Models of computing

Page 3: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

3

Foundations

The theory of computation and the practical application it made possible — the computer — was developed by an Englishman called Alan Turing.

Page 4: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

4

Alan Turing1912 (23 June): Birth, Paddington, London

1931-34: Undergraduate at King's College, Cambridge University

1932-35: Quantum mechanics, probability, logic

1936: The Turing machine, computability, universal machine

1936-38: Princeton University. Ph.D. Logic, algebra, number theory

1938-39: Return to Cambridge. Introduced to German Enigma cipher machine

1939-40: The Bombe, machine for Enigma decryption

1939-42: Breaking of U-boat Enigma, saving battle of the Atlantic

1946: Computer and software design leading the world.

1948: Manchester University

1949: First serious mathematical use of a computer

1950: The Turing Test for machine intelligence

1952: Arrested as a homosexual, loss of security clearance

1954 (7 June): Death (suicide) by cyanide poisoning, Wilmslow, Cheshire.

—from Andrew Hodges

http://www.turing.org.uk/turing/

Page 5: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

5

The Decision Problem

In 1928 the German mathematician, David Hilbert (1862-1943), asked whether there could be a mechanical way (i.e. by means of a fully specifiable set of instructions) of determining whether some statement in a formal system like arithmetic was provable or not.In 1936 Turing published a paper the aim of which was to show that there was no such method. “On computable numbers, with an application to the Entscheidungs problem.” Proceedings of the London Mathematical Society, 2(42):230-265).

Page 6: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

6

The Turing Machine

In order to argue for this claim, he needed a clear concept of “mechanical procedure.”His idea — which came to be called the Turing machine — was this:

(1) A tape of infinite length

(2) Finitely many squares of the tape have a single symbol from a finite language.

(3) Someone (or something) that can read the squares and write in them.

(4) At any time, the machine is in one of a finite number of internal states.

(5) The machine has instructions that determine what it does given its internal state and the symbol it encounters on the tape. It can

change its internal state;

change the symbol on the square;

move forward;

move backward;

halt (i.e. stop).

Page 7: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

7

0

1

1

1

1

Current state = 1

If current state = 1and current symbol = 0then new state = 10new symbol = 1move right

0

Page 8: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

8

1

1

1

1

1

Current state = 10

If current state = 1and current symbol = 0then new state = 10new symbol = 1move right

Page 9: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

9

1

1

1

1

1

Current state = 10

If current state = 1and current symbol = 0then new state = 10new symbol = 1move right

Page 10: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

10

FunctionsIt is essential to the idea of a Turing machine that it is not a physical machine, but an abstract one — a set of procedures.

It makes no difference whether the machine is embodied by a person in a boxcar on a track, or a person with a paper and pencil, or a smart and well-trained flamingo.

Page 11: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

11

Turing’s TheoremIn the 1936 paper Turing proved that there are “general-purpose” Turing machines that can compute whatever any other Turing machine.

This is done by coding the function of the special-purpose machine as instructions of the other machine — that is by “programming” it. This is called Turing’s theorem.

These are universal Turing machines, and the idea of a coding for a particular function fed into a universal Turing machine is basically our conception of a computer and a stored program.

The concept of the universal Turing machine is just the concept of the computer as we know it.

Page 12: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

12

First computers: custom computing machines

1950 -- Eniac: the control is hardwired manually foreach problem.

Control

Input tape (read only)

Output tape (write only)

Work tape (memory)

1940: VON NEUMANN: DISTINCTION BETWEEN DATA AND INSTRUCTIONS

Page 13: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

13

Can Machines Think?In “Computing machinery and intelligence,” written in 1950, Turing asks whether machines can think.He claims that this question is too vague, and proposes, instead, to replace it with a different one.That question is: Can machines pass the “imitation game” (now called the Turing test)? If they can, they are intelligent. Turing is thus the first to have offered a rigorous test for the determination of intelligence quite generally.

Page 14: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

14

The Turing TestThe game runs as follows. You sit at a computer terminal and have an electronic conversation. You don’t know who is on the other end; it could be a person or a computer responding as it has been programmed to do.

If you can’t distinguish between a human being and a computer from your interactions, then the computer is intelligent.

Note that this is meant to be a sufficient condition of intelligence only. There may be other ways to be intelligent.

Page 15: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

15

Artificial Intelligence

Page 16: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

16

The Church-Turning Thesis

Turing, and a logician called Alonzo Church (1903-1995), independently developed the idea (not yet proven by widely accepted) that whatever can be computed by a mechanical procedure can be computed by a Turing machine.This is known as the Church-Turing thesis.

Page 17: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

17

AI: The ArgumentWe’ve now got the materials to show that AI is possible:

P1: Any function that can be computed by a mechanical procedure can be computed by a Turing machine. (Church-Turing thesis)

P2: Thinking is nothing more than the computing of functions by mechanical procedures (i.e., thinking is symbol manipulation). (Functionalist-Computationalist thesis)

C1: Therefore, thinking can be performed by a Turing machine.

P3: Turing machines are multiply realizable. In particular, they can be realized by computers, robots, etc.

It is possible to build a computer, robot, etc. that can think. That is, AI is possible.

Page 18: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

18

Turing Machines

Page 19: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

19

The Language Hierarchy

*aRegular Languages

Context-Free Languagesnnba Rww

nnn cba ww?

**ba

?

Page 20: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

20

*aRegular Languages

Context-Free Languagesnnba Rww

nnn cba ww

**ba

Languages accepted byTuring Machines

Page 21: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

21

A Turing Machine

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

Read-Write head

Control Unit

Page 22: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

22

The Tape

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

Read-Write head

No boundaries -- infinite length

The head moves Left or Right

Page 23: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

23

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

Read-Write head

The head at each time step:

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

Page 24: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

24

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

Example:Time 0

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

1. Reads

2. Writes

a a cb

a b k c

a

k3. Moves Left

Page 25: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

25

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

a b k c

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

a k cf

1. Reads

2. Writes

bf

3. Moves Right

Page 26: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

26

The Input String

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

Blank symbol

head

a b ca

Head starts at the leftmost positionof the input string

Input string

Page 27: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

27

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

Blank symbol

head

a b ca

Input string

Remark: the input string is never empty

Page 28: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

28

States & Transitions

1q 2qLba ,

Read Write Move Left

1q 2qRba ,

Move Right

Page 29: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

29

Example:

1q 2qRba ,

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

Time 1

1qcurrent state

Page 30: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

30

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

1q 2qRba ,

............ a b cbTime 2

1q

2q

Page 31: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

31

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

1q 2qLba ,

............ a b cbTime 2

1q

2q

Example:

Page 32: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

32

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

1q 2qRg,

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

1q

2q

Example:

Page 33: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

33

Determinism

1q

2qRba ,

Allowed Not Allowed

3qLdb ,

1q

2qRba ,

3qLda ,

No lambda transitions allowed

Turing Machines are deterministic

Page 34: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

34

Partial Transition Function

1q

2qRba ,

3qLdb ,

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

1q

Example:

No transitionfor input symbol c

Allowed:

Page 35: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

35

Halting

The machine halts if there areno possible transitions to follow

Page 36: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

36

Example:

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

1q

1q

2qRba ,

3qLdb ,

No possible transition

HALT!!!

Page 37: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

37

Final States

1q 2q Allowed

1q 2q Not Allowed

• Final states have no outgoing transitions

• In a final state the machine halts

Page 38: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

38

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 39: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

39

Turing Machine Example

A Turing machine that accepts the language:

*aa

0q

Raa ,

L,1q

Page 40: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

40

aaTime 0

0q

a

0q

Raa ,

L,1q

Page 41: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

41

aaTime 1

0q

a

0q

Raa ,

L,1q

Page 42: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

42

aaTime 2

0q

a

0q

Raa ,

L,1q

Page 43: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

43

aaTime 3

0q

a

0q

Raa ,

L,1q

Page 44: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

44

aaTime 4

1q

a

0q

Raa ,

L,1q

Halt & Accept

Page 45: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

45

Rejection Example

0q

Raa ,

L,1q

baTime 0

0q

a

Page 46: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

46

0q

Raa ,

L,1q

baTime 1

0q

a

No possible Transition

Halt & Reject

Page 47: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

47

Infinite Loop Example

0q

Raa ,

L,1q

Lbb ,

A Turing machine for language *)(* babaa

Page 48: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

48

baTime 0

0q

a

0q

Raa ,

L,1q

Lbb ,

Page 49: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

49

baTime 1

0q

a

0q

Raa ,

L,1q

Lbb ,

Page 50: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

50

baTime 2

0q

a

0q

Raa ,

L,1q

Lbb ,

Page 51: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

51

baTime 2

0q

a

baTime 3

0q

a

baTime 4

0q

a

baTime 5

0q

a

Infinite

loop

Page 52: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

52

Because of the infinite loop:

•The final state cannot be reached

•The machine never halts

•The input is not accepted

Page 53: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

53

Another Turing Machine Example

Turing machine for the language }{ nnba

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

Page 54: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

54

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

ba

0q

a bTime 0

Page 55: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

55

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

bx

1q

a b Time 1

Page 56: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

56

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

bx

1q

a b Time 2

Page 57: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

57

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

2q

a b Time 3

Page 58: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

58

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

2q

a b Time 4

Page 59: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

59

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

0q

a b Time 5

Page 60: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

60

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

1q

x b Time 6

Page 61: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

61

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

1q

x b Time 7

Page 62: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

62

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx x y

2q

Time 8

Page 63: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

63

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx x y

2q

Time 9

Page 64: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

64

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

0q

x y Time 10

Page 65: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

65

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

3q

x y Time 11

Page 66: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

66

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

3q

x y Time 12

Page 67: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

67

0q 1q 2q3qRxa ,

Raa ,Ryy ,

Lyb ,

Laa ,Lyy ,

Rxx ,

Ryy ,

Ryy ,4q

L,

yx

4q

x y

Halt & Accept

Time 13

Page 68: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

68

If we modify the machine for the language }{ nnba

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

Observation:

Page 69: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

69

Formal Definitionsfor

Turing Machines

Page 70: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

70

Transition Function

1q 2qRba ,

),,(),( 21 Rbqaq

Page 71: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

71

1q 2qLdc ,

),,(),( 21 Ldqcq

Transition Function

Page 72: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

72

Turing Machine:

),,,,,,( 0 FqQM

States

Inputalphabet

Tapealphabet

Transitionfunction

Initialstate

blank

Finalstates

Page 73: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

73

Configuration

ba

1q

a

Instantaneous description:

c

baqca 1

Page 74: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

74

yx

2q

a b

Time 4

yx

0q

a b

Time 5

A Move: aybqxxaybq 02

Page 75: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

75

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 76: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

76

bqxxyybqxxaybqxxaybq 1102

bqxxyxaybq 12

Equivalent notation:

Page 77: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

77

Initial configuration: wq0

ba

0q

a b

w

Input string

Page 78: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

78

The Accepted Language

For any Turing Machine M

}:{)( 210 xqxwqwML f

Initial state Final state

Page 79: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

79

Standard Turing Machine

• Deterministic

• Infinite tape in both directions

•Tape is the input/output file

The machine we described is the standard:

Page 80: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

80

Computing Functionswith

Turing Machines

Page 81: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

81

A function )(wf

Domain: Result Region:

has:

D

Dw

S

Swf )()(wf

Page 82: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

82

A function may have many parameters:

yxyxf ),(

Example: Addition function

Page 83: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

83

Integer Domain

Unary:

Binary:

Decimal:

11111

101

5

We prefer unary representation:

easier to manipulate with Turing machines

Page 84: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

84

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 85: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

85

)(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 86: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

86

Example

The function yxyxf ),( is computable

Turing Machine:

Input string: yx0 unary

Output string: 0xy unary

yx, are integers

Page 87: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

87

0

0q

1 1 1 1

x y

1 Start

initial state

The 0 is the delimiter that separates the two numbers

Page 88: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

88

0

0q

1 1 1 1

x y

1

0

fq

1 1

yx

11

Start

Finish

final state

initial state

Page 89: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

89

0

fq

1 1

yx

11Finish

final state

The 0 helps when we usethe result for other operations

Page 90: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

90

0q

Turing machine for function

1q 2q 3qL, L,01

L,11

R,

R,10

R,11

4q

R,11

yxyxf ),(

Page 91: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

91

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 92: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

92

0

0q

1 1Time 0

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

L,11

R,

R,10

R,11

4q

R,11

1 1

Page 93: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

93

0q

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

L,11

R,

R,10

R,11

4q

R,11

01 11 1Time 1

Page 94: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

94

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

L,11

R,

R,10

R,11

4q

R,11

0

0q

1 1 1 1Time 2

Page 95: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

95

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

L,11

R,

R,10

R,11

4q

R,11

1q

1 11 11Time 3

Page 96: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

96

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

L,11

R,

R,10

R,11

4q

R,11

1q

1 1 1 11Time 4

Page 97: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

97

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

L,11

R,

R,10

R,11

4q

R,11

1q

1 11 11Time 5

Page 98: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

98

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

L,11

R,

R,10

R,11

4q

R,11

2q

1 1 1 11Time 6

Page 99: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

99

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

L,11

R,

R,10

R,11

4q

R,11

3q

1 11 01Time 7

Page 100: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

100

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

L,11

R,

R,10

R,11

4q

R,11

3q

1 1 1 01Time 8

Page 101: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

101

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

L,11

R,

R,10

R,11

4q

R,11

3q

1 11 01Time 9

Page 102: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

102

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

L,11

R,

R,10

R,11

4q

R,11

3q

1 1 1 01Time 10

Page 103: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

103

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

L,11

R,

R,10

R,11

4q

R,11

3q

1 11 01Time 11

Page 104: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

104

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 105: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

105

Another Example

The function xxf 2)( is computable

Turing Machine:

Input string: x unary

Output string: xx unary

x is integer

Page 106: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

106

0q

1 1

x

1

1

fq

1 1

x2

11

Start

Finish

final state

initial state

Page 107: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

107

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 108: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

108

0q 1q 2q

3q

R,1$

L,1

L,

R$,1 L,11 R,11

R,

Turing Machine for xxf 2)(

Page 109: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

109

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 110: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

110

Another Example

The function ),( yxf

is computable0

1 yx

yx

if

if

Page 111: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

111

Turing Machine for

Input: yx0

Output: 1 0or

),( yxf0

1 yx

yx

if

if

Page 112: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

112

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 113: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

113

Combining Turing Machines

Page 114: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

114

Block Diagram

TuringMachine

input output

Page 115: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

115

Example:

),( yxf0

yx yx

yx

if

if

Comparer

Adder

Eraser

yx,

yx,

yx

yx

yx

0

Page 116: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

116

Computational complexity

The Turing machines we have studied have all been deterministic, i.e., when the transition rules are represented as five-tuples (s, x, s’, x’, d), were s, x are the current state and tape symbol, s’, x’ are the next state and tape symbol, and d is the move direction, then no two transition rules begin with the same pair (s, x), i.e., the mapping(s,x) → (s’, x’, d) is a function.

In a nondeterministic Turing machine there maybe more that one transition rule beginning with the same pair (s, x).

Page 117: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

117

Decision problemA decision problem asks whether statements from a

particular class of statements are true. Decision problems are also known as yes-or-no problems.

When there is an effective algorithm that decides whether instances of a decision problem are true, we say that this problem is solvable or decidable

The halting problem is the decision problem that asks whether a Turing machine T eventually halts when given an input string x.

The halting problem is an unsolvable decision problem. That is, no Turing machine exists that, when given an encoding of a Turing machine T and its input string x as input, can determine whether T eventually halts when started with x written on its tape (proof in Section 3.1).

Page 118: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

118

P class of decision problems

A decision problem is in class P of polynomial-time problems if it can be solved by a deterministic Turing machine in a polynomial time as function of the size of the input string, i.e., there is a deterministic Turing machine T that solves the problem and halts in a final state after no more than p(n) transitions when the input to T is a string of length n.

Problems in P are called tractable while problems not in P are called intractable.

Page 119: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

119

Examples of tractable problems:

(1) determining whether an item is in a list of n elements is a,

(2) determining whether a given positive integer n is prime is tractable (this fact was only proven in 2002!).

Page 120: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

120

NP class of decision problemsA decision problem is in class NP of

nondeterministic polynomial-time problems if it can be solved by a nondeterministic Turing machine in a polynomial time as function of the size of the input string, i.e., there is a nondeterministic Turing machine T that solves the problem and halts in a final state after no more than p(n) transitions when the input to T is a string of length n.

We haveNPP

Page 121: 1 Turing Machines (13.5) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch

121

P and NPOne of the most challenging questions is

computer science is whether P = NP, i.e., whether every problem in P is also in NP.

A problem S is NP-complete if it belongs to NP and if S can be shown to belong to P then every problem in NP must also belong to P, i.e., the existence of polynomial-time algorithm to solve S, implies the existence of a polynomial-time algorithm for every problem in NP.

Examples of NP-complete problems: (1) whether a simple graph has a Hamilton circuit (a simple circuit that passes through every vertex exactly once) and (2) whether a proposition in n-variables is a tautology.


Top Related