fall 2004comp 3351 a universal turing machine. fall 2004comp 3352 turing machines are...

56
Fall 2004 COMP 335 1 A Universal Turing Machine

Post on 21-Dec-2015

225 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 1

A Universal Turing Machine

Page 2: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 2

Turing Machines are “hardwired”

they executeonly one program

A limitation of Turing Machines:

Real Computers are re-programmable

Page 3: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 3

Solution: Universal Turing Machine

• Reprogrammable machine

• Simulates any other Turing Machine

Attributes:

Page 4: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 4

Universal Turing Machine

simulates any other Turing MachineM

Input of Universal Turing Machine:

Description of transitions of M

Initial tape contents of M

Page 5: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 5

Universal Turing Machine M

Description of

Tape Contents of

M

State of M

Three tapes

Tape 2

Tape 3

Tape 1

Page 6: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 6

We describe Turing machine as a string of symbols:

We encode as a string of symbols

M

M

Description of M

Tape 1

Page 7: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 7

Alphabet Encoding

Symbols: a b c d

Encoding: 1 11 111 1111

Page 8: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 8

State Encoding

States: 1q 2q 3q 4q

Encoding: 1 11 111 1111

Head Move Encoding

Move:

Encoding:

L R

1 11

Page 9: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 9

Transition Encoding

