Examples of Unlimited Register Machine programs for Turingcomputable functions 18 February 2012 at 13:01 Public It will be a matter of interest for me over the next few months to formulate (and collect) numerous examples of basic URM programs to implement simple Turing-computable functions. I'll do this here. Background: Unlimited Register Machines (URMs) were introduced into the mathematical literature in the early 1960s as an easier version of Turing machines to work with. (Detailed history and references can be found here:http://en.wikipedia.org/wiki/register_machine). Turing machines (and URMs) are idealized computers for the study of the algorithmic computability of functions. The idea is that not all functions are able to be computed algorithmically. Those functions that ARE algorithmically computable are called Turing-computable and for such functions it is possible to write a program which will implement them on a Turing machine (or equivalently a URM) in a finite number of steps. According to the famous Church-Turing Thesis, the class of algorithmically computable functions is precisely the class of functions which are recursive (a recursive function is one that can be obtained from certain more basic functions by certain elementary operations implemented a finite number of times). I want to use this note to practise formulating (and also just to collect) specific examples of short URM programs which will implement simple Turing-computable functions. The basic features of the type of URM programs I am interested in are summarised in the following printed note (the sample URM program given here is one that performs addition of two numbers):
------------------------------------------------------------------------------------------------------------------------------------------------- EXAMPLE 1 The following URM program computes three partial functions which I will discuss below (a partial function is a function whose domain is a subset of Nᵏ, the k-dimensional Cartesian product of the set of natural numbers. A function whose domain is the whole of Nᵏ is a total function): 1. J(1, 3, 6) 2. S(2) 3. S(2) 4. S(3) 5. J(1, 1, 1) 6. C(2, 1) This is what one obtains when this program is implemented with the input (2, 1, 1):
To work out the partial function f¹ we consider an initial input n. In the first pass we would have R 2 go from 0 to 2, and R 3 go from 0 to 1. In the next pass R 2 goes to 4, and R 3 goes to 2. This continues until R 2 contains 2n and R 3 contains n. This will occur for any non-negative n, so this partial function is actually total and we have f¹(n) = 2n. To work out the partial function f² we consider an initial input (n 1, n 2 ). In the first pass we would have R 2 go from n 2 to n 2 +2, and R 3 go from 0 to 1. In the next pass R 2 goes to n 2 +4, and R 3 goes to 2. This continues until R 2 contains 2n 1 + n 2, and R 3 contains n 1. This will occur for any non-negative n 1 and n 2, so the function is total and we have f²(n 1, n 2 ) = 2n 1 + n 2. Finally, to work out the partial function f³ we assume initial input (n 1, n 2, n 3 ). We can see straight away that if n 3 > n 1 the program will never halt. Therefore the function is not defined for such values and cannot be a total function. If n 1 = n 3 the output will be n 2. And if n 1 > n 3 we will have R 2 going to n 2 +2(n 1 -n 3 ), and R 3 going to n 1. Therefore this function is not total and we have: f³(n 1, n 2, n 3 ) = n 2 +2(n 1 -n 3 ) for n 1 > n 3 ; f³(n 1, n 2, n 3 ) = n 2 for n 1 = n 3 ; f³(n 1, n 2, n 3 ) is undefined for n 1 < n 3. ----------------------------------------------------------------------------------------------------------------------------------------------- EXAMPLE 2 The following URM program computes the function f(n) = n if n is odd, and f(n) = 0 if n is even: 1. J(1, 2, 8) 2. S(2) 3. J(1, 2, 8) 4. S(2) 5. J(1, 2, 7) 6. J(1, 1, 2) 7. Z(1) = 0 For example, the following is obtained with the input (3, 0): And the following is obtained with the input (4, 0):
------------------------------------------------------------------------------------------------------------------------------------------------ EXAMPLE 3 The following URM program computes the function f(n, m) = n if n m, f(n, m) = m otherwise. In other words, it computes min(n, m). 1. J(1, 2, 7) 2. J(1, 3, 7) 3. J(2, 3, 6) 4. S(3) 5. J(1, 1, 2) 6. C(2, 1) For example, the following is obtained with the input (2, 3): And the following is obtained with the input (3, 2):
Note that to compute max(n, m), i.e., the function f(n, m) = n if n m, f(n, m) = m otherwise, it is only necessary to switch around the last digits in the Jump commands in lines 2 and 3, so the jump command in line 2 now goes to line 6, while the jump command in line 3 now goes to (non-existent) line 7. No other changes are needed. ----------------------------------------------------------------------------------------------------------------------------------------------- EXAMPLE 4 The following URM program computes the function f(n, m) = nm. In other words, it carries out multiplication. 1. J(1, 4, 14) 2. J(2, 4, 13) 3. C(1, 3) 4. Z(1) 5. S(1) 6. S(4) 7. J(3, 4, 9) 8. J(1, 1, 5) 9. S(5) 10. J(2, 5, 14) 11. Z(4) 12. J(1, 1, 5) 13. Z(1) For example, the following is obtained with the input (2, 3):
-------------------------------------------------------------------------------------------------------------------------------------------------