On the complexity of universal programs - Alain Colmerauer

final configuration corresponding to c, if c is final for P2. After having computed the column vector B and the matrix A, using Theo- rem 2, we have verified that U2 ...
403KB taille 5 téléchargements 341 vues
On the complexity of universal programs Alain Colmerauer Laboratoire d’Informatique Fondamentale de Marseille, CNRS et Universit´es de Provence et de la M´editerran´ee

Abstract. This paper provides a framework enabling to define and determine the complexity of various universal programs U for various machines. The approach consists of first defining the complexity as the average number of instructions to be executed by U , when simulating the execution of one instruction of a program P with input x. To obtain a complexity that does not depend on P or x, we then introduce the concept of an introspection coefficient expressing the average number of instructions executed by U , for simulating the execution of one of its own instructions. We show how to obtain this coefficient by computing a square matrix whose elements are numbers of executed instructions when running selected parts of U on selected data. The coefficient then becomes the greatest eigenvalue of the matrix. We illustrate the approach using two examples of particularly efficient universal programs: one for a three-symbol Turing Machine (blank symbol not included) with an introspection coefficient of 3 672.98, the other for an indirect addressing arithmetic machine with an introspection coefficient of 26.27.

1

Introduction

For the past several years I have been teaching an introductory course designed to initiate undergraduate students to low level programming. My approach was to start teaching them how to program Turing machines. The main exercise in the course consisted of completing and testing a universal program whose architecture I provided. The results were disappointing, the universal program being too slow for executing sizeable programs. Among others it was impossible to run the machine on its own code, in the sense explained in section 4. In subsequent years, I succeeded in designing considerably more efficient universal programs, even though they became increasingly more complex. These improved programs were capable to execute their own code in reasonable times. For simulating the execution of one of its own instructions, the last program executes an average number of 3 672.98 instructions, or more exactly its introspection coefficient – a key concept introduced in this paper – is equal to 3 672.98. This paper presents this result in a more general context concerning machines other then Turing machines. It is organized in 5 sections followed by an appendix. The first constitutes this introduction and the last the conclusion. Section 2 introduces the concepts of programmed machine, machine, program,

2 transition and instruction. Section 3 illustrates those concepts on three examples: Turing machines, Turing machines with internal direction (a useful variant of the previous machines), and an indirect addressing arithmetic machine. In Section 4, the main component of this paper, it is shown how to check the existence of introspection coefficients and how to compute their values. The proof of the theorem presented in that section is fairly lengthy. As most proofs it is omitted by lack of space. A more complete version of the paper, with all proofs, is under preparation. Sections 5 and 6 are devoted to two specially efficient universal programs: the first one, as already mentioned, for a Turing machine, the second one for an indirect addressing arithmetic machine. We are not aware of other work on the design of efficient universal programs. Let us however mention the well known contributions of M. Minsky [1] and Y. Rogozin [3] in the design of universal programs for Turing machines with very small numbers of states. Surprisingly, they seem particularly inefficient in terms of number of executed instructions.

2

Machines

2.1

Basic definitions

Definition 1 A programmed machine is an ordered pair (M, P ), where M is a machine and P a program for M. Definition 2 A machine M is a 5-tuple (Σ, C, α, ω, I), where Σ, the alphabet of M, is a finite not empty set; C, is a set, generally infinite, of configurations; the ordered pairs (c, c0 ) of elements of C are called transitions; α, the input function, maps each element x of Σ ? to a configuration α(x); ω, the ouput function, maps each configuration c to an element ω(c) of Σ ? ; I, is a countable set of instructions, an intruction being a set of compatibles transitions, i.e., whose first components are all distinct. Definition 3 A program P for a machineSM is a finite subset of the instructions 1 set I of M, such that the transitions of P are compatible. A configuration c S of M is final for P , if there exists no transition of P starting with c. 2.2

How a machine operates

Let M = (Σ, C, α, ω, I) be a machine and P a program for M. The operation of the machine (M, P ) is explained by the diagram:

1

x ↓ c0 −→ c1 −→ c2 S

···

cn−1

y ↑ −→ cn

P being a set of sets P denotes the set of elements which are member of at least one element of P and thus the set of transitions involved in program P .

