• Keine Ergebnisse gefunden

G¨odel Numbering of GOTO Programs

In mathematical logic, G¨odel numbering refers to a function that assigns to each well-formed formula of some formal language a unique natural number called its G¨odel number. This concept was introduced by the logician Kurt G¨odel (1906-1978) for the proof of incompleteness of elementary arithmetic (1931).

Here G¨odel numbering is used to provide an encoding of GOTO programs.

For this, letN0denote the union of all cartesian productsNk0,k≥0. In particular,N00={ǫ}, where ǫ is the empty string. The Cantor pairing function J2 : N20 → N0 can be used to define an encoding J :N0→N0 as follows:

J(ǫ) = 0, (5.1)

J(x) =J2(0, x) + 1, x∈N0, (5.2)

J(x, y) =J2(J(x), y) + 1, x∈N0, y∈N0. (5.3) Note that the second equation is a special case of the third one, since for eachy∈N0,

J(ǫ, y) =J2(J(ǫ), y) + 1 =J2(0, y) + 1 =J(y). (5.4) Example 5.1.We have

J(1,3) =J2(J(1),3) + 1 =J2(J2(0,1) + 1,3) + 1 =J2(2,3) + 1 = 17 + 1 = 18.

♦ Proposition 5.2.The encoding function J is a primitive recursive bijection.

Proof. First, claim thatJ is primitive recursive. Indeed, the functionJ is primitive recursive for strings of length≤1, sinceJ2 is primitive recursive. Assume thatJ is primitive recursive for strings of length

≤k, wherek≥1. For strings of lengthk+1, the functionJ can be written as a composition of primitive recursive functions:

J =ν◦J2(J(π(k+1)1 , . . . , πk(k+1)), πk+1(k+1)). (5.5) By induction hypothesis,Jis primitive recursive for strings of length≤k+1 and thus the claim follows.

Second, let A be the set of all numbers n ∈ N0 such that there is a unique string x ∈ N0 with J(x) =n. Claim thatA=N0. Indeed, 0 lies inAsinceJ(ǫ) = 0 andJ(x)>0 for allx6=ǫLetn >0 and assume that the assertion holds for all numbersm < n. Define

u=K2(n−1) and v=L2(n−1). (5.6)

Then J2(u, v) = J2(K2(n−1), L2(n−1)) =n−1. By construction,K2(z)≤z and L2(z)≤z for all z ∈N0. Thusu=K2(n−1)< nand hence u∈A. By induction, there is exactly one stringx∈Nk0 such thatJ(x) =u. ThenJ(x, v) =J2(J(x), v)) + 1 =J2(u, v) + 1 =n.

Assume that J(x, v) = n = J(y, w) for some x,y ∈ N0 and v, w ∈ N0. Then by definition, J2(J(x), v) = J2(J(y), w). But the Cantor pairing function is bijective and thus J(x) = J(y) and v=w. SinceJ(x)< nit follows by induction thatx=y. Thusn∈Aand so by the induction axiom,

A=N0. It follows thatJ is bijective. ⊓⊔

The encoding functionJ gives rise to two functionsK, L:N0→N0 defined as

K(n) =K2(n−˙ 1) and L(n) =L2(n−˙ 1), n∈N0. (5.7) Note that the following marginal conditions hold:

K(1) =K(0) =L(0) =L(1) = 0. (5.8)

Proposition 5.3.The functions K and L are primitive recursive, and for each number n≥1, there are unique x∈N0 andy∈N0 withJ(x, y) =nsuch that

J(x) =K(n) and y=L(n). (5.9)

Proof. By Proposition 2.27, the functions K2 and L2 are primitive recursive and so K and L are primitive recursive, too.

Let n≥1. By Proposition 5.2, there are unique x∈N0 andy ∈ N0 such thatJ(x, y) =n. Thus J2(J(x), y) =n−1. ButJ2(K2(n−1), L2(n−1)) =n−1 and the Cantor pairing functionJ2is bijective.

ThusK2(n−1) =J(x) andL2(n−1) =y, and soK(n) =J(x) andL(n) =y. ⊓⊔ The length of a string can be determined by its encoding.

Proposition 5.4.If xis a string inN0 of lengthk, thenkis the smallest number such that Kk(J(x)) = 0.

Proof. In view of the empty string, K0(J(ǫ)) = J(ǫ) = 0. Let x =x1. . . xk be a non-empty string.

