Top Banner
Computability Dr. Colin Campbell Course Element 2 (EMAT20531)
30

Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Mar 28, 2015

Download

Documents

Jesus Bennett
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: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Computability

Dr. Colin CampbellCourse Element 2

(EMAT20531)

Page 2: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

What is a Computable function?

Consider a function f:NN A super-human being like God

could write out the whole table for this function.

Humans can’t because this would require us to store an infinite number of pairs (n,f(n))

Page 3: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

An Intuitive Definition

The function f is said to be effectively computable if

a finite list of instructions can be given that in principle make it possible to determine f(n) for any argument n.

The instructions must be definite and explicit.

Allowed – f(n+1)=f(n)+1 Not Allowed – Ask God.

Page 4: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Computability vs Complexity Computability refers to whether of

not in principle it is possible to evaluate f(n) by following a set of instructions.

We are not for the moment worried if this computation requires 1,000,000 or more consecutive steps.

The latter refers to complexity which we will return to later.

Page 5: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Turing Machines

1 0 0 1 0-

• A Turing machine consists of an infinite tape divided into square boxes.• In each box is written either 1 or 0.• A device runs along the tape as if on a railway track.• The device can read the symbol on its current square and also write 1 or 0.

Page 6: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

States, Instructions and Actions

A Turing machine can be in any of a number of states q1,…,qm

The machine can carry out the following actions:• Erase: write 0 in place of whatever is in the scanned square.• Print: write 1 in place of whatever is in the scanned square.• Move one square to the left.• Move one square to the right.• Halt the computation.

Instructions require action dependent on state. e.g. If state is qi and 1 the erase and switch to state qj

qi10qj

Page 7: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Implementing a program

State Action: New state

Search rule to match state and scanned symbol. Rule= (state action state)

Rules must be consistente.g. cannot have both the following rules:q110q2 and q11Lq2

ScanE.g. 1 or 0

Page 8: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

A Simple Program

The objective is to write a sequence of three 1s on the tape

There are three states q1,q2,q3 one for each of the 1s

• q101q1 – if in q1 and scan 0 then write 1 and remain q1

• q11Rq2 – if in q1 and scan 1 then right and q2

• q201q2 – if in q2 and scan 0 then write 1 and remain q2 • q21Rq3 – if in q2 and scan 1 then right and q3 • q301q3 – if in q3 and scan 0 then write 1 and remain q3

Start state is q1

Page 9: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Implementation

0 1 0 0

q1

1 1 0 0

q1

1 1 0 0

q2

1 1 0 0

q3

1 1 1 0

q3

q101q1

q11Rq

2

q21Rq3

q301q

3

Page 10: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Other Program Representations

Flow Chart

q1

0:1

1:Rq2

0:1

1:Rq3

0:1

Machine Tablescan/state 0 1

q11q1 Rq2

q21q2 Rq3

q31q3

Page 11: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

A Harder Program

Start scanning the leftmost 1 in a block of 1s on an otherwise blank tape. It ends scanning the leftmost 1 in a block of 1s of double the length.

q1 q2 q3 q4 q5 q6 q7 q8 q9 q10

q11

q12

1:L 1:L

0:L

1:L

0:10:1

1:R

1:R

0:R

1:R

0:L

1:0

0:L 1:L

1:L

0:L

1:L0:L

1:L0:R

0:R

Page 12: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

How it works

…by repeatedly writing two 1s to the left and erasing single 1s to the right

q1

1:LMove one left from leftmost 1 q2

1:L

0:L

Move left unconditionally

q3 q4

1:L

0:10:1

1:RWrite two 1s on the left and then move right

q5 q6

1:R

0:R

1:R

0:LFinds a sequence 01…10 and moves to the rightmost 1 (i.e. finds the remains of the original block of 1s)

Page 13: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

How it works: 2

q7

1:0

0:L

Replace rightmost 1 with 0

q8

q11

q12

0:L

1:L0:R

If all original 1s deleted then move left until at the leftmost 1 of the new block

q8 q9

1:L

1:L

0:L Else find the rightmost 1 in new block

q10

1:L

0:R

q2 Move to the leftmost 1 in the new block and repeat from q2

Page 14: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Example

1111 02111q1

1:L

030111q2

1:L

0:L

q3 q4

1:L

0:10:1

1:R

0410111 1410111130111 1150111

q5 q6

1:R

0:R

1:R

0:L1105111 1101611 1101161 1101116 1101110

61101117

Page 15: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Example: 2

q7

1:0