3 and more precisely by the definition of the following functions2 , where x is a word on Σ and c, c0 configurations of C:  the longest sequence c0 , c1 , c2 , . . . with S orbit M (P, x) = c0 = α(x) and each (ci , ci+1 ) an element of P . (

%,

out M (P, x) =

if orbit(P, x) is infinite,

ω(cn ), if orbit(P, x) ends with cn

and, for dealing with complexity,  the shortest sequence of the form    (c0 , c1 ) (c1 , c2 ) (c2 , c3 ) . . . (cn−1 , cn ), track M (P, c, c0 ) = with c = c0 , each (ci , ci+1 ) ∈ S P , cn = c0 , if it exists,     %, if this shortest sequence does not exist,

track M (P, x)

 the longest sequence of the form = (c0 , c1 ) (c1 , c2 ) (c2 , c3 ) . . .  with orbit(P, x) = c0 , c1 , c2 , . . . . ( ∞,

cost M (P, x)

=

if track (P, x) is infinite,

|track (P, x)|, if track (P, x) is finite,

where |track (P, x)| denotes the length of the finite sequence track (P, x). 2.3

Simulation of a machine by another

Let M1 and M2 be two machines of same alphabet Σ and let P1 and P2 be the sets of their programs. Definition 4 Two programmed machines of the form (M1 , P1 ) and (M2 , P2 ) are equivalent if, for all x ∈ Σ ? , out M1 (P1 , x) = out M2 (P2 , x), cost M1 (P1 , x) = cost M2 (P2 , x). Definition 5 The program transformation f1 : P1 → P2 simulates M1 on M2 if, for all P1 ∈ P1 , the programmed machines (M1 , P1 ) and (M2 , f1 (P1 )) are equivalent.

3

Examples of machines

3.1

Turing machines

Informally these are classical Turing machines with a bi-infinite tape and instructions written [qi , abd, qj ], with d = L or d = R, meaning : if the machine 2

Index M is omitted when there is no ambiguity.

4 is in state qi and the symbol read by the read-write head is a, the machine replaces a by b, then moves its head one symbol to the left or the right, depending whether d = L or d = R, and change its state to qj . Initially the entire tape is filled with blanks except for a finite portion which contains the initial input, the read-write head being positioned on the symbol which precedes this input. When there are no more instructions to be executed the machine output the longest word which contains no blank symbols and which starts just after the position of the read-write head. Formally one first introduces an infinite countable set {q1 , q2 , . . .} of states and a special symbol u, the blank. For any alphabet word x on an alphabet of the form Σ ∪ {u}, one writes ·x for x, with all its beginning blanks erased, and x· for x, with all its ending blanks erased. Definition 6 A Turing machine has a 5-tuple of the form (Σ, C, α, ω, I) where, – Σ 6= Σu , with Σu = Σ ∪ {u}, – C is the set of 4-tuples of the form [qi , ·x, a, y·], with qi being any state, x, y taken from Σu? and a taken from Σu , – α(x) = [q1 , ε, u, x], for all x ∈ Σ ? , – ω([qi , ·x, a, y·]) is the longest element of Σ ? beginning y·, – I is the set of instructions denoted and defined, for all sates qi , qj and elements a, b of Σu , by def [qi , abL, qj ] = {([qi , ·xc, a, y·], [qj , ·x, c, by·]) | (x, c, y) ∈ E}, def

[qi , abR, qj ] = {([qi , ·x, a, cy·], [qj , ·xb, c, y·]) | (x, c, y) ∈ E}, with E = Σu? × Σu × Σu? . 3.2

Turing machines with internal direction

These are a variant of the above described Turing machines with an internal moving head direction whose initial value is equal to left-right. The instructions are written [qi , abs, qj ], with s = + or s = −, meaning : if the machine is in state qi and the symbol read by the read-write head is a, the machine replaces a by b, keeps its internal direction or changes it depending whether s = + or s = −, moves its read-write head one symbol in the new internal direction, and changes its states to qj . Formally we get: Definition 7 A Turing machine with internal direction has a 5-tuple of the form (Σ, C, α, ω, I) where, – Σ 6= Σu , with Σu = Σ ∪ {u}, – C is the set of 5-tuples of the form [d, qi , ·x, a, y·], with d ∈ {L, R}, qi being a state, x, y taken from Σu? and a taken from Σu , – α(x) = [R, q1 , ε, u, x], for all x ∈ Σ ? , – ω([d, qi , ·x, a, y·]) is the longest element of Σ ? beginning y·,

5 – I is the set of instruction denoted and defined, for all states qi , qj , all elements a, b of Σu and all s ∈ {+, −}, by def

[qi , abs, qj ] = {([d, qi , ·xc, a, y·], [L, qj , ·x, c, by·]) | (d, s) ∈ E1 and (x, c, y) ∈ F }} ∪ {([d, qi , ·x, a, cy·], [R, qj , ·xb, c, y·]) | (d, s) ∈ E2 and (x, c, y) ∈ F }, with E1 = {(L, +), (R, −)}, E2 = {(R, +), (L, −)} and F = Σu? × Σu × Σu? . 3.3

Relationship between the two types of Turing machines

Let M1 and M2 be machines of same alphabet Σ, the first one of type Turing and the second one of type Turing with internal direction, and let P1 and P2 denote the sets of their programs. As we will see, there exists a strong relation between these two types of machines. First it can be shown that: Property 1 The program transformations g1 : P1 → P2 and g2 : P2 → P1 , defined below, simulate M1 on M2 and M2 on M1 : def

g1 (P1 ) = {[q2i−h , abd, q2j−k ] | [qi , abs, qj ] ∈ P 0 and (h, k, d, s) ∈ E}, def

g2 (P2 ) = {[q2i−h , abs, q2j−k ] | [qi , abd, qj ] ∈ P and (h, k, s, d) ∈ E}, with

    (1, 1, +, R) (0, 1, −, R) E= ∪ . (1, 0, −, L) (0, 0, +, L)

Let us now introduce the following concepts concerning a program P` for M` , with ` = 1 or ` = 2. Definition 8 A state qi is reachable in P` , if i = 1 or if there exists a subset of P` of the form {[qk0 , a1 b1 e1 , qk1 ], [qk1 , a2 b2 e2 , qk2 ], . . . , [qkm−1 , am bm em , qkm ]}, with k0 = 1 ank km = i, the ai ’s and bi ’s being taken from Σ and the ei ’s being taken from {L, R} or {+, −}, depending on whether ` = 1 or ` = 2. Definition 9 For all subsets of P` of the form {[qk0 , a1 b1 e1 , qk1 ], [qk1 , a2 b2 e2 , qk2 ], . . . , [qkm−1 , am bm em , qkm ]}, with the ai ’s and bi ’s taken from Σ and the ei ’s from {L, R} or {+, −}, depending whether ` = 1 or ` = 2, the sequence of 3-tuples a1 b1 e1 , a2 b2 e2 , . . . , am bm em is called a potential effect of state qk0 . Two states occurring in P which have the same set of potential effects are said to be mergeable. Definitions 10 – reachable(P` ) denotes the set of instructions of P` involving reachable states of P` ,