ThenJ(x) =n≥1. By Proposition 5.3,J(x1. . . xk−1) =K(n). By induction,J(x1. . . xi) =Kk−i(n) for each 0 ≤i ≤k. In particular, for each 0≤ i < k, Kk−i(n) is non-zero, since x1. . . xi is not the empty string. Moreover,Kk(n) =J(ǫ) = 0. The result follows. ⊓⊔

Note that the converse of the above assertion is also valid. As an example, take a numberx∈N0, a string of length one. Then by (5.4),J(ǫ, x) =J(x) =J2(0, x) + 1 =n≥1 and so by (5.9), K(n) =J(ǫ) = 0 andL(n) =x.

In view of Proposition 5.4, define the mapping f :N0×N0→N0 as

f : (x, k)7→Kk(J(x)). (5.10)

Minimalization of this function yield thelength functionlg :N0→N0 given by lg(x) =µf(x) =

kifksmallest withf(x, k) = 0 andf(x, i)>0 for 0≤i≤k,

↑ otherwise. (5.11)

Proposition 5.5.The length functionlg is primitive recursive.

Proof. The length function is partial recursive, since it is obtained by minimalization of a primitive recursive function. This minimization is bounded with the bound given by the argumentxinterpreted as natural number because a natural number is as least as large as its length. Since bounded minimalization of a primitive recursive function is primitive recursive, the result follows. ⊓⊔ Proposition 5.6.Let n≥1. The inverse value J−1(n)is given by

(Kk−1(n), L◦Kk−2(n), . . . , L◦K(n), L(n)), (5.12)

The primitive recursive bijection J allows to encode the standard GOTO programs, SGOTO pro-grams for short. These are GOTO propro-gramsP =s0;s1;. . .;sq that have a canonical labelling in the sense thatλ(sl) =l, 0≤l≤q. It is clear that for each GOTO program there is a semantically equiv-alent SGOTO program. SGOTO programs are used in the following since they will permit a slightly simpler G¨odel numbering than arbitrary GOTO programs. In the following, let PSGOTO denote the class of SGOTO programs.

The numberI(sl) is called theG¨odel numberof the instructionsl, 0≤l≤q. The functionIis primitive recursive, since it is defined by cases and the functions involved are primitive recursive.

Note that the function I allows to identify the lth instruction of an SGOTO program given its G¨odel numbere. Indeed, the residue ofemodulo 3 provides the type of instruction and the quotient of emodulo 3 gives the encoding of the parameters of the instruction. More concretely, write

e= 3n+t, (5.14)

wheren=÷(e,3) andt= mod(e,3). Then the instruction can be decoded by using Proposition 5.6 as follows: Proposition 5.7.The functionΓ :PSGOTO→N0 is bijective and primitive recursive.

Proof. The mappingΓ is bijective sinceJ is bijective and the instructions encoded byI are uniquely determined as shown above. Moreover, the functionΓ is a composition of primitive recursive functions

and thus is primitive recursive. ⊓⊔

The SGOTO program P with G¨odel numbere is denoted by Pe. G¨odel numbering provides a list of all SGOTO programs

P0, P1, P2, . . . . (5.17)

Conversely, each numberecan be assigned the SGOTO program P such thatΓ(P) =e. For this, the length of the string encoded bye is first determined by the minimalization given in Proposition 5.4.

Suppose the string has lengthn+ 1, wheren≥0. Then the task is to find x∈Nn0 and y ∈N0 such that J(x, y) = n. But by (5.9), K(n) =J(x) and L(n) = y and so the preimage of n under J can be repeatedly determined. Finally, when the string is given, the preimage (instruction) of each number can be established as described in (5.15).

For each number eand each numbern≥0, denote the n-ary partial recursive function computing the SGOTO program with G¨odel numbereby

φ(n)e =kPekn,1. (5.18)

If f is ann-ary partial recursive function, each number e ∈N0 with the propertyf =φ(n)e is called anindex of f. The index of a partial recursive functionf provides the G¨odel number of an SGOTO program computing it. The list of all SGOTO program in (5.17) yields a list of alln-ary partial recursive functions:

φ(n)0 , φ(n)1 , φ(n)2 , . . . . (5.19) Note that the list contains repetitions, since eachn-ary partial recursive function has infinitely many indices.