Title: Macros
1Macros
The basic macros are MRk (moves past k natural
numbers to right) MLk (moves past k natural
numbers to left) FR (moves head into position
to process the first natural number to the
right) FL (moves head into position to
process the first natural number to the
left) Ek (erases k natural numbers to the
right) CPYk (copies the k natural numbers to the
right) CPYk,i (copies the first k of ki numbers
to the right) T (moves the
first number to the right into position to be
processed) plus one more BRN takes a number as
input, checks to see whether it is zero or not,
and halts in either of two states accordingly
n 0
?
BRN
?
n gt 0
?
2Using macros
- Earlier we saw a TM to compute the projection
p(2)1. - With the help of macros we can describe a TM to
compute p(k)i by the strategy of - erasing the first i-1 arguments
- translating the i-th argument to start at tape
cell 1 - erasing the rest of the input arguments.
?
Ei-1
?
T
?
MR1
FR
Ek-i
?
?
FL
?
3Using macros and other TMs
To build a complex TM we may use, in addition to
the macros, any TMs we may have built
previously. Recall, for example, that we
previously built a TM to add two natural numbers.
Call this TM A. We can use A, together with some
macros, to build a TM that computes f(n) 2n.
?
CPY1
?
A
?
Given an input n, a computation generates the
following sequence of configurations B n
B CPY1 B n B n B A B nn B How could we
build a TM to compute the function f(n) 3n?
4Multiplication
Given arguments n and m, their product may be
computed by making n copies of m and adding.
5Composition of functions
If g N ? N and h N ? N then h?g N ? N is
given by h?g(x) h(g(x)). What if g or h is
partial? Then we define h?g(x) ? if g(x)? or
if g(x) y and h(y)? h(g(x)) otherwise. Can
we generalise to functions taking gt 1
argument? Suppose g1 N ? N and g2 N ? N, and
suppose that h N?N ? N. Then h?(g1, g2) N ? N
is given by h?(g1, g2)(x) h(g1(x),
g2(x)). E.g. take g1 s, g2 z, and h p(2)1
then h?(g1, g2)(3) Definition Given h Nn ?
N and g1 Nk ? N, ..., gn Nk ? N, the
composition h?(g1, g2, ..., gn) Nk ? N is given
by h?(g1, ..., gn)(x1, ..., xk) h(g1(x1,
..., xk), ..., gn(x1, ..., xk)).
6Composition and computability
We have seen basic Turing computable functions
like s, z, and the p(k)i. Theorem The
composition of Turing computable functions is
again Turing computable. For example, suppose g1,
g2, and h are Turing computable by TMs G1, G2,
and H where gi N ? N and h N?N ? N. Then h?(g1,
g2) is computable too. BnB CPY1 BnB
nB MR1 BnBnB G1 BnBg1(n)B
ML1 BnBg1(n)B CPY1,1 BnBg1(n)BnB
MR2 BnBg1(n)BnB G2 BnBg1(n)Bg2(n)B
ML1 BnBg1(n)Bg2(n)B H BnBh(g1(n),
g2(n))B ML1 BnBh(g1(n), g2(n))B E1 BB
... Bh(g1(n), g2(n))B T Bh(g1(n), g2(n))B
7To show computability
The basic way to show that a function f is Turing
computable is to give a TM that computes f. We
have a second way show that f is the composition
of functions already known to be Turing
computable. Example 1 The constant function
c(3)4 takes 3 arguments and always gives the
output 4. We could easily build a TM to compute
c(3)4 but another way to show it computable is to
note that c(3)4 s?s?s?s?z?p(3)1 Example
2 Weve seen that add is computable. The
function sq N?N ? N given by sq(n) n2 is
computed by
?
CPY1
?
MULT
?
Now smsq(n, m) n2 m2 is computable
since smsq add ?(sq?p(2)1, sq?p(2)2)
8Which functions are computable?
Are all functions f Nk ? N computable?
Can we describe the Turing computable functions
in a way that doesnt mention Turing machines?