Computable Func
Computable Func
machines
Turing Machines with Outputs
• When we begin the computation the tape
contains the input.
• When the TM accepts (halts) return what is
written in the tape.
• TM doesn’t reject in any input.
Number representation
• Decimal: 12
• Binary: 1100
• Unary: 111111111111
0 0
1 2
N 2 4
N
3 6
4 8
… …
Total and Partial Functions
• A function f : N → N is called partial when f(n)
is defined for some n.
Example: f(n) = logn
f
1 0
0 2 1
3
N 6 5 4 2
N
7 3
9
8 3
… …
Computable and Partially Computable
Functions
• A (total) function f : N → N is (total)
computable if we can find a Turing Machine
that computes it (given any number n in Unary
as input in the tape, after completing the
computation the tape contains f(n) in Unary).
• A partial function f : N → N is said to be
partially computable if there is a Turing
Machine that partially computes it (if f is
defined for n then the machine should output
f(n), else it should loop for ever).
Example: f(n) = 2n is computable
We design a TM that computes f(n).
High Level Program:
• The tape is divided into input and output (output is
right after the first blank after the input)
• Repeat:
– Erase one 1 from the input.
– Pass along the rest of the input
– Pass the blank that separates the input from the output.
– Pass along the output until you reach the end (blank).
– write two 1s.
– Go to the beginning of the input.
• Until the input is erased (accept).
Example: f(n) = 2n is computable
The machine for f(n) = 2n
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: ε
… …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: ε
… …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = 2n is computable
• Test input: 11
… 1 1 1 1 …
1→1,R 1 → 1, R
1→□,R □→□,R
q0 q1 q2
□→□,L □→1,L
qf q5 q4 q3
1 → 1, L 1 → 1, L
Example: f(n) = logn is partially
computable.
We design a TM that partially computes f(n).
High Level Program:
• Add a $ in the beginning and the end of the input (this will
make the task of going from one state to another easier)
• Repeat:
– For every two ones in the input erase the first and leave the
second there.
– If there was an odd > 1 number of 1s then loop for ever (the
function is undefined)
– If the number of 1 is even then pass the $ sign
– Pass along the output until you reach the end (blank).
– Write one 1 in the output (after the $).
– Go to the beginning of the input.
• Until there is only one 1 in the input.
• Erase the two $ signs and accept.
Example: f(n) = logn is partially
computable.
qf
$E
1→1,R 1→□,R
$R 1 ev 1→1,R od
1→1,R
□→$,L
1→□,R
□→$,R L
$L 0 ou
1→1,L $
1 → 1, L □→□,R □→□,L 1 → 1, L
Example: f(n) = logn is partially
computable.
Try to run the machine by hand
Test inputs:
• ε (shouldn’t accept)
• 1 (should accept)
• 11 (should accept)
• 111 (shouldn’t accept)
• 111111 (shouldn’t accept)
• 11111111 (should accept)
k-ary functions
• A function f might have more than one
parameters.
• f: N x N x … x N → N is called k-ary function
k times
Examples:
• + : N x N → N (addition of integers) is a binary
function.
Representation of a k-tuple in a DTM
A k-tuple (x1 , x2 , …, xk) can be represented in a
Turing Machine by the following way:
x1 x2 xk
… 1 1 … 1 0 1 … 1 0 … 1 … 1 …
head
• Example: (2, 4)
… 1 1 0 1 1 1 1 …
Binary addition is computable
• High level program:
– Remove the 0 from the middle and make the 1s in
the input consecutive.
• TM for this function:
1 → 1, R 1 → 1, R 1 → 1, R
… 1 1 0 1 1 1 …
1 → 1, R 1 → 1, R 1 → 1, R
… 1 1 0 1 1 1 …
1 → 1, R 1 → 1, R
… 1 1 0 1 1 1 …
1 → 1, R 1 → 1, R
… 1 1 1 1 1 1 …
1 → 1, R 1 → 1, R
… 1 1 1 1 1 1 …
1 → 1, R 1 → 1, R
… 1 1 1 1 1 1 …
1 → 1, R 1 → 1, R
… 1 1 1 1 1 1 …
1 → 1, R 1 → 1, R
… 1 1 1 1 1 1 …
1 → 1, R 1 → 1, R
… 1 1 1 1 1 …
1 → 1, R 1 → 1, R
□→□,R
q0 qf
Q(x,y) is computable
• High level program:
- Remove one 1 from both x and y. If you can do
that for all the 1s in x then accept, else reject.
• TM for this predicate:
0→0,R
1 → 1, R x → x, R x → x, L
1 → 1, L
x → x, R q4
1 → 1, L
Computable Sets, Characteristic
function
• The characteristic function χΑ of a set A is
defined as follows:
1, x A
A ( x)
0, x A
A a2 b2 B A a2 b2 B
a3 b3 a3 b3
… … …
b4
…
Countable Sets
• A set is countable if you can find an one to one and
onto correspondence with the natural numbers
(intuitively this means that it has the same number
of elements as the natural numbers)
a 1
b 2
A c 3
N
d 4
e 5
… …
The set of the even numbers is
countable
• There is an one to one an onto function from
E (the even numbers) to N: f(n) = n/2
0 0
2 1
E 4 2 N
6 3
8 4
… …
N x N is countable
0 1 8 9 24
(0,0) (0,1) (0,2) (0,3) (0,4) . . .
<MP> = 100110010101101011
□→□,R
q0 qf
Uncountable Sets
• Countable sets are infinite.
• However there are some sets that are considered
“even larger”.
• There is no way to enumerate them.
• Diagonalization method: Suppose that there is an
enumeration of all the elements of the set.
• Obtain a new element by taking different parts of
each element and changing them.
• The new element is not in the enumeration.
Contradiction!!!
The set of N →{0,1} Predicates is
not countable
Suppose that it was. An enumeration of all the
predicate would be the following:
1 2 3 4 5 6
1 0 1 0 1 1 1 f(1) = 1
2 1 0 1 1 0 0 . . . f(2) = 1
3 0 0 1 0 1 1 f(3) = 0
4 1 1 1 0 1 1 f(4) = 1
.
.
.