Transition: ),,(),( 21 Lbqaq

Encoding: 10110110101

separator

Page 10: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 10

Machine Encoding

Transitions:

),,(),( 21 Lbqaq

Encoding:

10110110101

),,(),( 32 Rcqbq

110111011110101100

separator

Page 11: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 11

Tape 1 contents of Universal Turing Machine:

encoding of the simulated machine as a binary string of 0’s and 1’s

M

Page 12: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 12

A Turing Machine is described with a binary string of 0’s and 1’s

The set of Turing machines forms a language:

each string of the language isthe binary encoding of a Turing Machine

Therefore:

Page 13: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 13

Language of Turing Machines

L = { 010100101,

00100100101111,

111010011110010101, …… }

(Turing Machine 1)

(Turing Machine 2)

……

Page 14: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 14

Countable Sets

Page 15: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 15

Infinite sets are either: Countable

or

Uncountable

Page 16: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 16

Countable set:

There is a one to one correspondencebetween elements of the setand Natural numbers

Any finite set

Any Countably infinite set:

or

Page 17: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 17

Example:

Even integers: ,6,4,2,0

The set of even integersis countable

Positive integers:

Correspondence:

,4,3,2,1

n2 corresponds to 1n

Page 18: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 18

Example: The set of rational numbersis countable

Rational numbers: ,87

,43

,21

Page 19: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 19

Naïve Proof

Rational numbers: ,31

,21

,11

Positive integers:

Correspondence:

,3,2,1

Doesn’t work:

we will never count numbers with nominator 2:

,32

,22

,12

Page 20: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 20

Better Approach

11

21

31

41

12

22

32

13

23

14

Page 21: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 21

11

21

31

41

12

22

32

13

23

14

Page 22: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 22

11

21

31

41

12

22

32

13

23

14

Page 23: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 23

11

21

31

41

12

22

32

13

23

14

Page 24: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 24

11

21

31

41

12

22

32

13

23

14

Page 25: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 25

11

21

31

41

12

22

32

13

23

14

Page 26: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 26

Rational Numbers: ,22

,31

,12

,21

,11

Correspondence:

Positive Integers: ,5,4,3,2,1

Page 27: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 27

We proved:

the set of rational numbers is countable by describing an enumeration procedure

Page 28: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 28

Definition

An enumeration procedure for is aTuring Machine that generatesall strings of one by one

Let be a set of strings S

S

S

and

Each string is generated in finite time

Page 29: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 29

EnumerationMachine for

,,, 321 sss

Ssss ,,, 321

Finite time: ,,, 321 ttt

strings

Soutput

(on tape)

Page 30: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 30

Enumeration MachineConfiguration

Time 0

0q

Time

sq

1x 1s#1t

Page 31: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 31

Time

sq

3x 3s#3t

Time

sq

2x 2s#2t

Page 32: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 32

If for a set there is an enumeration procedure, then the set is countable

Observation:

Page 33: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 33

Example:

The set of all stringsis countable

},,{ cba

We will describe an enumeration procedure

Proof:

Page 34: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 34

Naive procedure:

Produce the strings in lexicographic order:

aaaaaa

......

Doesn’t work: strings starting with will never be produced

b

aaaa

Page 35: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 35

Better procedure:

1. Produce all strings of length 1

2. Produce all strings of length 2

3. Produce all strings of length 3

4. Produce all strings of length 4

..........

Proper Order

Page 36: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 36

Produce strings in Proper Order:

aaabacbabbbccacbcc

aaaaabaac......

length 2

length 3

length 1abc

Page 37: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 37

Theorem: The set of all Turing Machinesis countable

Proof:

Find an enumeration procedure for the set of Turing Machine strings

Any Turing Machine can be encodedwith a binary string of 0’s and 1’s

Page 38: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 38

1. Generate the next binary string of 0’s and 1’s in proper order

2. Check if the string describes a Turing Machine if YES:YES: print string on output tape if NO:NO: ignore string

Enumeration Procedure:

Repeat

Page 39: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 39

Uncountable Sets

Page 40: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 40

A set is uncountable if it is not countable

Definition:

Page 41: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 41

Theorem:

Let be an infinite countable set

The powerset of is uncountable S2 S

S

Page 42: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 42

Proof:

Since is countable, we can write S

},,,{ 321 sssS

Elements of S

Page 43: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 43

Elements of the powerset have the form:

},{ 31 ss

},,,{ 10975 ssss

……

Page 44: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 44

We encode each element of the power setwith a binary string of 0’s and 1’s

1s 2s 3s 4s

1 0 0 0}{ 1s

Powersetelement

Encoding

0 1 1 0},{ 32 ss

1 0 1 1},,{ 431 sss

Page 45: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 45

Let’s assume (for contradiction) that the powerset is countable.

Then: we can enumerate the elements of the powerset

Page 46: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 46

1 0 0 0 0

1 1 0 0 0

1 1 0 1 0

1 1 0 0 1

Powerset element Encoding

1t

2t

3t

4t

Page 47: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 47

Take the powerset elementwhose bits are the complements in the diagonal

Page 48: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 48

1 0 0 0 0

1 1 0 0 0

1 1 0 1 0

1 1 0 0 1

1t

2t

3t

4t

New element: 0011

(birary complement of diagonal)

Page 49: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 49

The new element must be someof the powerset

it

However, that’s impossible:

the i-th bit of must be the complement of itself

from definition of it

it

Contradiction!!!

Page 50: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 50

Since we have a contradiction:

The powerset of is uncountable S2 S

Page 51: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 51

An Application: Languages

Example Alphabet : },{ ba

The set of all Strings:

},,,,,,,,,{},{ * aabaaabbbaabaababaS infinite and countable

Page 52: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 52

Example Alphabet : },{ ba

The set of all Strings:

},,,,,,,,,{},{ * aabaaabbbaabaababaS infinite and countable

A language is a subset of :

},,{ aababaaL

S

Page 53: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 53

Example Alphabet : },{ ba

The set of all Strings:

},,,,,,,,,{},{ * aabaaabbbaabaababaS infinite and countable

The powerset of contains all languages:

}},,,}{,{},{},{{2 aababaabaaS 1L 2L 3L 4L

uncountable

S

Page 54: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 54

Languages: uncountable

Turing machines: countable

1L 2L 3L kL

1M 2M 3M

?

There are more languagesthan Turing Machines

Page 55: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 55

There are some languages not acceptedby Turing Machines

(These languages cannot be described by algorithms)

Conclusion:

Page 56: Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing

Fall 2004 COMP 335 56

Languages Accepted by Turing Machines

Languages not accepted by Turing Machines

kL