Presentation on theme: "Computability Dr. Colin Campbell Course Element 2 (EMAT20531)"— Presentation transcript:
Computability Dr. Colin Campbell Course Element 2 (EMAT20531)
What is a Computable function? Consider a function f:N N A super-human being like God could write out the whole table for this function. Humans cant because this would require us to store an infinite number of pairs (n,f(n))
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.
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.
Turing Machines 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.
States, Instructions and Actions A Turing machine can be in any of a number of states q 1,…,q m 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 q i and 1 the erase and switch to state q j q i 10q j
Implementing a program State Action: New state Search rule to match state and scanned symbol. Rule= (state action state) Rules must be consistent e.g. cannot have both the following rules: q 1 10q 2 and q 1 1Lq 2 Scan E.g. 1 or 0
A Simple Program The objective is to write a sequence of three 1s on the tape There are three states q 1,q 2,q 3 one for each of the 1s q 1 01q 1 – if in q 1 and scan 0 then write 1 and remain q 1 q 1 1Rq 2 – if in q 1 and scan 1 then right and q 2 q 2 01q 2 – if in q 2 and scan 0 then write 1 and remain q 2 q 2 1Rq 3 – if in q 2 and scan 1 then right and q 3 q 3 01q 3 – if in q 3 and scan 0 then write 1 and remain q 3 Start state is q 1
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. q1q1 q2q2 q3q3 q4q4 q5q5 q6q6 q7q7 q8q8 q9q9 q 10 q 11 q 12 1:L 0:L 1:L 0:1 1:R 0:R 1:R 0:L 1:0 0:L1:L 0:L 1:L 0:L 1:L 0:R
How it works …by repeatedly writing two 1s to the left and erasing single 1s to the right q1q1 1:L Move one left from leftmost 1 q2q2 1:L 0:L Move left unconditionally q3q3 q4q4 1:L 0:1 1:R Write two 1s on the left and then move right q5q5 q6q6 1:R 0:R 1:R 0:L Finds a sequence 01…10 and moves to the rightmost 1 (i.e. finds the remains of the original block of 1s)
How it works: 2 q7q7 1:0 0:L Replace rightmost 1 with 0 q8q8 q 11 q 12 0:L 1:L 0:R If all original 1s deleted then move left until at the leftmost 1 of the new block q8q8 q9q9 1:L 0:L Else find the rightmost 1 in new block q 10 1:L 0:R q2q2 Move to the leftmost 1 in the new block and repeat from q 2
Turing Computable Functions A function f:N N is Turing computable if there is a Turing machine… Which given input 01 1 …..10 containing a block of n 1s Terminates on 01 n ….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.
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. Turings 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.
Non-Turing Computable Functions Its clear that not all functions are Turing computable. The are uncountably many functions f:N N However there are only countably many Turing machines. Because each is characterised by a finite set of instructions.
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 q 1 01q 1, q 1 1Rq 2, q 2 01q 2, q 2 1Rq 3, q 3 01q 3 q1q1 0:1 1:R q2q2 0:1 1:R q3q3 0:1
Enumerating: 2 We will base the mapping on the instruction set representation. If there are n states assume that q 1 is the start state and q n 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.
The Diagonal Function For Turing machine M let (M) be its allocated number. Consider the set of Turing computable functions of 1 variable. Let them be ordered f 1,f 2,f 3,….., where (M i ) < (M i+1 ) for M i is the Turing machine with the smallest number for computing f i. Define the diagonal function
The Diagonal Function: 2 The diagonal function d(n) is not computable Suppose d(n) is computable then d(n)=f m (n) for some function f m in the list of computable functions. Hence, for n=m But this is a contradiction.
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 is returned 01 n
The Halting Problem: 2 We also design the following Turing machine L which loops given input 1 and halts given input >1 q1q1 1:R q2q2 1:L q3q3 0:L halt loop
The Halting Problem: 3 We can now combine the three Turing machines in sequence to give a new machine C C=D H L 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.
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.