6 – merged (P` ) denotes the program obtained by replacing in P , and in parallel, every occurrence of a state qi by the state qj of smallest index such that qi and qj are mergeable, – compact(P` ) denotes the program obtained by renaming each state qi of P` by qi0 in such a way that the integers i0 are as small as possible and that i < j entails i0 < j 0 , – clean(P` ) = compact(reachable(merged (P` ))). One proves that for ` = 1 and ` = 2: Property 2 The programmed machines (M` , clean(P` )) and (M` , P` ) are equivalent. One also proves that: Theorem 1 The program transformations f1 : P1 → P2 and f2 : P2 → P1 , defined by f = clean ◦ g` , with g` defined in Property 1, simulate M1 on M2 and M2 on M1 and are such that f2 ◦f1 ◦f2 ◦f1 = f2 ◦f1 and f1 ◦f2 ◦f1 ◦f2 = f1 ◦f2 .

3.4

Indirect addressing arithmetic machine

This is a machine with an infinity of registers r0 , r1 , r2 , . . .. Each register contains an unbounded natural integer. Each instruction starts with a number and the machine always executes the instruction whose number is contained in r0 and, except in one case, increases r0 by 1. There are five types of instructions: assigning a constant to a register, addition and subtraction of a register to/from another, two types of indirect assignment of a register to another and zero-testing of a register content. More precisely and in accordance with our definition of a machine: Definition 11 An indirect addressing arithmetic machine has a 5-tuple of the form (Σ, C, α, ω, I), where, – Σ = {c1 , . . . , cm }, – C is the set of infinite sequences r = (r0 , r1 , r2 , . . .) of natural integers, – α(a1 . . . an ) = (0, 25, 1, . . . , 1, r24+1 , . . . , r24+n , 0, 0, . . .), with r24+i equal to 1, . . . , m depending whether ai equals c1 , . . . , cm , – ω(r0 , r1 , . . .) = a1 . . . an , with ai equal to c1 , . . . , cm depending whether rr1+i equals 1, . . . , m, and n being is the greatest integer such that rr1 , . . . , rr1+n are elements of {1, . . . , m}, – I is the set of instructions denoted and defined, for all natural integers i, j, k, by:

7 [i, cst, j, k]

def

= {(r, s0 ) ∈ C 2 | r0 = 1, sj = k and si = ri elsewhere},

def

[i, plus, j, k] = {(r, s0 ) ∈ C 2 | r0 = 1, sj = rj +rk and si = ri elsewhere}, [i, sub, j, k]

def

= {(r, s0 ) ∈ C 2 | r0 = 1, sj = rj ÷rk and si = ri elsewhere},

def

[i, from, j, k] = {(r, s0 ) ∈ C 2 | r0 = 1, sj = rrk and si = ri elsewhere}, def

= {(r, s0 ) ∈ C 2 | r0 = 1, srj = rk and si = ri elsewhere},  r , if rj = 0, def [i, ifze, j, k] = {(r, s0 ) ∈ C 2 | r0 = 1, s0 = k and si = ri elw.}, r0 , if rj 6= 0 with s0 equal to s except that s00 = s0 + 1 and with rj ÷rk = max{0, rj −rk }.

[i, to, j, k]

4 4.1

Universal programs and codings Introduction

Let M = (Σ, C, α, ω, I) be a machine and let us code each program P for M by a word code(P ) on Σ. Definition 12 The pair (U, code), the program U and the coding function code, are said to be universal for M, if, for all programs P of M and for all x ∈ Σ ? , out(U, code(P ) · x) = out(P, x) .

(1) n

If in the above formula we replace P by U , and x by code(U ) · x we obtain: n+1

out(U, code(U )

n

· x) = out(U, code(U ) · x)

and thus: Property 3 If (U, code) is a universal pair, then for all n ≥ 0 and x ∈ Σ ? , n

out(U, code(U ) · x) = out(U, x) . 4.2

(2)

Complexity and introspection coefficient

Let (U, code) be a universal pair for the machine M = (Σ, C, α, ω, I). The complexity of this pair is the average number of transitions performed by U for producing the same effect as a transition of the program P occurring in the input of U . More precisely: Definition 13 Given a program P for M and a word x on Σ with cost(P, x) 6= ∞, the complexity of (U, code) is the real number denoted and defined by λ(P, x) =

cost(U, code(P ) · x) . cost(P, x)

8 The disavantage of this definition is that the complexity depends on the input of U . For an intrinsic complexity, independ of the input of U , we introduce the introspection coefficient of (U, code) whose definition is justified by Property 2: Definition 14 If for all x ∈ Σ ? , with cost(U, x) 6= ∞, the real number n+1

n

cost(U, code(U ) · x) n n→∞ cost(U, code(U ) · x)

lim λ(U, code(U ) · x) = lim

n→∞

exists and does not depend on x, then this real number is the introspection coefficient of the universal pair (U, code). 4.3

Keeping the same complexity and introspection coefficient

Let M1 and M2 be two machines, with same alphabet Σ, let P1 and P2 be the sets of their programms, let f1 : P1 → P2 and f2 : P2 → P1 be to program transformation and let (U2 , code 2 ) be a universal pair for M2 . Let us make the following hypothesis: Hypothesis 1 The transformation f1 simulates M1 on M2 , the transformation f2 simulates M2 on M1 and code 2 ◦ f1 ◦ f2 = code 2 . From Theorem 1 at page 6 it follows: Property 4 In the particular case where M1 is a Turing machine and M2 a Turing with internal direction, Hypothesis 1 is satisfied by taking the transformations f1 and f2 of Theorem 1 and by taking code 2 of the form code 02 ◦ f1 ◦ f2 , with code 02 a mapping of type P2 → Σ ? . For the sequel, let x, P1 , P2 respectivley denote an element of Σ ? , P1 , P2 . We have the following property: Property 5 With Hypothesis 1 and if P1 = f2 (P2 ) or P2 = f1 (P1 ), the pair (U1 , code 1 ), with U1 = f2 (U2 ) and code 1 = code 2 ◦ f1 , 1. is universal for M1 , 2. has a complexity λ1 (P1 , x), undefined or equal to the complexity λ2 (P2 , x) of the pair (U2 , code 2 ), depending whether the real number λ2 (P2 , x) is undefined or defined,3 3. admits the same introspection coefficient as (U2 , code2 ) or does not admit an introspection coefficient, depending whether (U2 , code2 ) admits or does not admit one, 4. is such that code 1 (P1 ) = code 2 (P2 ). 3

Of course λi (Pi , x) =

cost Mi (Ui , code i (Pi )·x) . cost Mi (Pi , x)

9 Proof Let us first prove claim 4. If P2 = f1 (P1 ), since code1 = code 2 ◦ f1 , we have code 1 (P1 ) = code 2 (f1 (P1 )) = code(P2 ). If P1 = f2 (P2 ), since code 2 = code 2 ◦ f1 ◦ f2 and code 2 ◦ f1 = code 1 , we have code 2 = code 1 ◦ f2 and thus code 2 (P2 ) = code 1 (f2 (P2 )) = code 1 (P1 ). Claim 1 is proven by the equalities below, where Q1 is any element of P1 : out M1 (Q1 , x) = out M2 (f1 (Q1 ), x) = out M2 (U2 , code 2 (f1 (Q1 ))·x) = out M1 (f2 (U2 ), code 2 (f1 (Q1 ))·x) = out M1 (U1 , code 1 (Q1 )·x).

(since (since (since (since

f1 simulates M1 on M2 ) (U2 , code 2 ) is universal for M2 ) f2 simulates M2 on M1 ) f2 (U2 ) = U1 and code 2 ◦ f1 = code 1 )

Claim 2 is proven by showing the equality of pairs     cost M1 (U1 , code 1 (P1 ) · x) cost M2 (U2 , code 2 (P2 ) · x) = . cost M1 (P1 , x) cost M2 (P2 , x)

(3)

First of all, cost M1 (U1 , code 1 (P1 )·x) = (since U1 = f2 (U2 ), code 1 (P1 ) = code 2 (P2 )) cost M1 (f2 (U2 ), code 2 (P2 )·x) = (since f2 simulates M2 on M1 ) cost M2 (U2 , code 2 (P2 )·x). Secondly, since f2 simulates M2 on M1 , if P1 = f2 (P2 ), and since f2 simulates M1 on M2 , if P1 = f2 (P2 ), we have cost M1 (P1 , x) = cost M2 (P2 , x). Finally claim 3 is proven by the sequence of equalities:   n cost M1 (U1 , code 1 (U1 ) · code 1 (U1 ) · x) = (by replacing P1 by U1 and n cost M1 (U1 , code 1 (U1 ) · x) x by code 1 (U1 )n · x in (3))   n cost M2 (U2 , code 2 (U2 ) · code 1 (U1 ) · x) = (since code 1 (U1 ) = code 2 (U2 )) n cost M1 (U2 , code 1 (U1 ) · x)   n cost M2 (U2 , code 2 (U2 ) · code 2 (U2 ) · x) . n cost M2 (U2 , code 2 (U2 ) · x) This completes the proof.

4.4

Existence and value of the introspection coefficient

Let (U, code) be a universal pair for a machine M = (Σ, C, α, ω, I). Given a word x on Σ, we assume that the computation of the word y by y = out(U, x) can be

10 synchronized with the computation of the same word y by y = out(U, code(U ) · x), according to the following diagram: x ↓

y ↑ 1

1

1

2

2

1

3

• −−−−→• −−−−→• −−−−→• −−−−→• −−−−→• y ↓ ↓ ↓ ↓ ↓ &↑

code(U )·x ↓ 4

3

1

2

3

3

2

3

3

3

1

3

3

1

5

5

•→→→• →→ • →→→ • →→→ • →→ • →→→→→ • More precisely we make the hypothesis: Hypothesis 2 There exists – a synchronization function Φ : CU → CU , with Φ(c) final for U when c is final for U , S – a labelling function µ : ( U )? → (1..n)? with n a positive integer andSµ being surjective, such that µ(t1 . . . tk ) = µ(t1 ) . . . µ(tk ), for all t1 . . . tk ∈ ( U )? , – an initial sequence of labels δ ∈ (1..n)? , independent of x, such that δ = µ(track (U, α(code(U )·x), Φ(α(x)))), for all x ∈ Σ ? , S ? – a label rewriting ϕ : 1..n → (1..n) such that, for all (c, c0 ) ∈ U , ϕ(µ(c, c0 )) = µ(track (U, Φ(c), Φ(c0 ))). We then introduce the column vector B and the square matrix A:   b1   bi = number of occurrences of i in δ, B =  ...  , bn (4)   a11 · · · ann  ..  , a = number of occurrences of i in ϕ(j). A =  ... .  ij a1n · · · ann and we conclude by the main theorem of the paper: Theorem 2 If the matrix A admits a real eigenvalue λ, whose multiplicity is equal to 1 and whose value is strictly greater than 1 and strictly greater then the absolute value λ0 of the other eigenvalues of A then: – the limit matrix A¯ = limn→∞ ( λ1 A)n exists and has at least one non-zero element, ¯ – if ||AB|| 6= 0, the introspection coefficient of U exists and is equal to λ, – if ` is a real number such that λ0 < ` < λ and the Xi ’s column vectors defined by X0 = B and Xn+1 = 1` AXn , then, when n → ∞, ( ¯ 0, if ||AB|| = 0, ||Xn || → ¯ ∞, if ||AB|| 6= 0. Here ||X|| denotes the sum of the components of X.

11

5

Our universals pairs for the two types of Turing machines

5.1

Introduction

We now present two particularly efficient universal pairs, (U1 , code 1 ), (U2 , code 2 ), one for the Turing machine M1 with alphabet Σ = {o, i, z} and the other for the Turing machine with internal direction M2 and same alphabet Σ. The pair (U1 , code 1 ) is built from the pair (U2 , code 2 ) by taking U1 = f2 (U2 ) and code 1 = code 2 ◦ f1 , where f1 and f2 are the program transformations introduced in Theorem 1 at page 6. Since code 2 will be of the form code 02 ◦ f1 ◦ f2 , according to Properties 4 and 5, the pair (U1 , code 1 ) is indeed universal for M1 and has the same complexity properties as the pair (U2 , code 2 ). Let us mention that U1 has 361 instructions and 106 states while U1 has only 184 instructions and 54 states. It remains to present the pair (U2 , code 2 ). 5.2

Coding function of the universal pair (U2 , code 2 )

In order to assign a position to each instruction [qi , abs, qj ] of a program for M2 , we first introduce the numbers:  1, if a = u    2, if a = o , π(i) = 21 (f (i, o) + f (i, i)), π(i, a) = 4(i − 1) + 3, if a = i    4, if a = z defined for any positive integer i and any symbol a ∈ {u, o, i, z}. Then let P2 be a program for M2 and let P20 = f1 (f2 (P2 )). We take code 2 (P2 ) = code 02 (P20 ), with code 02 (P20 ) the word on {o, i, z} zI4n z . . . zIk+1 zIk zIk−1 z . . . zI1 zoi . . . izz, where n is the number of states of P20 , where the size of the shuttle oi . . . iz is equal to the longest size of the Ik ’s minus 5, and where, for all a ∈ Σu and i ∈ 1..n, ( [qi , abs, qj ], if there exists b, s, j with [qi , abs, qj ] ∈ P20 , Iπ(i,a) = oi, otherwise, with, [qi , a, b, s, qj ] =

( iam . . . a2 o, if π(j) − h(i, a) > 0, oa2 . . . am i, if π(j) − h(i, a) < 0,

with a2 a3 equal to io, oi, ii, depending whether b equals u, o, i, z, with a4 = o or a4 = i depending whether s = + or s = − and with iam . . . a5 a binary number (o for 0 and i for 1) whose value is equal to |π(j) − π(i, a)| + 23 .

12 5.3

Operation of the universal pair (U2 , code 2 )

As already mentioned, the program U2 has 54 states, q1 , . . . , q54 , and 184 instructions. These instructions are divided in 10 modules A, B, C, . . . , J organized as follows: 0

A Start I N S T R U C T I O N L O C A L I Z A T I O N

I Instruction orien tation test

8

1

J End

B Shuttle direction updating

H Shuttle reversing

7

2

G Shuttle counter decreasing

C Shuttle counter initialization

6

3

F Moving shuttle to next z

D Writing, moving, reading E Shuttle counter updating

5

9

I N S T R U C T I O N E X E C U T I O N

4

The numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 denote respectively the states q1 , q24 , q35 , q43 , q49 , q15 , q13 , q7 , q10 , q23 . The complete program U2 is given in the appendix as a graph whose vertices are the states and the edges the instructions of U2 : each instruction [qi , abs, qj ] is represented by an arrow, labeled abs, going from qi to qj . Note that the vertices a, b, c and 7 have two occurrences which must be merged. Initial configurations Initially the machines executing P2 is in the configuration

· · · uu x uu · · · ↑ R q 1 P2 and the machine executing u2 is in the correponding initial configuration code (P )

z

}|

{

. . . uu zI4n z . . . zIk+1 zIk zIk−1 z . . . zI1 zoi . . . izz | {z } ↑ shuttle R q 1 P2

x

uu . . .

While the machine executing P2 performs no transitions, the machine executing U2 performs a sequence of initial transitions, always the same, involving the

13 instructions of module A and some instructions already there in the modules I, H, G, F . Then the machines executing P2 and U2 end up respectively in the following current configurations with k = 1: Current configurations configuration

While the machine excuting P2 is in the current

v

a w ↑ d q i P2

the machine executing U2 is in the corresponding current configuration standard shuttle z }| {

v

uzzI4n z . . . zIk+1 zIk zd0 u . . . uzIk−1 z . . . zI1 zu ↑ L q24 U2

w (5)

or reversed shuttle z }| {

v

uzzI4n z · · · zIk+1 zu . . . ud0 zIk zIk−1 z · · · zI1 zu ↑ R q22 U2

w (6)

depending whether Ik , with k = π(i, a), is in the standard form iam . . . a2 o or in the reversed form iam . . . a2 o. The read-write points to a3 or to the z which follows Ik when Ik is the empty instruction oi. Depending whether d is equal to L or R, the symbol d0 is equal to u or o, if Ik is standard, and to o or u, if Ik is reversed. While the current configuration of P2 is not final, P2 performs one transition for reaching the next current configuration and U2 performs a sequence of transitions for reaching the next corresponding current configuration. More precisely, using the information contained in Ik , the program U2 – updates the internal direction contained in the shuttle (module B), – transfers in the shuttle the binary number serving as basis for computing the number of instructions to be jumped toward the left or the right, depending on whether the shuttle is standard or reversed (module C), – simulates the writing of a symbol, the read-write head move, and then the reading of a new symbol (module D), – taking into account the read symbol, updates the binary number contained in the shuttle in order to obtain the right number of instructions to be jumped by the shuttle for reaching the next instruction to be executed (module E), – moves the shuttle and eventually reverses it, for correctly positioning it alongside the next instruction to be executed (modules F, G, H, I).

14 When the current configuration of P2 becomes final, the corresponding current configuration of U2 is of the form (6) with Ik equal to the empty instruction oi. Then U2 performs a sequence of transitions (module J) for reaching the final corresponding configurations. The machines executing P2 and U2 end up respectively in the following final configurations: Final configurations While the machine executing P2 terminates in the final configuration

b y u ↑ d q m P2 the machine executing U2 terminates in the corresponding final configuration

uzzI4n z · · · zIk+1 zu . . . ud0 zIk zIk−1 z · · · zI1 zu y u ↑ D q23 U2 with Ik = oi, k = π(m, b) and d0 equal to o or u, depending whether d equals L or R.

6 6.1

Complexity and introspection coefficient of our two pairs General complexity

Let P2 be any program for M2 . From the way the coding function code 2 is defined, for ` = 2, |code ` (P` )| = O(n log n) , where n is the number of states of clean(P` ). This result also holds for ` = 1, with P1 being any program for M1 , the classical Turing mchine with same alphabet as M2 . This is due to the fact that code 1 (P1 ) = code 2 (f1 (P1 )) and that the number of instructions of clean(f1 (P1 )) is at most equal to twice the number of instructions of P1 . Returning to the way U2 operates at section 5.3, we conclude that if P2 performs h transitions then there exists positive integers ki indepent of h or n such that U2 performs at most: – k1 log2 n transitions for reaching the first configuration corresponding to the initial configuration of P2 , – hk1 log2 n transitions for transferring information from an instruction Ii to the adjacent shuttle, – hk2 n log n transitions for simulating the writing of a symbol, the move of the head and the reading of a symbol,

15 – hk3 n log2 n transitions for moving the shuttle, – hk4 n log2 n transitions for reaching a final configuration from a configuration corresponding to a final configuration of P2 , that is all together, at most hk5 n log2 n transitions. Thus for ` = 2, there exists a positive real number k, independent of x ∈ Σ ? , such that λ` (P` , x) ≤ n log2 n If instead of measuring the complexity in terms of n we do it in terms of m = |code ` (P` )|, we conclude that there exists a positive real number k, independent of x ∈ Σ ? , such that λ` (P` , x) ≤ m log m These two results also hold also for ` = 1, with P1 being any program for M1 . 6.2

Complexity on examples

On particular examples we have obtained the following complexity results for the pairs (U` , code ` ), with ` = 1 and ` = 2, cost( cost(U` , cost(U` , code ` (U` )· λ (U , λ` (P` , x) ` ` P` , x) code ` (P` )·x) code ` (P` )·x) code ` (P` )·x) ε 2 5 927 22 974 203 2 963.50 3 876.19 o 6 13 335 51 436 123 2 222.50 3 857.23 oi 12 23 095 88 887 191 1 924.58 3 848.76 oiz 20 35 377 136 067 693 1 768.85 3 846.22 oizo 30 49 663 190 667 285 1 655.43 3 839.22 x