0:L1101107 110118

q8 q9

1:L

1:L

0:L110191 110911 1110011

q10

1:L

0:R

q2 1101011 01011011 121011

Page 16: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Example: 3

q2

1:L

0:L

0311011

q3 q4

1:L

0:10:1

1:R1311011 04111011 14111011 11511011

q5 q6

1:R

0:R

1:R

0:L11151011 11115011 11110511

11110161 11110116 111101106

11110117

Page 17: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Example: 4

q7

1:0

0:L

11110107 1111018

q8 q9

1:L

1:L

0:L1111091 11111001

q10

1:L

0:R

q2 11111001 1211101

Page 18: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Example: 5

q2

1:L

0:L

03111101

q3 q4

1:L

0:10:1

1:R13111101 115111101

q5 q6

1:R

0:R

1:R

0:L111111017

q7

1:0

0:L 111111080

q8

q11

q12

0:L

1:L0:R

11211111

Page 19: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Turing Computable Functions

A function f:NN is Turing computable if there is a Turing machine…

Which given input 011…..10 containing a block of n 1s

Terminates on 01n….10 containing a block of f(n) 1s

We are only considering totally defined functions here but Turing machines can also deal with partial functions.

Page 20: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Church/Turing Thesis Clearly any Turing computable function is

effectively computable in the intuitive sense that we can write a set of instructions to evaluate it for any n.

Turing’s thesis is that all effectively computable functions are Turing computable.

i.e. Turing computability is a complete formalization of what it means to be intuitively computable.

Page 21: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Non-Turing Computable Functions

Its clear that not all functions are Turing computable.

The are uncountably many functions f:NN

However there are only countably many Turing machines.

Because each is characterised by a finite set of instructions.

Page 22: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Enumeration of Turing Machines

We can allocate a unique natural number to every Turing machine.

There are many ways of doing this and I will present just one…

Recall the Turing machine q101q1, q11Rq2, q201q2, q21Rq3, q301q3

q1

0:1

1:Rq2

0:1

1:Rq3

0:1

Page 23: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Enumerating: 2 We will base the mapping on the

instruction set representation. If there are n states assume that q1 is the

start state and qn is the termination state. If not simply add an extra termination state.

Up to now if the machine encounter a state and scan for which there is no instruction then it halts.

We now add an explicit termination state so that there is an explicit instruction for each state/scan combination.

Page 24: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Enumerating: 3

q101q1, q11Rq2, q201q2, q21Rq3, q301q3

q101q1, q11Rq2, q201q2, q21Rq3, q301q3,q311q3

1q1, Rq2, 1q2,Rq3, 1q3,1q3

Order instructions and remove redundant first terms

qii 01 12

L3 R42,1,4,2,2,2,4,3,2,3,2,3

22 31 54 72 112 132 174 193 232 293 312 373

Page 25: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

The Diagonal FunctionFor Turing machine M let (M) be it’s allocated number.

Consider the set of Turing computable functions of 1 variable.

Let them be ordered f1,f2,f3,….., where (Mi) < (Mi+1) for Mi is the Turing machine with the smallest number for computing fi.

Define the diagonal function

otherwise

if

1

12 nfnd n

Page 26: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

The Diagonal Function: 2

The diagonal function d(n) is not computable

Suppose d(n) is computable then d(n)=fm(n) for some function fm in the list of computable functions. Hence, for n=m

otherwise

if

1

12 mfmfmd m

m

But this is a contradiction.

Page 27: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

The Halting Problem The halting function h(n,m)=1 if Turing

machine with number n halts given input m and = 2 otherwise.

The function h is not Turing computable. Suppose that h was computable by Turing

machine H Further consider a Turing machine D that

takes and input and copies it. So e.g. 011110 is returned 01n110111

Page 28: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

The Halting Problem: 2

We also design the following Turing machine L which loops given input 1 and halts given input >1

q1

1:Rq2

1:Lq3

0:L

111 112 131 halt

11 102 11 loop

Page 29: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

The Halting Problem: 3

We can now combine the three Turing machines in sequence to give a new machine C

C=DHL Let n be the Turing number of C C(n) halts if H(n,n) returns 2 C(n) does not halt if H(n,n) returns 1 So C halts if and only if C does not

halt.

Page 30: Computability Dr. Colin Campbell Course Element 2 (EMAT20531)

Universal Turing Machines

A universal Turing machine takes 2 inputs n and m and returns the corresponding output of Turing machine with number n given in put m.

Modern digital computers are universal Turing machines.