Here P` , with P1 = f2 (P2 ), is a reversing program such that, for all n ≥, one gets out(P` , a1 a2 . . . an ) = an . . . a2 a1 , with the ai ’s taken from {o, i, z}. In both cases, ` = 1 and ` = 2, the program P` has 32 instructions and 9 states. We have |code ` (P` )| = 265 and |code ` (U` )| = 1552. 6.3

Introspection coefficient

To satisfy Hypothesis 2, code 2 (U2 ) = f1 (f2 (code 2 (U2 ))) and the labelling S function µ is defined so that, for all transitions (c1 , c2 ) and (c01 , c02 ) of U2 the integers µ(c1 , c2 ) and µ(c01 , c2 0) are equal if and only if all the conditions below are satisfied: – – – –

the the the the

states of c1 and c01 are equal, symbols pointed by the read-write heads in c1 and c01 are equal, symbols pointed by the read-write heads in c2 and c02 are equal, directions in c2 and c02 are the same.

16 The function Φ is defined, for all configuration of U2 , with P2 = U2 by, ( current configuration corresponding to c, if c is not final for P2 , Φ(c) = final configuration corresponding to c, if c is final for P2 . After having computed the column vector B and the matrix A, using Theorem 2, we have verified that U2 admits an introspect coefficient and computed its value: for ` = 2 and all words x on Σ such that cost(P, x) 6= ∞, cost(U` , code ` (U` )n+1 ·x) = 3 672.98 n→∞ cost(U` , code(U` )n ·x) lim

This result also holds for ` = 1.

7

Our universal program for the indirect addressing arithmetic machine

It is interesting to compare the complexities of our universal program for a Turing machine with the complexity of a universal program for the indirect addressing arithmetic machine with same alphabet Σ = {c1 , c2 , c3 }, with c1 = o, c2 = i and c3 = z. We have written such a universal program U3 using 103 instructions. From the operation of our universal pair (U3 , code 3 ) we have been able to show that: Property 6 There exists a positive number k such that, for all programs P3 and word x on Σ, with cost(P3 , x) 6= ∞, λ3 (P3 , x) =

cost(U3 , code 3 (P3 ) · x) |code(P )| ≤ 35 + k cost(P3 , x) cost(P3 , x)

Thus the size of the program P3 becomes irrelevant when a large number of transitions is performed. On particular examples we have obtained the following results: cost( cost(U3 , cost(U3 , code 3 (U3 )· λ (U , λ3 (P3 , x) 3 3 P3 , x) code 3 (P3 )·x) code 3 (P3 )·x) code 3 (P3 )·x) ε 12 2 372 72 110 197, 66 30, 40 o 16 2 473 74 758 154, 56 30, 23 oi 31 2 860 84 916 92, 26 29, 69 oiz 35 2 961 87 564 84, 60 29, 57 oizo 50 3 348 97 722 66, 96 29, 19 x

where P3 is a reversing program of 21 instructions such that, for all n ≥ 0 one obtains out(P, a1 a2 . . . an ) = an . . . a2 a1 , with the ai ’s taken from {o, i, z}. Additionally, |code 3 (P3 )| = 216 and |code 3 (U3 )| = 1042. The introspection coefficient obtained is: cost(U3 , code(U3 )n+1 ·x) = 26.27 n→∞ cost(U3 , code(U3 )n · x) lim

17

8

Conclusion

Unless one “cheats”, it is difficult to improve the introspection coefficient of our universal Turing machine which took us considerable development effort. Suppose, which is the case, that we have at our disposal a first universal pair (U, code) for a Turing machine. A first way of cheating consists of constructing the pair (U, code 0 ) from the universal pair (U, code), with  ε, if P = U , code 0 (P ) = code(P ), if P 6= U . Then we have

cost(U 0 , code(U 0 )n+1 ·x) cost(U 0 , code(U 0 )n ·x)

=

cost(U 0 , x) cost(U 0 , x)

=1

and (U, code 0 ) is a universal pair with an introspection coefficient equal to 1. There is a second more sophisticated way of cheating, without modifying the coding function code. Starting from the universal program U we construct a program U 0 , which, after having erased as many times as possible a given word z occurring as prefix of the input, behave as U on the remaining input. According to the recursion theorem [2, 4], it is possible to take z equal to code(U 0 ) and thus to obtain a universal program U 0 such that, for all y ∈ Σ ? having not code(U )0 as prefix, cost(U 0 , code(U 0 )n · y) = nk1 + k2 (y), where k1 and k2 (y) are positive integers, with k1 being independent of y. Then we have cost(U 0 , code(U 0 )n+1 ·y) cost(U, x)+(n+1)k1 +k2 (y) = cost(U 0 , code(U 0 )n ·y) = cost(U, x)+nk1 +k2 (y) 1+

k1 cost(U, x)+k2 (y)+nk1 .

By letting n tend toward infinity we obtain an introspection coefficient equal to 1 for the pair (U 0 , code). Unfortunately our introspection coefficient definition, page 8, does not disallow these two kinds of cheating. By imposing Hypothesis 2, the first way of cheating is still possible and the second one can be prevented by imposing that the function ϕ never produces the empty sequence. But this last restriction seems to be ad hoc. What one really would like to prevent is that the function code or the program U “behaves differently” on the program P , depending whether P is or is not equal to U . It is an open problem to express this restriction in the definition of the introspection coefficient.

References 1. Marvin Minsky, Computations: Finite and Infinite Machines, Prentice-Hall, 1967. 2. Hartley Rogers, Theory of Recursive Functions and Effective Computability, McGraw-Hill, 1967, also MIT Press, fifth printing, 2002.

18 3. Yurii Rogozin, Small universal Turing machines, Theoretical Computer Science, Volume 168, number 2, november 1996. 4. Michael Sipser, Introduction to the Theory of Computation, PWS Publishing Company, 1997.

19

Appendix: graph of the universal program U2 iu+ oo+ ui+ zu−

0 z i z i + +

7

o u o z + +

zz+ uo−

uu+

oo+

+ + +

ii+

uu−

o i z o i z + + +

iu−

zz+ uu+

b

oo+

ou−

io−

oi− o i z o i z + + +

iu+

7

iu− iu+

uu− oi+

ui+ uu−

zz− io+

u o i u o u + + +

uo+ zz−

ou+ ou−

z i o z i o + + +

6

zz−

u o +

o i o i + +

zz+ oo+

zi+ ii+

2 oz− zu+ iu+

o i z o i z + + +

uo+

zz−

iu−

oi+ zo+ iz−

o i z i o u + + −

oo+ ui+ io+ ou+ uo+ uz+ oz+

uu+

zo−

ui+ i o i o + +

oo+ ii+

oo+ ii+

o i o i + +

uz+

zu+ uu+

zz−

ii−

uo+

zi−

uu+

i o u i o u + + +

oo−

oo+

zi+ oi− ii−

5

3

z i z i + +

o u o u + +

oo−

uu− ou− iu− zu− uz+

z i o z i o + + +

zz−

z i o z i o + + + uu−

zu−

iz− zz−

io− o i + oz+ zz−

o i z o i z + + + ui o u ou u i −− − −

uu− uz+

o i z o i z + + + uz−

oz−

uz− io−

b

oo+

iz+

a oo+ oo− zz+

uo+

zz+

iu+

ii+

oo+

oz+ oz+

i o u i o u + + +

4

i z

9 o i z

ii+

zz−

a

o

zz+

1

d ii− zz+

d

zz−

ii+

oo+

c

ui−

c oo+

oo+

zz+

8

zu+ uu+

zo+ oi+ iz+ zi+ ii+

ou+ io+ ui+ iu+