<<

Primitive recursive functions: problems

Armando B. Matos

October 24, 2014

Abstract

Although every primitive recursive (PR) function is total, many prob- lems related to PR functions are undecidable. In this work we study several questions associated with PR functions and characterize their de- gree of undecidability. For instance, we show that the injectivity problem 0 0 belongs to the class Π1 \ ∆0 of the arithmetic hierarchy, while the surjec- 0 0 0 tivity and the bijectivity problems belong to Π2 \ (Σ1 ∪ Π1). It follows that these subclasses of PR functions can not be enumerated – and thus cannot be characterized by an effective property. Several other PR deci- sion problems are studied such as, problems related to the existence and number of zeros, and problems related to the size of the codomain. We consider a specific but important , “does a given PR function has at least one zero?”, and establish the necessary and suf- ficient input and output restrictions for decidability – the “frontiers of decidability” of this problem. We also study undecidability results for a more general class of problems, namely existential first order with and composition of PR functions. A PR function as a part of an “acyclic PR function graph” is also studied. This setting may be useful to evaluate the relevance of a specific PR function as a component of a larger PR structure.

1 Contents

1 Introduction3 2 Preliminaries5 2.1 Languages, reductions and the arithmetic hierarchy...... 6 2.2 Decision problems...... 8 2.3 Models of computation...... 9 2.4 Primitive recursive functions...... 10 2.5 Context free grammars...... 10 3 Decision problems associated with PR functions 12 3.1 Some undecidable problems...... 12 3.2 Size of the codomain...... 18 3.3 Injectivity, surjectivity, and bijectivity...... 19 3.4 Primitive recursive versus partial recursive problems...... 22 4 Frontiers of decidability: the HAS-ZEROS problem 29 4.1 The meaning of restricted HAS-ZEROS problems...... 31 4.2 The HAS-ZEROS-f·g class of problems...... 32 4.3 The HAS-ZEROS-h·f class of problems...... 34 4.4 The HAS-ZEROS-h·f·g class of problems...... 34 4.5 A generalization: the output of g is a tuple...... 35 4.6 Using HAS-ZEROS-h·f·g to analyze other decision problems.. 35 4.7 Classifying a problem – testing the properties of g and h ..... 35 5 Generalizations of the PR decision problems 36 5.1 Existential first order logic with PR functions...... 37 5.2 A PR function f in an acyclic PR structure: normal form.... 38 5.3 Composition of f with itself...... 42 6 Comment: on a paper by Stefan Kahrs 45 7 Conclusions and open problems 47

2 1 Introduction

The primitive recursive (PR) functions form a vast and important enumerable sub-class of the class of recursive (total) functions. Its vastness is obvious from the fact that every total recursive function whose is bounded by a primitive recursive function is itself primitive recursive, while its importance is well expressed by the Kleene normal form [23,3, 32] and by the fact that every recursively enumerable set can be enumerated by a primitive recursive function1. The meta-mathematical and algebraic properties of PR functions have been widely studied, see for instance [23, 36, 34, 41, 37]. Special subclasses (such as unary PR functions, see for instance [35, 39]) and hierarchies (see for instance [18,1, 28, 30,2, 14] and [44, Ch. VI]) of PR functions were also analyzed. Efficiency lower bounds of primitive recursive have also been studied, see [4,5,6,8, 30, 31, 12, 43, 42]. In this work we concentrate on decidability questions related to PR functions. There are several questions related to PR functions that are known to be un- decidable. For instance, the question “given a PR function f(x, y) and an integer x, is there some y such that f(x, y) = 0?” is undecidable ([3]). In this paper we show that many other questions related to PR functions are unde- cidable, and classify their degree of undecidability according to the arithmetic hierarchy. Let us mention two examples of the problems studied in this work: “does a given PR function have exactly one zero?”, and “is a given PR function surjective (onto)?”. The undecidability of some of these problems has consequences. For instance, when studying reversible computations, it would be useful to have a method for enumerating the bijective PR functions. As we will see, that is not possible: although the set of PR functions is enumerable, the set of bijective PR functions 0 0 0 is not: it belongs Π2 \ (Σ1 ∪ Π1). We also study classes of PR problems in which a PR function f is a part of a larger PR system S. We obtained a simple decidability condition for the case in which S(x) = h(f(g(x))), where g and h are fixed PR functions, but not for the general case illustrated in Figure1 (page4). Organization and contents of the paper. The main concepts and results needed for the rest of the paper are presented in Section2 (page5). The rest of the paper can be divided in two parts.

1In the sense that, if is recursively enumerable, there is a primitive recursive function f such that L ∪ {0} = {f(i): i ∈ N}.

3 x f y

S

Figure 1: A PR function f is considered to be an important part of a complex structure S if the following problem is undecidable: instance: f, question: “∃x : S(x) = 0?”. We will show that an arbitrary acyclic system S containing one occurrence of f can always be reduced to the normal form illustrated in Figure9 (page 43).

Part I, specific problems

In Section3 (page 12) several decision problems associated with PR functions are studied. These problems include the existence of zeros, the equivalence of functions, “domain problems”, and problems related with the injectivity, surjectivity, and bijectivity of PR functions. For each of these problems the degree of undecidability is established in terms of their exact location in the in the arithmetic hierarchy; see Figures2 (page 23) and3 (page 23).

Part II, classes of problems

Suppose that the PR function f, the instance of a decision problem, is “placed” somewhere inside a larger PR system S, see Figure1. In algebraic terms this means that S is obtained by composing fixed PR functions with the instance f. A more general form of composition, based on acyclic graphs is also studied, see Figure8 (page 40). Then we ask an important question about y = S(x), namely, “∃x : S(x) = 0”? This is in fact a fundamental question:

– In terms of the Kleene normal form, the existence of a zero is the basic undecidable question, and it is intimately related – in fact, equivalent – to the .

– Many other decision problems can be reduced to this problem.

The class of problems, parametrized by S, is: Instance: A PR function f. Question: Is there some x such that S(x) = 0? In some sense we can say that f can be considered an important component of S if (and only if) this problem is undecidable.

4 Part II of this work includes

– Section4 (page 29), where we study the “frontiers of decidability” of the problem “does a given PR function has at least one zero?”. More precisely, we find the input and output restrictions that are necessary and sufficient for decidability; these restrictions are obtained by pre- or post-applying fixed PR functions to the PR function which is the instance of the problem. This is a particular form of the arbitrary composition described above.

– A more general setting in considered in Section5 (page 36), where we study existential first order logic with equality and composition of PR functions and also “acyclic PR” structures. The problem of composing the instance PR function f with itself is also studied.

– Section6 includes some comments on Kahrs method.

The initial motivation for this work was to generalize Rice Theorem to PR functions. Rice Theorem is simple: for any non trivial mathematical property of a partial recursive function, it is undecidable whether the function, defined by a given description (or index), has that property. A version of Rice Theorem applicable to to PR functions is necessarily more complex because, unlike the case of partial recursive functions, only quantified questions can be undecidable. Questions like “given a description of f, is f(2) = 5?” are clearly decidable. A result of this paper that can be seen as a first step to such a “Rice-like PR Theorem” is Theorem 24 (page 34).

2 Preliminaries

The notation used in this paper is straightforward. “Iff” denotes “if and only if” and “def=” denotes “is defined as”. The logical negation is denoted by “¬”. The complement of the set A is denoted by A, while the difference between the sets A and B is denoted by A \ B. A function f : A → B is injective (or one- to-one) if x 6= y implies f(x) 6= f(y); it is surjective (or onto) if for every y ∈ B there is at least one x ∈ A such that f(x) = y; and it is bijective if it is both injective and surjective. By f −1(y) we denote the set {x : f(x) = y}. The letters of the alphabet are denoted by 0, 1, a, b. . . ; the words by x, y. . . The length of the word x is denoted by |x|. For n ≥ 0, the sequence of arguments “x1, x2, . . . , xn” is denoted by x. A function f(x) with zero arguments (n = 0) is a constant.

Definition 1 Let x = hx1, . . . , xni and y = hy1, . . . , ymi; by y = f(x) we mean that, for 1 ≤ i ≤ m, each of the yi is a function of x. We say that f is a multiple function.

Some fixed computable bijection for coding words as integers is assumed.

5 We will use the following word order, where x and y are words, see for in- stance [27]. x < y iff (i) |x| < |y| or (ii) |x| = |y| and x < y in lexicographic order.

2.1 Languages, reductions and the arithmetic hierarchy

The terms “unsolvable”, “recursively unsolvable” ([38]), and “undecidable” will be used interchangeably. It is assumed that the reader is familiar with the arithmetic hierarchy of lan- guages (AH), see for instance [32, 38, 23, 26, 25, 24, 20]. The arithmetic hi- erarchy is used in this paper with the purpose of measuring the degree of un- decidability of PR decision problems. This is usual in Recursion Theory, see for instance its use for problems studied in [10, 40]. This is similar to the classification of the difficulty of a (decidable) problem in the hierarchy (PH). The only important definitions and results that the reader should be aware are mentioned in the beginning of the Chapter 14 of [38], namely:

0 0 – A relation is in the arithmetic hierarchy if R is recursive (Class Σ0 = Π0) or if there is a recursive relation S such that R can be obtained from S by a finite sequence of complement and/or projection operations.

– Theorem I, page 302, Theorem III, page 307.

– The relationship between the classes of the AH (and of the PH) and the sequence of alternating quantifiers in the question associated with the decision problem. Se for instance Sections 14.1 and 14.2 of [38]. More 0 0 precisely, a decision (or complexity problem) belongs to Σn or Πn iff the formula of the associated question, written in prenex normal form, has n (alternating) quantifiers in the prefix, the outer one being, respec- tively, existential or universal (partial transcription from [32]). See for instance [32] (Definition IV.1.6, page 367), [38] (Chapter 14, Theorem I, page 302), and [13] (Chapter 7, Theorem 7.4, page 163).

– A relation R is in AH iff R is definable in elementary arithmetic (definition in [38]). This property justifies the name “arithmetic” for a hierarchy of relations or functions.

In the literature the superscript 0 is sometimes omitted.

0 0 0 We denote by ∆ the set Σ0 = Π0 = ∆0. Thus the class of recursively enumer- 0 able, but not recursive sets is Σ1 \ ∆. The following table lists some AH classes (languages) and the descriptions of the corresponding decision problems.

6 AH class Decision problem 0 Σ1 Semi-decidable 0 Σ1 \ ∆ Undecidable, semi-decidable 0 Π1 Complement of a semi-decidable problem 0 Π1 \ ∆ Undecidable, complement of a semi-decidable prob- lem 0 0 0 Σ2 \ (Σ1 ∪ Π1) Neither semi-decidable nor the complement of a semi-decidable problem, but expressible as “∃x ∀y : P (x, y)”, where P is decidable (see the references to the AH cited above) and x and y represent tuples of variable.

Given this correspondence, we will sometimes abuse the language, using an AH class to denote either a decision problem or the corresponding language.

Definition 2 (many-one, PR ) Suppose that the languages L and M are defined over the alphabets ΣL and ΣM respectively. L reduces (many-one) ? ? to M, L≤mM, if there is a primitive recursive function f :ΣL → ΣM such that x ∈ L if and only if f(x) ∈ M.

If L≤mM,

1. M ∈ ∆ implies L ∈ ∆. Proof. To decide if “x ∈ L” compute f(x) and use the decision for “f(x) ∈ M”.

2. L≤mM. Proof. “x ∈ L iff f(x) ∈ M” is the same as “x ∈ L iff f(x) ∈ M”.

0 0 3. M ∈ Σ1 implies L ∈ Σ1. Proof. Assuming that M is enumerable, use the following procedure to enumerate L Y ← ∅ loop Enumerate the next element y of M. Y ← Y ∪ {y}. ? Consider the next element x of ΣL. Compute f(x). If f(x) ∈ Y , list x. For every x0 < x that was not listed, if f(x0) = y, list x0. endloop

0 0 4. M ∈ Π1 implies L ∈ Π1. Proof. Use properties2 and3.

Note. Properties3 and4 imply Property1.

A set P is ≤m-complete in the class C if P ∈ C and Q≤mP for every Q ∈ C.

7 2.2 Decision problems

The following three well known decision problems are undecidable, but semi- 0 decidable, i.e. they belong to the class Σ1 \ ∆ [3, 19, 32,9].

Definition 3 HP, halting problem. Instance: a T and a word x. Question: does the computation T (x) halt?

Definition 4 SHP, self halting problem. Instance: a Turing machine T . Question: does the computation T (i) halt, where i is a G¨odelindex of T ?

Definition 5 PCP, Post correspondence problem. Instance: two finite sets of non-null words, {x1, . . . , xn} and {y1, . . . , yn}, defined over the same finite alphabet with at least two letters.

Question: is there a finite non-null sequence i1, . . . , ik such that xi1 xi2 . . . xik = yi1 yi2 . . . yik ?

Another important is the following.

Definition 6 TOTAL, is a function total? Instance: a partial recursive function f(x) given by a Turing machine T . Question: Is f(x) defined for every x?

Theorem 1 The language associated with the TOTAL problem belongs to the 0 0 0 class Π2 \ (Σ1 ∪ Π1).

Proof. (See for instance [33]). 0 (i) LTOTAL ∈ Π2. The TOTAL “question”, with instance f(x), can be written ∀x ∃t :(F (x, t) = 1) where F (x, t) is the PR function

 0 if T (x) does not converge in t steps F (x, t) = 1 otherwise and T is a Turing machine that computes f. 0 (ii) LTOTAL 6∈ Σ1. Reduction (¬HP)≤mTOTAL: using a Turing machine T that computes f, de- fine g as follows (using the Smn Theorem)  def 1 if T (x) does not converge in t steps g (t) = f(x, t) = x undefined otherwise

Clearly gx is a total function iff T (x) does not halt. 0 (iii) LTOTAL 6∈ Π1.

8 Reduction HP≤mTOTAL: given the instance hT, xi of HP, define the func- tion g(y) that (ignores the input y and) simulates the computation T (x); if it halts, the output is 0; if not, g(y) is undefined. The function g(y) is total iff the computation T (x) halts. 

2.3 Models of computation

Deterministic finite automata (DFA), Turing machines (TM), and Context free grammars (CFG) and examples of “models of computation”. In order to find the properties that a model of computation should satisfy, let us begin with an example. Every Turing machine M can be uniquely described by a word2 d(M) that encodes its properties: states, initial state, final states, transition function. Alternatively a Turing machine can be described by its G¨odelindex. Thus, the descriptions of Turing machines can be effectively enumerated by the following method, where for simplicity, we assume that the alphabet of the description is a, b.

– Successively generate in order all words x = ε, a, b, aa, ab, . . . Whenever x is the description of a Turing machine, output x.

If i is a G¨odelindex of the Turing machine T , the partial function implemented by T is denoted by φi or alternatively by {i}. When we write φi(x) = y we mean two things:

1. The corresponding computation halts; we write “(the computation corre- sponding to) φi(x) halts”; instead of φi(x) we can of course write {i}(x). 2. The output of the computation is y.

The “dovetailing” technique

Consider a recursively enumerable set of Turing machines M1, M2. . . and sup- pose that we want to list the outputs of all the computations Mi(x) for some fixed x. That is, for every i, if the computation Mi(x) halts, its output is listed. This can be effectively done by the following method: – Successively simulate one step of computation for each machine, in the fol- lowing order

Machine: M1 M1 M2 M1 M2 M3 M1 M2 M3 M4 M1 ... Step: (1) (2) (1) (3) (2) (1) (4) (3) (2) (1) (5)

Note that every machine Mi is completely simulated: either “forever” or until it halts. During this simulation, whenever some machine Mi halts, print its output. 2In fact by an infinity of “equivalent” words.

9 Properties of a model of computation

The fundamental assumptions associated with the intuitive idea of “model of computation” are the following.

Assumption 1 Every instance of a “model of computation” is codified in a word such that

(i) There is an algorithm that tests if a given word is a valid characterization of an instance of the model. As a consequence, the set of valid character- izations is effectively enumerable. (ii) From a valid word it is be possible to effectively “extract” the semantic properties of the instance it represents.

We may for instance conclude that no model of computation characterizes the set of total recursive functions because that set is not enumerable (see for in- stance [33]).

2.4 Primitive recursive functions

It is assumed that the reader is familiar with the classical definition of primitive recursive functions [3, 32], with the usage of register languages to characterize those functions (particularly with the Loop language [28, 29]), and with the Kleene normal form theorem [23,3]. The binary function “−· ” defined below is PR

 x − y if x ≥ y x −· y = 0 otherwise

The following property will be useful.

Property 1 Let a and b be arbitrary integers. Then a = b if and only if (a −· b) + (b −· a) = 0.

The Smn Theorem will often be used without mention.

Theorem 2 (Smn Theorem) Given a G¨odelnumbering ϕ of PR functions, there is a PR function s of two arguments such that: for every G¨odelnumber p of a partial recursive function f(x, y) with two arguments, ∀x, y : f(x, y) = ϕs(p,x)(y). In the sequel the function ϕs(p,x)(y) will often be denoted by fx(y).

2.5 Context free grammars

The language generated by the context-free grammar (CFG) G is denoted by L(G). A CFG G is ambiguous if there is at least one word in L(G) with

10 more than one leftmost derivation. In this definition we can replace “leftmost derivation” by “parsing tree”. The symbols “→” and “⇒” will be used with the usual meaning.

Definition 7 A CFG is ε-free if it has no productions of the form A → ε.

Theorem 3 For every CFG G there is an ε-free grammar G0 such that L(G0) = L(G) \{ε}.

Theorem 4 For every CFG G there is a primitive recursive parser that recog- nizes L(G).

Proof. In an ε-free grammar, w ⇒ z implies |w| ≤ |z|. To see if x ∈ L(G), we can use a brute force search in which every derivation that contains the same word twice, S ⇒ ... ⇒ w ⇒ ... ⇒ w . . ., is discarded, i.e. the search tree is pruned. A PR bound on the length of every possible derivation can thus be established and this algorithm can be “implemented” as a primitive recursive function. 

Definition 8 Given a CFG G, the extended grammar G0 is the CFG that con- tains all the letters, non-terminals, and productions of G plus the productions “S → C”, “C → c”, and “C → Cc” where S is the initial of G (and of G0), C is a new non-terminal symbol, c is a new letter. We say that G0 is an “extended context free grammar” or E-CFG. The problem of deciding if a given E-CFG is ambiguous is called the E-CFG ambiguity problem, or E-CFG-amb.

Clearly, G is ambiguous iff G0 is ambiguous, and L(G0) = L(G) ∪ {c, , ccc . . .} (disjoint union).

Theorem 5 The E-CFG ambiguity problem is undecidable.

Proof. We reduce PCP to the E-CFG ambiguity problem. Let the PCP instance be {x1, . . . , xn}, {y1, . . . , yn} (n ≥ 1) and let a1,. . . , an, and c be new letters. Consider the E-CFG G S → A | B | C A → xiAai | xiai for i = 1, 2 . . . , n B → yiBai | yiai for i = 1, 2 . . . , n C → c | Cc

In G every derivation is leftmost. There are at most two possible derivations of a word not containing the letter c, starting with “S ⇒ A” and “S ⇒ B”. Due to the presence on the right of the “new” letters ai, they correspond to a solution of the PCP problem. Conversely, if the PCP has a solution, the E-CFG G is ambiguous. 

11 3 Decision problems associated with PR functions

We study the decidability of some problems in which one (f) or two (f and g) primitive recursive functions are given as the instance. First, in Section 3.1, we study several problems related to the existence of zeros of the function f and to the equivalence of the functions f and g, then, in Section 3.2, some properties related to the codomain of f are studied, and finally, in Section 3.3 we prove results associated to the injectivity, surjectivity, and bijectivity of f. The reader can find a summary of some of these results in Figure2 (page 23). In Section 3.4 (page 22) we consider also the case in which the instance is a partial recursive function and compare the two cases. Figures5 (page 25) and6 (page 30) contain a summary of this comparision.

3.1 Some undecidable problems

Several decision problems related with the zeros and the equivalence of PR functions are studied. They are all proved to be undecidable. In particular we present a new proof of the undecidability of the PR equivalence problem.

3.1.1 Problems

In the decision problems listed below the corresponding class in the arithmetic hierarchy is listed. In every case it is assumed that a PR function is specified by a primitive recursive index.

Definition 9 In the following decision problems the specification of the partic- ular instance is: “a primitive recursive function f(x, y), and the value of x”. 3 Using the Smn Theorem (page 10), this instance is equivalent to the simpler form “a primitive recursive function g(y)”. This form will be often used.

– HAS-ZEROS,“f(x, y) has at least one zero”. Question: Is there some y such that f(x, y) = 0? 0 Class: Σ1 \ ∆, Theorem6 (page 14). – EXACTLY-ONE-ZERO. Question: Does f(x, y) have exactly one zero? 0 0 0 Class: Σ2 \ (Σ1 ∪ Π1), Theorem7 (page 14). – AT-LEAST-k-ZEROS. Question: Does f(x, y) have at least k 0’s? (k ≥ 1 fixed). 0 Class: Σ1 \ ∆, Theorem8 (page 15).

3 Where g(y) ≡ fx(y).

12 – EXACTLY-k-ZEROS. Question: Does f(x, y) have exactly k zeros? (k ≥ 1 fixed). 0 0 0 Class: Σ2 \ (Σ1 ∪ Π1), Theorem9 (page 15). – EQUAL-NEXT. Question: Is there some y such that f(x, y) = f(x, y + 1)? 0 Class: Σ1 \ ∆, Theorem 10 (page 15). – ZERO-FUNCTION. Question: Is f(x, y) the 0(y) ≡ 0 function? 0 Class: Π1 \ ∆, Theorem 11 (page 15). – ∞-ZEROS. Question: Does f(x, y) have infinitely many zeros? 0 0 0 Class: Π2 \ (Σ1 ∪ Π1), Theorem 12 (page 16).

Definition 10 EQUAL-AT-ONE-POINT, “functions equal at one point”. Instance: primitive recursive functions f(x) and g(x). Question: Is there an input x such that f(x) = g(x)? 0 Class: Σ1 \ ∆, Theorem 13 (page 16).

Definition 11 EQUIVALENCE. Instance: primitive recursive functions f(x) and g(x). Question: Is f(x) = g(x) for every x? 0 Class: Π1 \ ∆, Theorem 14 (page 16).

We also consider the equivalence of f to any particular (i.e. fixed) primitive recursive function.

Definition 12 Problem EQUIVALENCEi for each i ∈ N. Comment. For each problem the value i ∈ N is fixed. Instance: primitive recursive function f(x). Question: Is f(x) = φi(x) for every x? 0 Class: Π1 \ ∆, Theorem 16 (page 17).

3.1.2 and the HAS-ZEROS problems

For each instance f(x) of the HAS-ZEROS problem there is an integer (with integer coefficients) polynomial p(x1, . . . , xn), such that p has a zero iff f(x) has a zero. Let us begin by quoting [11].

In an unpublished and undated manuscript from the 1930s found in G¨odel’sNachlass and reproduced in Vol. III of the Collected Works, he showed that every statement of the form “∀x : R(x)” with R primitive recursive [relation] is equivalent to one in the form

∀x1, . . . , xn ∃y1, . . . , ym :[p(x1, . . . xn, y1 . . . ym) = 0]

13 in which the variables range over natural numbers and p is a polynomial with integer coefficients; it is such problems that G¨odelreferred to as Diophantine in the Gibbs lecture. It follows from the later work on Hilbert’s 10th problem by Martin Davis, Hilary Putnam, Julia Robin- son and – in the end – Yuri Matiyasevich that, even better, one can take m = 0 in such a representation, when the “=” relation is replaced by “6=” [that is, ∀x : R(x) iff ∀x : P (x) 6= 0].

In terms of PR functions, a PR relation R(x) can be represented by a PR function f(x) such that R(x) holds iff f(x) 6= 0. This is of course one, among many, possible representations. We have (with m = 0) the equivalences

∀x : R(x) ⇔ ∀x1, . . . , xn :[p(x1, . . . xn) 6= 0]

∀x : f(x) 6= 0 ⇔ ∀x1, . . . , xn :[p(x1, . . . xn) 6= 0]

∃x : f(x) = 0 ⇔ ∃x1, . . . , xn :[p(x1, . . . xn) = 0]

Thus, given that there is an algorithm that computes p from f, and relatively to the decidability of the HAS-ZEROS problem, an arbitrary PR function is no more general than a (multiple variable) integer polynomial.

3.1.3 Results

Theorem 6 The HAS-ZEROS problem is undecidable but semi-decidable (see [3]).

Proof. The semi-decidability is obvious. The undecidability follows from two facts: the Kleene normal form Theorem and the undecidability of the halting problem. 

Corollary 1 Let f(x1, . . . , xn, y) and g(x1, . . . , xn, y) be primitive recursive func- tions, with n ≥ 1. The following problem is undecidable but semi-decidable: given x1,. . . , xn, is there some y such that f(x1, . . . , xn, y) = g(x1, . . . , xn, y)?

Proof. Using the SmnTheorem (page 10), we replace f(x, y) and g(x, y) by f(y) and g(y) respectively. Property1 (page 10) says that f(y) = g(y) iff (f(y) −· g(y)) + (g(y) −· f(y)) = 0. The result follows from Theorem6 (page 14) 

Theorem 7 The language associated with the EXACTLY-ONE-ZERO problem 0 0 0 is Σ2 \ (Σ1 ∪ Π1).

0 Proof. In Σ2. Given the PR function f(x), the question associated with the problem can be expressed as

∃x ∀x0 : [(f(x) = 0) ∧ (x0 6= x ⇒ f(x0) 6= 0)] ?

0 which shows that the language belongs to Σ2. 0 Not in Π1. Reduce HAS-ZEROS to EXACTLY-ONE-ZERO:

14 let f be the instance of HAS-ZEROS. Define g as

 0 if f(x) = 0 and [x0 < x ⇒ f(x0) 6= 0] g(x) = 1 otherwise

Clearly g is PR and f has at least one zero iff g has exactly one zero. Thus the problem EXACTLY-ONE-ZERO is undecidable and is not the complement of a semi-decidable problem. 0 Not in Σ1. Reduce ¬(HAS-ZEROS) to EXACTLY-ONE-ZERO: let f be the instance of ¬(HAS-ZEROS). Define g as   0 if x = 0 g(x) = 1 if x ≥ 1 and f(x − 1) 6= 0  0 if x ≥ 1 and f(x − 1) = 0

The function g has exactly one zero iff the function f has no zeros. It follows that EXACTLY-ONE-ZERO is not a semi-decidable problem. 

Theorem 8 The AT-LEAST-k-ZEROS problem is undecidable but semi-decidable.

Proof. The AT-LEAST-k-ZEROS problem is clearly semi-decidable and HAS- ZEROS (instance f(x)) reduces easily to AT-LEAST-k-ZEROS (instance g(x)) if we define for each x ≥ 0

g(kx) = g(kx + 1) = ... = g(kx + (k − 1)) = f(x) so that each zero of f corresponds to k zeros of g. 

Theorem 9 For every k ≥ 1 the language associated with the EXACTLY-k- 0 0 0 ZEROS problem is in Σ2 \ (Σ1 ∪ Π1).

Proof. Similar to the proof of Theorem7. 

Theorem 10 The EQUAL-NEXT problem is undecidable but semi-decidable.

Proof. Let g(x) def= (f(x + 1) −· f(x)) + (f(x) −· f(x + 1)) and h(x) def= Pi=x−1 i=0 f(i). We have g(x) = 0 iff f(x) = f(x + 1) and h(x) = h(x + 1) iff f(x) = 0. It follows that HAS-ZEROS≤mEQUAL-NEXT and EQUAL-NEXT≤mHAS-ZEROS. The proposition follows. 

Theorem 11 The language associated with the problem ZERO-FUNCTION is 0 in Π1 \ ∆.

Proof. The complement of ZERO-FUNCTION is semi-decidable (belongs to 0 0 the class Σ1) so that ZERO-FUNCTION belongs to Π1.

15 Undecidability (not in ∆): reduce HAS-ZEROS to ¬(ZERO-FUNCTION). Given an instance f of HAS-ZEROS, define the function g as

 0 if f(x) 6= 0 g(x) = 1 if f(x) = 0

Clearly, g is PR; also g has at least one zero iff f has at least one nonzero. 

0 Theorem 12 The language associated with the problem ∞-ZEROS is in Π2 \ 0 0 (Σ1 ∪ Π1).

0 Proof. In Π2. The question associated with the problem can be expressed as ∀m ∃ x :(x ≥ m) ∧ (f(x) = 0) ? or: ∀m ∃x, y :(x = m + y) ∧ (f(x) = 0) ?

0 Not in Π1:. Reduction HAS-ZEROS to ∞-ZEROS: let f be an instance of HAS-ZEROS. Define g as

 0 if x, written in binary notation is in 10n1(0 + 1)? and f(n) = 0 g(x) = 1 otherwise where the standard notation for regular expressions is used. Clearly, f(x) has at least one zero iff g(x) has infinitely many zeros.

0 Not in Σ1. Reduction ¬(HAS-ZEROS) ≤m ∞-ZEROS: let f be an instance of ¬(HAS-ZEROS). Define g as

 1 if f(x0) = 0 for some x0 ≤ x g(x) = 0 otherwise

The function f(x) has no zero iff g(x) has infinitely many zeros. 

Theorem 13 The EQUAL-AT-ONE-POINT problem is undecidable but semi- decidable.

Proof. Easy, consider the PR function (f(x) −· g(x)) + (g(x) −· f(x)). 

Theorem 14 The EQUIVALENCE problem is undecidable; its complement is semi-decidable.

Proof. The complement of the EQUIVALENCE problem is clearly semi-decidable. Two CFG languages are equal iff the functions defined by the corresponding parsers are equal. A CFG parser can be written as an primitive recursive al- gorithm having as input an integer that codes the words of the alphabet and an output which is either 0 (reject) or 1 (accept), see Theorem4 (page 11). Thus, as the CFG language equivalence is undecidable (see for instance [21]), the EQUIVALENCE problem is also undecidable.

16 Another proof. The following function is PR Given the description d(M) of a Turing machine T and an input x, the following function is primitive recursive4.

 0 if M(x) has halted by time t f(d(M), x, t) = 1 otherwise

We reduce the SHP to EQUIVALENCE. The function

 0 if M(d(M)) has halted by time t f 0(d(M), t) = 1 otherwise is also PR. Given d(M), instance of the SHP, the computation φd(M)(d(M)) does not halt iff the unary function f 0(d(M), t) (with d(M) fixed, t is the ar- gument) is equivalent to the zero function 0(t); this is a particular case of EQUIVALENCE. Thus EQUIVALENCE cannot be decidable.  In fact, the last sentence of the proof above gives us another very simple proof: Theorem 11 (page 15) shows that a particular case of EQUIVALENCE is al- ready undecidable; thus, so is EQUIVALENCE. A reduction of EQUIVALENCE to ZERO-FUNCTION is also possible: by Property1 (page 10) f(y) = g(y) iff (f(y) −· g(y)) + (g(y) −· f(y)) = 0. Thus EQUIVALENCE reduces to ZERO-FUNCTION.

Theorem 15 For every integer i the problem EQUIVALENCEi is undecidable; its complement is semi-decidable.

Proof. We only prove the undecidability of EQUIVALENCEi, the other part is easy (see the proof of Theorem 14). Let i be any fixed integer. We reduce ZERO-FUNCTION to EQUIVALENCEi. Let f be an instance of ZERO-FUNCTION. Define the primitive recursive function g(x) = f(x) + φi(x). Clearly, the function f is the zero function 0(x) iff g(x) is equivalent to φi(x).  We can further generalize Theorem 16, considering the equality of the func- tions f(x) and φi(x), not for all x ∈ N but only for an infinite PR predeter- mined of the domain. By this, and anticipating the terminology used in Section4, page 29, we mean that there is a fixed primitive recursive function g, such that the equality f(y) = φi(y) is only considered for the values y = g(x) with x ∈ N.

Theorem 16 For every integer i and for every primitive recursive function g with infinite domain, the problem “is f(y) = φi(y) for every y in the codomain of g?” is undecidable; its complement is semi-decidable.

Proof. (Brief sketch). Consider the problem “is f(g(x)) = 0 for every x ∈ N?”. Note that f(g(x)) has a zero iff (f(y) −· 1) + 1 is not zero for all y in the

4The function f is related to one PR function of the Kleene normal form, namely to the function under the scope of the unbounded minimization operator.

17 codomain of g. Assume that this codomain is infinite and continue the proof as in Theorem 16, but using the idea of the proof of Theorem 22, page 33. 

3.2 Size of the codomain

The size of the codomain cod(f) of a PR function f may determine if a problem belonging to a certain class (see Section 4.2, page 32) is decidable or not. We study two decision problems related with this size. In the following problems, the instance is the PR function f. The problem INFINITE-CODOMAIN is also mentioned in Section 4.7 (page 35). Problem CODOMAIN-k, Finite, fixed size codomain, where k is any fixed positive integer. Question: Does the codomain of f have size k? 0 Class: Π1 \ ∆ for k = 1 (Theorem 17, page 18) 0 0 0 Class: Σ2 \ (Σ1 ∪ Π1) for k ≥ 2 (Theorem 18, page 18)

Theorem 17 For k = 1 the language associated with the problem CODOMAIN-k 0 belongs to the class Π1 \ ∆.

Proof. A positive answer to CODOMAIN-k for k = 1 can be expressed as 0 ∀x :(f(x) = f(0)), so that CODOMAIN-k for k = 1 is in Π1. Reduce ZERO-FUNCTION to CODOMAIN-k (k = 1) as follows. Given an instance f of ZERO-FUNCTION consider the instance g of CODOMAIN-k

 g(0) = 0 g(x) = f(x − 1) for x ≥ 1

The function g has codomain with size 1 iff f(x) ≡ 0. Thus CODOMAIN-k (k = 1) is undecidable. 

Theorem 18 For any integer k ≥ 2 the language associated with the problem 0 0 0 CODOMAIN-k belongs to the class Σ2 \ (Σ1 ∪ Π1).

0 Proof. In Σ2. A positive answer to CODOMAIN-k can be expressed as a ∃∀–expression; we exemplify for the case k = 2

∃y1, y2, x1, x2 ∀z :(f(x1) = y1)∧(f(x2) = y2)∧(y1 6= y2)∧(f(z) = y1∨f(z) = y2)

0 so that CODOMAIN-k is in Σ2 for any k ≥ 2. 0 Not in Σ1. Reduce ZERO-FUNCTION to CODOMAIN-k: let f be an instance of ZERO-FUNCTION. Define g as

 x for 0 ≤ x < k g(x) = 2kf(x − k) for x ≥ k

0 Clearly |cod(g)| = k iff f(x) ≡ 0. Thus CODOMAIN-k is not in Σ1 (Property4, page7).

18 0 Not in Π1. Reduce (¬ZERO-FUNCTION) to CODOMAIN-k: let f be an instance of (¬ZERO-FUNCTION). For each x ∈ N define the k values  0 if f(x) = 0 g(kx + i) = (for 0 ≤ i < k) i if f(x) 6= 0

0 Clearly |cod(g)| = k iff f(x) 6= 0 for some x. Thus CODOMAIN-k is not in Π1 (Property3, page7).  Problem FINITE-CODOMAIN, finite codomain Question: Is the codomain of f finite?

0 0 0 Theorem 19 FINITE-CODOMAIN belongs to the class Σ2 \ (Σ1 ∪ Π1).

0 Proof. In Σ2. The FINITE-CODOMAIN statement can be expressed as ∃m∀x : f(x) ≤ m. 0 Not in Σ1. Reduce ZERO-FUNCTION to FINITE-CODOMAIN: let f be an instance of ZERO-FUNCTION. Define g as

 0 if f(0) = f(1) = ... = f(x) = 0 g(x) = x otherwise

The codomain of g is finite (with size 1) iff f(x) ≡ 0. It follows that 0 FINITE-CODOMAIN is not in Σ1. 0 Not in Π1. Reduce ¬HAS-ZEROS to FINITE-CODOMAIN: use the function  0 if f(y) 6= 0 for some y ≤ x g(x) = x otherwise

The codomain of g is finite iff f(x) is nonzero for some x. It follows that 0 FINITE-CODOMAIN is not in Π1.  The problem INFINITE-CODOMAIN is the negation of the problem FINITE-CODOMAIN. It follows from Theorem 19 that INFINITE-CODOMAIN 0 0 0 belongs to the class Π2 \ (Σ1 ∪ Π1).

3.3 Injectivity, surjectivity, and bijectivity

The problems of deciding if a given PR function is injective, surjective, or bijective are considered in this section. First we define the three problems studied in this section.

Definition 13 INJECTIVE, primitive recursive injectivity. Instance: a PR function f, specified by a Loop program. Question: is f an injective function?

Definition 14 ONTO, primitive recursive surjectivity.

19 Instance: a PR function f, specified by a Loop program. Question: is f a surjective function?

Definition 15 BIJECTIVE, primitive recursive bijectivity. Instance: a PR function f, specified by a Loop program. Question: is f a bijective function?

Clearly, if the INJECTIVE and the ONTO problems were decidable then BI- JECTIVE would also be decidable. However, all these problems are undecidable (with various degrees of undecidability).

3.3.1 Injectivity

We will use the following lemma to prove that the problem of determining if a given PR function is injective is undecidable.

Lemma 1 For every CFG G there is a PR function fG whose input is an integer n that codifies some word d and with the following output.

– fG(n) = y if n codifies a word d which is a leftmost derivation of some word x in G; suppose that the integer y codifies the word x, say y = c(x), and assume that y starts with “10”. This situation is illustrated in the following diagram.

fG

G ) n o / d +3 ? x o / y = 10 ... ∈ ∈ ∈ ∈

N Σ? Σ? N

– fG(n) = 11n if d is not a leftmost derivation in G.

Proof. The PR function fG checks if n codifies a leftmost derivation of a word x. If it does, the result is the integer y = c(x) = 10 .... Otherwise, the result is the integer 11n.



Theorem 20 The problem INJECTIVE is undecidable, being the complement 0 of a semi-decidable problem, that is, it belongs to the class Π1 \ ∆.

As a consequence of this result the injective PR functions can not be effectively enumerated and can not be characterized by a “model of computation”, see Assumption1 (page 10). Proof. The INJECTIVE statement can be expressed as

∀m, n :(m 6= n) ⇒ (f(m) 6= f(n))

20 0 This INJECTIVE belongs to the class Π1. The E-CFG ambiguity problem, E-CFG-amb (page 11) is undecidable and the 0 set of E-CFG ambiguous grammars belongs to Σ1. We reduce E-CFG-amb to ¬INJECTIVE. Let G be an E-CFG. Using Lemma1, define a PR function fG as described in the Lemma. It is clear that G is ambiguous iff the function fG is not injective. Thus INJECTIVE is not decidable. 

3.3.2 Surjectivity and bijectivity

An instance f of ONTO can be expressed as ∀y∃x : f(x) = y. It follows the 0 problem is in the class Π2. An instance f of BIJECTIVE can be expressed as

∀y, x1, x2 ∃x :[f(x) = y] ∧ [x1 6= x2 ⇒ f(x1) 6= f(x2)]

0 Thus BIJECTIVE also belongs to the class Π2. We first prove that neither of these two problems is semi-decidable, and then that neither is the complement of a semi-decidable problem.

3.3.3 Neither problem is semi-decidable

Given the description d(M) of a Turing machine T and an input x, the following function is PR.  0 if M(x) is halted at time t f(d(M), x, t) = 1 otherwise

Given a Turing machine M described by d(M), the function g below is also PR.

 0 if f(d(M), d(M), t) = 0 [M(d(M)) is halted at time t] g(t) = t if f(d(M), d(M), t) = 1 [otherwise]

Notice that M(d(M)) diverges iff the PR function g is surjective; thus, we have a reduction ¬SHP≤mONTO (1) As the self-halting problem is undecidable but semi-decidable, we have proved that ONTO is undecidable and not semi-decidable – otherwise ¬SHP would be semi-decidable, which is false (see also the Property4 in page7). Thus,

0 ONTO 6∈ Σ1 Note that the function g defined above also satisfies: g is a bijection iff M(d(M)) diverges, so we also have a reduction

¬SHP≤mBIJECTIVE (2) which proves that 0 BIJECTIVE 6∈ Σ1

21 Neither problem is the complement of a semi-decidable problem

Consider now the PR function h(t)

 t − t the computation M(d(M)) halted at time t ≤ t h(t) = 0 0 0 not halted at time t

Clearly h(t) is surjective iff the the answer to the HP is yes, so that we have a reduction SHP≤mONTO (3) As the self-halting problem is undecidable but semi-decidable, we have proved 0 that ONTO is not the complement of a semi-decidable problem, ONTO 6∈ Π1. Finally, consider the PR function   0 if the computation M(d(M)) halts at time t h(t) = t + 1 not halted yet  t otherwise (halted before t)

As an example, we list the first values of h(t) in two cases. First, when the computation M(d(M)) diverges:

t :0123456789 ... h(t) : 1 2 3 4 5 6 7 8 9 10 ... and then when it halts at time 5: t : 0123456789 ... h(t):1234506789 ...

We see that h(t) is bijective iff the the answer to the HP is yes, so that we have a reduction SHP≤mBIJECTIVE (4) 0 Thus BIJECTIVE 6∈ Π1. 0 Note. This reduction could also have been used to prove that ONTO 6∈ Π1.  The table in Figure2 (page 23) summarizes our undecidability results about PR functions. The reductions used in the proofs of this section are represented in Figure4 (page 24).

3.4 Primitive recursive versus partial recursive problems

It is interesting to compare the degree of undecidability of the same problem about a function f in two cases: (i) f if primitive recursive, (ii) f is partial recursive.

Theorem 21 Let A be a PR decision problem corresponding to the question “does a given PR function have the property P ?” and let X be any decision

22 Num PR problem Class Proof

0 1 HAS-ZEROS Σ1 \ ∆ page 14 0 0 0 2 EXACTLY-ONE-ZERO Σ2 \ (Σ1 ∪ Π1) page 14 0 3 AT-LEAST-k-ZEROS Σ1 \ ∆ page 15 0 0 0 4 EXACTLY-k-ZEROS Σ2 \ (Σ1 ∪ Π1) page 15 0 5 ZERO-FUNCTION Π1 \ ∆ page 15 0 0 0 6 ∞-ZEROS Π2 \ (Σ1 ∪ Π1) page 16 0 7 CODOMAIN-k, k = 1 Π1 \ ∆ page 18 0 0 0 8 CODOMAIN-k, k ≥ 2 Σ2 \ (Σ1 ∪ Π1) page 18 0 0 0 9 FINITE-CODOMAIN Σ2 \ (Σ1 ∪ Π1) page 19 0 10 INJECTIVE Π1 \ ∆ page 20 0 0 0 11 ONTO Π2 \ (Σ1 ∪ Π1) Section 3.3.2 0 0 0 12 BIJECTIVE Π2 \ (Σ1 ∪ Π1) Section 3.3.2

Figure 2: Some decision problems studied in this paper. In every problem the instance is a PR function. The problems are numbered (first column, in this color) for reference in Figure3, page 23.

0 0 Π2 Σ2 6, 11,12 2, 4, 8, 9

0 0 Π1 Σ1 5, 7, 10 1, 3 0 ∆0 (decidable problems)

Figure 3: Location in the arithmetic hierarchy of the problems mentioned in Figure2, page 23. The problem numbers (1 to 12 in this color) refer to the numbers in the first column of Figure2.

23 PCP ¬SHP SHP 5 3  55  33  5  3  55  33  5  3 E-CFG-amb  55  33  5  3  55  33 ¬  55  33  5  3 INJECTIVE ONTO BIJECTIVE ONTO BIJECTIVE

Figure 4: Reductions used in the proofs of Section 3.3.

0 0 problem. If X≤mA, then X≤mA , where A corresponds to the question “does a given partial recursive function have the property P ?”.

Proof. Let f be the function corresponding to the reduction X≤mA. The image by f of a (positive or negative) instance x of X is a PR function, thus it is also a 0 partial function. So, we can use the same function f for the reduction X≤mA .  Let F (x, t) be the that outputs true iff the computation f(x) halts at time t. We should have some care when dealing with a partial recursive function f because when we say something like f(x) = 0 we really mean two things: (i) the computation of f(x) converges and (ii) its output is 0. We now justify the classes in the last column of Figure5 (page 25).

1. f(0) = 0: well known result.

2. TOTAL: see Theorem1, page8.

3. HAS-ZEROS: well known result.

4. NO-ZEROS, f has no zeros. The statement can be expressed as ¬[∃x, t : 0 F (x, t) ∧ f(x) = 0] Thus it belongs to Π1. We describe a reduction ¬SHP≤mNO-ZEROS: let n be an instance of ¬SHP; define  0 if φ (n) halts in time t g(t) = n 1 otherwise

The function g has no zeros iff φn(n) does not halt. We conclude that 0 NO-ZEROS belongs to Π1 \ ∆. 5. EXACTLY-ONE-ZERO: it is easy to see that this problems belongs to the same class as HALTS-ONE whose question is “is f(x) defined for exactly one value of x?”. The statement corresponding to HALTS-ONE is

∃x, t : F (x, t) ∧ [∀y :(y 6= x) ⇒ (∀t : ¬F (y, t))]

24 Problem f is primitive rec. f is partial rec.

0 ↑ f(0) = 0 ∆ Σ1 \ ∆ 0 0 0 ↑ TOTAL ∆ Π2 \ (Σ1 ∪ Π1) 0 0 = HAS-ZEROS Σ1 \ ∆ Σ1 \ ∆ 0 0 = NO-ZEROS Π1 \ ∆ Π1 \ ∆ 0 0 0 0 0 0 = EXACTLY-ONE-ZERO Σ2 \ (Σ1 ∪ Π1)Σ2 \ (Σ1 ∪ Π1) 0 0 = AT-LEAST-k-ZEROS Σ1 \ ∆ Σ1 \ ∆ 0 0 0 0 0 0 = EXACTLY-k-ZEROS Σ2 \ (Σ1 ∪ Π1)Σ2 \ (Σ1 ∪ Π1) 0 0 0 0 ↑ ZERO-FUNCTION Π1 \ ∆ Π2 \ (Σ1 ∪ Π1) 0 0 0 0 0 0 = ∞-ZEROS Π2 \ (Σ1 ∪ Π1)Π2 \ (Σ1 ∪ Π1) 0 0 0 0 ↑ CODOMAIN-k, k = 1 Π1 \ ∆ Π2 \ (Σ1 ∪ Π1). 0 0 0 0 0 0 6∼ CODOMAIN-k, k ≥ 2 Σ2 \ (Σ1 ∪ Π1)Π2 \ (Σ1 ∪ Π1) 0 0 = INJECTIVE Π1 \ ∆ Π1 \ ∆ 0 0 0 0 0 0 = ONTO Π2 \ (Σ1 ∪ Π1)Π2 \ (Σ1 ∪ Π1). 0 0 0 0 0 0 = BIJECTIVE Π2 \ (Σ1 ∪ Π1)Π2 \ (Σ1 ∪ Π1).

Figure 5: The degree of undecidability of some decision problems about a func- tion f. Two cases are compared: f is a primitive recursive function (PR) and f is a partial recursive function. The symbol “↑” means that the partial recursive is “more undecidable” than the corresponding PR problem. The symbols “=” and “6∼” mean “equally undecidable (in the same class of the ARithmetic Herarchy) or “incomparable”.

25 or ∃x, t ∀y, t0 : F (x, t) ∧ [(y 6= x) ⇒ (¬F (y, t))] 0 Thus, HALTS-ONE (and EXACTLY-ONE-ZERO) belong to the class Σ2. 0 (ii) EXACTLY-ONE-ZERO 6∈ Σ1. Reduction (¬HP)≤mEXACTLY-ONE-ZERO: Let hT, xi be the instance of HP where the Turing machine T computes f. Define g as follows

 0 if t = 0 def  gx(t) = f(x, t) = 1 if T (x) does not converge in ≤ t steps  0 otherwise

Clearly gx(t) has exactly one zero iff T (x) does not halt. 0 (iii) EXACTLY-ONE-ZERO 6∈ Π1. Reduction HP≤mEXACTLY-ONE-ZERO: given the instance hT, xi of HP, define the function g(y) that, for y = 0 outputs 0; and for y 6= 0 simulates the computation T (x); if it halts, the output is 0; if not, g(y) is undefined. The function g(y) has exactly one zero iff the computa- tion T (x) halts. 0 0 0 Thus EXACTLY-ONE-ZERO belongs to Σ2 \ (Σ1 ∪ Π1). 0 6. AT-LEAST-k-ZEROS (k fixed): easy to show that it is in Σ1 (“dovetail- ing” technique); HAS-ZEROS reduces easily to AT-LEAST-k-ZEROS, see the proof of Theorem8 (page 15).

7. EXACTLY-k-ZEROS (k fixed): proof similar to EXACTLY-ONE-ZERO, see item5. For instance, the statement corresponding to HALTS-TWO 5 can be written

∃x1, x2, t1, t2 ∀y, t : F (x1, t1) ∧ F (x2, t2) ∧ [(y 6= x1) ∧ (y 6= x2) ⇒ (¬F (y, t))]

0 Thus EXACTLY-k-ZEROS belongs to Σ2. As in item5, both HP and ¬HP can be reduced to EXACTLY-k-ZEROS. 0 0 0 It follows that EXACTLY-k-ZEROS belongs to Σ2 \ (Σ1 ∪ Π1). 8. ZERO-FUNCTION: The corresponding question can be expressed as

¬[[∃x, t : F (x, t) ∧ (f(x) 6= 0)] ∨ [∃x ∀t : ¬F (x, t)] ]

0 so that ZERO-FUNCTION belongs to Π2. HP with instance n reduces to ZERO-FUNCTION using the function

 0 if φ (n) converges f(x) = n undefined otherwise

(The input is ignored) ¬HP with instance n reduces to ZERO-FUNCTION

5Which is equivalent (in the sense that each one reduces to the other) to the problem AT- LEAST-k-ZEROS for k = 2.

26 using the function

 0 if φ (n) does not converge in t steps f(t) = n 1 otherwise

0 0 0 It follows that ZERO-FUNCTION belongs to Σ2 \ (Σ1 ∪ Π1). 0 9. ∞-ZEROS: In Π2. The question associated with the problem can be expressed as

∀m ∃x, t :(x ≥ m) ∧ F (x, t) ∧ (f(x) = 0) or: ∀m ∃x, y, t :(x = m + y) ∧ F (x, t) ∧ (f(x) = 0)

0 Thus ∞-ZEROS belongs to Π2. By Theorem 21 (page 22) the reductions used in the proof of Theorem 12 (page 16) are also valid in this case. It follows that ∞-ZEROS (for partial 0 0 0 recursive functions) belongs to Π2 \ (Σ1 ∪ Π1). 10. CODOMAIN-k, k = 1: can be expressed as the negation of

(1) (2) z }| { z }| { ¬[∃x, t : F (x, t)] ∨ ∃x, x0, t, t0, : F (x, t) ∧ F (x0, t0) ∧ f(x) 6= f(x0)

The part (1) means “f it is the totally undefined function” while part (2) means “there are at least two values for which f is defined and has different results”. We can rewrite this logical statement, which is the negation of CODOMAIN-k for k = 1, as

∃x1, x2, t1, t2 ∀x, t :[¬F (x, t)] ∨ [F (x1, t1) ∧ F (x2, t2) ∧ f(x1) 6= f(x2)]

0 Thus CODOMAIN-k for k = 1 belongs to Π2. We reduce ¬SHP to (CODOMAIN-k, k = 1). Let n be the instance of ¬SHP. Define   0 if t = 0 f(t) = 0 if φn(n) does not converge in ≤ t steps (t ≥ 1)  1 otherwise (t ≥ 1)

Clearly φn(n) diverges iff the codomain of f has size 1. Now reduce SHP to (CODOMAIN-k, k = 1). Let n be the instance of SHP. Define  undefined if φ (n) does not converge in ≤ t steps f(t) = n 0 otherwise

The computation φn(n) halts iff the codomain of f has size 1. Thus 0 0 0 CODOMAIN-k for k = 1 belongs to Π2 \ (Σ1 ∪ Π1). 11. CODOMAIN-k, k ≥ 2: we exemplify for the case k = 2, the cases k ≥ 3

27 being similar. The negation of the statement is

[∀x, t : ¬F (x, t)] size=0 ∨ [∃x0, t0∀x00, t00 : P (x0, t0, x00, t00)] size=1 ∨ [∃x1, x2, x3, t1, t2, t3 : Q(x1, x2, x3, t1, t2, t2)] size≥ 3

where P (x0, t0, x00, t00) denotes

F (x0, t0) ∧ (F (x00, t00) ⇒ f(x00) = f(x0))

and Q(x1, x2, x3, t1, t2, t2) denotes

F (x1, t1) ∧ F (x2, t2) ∧ F (x3, t3) ∧ f(x1) 6= f(x2) ∧ f(x2) 6= f(x3) ∧ f(x3) 6= f(x1) The negation of the statement can be rewritten as

0 0 00 00 ∃x , t , x1, x2, x3, t1, t2, t3∀x, t, x , t : ¬F (x, t) ∨ P ∨ Q

where the arguments of P and Q have been omitted. It follows that 0 CODOMAIN-k for k = 2 belongs to Π2. 0 To prove that CODOMAIN-k for k = 2 is not in Π1, reduce SHP (in- stance n) to CODOMAIN-k, k = 2   0 if t = 0 f(t) = 0 if φn(n) did not converge in ≤ t − 1 steps (t ≥ 1)  1 if φn(n) converges in ≤ t − 1 steps (t ≥ 1)

(the case f(0) = 0 is considered because the possibility of convergence for t = 0). The function f has codomain with size 2 iff φn(n)↓. 0 To prove that CODOMAIN-k for k = 2 is not in Σ1, reduce ¬SHP (in- stance n) to CODOMAIN-k, k = 2

 0 if t = 0   1 if t = 1 f(t) = 0 if φn(n) did not converge in ≤ t − 2 steps (t ≥ 2)   2 if φn(n) converges in ≤ t − 2 steps (t ≥ 1)

The function f has codomain with size 2 iff φn(n)↑. 12. FINITE-CODOMAIN:

13. ∞↑: the function f diverves at infinitely many points. It can be stated as

∀n∃m∀t :(m ≥ n) ∧ (¬F (m, t))

0 It follows that ∞↑ belongs to Π3. Unfinished.

(a) Reductions TOTAL≤m∞↑ and ∞↑≤mTOTAL? 0 (b) The problem “is f defined at least at one point?” is Σ1.

28 (c) The negation can be expressed as ∃m : fm→∞ is total. The correspond- ing “parameterized” problem is “given f and m, is fm→∞ total?”.

14. INJECTIVE: for partial recursive functions the INJECTIVE statement can be expressed as

¬[∃x, y, t, t0 : F (x, t) ∧ F (y, t0) ∧ (f(x) = f(y))] (5)

where F (x, t) has the same meaning as before (page 24). Notice that in a logic statement like this, when we talk about f(x) we implicitly assume that ∃t : F (x, t); however this assumption, and a similar assumption for f(y), are already included in (5). It is easy to see that INJECTIVE 0 is undecidable. Thus it belongs to the class Π1 \ ∆. 15. ONTO: for partial recursive functions the ONTO statement can be ex- pressed as ∀y ∃x, t : F (x, t) ∧ (f(x) = y) 0 Thus ONTO is in Π2. As PR functions are partial recursive functions, the reductions (1) (page 21) and (3) (page 22) are also valid here. It follows that, as in the PR function 0 0 0 case, ONTO belongs to the class Π2 \ (Σ1 ∪ Π1). 16. BIJECTIVE: for partial recursive functions the BIJECTIVE statement can be expressed as

∀y, x, x1, x2 ∃t : F (x, t) ∧ f(x) = y ∧ [(x1 6= x2) ⇒ f(x1) 6= f(x2)]

Note that this implies “∀x∃t : F (x, t)”, so that we can talk about f(x1) 0 and f(x2) without more proviso. Thus BIJECTIVE is in Π2. As PR functions are partial recursive functions, the reductions (2) (page 21) and (4) (page 22) are also valid here. It follows that, as in the PR function 0 0 0 case, BIJECTIVE belongs to the class Π2 \ (Σ1 ∪ Π1).

4 Frontiers of decidability: the HAS-ZEROS problem

In this section we consider the problem of determining whether a given unary PR function has at least one zero. As explained below, the function which is studied is a restriction of a general PR function f. The set of possible input (argument) values and the set of outputs will be restricted. We will find necessary and sufficient conditions for decidability of the problem “does the modified function has a zero?”. A possible way of restricting the inputs of a PR function f is to pre-apply to f some PR function6 g. The outputs of f can be similarly restricted by post-applying to f some fixed PR function h. Both operations – restrict the

6We use a different text font for fixed PR functions like g and h.

29 0 0 Π2 Σ2

CODOMAIN≥ 2

0 0 Π1 Σ1

f(x) ≡ 0

CODOMAIN=1 0 ∆0

TOTAL f(0) = 0

Figure 6: The classes of five particular problems when the instance is a primitive recursive function (origin of the arrow) and when it is a partial recursive function (tip of the arrow). CODOMAIN=1 denotes the problem CODOMAIN-k with k = 1, CODOMAIN≥ 2 denotes the problem CODOMAIN-k for some fixed k ≥ 2, and f(x) ≡ 0 denotes the ZERO-FUNCTION problem. See also Figure5, page 25.

30 input and restrict the output – can be simultaneously applied, with the aid if two fixed PR functions g and h, see Figure7 (page 32). Thus, we will study the decidability of a restricted form of the HAS-ZEROS problem, namely the existence of zeros of the function h(f(g(x))). A more general form of placing a PR function f in a fixed system consisting of PR functions is studied in Section 5.2, page 38. Thus, we study three classes of PR decision problems, namely

1.“ ∃ x : f(g(x)) = 0?”, where g is a fixed PR function.

2.“ ∃ x : h(f(x)) = 0?”, where h is a fixed PR function.

3.“ ∃ x : h(f(g(x))) = 0?”, where g and h are fixed PR functions. where x denotes the sequence of arguments x1, x2..., xn (n ≥ 1). As an example of one problem of one of these classes, let g(x) = λx [2x2 + 1]. The question is: “∃x : f(g(x)) = f(2x2 + 1) = 0?”. This problem belongs to the class studied in Section 4.2. We will see that the conditions for the decidability of (c) are simply the con- junction of the decidability conditions for (a) and for (b). In this sense, the input and the output restrictions are independent.

Why study these families of problems?

There are several reasons for studying these “compositional” problems. For instance, many atomic predicates can be written as an equality of the form F (x) = 0, where F (x) is obtained by composing f with fixed PR functions. As an example, the question “∃x : f(x) = c?”, where c is a constant, can be expressed as “∃x :(f(x) −· c) + (c −· f(x)) = 0?” which is equivalent to “∃x : h(f(x)) = c?” where h(z) = λz [(z −· c) + (c −· z)]. However, our main interest in this section is to look to a well known undecidable problem, namely HAS-ZEROS, and restrict the inputs and outputs of the function being studied, in order to know “when the problem become decidable”. This decidability frontier is given by 22, 23, and 24, respectively in pages 33, 34, and 34. This motivation is further explained in the next section.

4.1 The meaning of restricted HAS-ZEROS problems let g and h be fixed PR functions. We can interpret Theorem 24 (page 34) as saying that the question “∃x : h(f(g(x))) = 0?” is “almost always” undecidable. The general case of the problem, namely HAS-ZEROS, is undecidable, Theo- rem6 (page 14).

31 n h(a) = 0 g(N ) is ∃ a, b . . . h(b) 6= 0 n infinite N +3 g +3 f / h / N

Figure 7: Restricting the HAS-ZEROS problem. The necessary and sufficient conditions for undecidability are listed over the arrows. Notice that the compos- ite value is h(f(gx))) ≡ (h·f·g)(x). The generalization mentioned in Section 4.5 (page 35) is assumed, i.e., the output of g may be a tuple of integers.

We can restrict the input of f by pre-applying a PR function g. In this case the problem remains undecidable if and only if the set of possible inputs of f (the codomain of g) is infinite, see Theorem 22, page 33. The output of f is restricted by post-applying some other PR function h. As Theorem 23 (page 34) shows, the problem remains undecidable if and only if the codomain of h includes 0 and some nonzero integer. The sufficient and necessary conditions for the undecidability of the existence of a zero of the function hf(g(x))) are illustrated the diagram of Figure7. It is useful to summarize the conclusions of this section:

1. Each of the following conditions trivially implies decidability: (i) the set of possible inputs is finite, (ii) the output is always (that is, for every input g(x) of f) nonzero, (iii) the output is always zero.

2. If neither of these conditions is satisfied, the problem is undecidable.

Note. It would have been possible to prove first Theorem 24 (page 34), and then present Theorems 22 (page 33) and 23 (page 34) as corollaries (whose proof consist in taking g or h equal to the identity function). However, for pedagogical reasons it is better to prove the simpler results first. 

4.2 The HAS-ZEROS-f·g class of problems

Each problem in the class is specified by the PR function g.

Definition 16 (HAS-ZEROS-f·g) Let g be a fixed PR function. Instance: PR function f. Question: ∃ x : f(g(x)) = 0?

As we will see in Theorem 22 (page 33), the decidability of the problem depends on whether the codomain of g is infinite. As an illustrative example, we first prove the undecidability of a particular problem of this class.

32 Example 1 Let g(x) = 2x+1. To prove the undecidability of the HAS-ZEROS-f·g problem we reduce HAS-ZEROS to HAS-ZEROS-f·g. Let u be an instance of the HAS-ZEROS problem. Define the transformed function f (instance of HAS-ZEROS-f·g) as f(x) = u(bx/2c) We have f(g(x)) = f(2x + 1) = u(b(2x + 1)/2c) = u(x), so that u(x) has at least one zero iff f(x) is a positive instance of the “f(g(x)) problem” for g(x) = 2x + 1.

Now we consider and prove the general case. For this purpose we will have to look more closely at the Kleene normal form.

Theorem 22 The problem HAS-ZEROS-f·g is undecidable if and only if the codomain of g is infinite.

Proof. The following is a decision procedure when the codomain of g is finite: let cod(g) = {y1, . . . , yn}; compute f(y1),. . . , f(yn); answer yes iff any of these integers is 0, answer no otherwise. Suppose now that the codomain of g is infinite. It is a consequence of the Kleene normal form Theorem that any partial recursive function f(x) can be written as f(x) = v(x, µy(u(x, y))) where

– The PR function u “evaluates y steps” of the computation T (x), where T is the Turing machine that corresponds to f. At the end, it returns 0 if the computation has already finished, and 1 otherwise (if u(x, y) is 0 for some y, it is also 0 for all y0 ≥ y).

– The PR function v is similar to u, but when it is “called” – if it is “called” – the value of the last argument, µy(u(x, y)), guarantees that the computa- tion has halted; it then returns the result of the computation T (x) = f(x).

As g has an infinite codomain, the sequence g(0), g(1). . . has an increasing infinite sub-sequence g(y0) < g(y1) < . . . (with y0 < y1 < . . .), so that

f(x) = v(x, µy(u(x, y))) = v(x, µy(u(x, g(y)))) (6)

This holds because there are g(y)’s arbitrarily large. Using the Smn Theorem, the arguments x can be “included” in the function u; let ux(g(y)) be the - sulting (PR) function. The HP (unary halting problem) can now be reduced to the HAS-ZEROS-f·g problem. Let hf, xi be the instance of HP. The corresponding instance of HAS-ZEROS-f·g is the ux function, constructed from f and x as described above. The computation f(x) halts iff there is some y such that ux(g(y)) = 0. 

33 4.3 The HAS-ZEROS-h·f class of problems

Each problem is specified by the PR function h. Instance: PR function f. Question: ∃ x : h(f(x)) = 0? The decidability of this problem is related to h−1(0).

Theorem 23 The HAS-ZEROS-h·f problem is undecidable if and only if h−1(0) n is neither ∅ nor N .

Proof. If h−1(0) is the empty set, h(f(x)) 6= 0 for every f and for every x, so that, for every instance f, the answer to “∃ x : h(f(x)) = 0?” is no. Similarly, −1 n if h (0) = N , h(f(x)) the answer is always yes. In both cases the problem is decidable. Suppose now that there are two tuples of integers a and b with h(a) = 0 and h(b) 6= 0. We reduce HAS-ZEROS to HAS-ZEROS-h·f. Let f be an instance of HAS-ZEROS, and define the function f 0(x)

 a if f(x) = 0 (⇒ h(f 0(x)) = 0) f 0(x) = b if f(x) 6= 0 (⇒ h(f 0(x)) 6= 0)

The function f 0 is also PR, as it may be obtained from f by the additional instruction “if f(x) = 0 then a else b”. Clearly, f(x) has at least one zero iff 0 h(f (x)) has at least one zero. 

4.4 The HAS-ZEROS-h·f·g class of problems

Each problem is specified by the PR functions g and h. Instance: PR function f. Question: ∃ x : h(f(g(x))) = 0?

Theorem 24 Let cod(g) be the codomain of g. The HAS-ZEROS-h·f·g prob- lem is undecidable if and only if the following two conditions hold: (i) cod(g) −1 n is infinite, (ii) h (0) is neither the empty set nor N .

−1 −1 n Proof. If the codomain of g is finite, or h (0) = ∅, or h (0) = N , the problem is clearly decidable. Suppose that (i) and (ii) hold. As in the proof of Theorem 22 (page 33), to which we refer the reader, we reduce the halting problem to HAS-ZEROS-h·f·g. The Turing machine T (x) halts iff there is some y such that ux(g(y)) = 0. Let h(a) = 0 and h(b) 6= 0. Recall that ux(z) is either 0 (computation not yet 0 halted) or 1 (computation halted). Define ux(z) as  0 a if ux(z) = 0 ux(z) = b if ux(z) = 1

34 0 Then, h(ux(z)) is 0 or 1 if ux(z) is 0 or 1, respectively, and it follows that T (x) 0 halts iff h(fx(g(y))) has at least one zero, where fx(z) = h(ux(z)). In summary,

T (x) halts ⇔ ∃y : u(x, y) = 0 ⇔ ∃y : ux(y) = 0 0 0 ⇔ ∃y : ux(g(y)) = 0 ⇔ ∃y : ux(g(y)) = a ⇔ ∃y : h(ux(g(y))) = 0



4.5 A generalization: the output of g is a tuple

As explained in the “preliminaries” section, when we say that the output of g is a tuple, say y = hy1, . . . , ymi = g(x), we mean that, for 1 ≤ i ≤ m, each of the yi is a function of x. In this case, the function f is assumed to have m input arguments. Theorems 22 (page 33) and 24 (page 34) can easily be adapted to this situation, as the set {hg1(x), g2(x),..., gn(x)i : x ∈ N} is infinite, iff at least one of the sets {gi(x): x ∈ N} is infinite.

4.6 Using HAS-ZEROS-h·f·g to analyze other decision problems

We can use the HAS-ZEROS-f·g, HAS-ZEROS-h·f, and HAS-ZEROS-h·f·g classes of problems (Theorems 22, 23, and 24 respectively) to prove the unde- cidability of many decision problems. As an example, we will now use Theorem 23 (page 34) to prove the undecid- ability of the following problem: given the PR function f,

∀x : [(f(x) −· 1) + f(x)] = 0? (7)

First consider the negation of the question (7),

∃x : [(f(x) −· 1) + f(x)] 6= 0? (8)

Clearly, (8) is decidable iff (7) is decidable. We can write the question (8) as “∃x : h(f(x)) = 0?” where h(y) = (y −· 1) + y. We have h−1(0) = {0}. As this set is neither empty nor N, we can use Theorem 23 to show that problem (7) is undecidable.

4.7 Classifying a problem – testing the properties of g and h

Given a problem in the class HAS-ZEROS-f·g, it is interesting to know if the function g has in fact infinite codomain; similarly for the classes HAS-ZEROS-h·f and HAS-ZEROS-h·f·g.

35 Consider the class HAS-ZEROS-f·g. According to Recursion Theory, if the function g is fixed, the problem “is the codomain of g infinite?” is decidable: as there is only one instance of the problem, the answer is fixed, either yes or no. However, in order to classify a problem in a class, we may want to analyze the problem, “is the codomain of a given PR function g infinite?”, and as we have seen in Theorem 19 (page 19) this problem is undecidable, belonging to 0 0 0 the class Π2 \ (Σ1 ∪ Π1). The problem associated with the post-function h can be expressed as Problem HAS-ZEROS-AND-NONZEROS Instance: PR function h. Question: ∃ a, b : h(a) = 0 and h(b) 6= 0?

Theorem 25 The problem HAS-ZEROS-AND-NONZEROS is undecidable, be- 0 longing to the class Σ1 \ ∆.

0 Proof. Membership in Σ1 is obvious. Reduce HAS-ZEROS to HAS-ZEROS- AND-NONZEROS. Let f be the instance of HAS-ZEROS, and let   1 if x = 0 g(x) = 0 if x ≥ 1 and f(x − 1) = 0  1 if x ≥ 1 and f(x − 1) 6= 0

Clearly, f has at least one zero iff there are integers a and b such that g(a) = 0 and g(b) 6= 0.  In summary, if the PR function h for the class HAS-ZEROS-f·g or HAS-ZEROS-h·f is given by a recursive definition or by Loop program, it is not decidable whether the condition expressed in Theorem 22 or 23 (pages 33 and 34 respectively) is satisfied. A similar situation occurs with the class HAS-ZEROS-h·f·g. Thus, the problem of knowing if a given problem belongs to one of the classes HAS-ZEROS-f·g, HAS-ZEROS-h·f, or HAS-ZEROS-h·f·g (the instance is g and/or h) is decid- able is itself undecidable.

5 Generalizations of the PR decision problems

Our goal in this section is to further generalize the results of the previous section. In particular we will

– Consider not only the zeros of PR functions but also first order logic predicates, implemented with PR functions, Section 5.1 (page 37). – Study systems in which the instance f may be composed with itself, Sec- tion 5.3 (page 42). – Consider not only compositions of the form h(f(g(x))), but also a general form of “placing” a PR function f (the instance of the decision problem) inside a fixed PR system S, Section 5.2 (page 38).

36 As previously, the instance of each problem is always be a PR function f, 0 while g, g , g1, g2..., h denote fixed PR functions.

5.1 Existential first order logic with PR functions

Logical connectives and predicate formulas can be represented by PR functions. There are many possible representations. We adopt the following conventions.

– False and True will be represented by the integers 0 and 1 respectively.

– The integer 0 will be interpreted as False and any integer different from 0 will be interpreted as True.

– The equality E = 0 will be represented by the PR function ZERO(E), with output 1 (True) if E = 0 and 0 otherwise.

– The Boolean connectives “¬”, “∧”, and “∨” are represented respectively by the PR functions NOT(·), AND(·, ·), and OR(·, ·), all with codomain {0, 1}.

– As illustrated in examples4 and5 below, comparison with 0 is enough to represent an inequality between two PR formulas E and F , that is a comparison of the form “E op F ”, where op ∈ {<, ≤, =, ≥, >, 6=}.

Example 2 (Truth value to integer) We have 4 + AND(2, 9) = 5 because

AND(2, 9) → AND(True, True) → True → 1 Note that, with this convention, a question like “∃x : f(x)?” asks for the existence of some x such that f(x) 6= 0.

Example 3 (Polynomials) Let a polynomial of y be a finite sum (“+”) or difference (“−· ”) of powers of y multiplied by integer coefficients. An example is y3 −· 4y + y. An equality of the form “(polynomial of)f(x) = 0”, where f is PR, is of course a particular case of Theorem 22, page 33.

Example 4 (Comparisons) This example illustrates the fact that we do not need predicates like “> 0”, “≥ 0”, etc. because we can represent them with the predicate “ZERO”. Consider for instance the “translation” of f(x) > 2.

f(x) > 2 ⇔ NOT((f(x) −· 2) = 0) ⇔ NOT(h(f(x)) = 0) ⇔ NOT(ZERO(h(f(x))) where h(x) def= λx [x −· 2].

37 Example 5 (Comparison of two PR formulas) Comparison with 0 is enough, as illustrated by this example. The predicate f(x) = f(x + 5) can be translated to a PR function:

f(x) = f(x + 5) ⇔ ZERO((f(x) −· f(x + 5)) + (f(x + 5) −· f(x))) ⇔ ZERO(h(f(x), f(g(x)))) where ( g(x) def= λx [x + 5] h(x, y) def= λx y [(x −· y) + (y −· x)]

We will generalize the previous results (essentially Theorem 24 in page 34), so that it applies to any composition of f with arbitrary, possibly non-unary, PR fixed functions. We may, for instance, be interested in

– A predicate represented by a PR function of the form

AND(ZERO(f(g1(x))), ZERO(f(g2(x)))) (9)

where g1 and g2 are fixed PR functions. – The use of functions like h and h0 below  f(x) if x is even h(f(x)) = 1 if x is odd

 f(x) if x is odd h0(f(x)) = 1 if x is even

Definition 17 (FOL existential PR problem) A FOL existential PR prob- lem is a problem of the form “∃x : E(x)?” where x denotes a tuple of variables and E(x) denotes a FOL PR expression, which is a composing fixed PR func- tions with one occurrence of f.

5.2 A PR function f in an acyclic PR structure: normal form

In Section 4.4 (page 34) we fully characterized the existence of zeros of a function with the form h(f(g(x))), where f is the instance of the problem and g and h are fixed PR functions. We consider now a more general situation in which there is a unique occurrence of f “inside” an arbitrary acyclic primitive recursive structure, see Section 5.2.1 (see also Figure1, page4). For any such structure there is an equivalent normal form, see Theorem 26 (page 40). The more general case in which several occurrences of f are possible is briefly studied in Section 5.3, page 42.

5.2.1 Acyclic PR expressions

We begin by defining acyclic PR expressions.

38 Definition 18 An acyclic PR expression (aPRe) is an acyclic directed graph whose nodes are PR functions, input variables xi, and the output variable y, and whose edges have the form (a, b) where a is either an input node or the output of a PR function, and b is either the input of a PR function or y.

A particular aPRe is illustrated in Figure8, page 40. An aPRe can be expanded into a single formula. In the example of Figure8, we get m(f(x1, g(x1, x2)), g(x1, x2), h(g(x1, x2), x2))

In general, sub-expressions are repeated; in this example, “g(x1, x2)” occurs 3 times. Another way of representing an aPRe is to use definitions in a system of equations. This method avoids the repetition of sub-expressions. In our example (Figure8, page 40) a possible system of equations is  z = g(x1, x2)   u = f(x1, z) v = h(z, x2)   y = m(u, z, v)

A system of equations equivalent to an aPRe must satisfy the following condi- tions

– Every left hand side (LHS) is the definition of a new variable, that is, a variable that does not occur in previous equations nor on the right hand side of this equation.

– The variable defined by the last expression is the output variable.

– Each RHS has the form f(w1, . . . , wn) where each wi is either an input variable or a variable previously defined.

5.2.2 The normal form of a acyclic PR expressions

Instead of the composition h(f(g(x))) we consider a general case, in which a given PR function f is placed somewhere inside a fixed acyclic PR structure (or aPRe) S. The decision problem is Instance: A PR function f Question: Does S(x) has at least a zero?

In this general case, and contrarily to the problem h(f(g(x))) = 0 (Theorem 24, page 34) it does not seem easy to get a simple condition for the decidability of the problem. As a possible step for the solution of this problem, we will show that such an arbitrary acyclic structure can be reduced to a normal form illustrated in Figure9, page 43. This normalization has nothing to do with primitive recursive functions and can be applied to arbitrary functions.

39 x1 f

g m y

x2 h

Figure 8: An example of an acyclic PR expression, or “aPRe”. In gen- eral, the corresponding output expression contains multiples occurrences of the same sub-expression. In this case the output expression is y = m(f(x1, g(x1, x2)), g(x1, x2), h(g(x1, x2), x2)).

Looking ahead, consider Figure 10, page 43, which represents the condition “∃x : S(x) = 0?”, where S has been reduced to the normal form (Theorem 26 below). We can see the origin of the difficulty of finding solutions of S(x) = 0, even when S is in the normal form: there must be a pair hx, y0i in the set h−1(0) such that, if we apply g and f in succession ro x, we get that same value y0. That is, (1) (2) z }| { z }| { ∃ hx, y0i ∈ h−1(0) : f(g(x)) = y0 We now have two interacting conditions ((1) and (2) above) for the existence of a zero, and this is the reason of the difficulty in finding an explicit condition for the existence of zeros of S(x) in the general case. The main result of this section is the following theorem.

Theorem 26 An arbitrary acyclic PR expression S(x) = y containing an oc- currence of f can be reduced to the form h(x, f(g(x))), where g is a fixed (not depending on f) PR multifunction (Definition1, page5) and h is a fixed PR function. The number of outputs of g is equal to the arity of f.

The structure of the normal form is illustrated in Figure9, page 43. Before proving this result we illustrate it with an example.

Example 6 Consider the function of Figure8 (page 40). We get  h(x1, x2, y) = m(y, g(x1, x2), h(g(x1, x2), x2)) g(x1, x2) = hx1, g(x1, x2)i and, as stated in Theorem 26 we have y = h(x, f(g(x))).

Proof. Consider an acyclic graph that corresponds to an aPRe. We describe an iterative algorithm that successively “eliminates” nodes of the graph until

40 an aPRe equivalent to h(x, f(g(x))) is obtained, see Figure9 (page 43). The output variable y of S must occur in a single equation (the last one) whose initial form is, say y = H0(...); the final form of H0 will be denoted by h. Let the function f be represented by the equation y0 = f(x0). This form of f will not change during the iterative process. With the exception of the input nodes x, of H0, and of f, the nodes of the graph are primitive recursive functions of the form u(w) that can be classified in 3 types

– INP-f: there is at least one path from the output of u(w) to an input of f.

– OUT-f: there is at least one path from the output y0 of f to one of the inputs w.

– NEITHER.

In Figure8 (page 40) g is an INP-f node, m is an OUT-f node, and h is a NEITHER node. We emphasize that x (the input nodes), H0, and f belong to neither of these classes and will never be eliminated (H0 may be modified during the normal- ization procedure). Notice also that as the graph is acyclic, no node can be simultaneously of the INP-f and OUT-f types. Step 1) Eliminate all nodes u of the INP-f type that are not immediate prede- cessors of f: The node u is eliminated and “included” in all the its successors (with the ex- ception of f), which may be of the INP-f, OUT-for NEITHER types (no loop is created). These modified nodes now have w among their inputs. This process may change the NEITHER nodes and the nodes in the path y0 to y. In both cases the reason is that the output of u may connect to inputs of those nodes. In the end of the elimination process, there is a single set of functions g between the inputs x of the system and the inputs of f. If the output of a function g0 of g is also connected to an OUT-f or to a NEITHER node, g0 is included in those nodes. Step 2) Eliminate all nodes u of the OUT-f type: In a similar way, these nodes are eliminated; NEITHER nodes (but not INP- fnodes, now all included in g) can change during the process. Also, outputs of NEITHER nodes (that were inputs of the OUT-f node u) can now be inputs of H0. Step 3) Eliminate all nodes u of the NEITHER type: they are included in the H0 node. In the end of the process, the final form of H0 (that is, H) needs only to have as inputs x and y. 

41 The graph of Figure8 (page 40) illustrates the procedure used in the previous proof.

Wow to obtain the normal form from the system of equations: illustration

There is an algorithm that, from a system of equations including the special function f, constructs the corresponding normal form. Instead of giving the algorithm in full detail, we illustrate it with the example of Figure8 (page 40). Please note that the function f is special, because it plays the role of an argu- ment of the system.   z = g(x1, x2) z = g(x1, x2)    u = f(x , z) (1)  u = f(x , z) 1 −→ 1 v = h(z, x2) v = h(g(x1, x2), x2)    y = m(u, z, v)  y = m(u, g(x1, x2), v)  z = g(x1, x2) (2)  −→ u = f(x1, z)  y = m(u, g(x1, x2), h(g(x1, x2), x2)) The first system of equations corresponds directly to Figure8. Although not done here, the first step would be to include all the inputs in the functions that have at least one input as argument (with exception of f). The definition of h would be changed to v = h(x1, x2, z).

Step (1). The definition of z depends only on the inputs x1 and x2 (and not on “intermediate” variables). Replace z by g(x1, x2) in every line after its definition, except in the “untouchable” function f; in this case, v = h(z, x2) is replaced by v = h(g(x1, x2), x2). In this case, the definition of z, namely z = g(x1, x2) is not deleted because its output is an input of f.

Step (2). The definition of v depends only on the inputs x1 and x2. Re- place v by h(g(x1, x2), x2) in every line after its definition; in this case

(a) The definition of y becomes y = m(u, g(x1, x2), h(g(x1, x2), x2)). (b) Also, the definition of v is deleted.

5.3 Composition of f with itself

5.3.1 Introduction

In Definition 17 (page 38) only one occurrence of f is allowed. This is because we view f as a part of a larger system S, obtained by composition or as an acyclic graph containing f as a node, see Figure1 (page4).

42 h y x0 y0 x g f

Figure 9: An arbitrary composition of one occurrence of f with PR functions can be reduced to this “normal form”. The corresponding expression has the form y = h(x, f(g(x))) where g has multiple outputs.

x h g

y = 0 h−1 x0

h f y0

Figure 10: Relationship between the values in Figure9, page 43. The global system S, y = S(x), has a zero iff, for some (x, y0) ∈ h−1(0), we have f(g(x)) = y0. For the particular case S(x) ≡ h(f(g(x))), that is, when there is no green arrow in the diagram, there is an explicit (“acyclic”) condition for the existence of a zero of S, see Theorem 24 (page 34). But no such condition is known for the general case.

However, it is interesting to study systems in which the compositions of f with itself are allowed. Recall the proof of Theorem 22 (page 33), where u takes the role of f. Part of the proof of this result involves the statement that, for any fixed function g with an infinite domain (see Equation (6)), we have

µy(f(x, y))) = µy(f(x, g(y))) (10)

If we consider an expression like f(x, f(y)) (instead of f(x, g(y))), the equal- ity (10) may not hold. If this case, that is, when g = f, the statement of Theorem 22 (page 33) is not useful. For instance, that criterion applied to the problem “Given f, does the function f(f(x)) have a zero?” (11) says that this problem is undecidable iff the codomain of f is infinite. But we can not characterize the decidability of a problem with instance f by an undecidable constraint on f itself, namely “the domain of f is infinite”.

43 5.3.2 Solution of some problems in which f is composed with itself

For the class of HAS-ZEROS problems in which f may be composed with itself, we do not know a general undecidability criterion. However, this problem seems interesting and we now study some particular recursive problems. All them turn out to be undecidable. The problems that we will consider are the following.

“FF”: given f, does the function f(f(x)) have at least one zero?”.

n f’s z }| { “F n”: given f, does the function f(f(··· f(x))) have at least one zero? (F 2 is the problem FF.) “FFZ2”: given f, does the function f(f(x)) have two or more zeros? — two or more zeros of the composition of f with itself.

We will use the concept of “graph of a function”.

Definition 19 The graph of a function f is the directed graph

(V,E) where V = N and E = {(i, j): i ∈ N, f(i) = j}

Theorem 27 The problem FFZ2 is undecidable.

Proof. We reduce HAS-ZEROS to FFZ2. Given an instance f of HAS-ZEROS, define the function g, instance of FFZ2, as

g(0) = 0 g(1) = f(0) g(2) = f(1) g(3) = f(2) ......

As g(g(0)) = g(0) = 0 the function g(g(x)) always has at least one zero. Also, if f(z) = 0 for some z, g(g(x)) has two or more zeros, because in this case we have g(g(z + 1)) = g(f(z)) = g(0) = 0 (and z + 1 6= 0!). On the other hand, if f(x) has no zeros and x > 0, we get

g(g(x)) = g(f(x − 1)) = g(y) = f(y − 1) 6= 0

def where y = f(x − 1) > 0. 

Theorem 28 The problem FF (page 43) is undecidable.

Proof. Notice that if the graph of g contains a path with length 2 ending in 0 then ∃x : g(g(x)) = 0, that is, the answer to FF (with instance g) is Yes, and that the reciprocal is also true.

44 We reduce HAS-ZEROS to FF. Given an instance f of HAS-ZEROS, define the graph of the function g, the instance of FF, as:

– The set of nodes is N.

– For every pair (i, j) in the graph of f, that is, for every f(i) = j with i ∈ N, there are two edges of the graph of g: (2i, 2i + 1) and (2i + 1, 2j).

In a sense, to every node i of the graph of f correspond two nodes of the graph of g: 2i and 2i + 1. See Figure 11 where the transformation is illustrated. Suppose that there is a solution of HAS-ZEROS. In the graph of g the so- lution f(x) = 0 corresponds a path with length 2 ending in 0, namely 2x → 2x + 1 → 0. So, g(g(2x)) = 0. Suppose that there is a solution of FF. The graph of g has a path of length 2 ending in 0, say g(g(x)) = 0; that path must have the form 2i → 2i + 1 → 0, because every even node 2i only connects to the successor node 2i + 1 (and never to 0). Thus, by the definition of g, we must have f(i) = 0.  The previous proof can be easily generalized.

Theorem 29 For every n ≥ 1 the problem F n is undecidable.

6 Comment: on a paper by Stefan Kahrs

Relatively to our PR undecidability results it is interesting to mention the following surprising result from [22]:

It is possible to “list all the primitive recursive functions without semantic duplicates, and in such a way that only the shortest ones of each equivalence class appears in the list”.

More specifically, the descriptions (programs, indices. . . ) of the PR functions are listed so that no two descriptions describe the same function – “without semantic duplicates”. For instance, if Loop programs are used to describe PR functions, if two programs are equivalent, only one is listed. In other words, it is possible to list the Loop programs Pi as follows

Listed: P0, P1, P2, ...

   f0 f1 f2 ...

Such that

1. P0 < P1 < P2 ...

45 0 1 2 3 4 5

10

9 11

0 1 2 3 5 8

4 7

6

Figure 11: Upper diagram: the initial part of the graph of a function f, such that f(0) = 1, f(1) = 1, f(2) = 0, f(3) = 4, f(4) = 0, and f(5) = 4. The decision problem is “is there some x such that f(x) = 0?”. Bottom diagram: the transformed graph, or graph of the function g. Each node i of the top diagram is “transformed” in two nodes, 2i (blue) and 2i+1 (yellow). For each edge (i, j) in f (top diagram) there are two edges in g (bottom diagram): (2i, 2i + 1) and (2i + 1, 2j). The decision problem associated with the instance g is “is there some x such that g(g(x)) = 0?”.

2.( i 6= j) ⇒ (fi 6≡ fj). No two functions are equal. No two programs are equivalent.

3. Each program Pi is the smallest element of each class of equivalence. 4. Every class of equivalent programs is represented by its smallest program.

5. Every PR function is represented by some program.

This result7, at first, seems to contradict the fact that the equivalence of two and programs is an undecidable problem. However, this is not as useful as it

7The proof is interesting and not dissimilar in technique from the proof of Proposition 1 in [15] (see also [16]), in the sense that two simultaneously growing integers are considered: the index of the Loop program (or PR function) and the maximum argument considered until the current step.

46 seems at first, because it is not difficult to prove that it is not possible in general to find the program of the listing that is equivalent to a given program. Note. The word “shortest” in the sentence “only the shortest ones of each equivalence class appears in the list” only means the first in some specified order, such as the word order described in Section2 (page5). There is no direct relation with the shortest universal description of the PR function (). 

7 Conclusions and open problems

The primitive recursive functions (PR) form a vast and important class of re- cursive (total computable) functions. Currently there has not been much re- search on PR functions, probably because they often correspond to trivially decidable problems. However, there are many undecidable – and interesting – problems directly related to PR functions. In this work we studied the degree of undecidability of relatively large number of decision problems related with PR functions. All the problems studied are undecidable and their degree of unsolvability (the location in the arithmetic hierarchy), have been settled. The exact conditions for the decidability of the central decision problem “∃x : h(f(g(x))) = 0?, where g and h are fixed PR functions and f is the instance of the problem (also a PR function), have been established, and this class of decision problems was studied. A more general situation is a PR function f – again, the instance of the prob- lem – placed somewhere inside a fixed PR acyclic graph S. Let the correspond- ing function be S(f, x); the question is “∃x : S(f, x) = 0?”. Other generalizations and topics related with PR decision were briefly studied include: decidability problems related with the representation of existential first order logic with PR functions, problems in which the instance f may compose with itself, and a PR enumeration method due to Kahrs. Of course, many problems remain open. Some of the more interesting are:

– Find the exact decidability conditions for the general situation S(f, x) de- scribed above. In this work these decidability conditions have not been es- tablished, but an algorithm for converting the PR graph to an equivalent “normal form” is described. This may be a helpful tool for further research. – Relate the representation of existential first order logic with PR functions (mentioned above) with the theory of PR-arithmetic, see for instance the for- mal system described in [17] where the axioms are related with PR definitions, and inference rules related to substitution and PR definition uniqueness. In this system there are neither explicit quantifiers nor logic connectives. – Study in general the decidability problems in which several occurrences of the instance f may occur; this includes in particular expressions in which f

47 composes with itself. In this work only some particular problems of this form were studied. – Study the completeness (within the arithmetic hierarchy) of the decision prob- lems mentioned in this work. Most of them, if not all, are complete, but we can ask: are there interesting examples of non-complete problems?

0 – Search for the existence of “PR problems” in the classes ∆i for some i ≥ 1. Also, search for problems in the analytical hierarchy8

References

[1] Paul Axt. On a subrecursive hierarchy and primitive recursive degrees. Transactions of the American Mathematical Society, 92:85–105, 1959.

[2] Stephen J. Bellantoni and Karl Heinz Niggl. Ranking primitive recur- sions: The low Grzegorczyk classes revisited. SIAM Journal of Computing, 29:401–415, 1998.

[3] George S. Boolos, John P. Burgess, and Richard C. Jeffrey. and Logic. Cambridge University Press, 2007. Fifth Edition.

[4] L¨oicColson. About primitive recursive algorithms. Theoretical Computer Science, 83:57–69, 1991.

[5] L¨oicColson and Daniel Fredholm. System T, call-by-value and the mini- mum problem. Theoretical Computer Science, 206:301–315, 1998.

[6] Tristan Crolard, Samuel Lacas, and Pierre Valarcher. On the expressive power of the Loop language. Nordic Journal of Computing, 13(1-2):46–57, 2006.

[7] Dennis F. Cudia. The degree hierarchy of undecidable problems of formal grammars. In Patrick C. Fischer, Robert Fabian, Jeffrey D. Ullman, and Richard M. Karp, editors, STOC, pages 10–21. ACM, 1970.

[8] Ren´eDavid. On the asymptotic behaviour of primitive recursive algo- rithms. Theoretical Computer Science, 266(1-2):159–193, 2001.

[9] Martin Davis. Computability and Unsolvability. Dover, 1985.

[10] J¨orgEndrullis, Herman Geuvers, Jakob Grue Simonsen, and Hans Zan- tema. Levels of undecidability in rewriting. Information and Compututa- tion, 209(2):227–245, 2011.

[11] Solomon Feferman. Are there absolutely unsolvable problems? G¨odel’s dichotomy. Philosophia Mathematica, 14(2):134–152, 2006.

8In [10] it is proved that some problems associated with rewriting systems belong to the analytic hierarchy (but not to the arithmetical hierarchy).

48 [12] Daniel Fredholm. Computing minimum with primitive recursion over lists. Theoretical Computer Science, 163(3):269–276, 1996.

[13] Michael R. Garey and David S. Johnson. Computers and Intractability: A Guide to the Theory of NP-Completeness. W. H. Freeman & Co., New York, NY, USA, 1979.

[14] Bernhard Goetze and Werner Nehrlich. Loop programs and classes of primitive recursive functions. In MFCS, pages 232–238, 1978.

[15] Oded Goldreich and Bernd Meyer. Computational indistinguishability: algorithms vs. circuits. Theoretical Computer Science, 19(1):215–218, 1998.

[16] Oded Goldreich and Madhu Sudan. Computational indistinguishability: A sample hierarchy. IEEE Conference on Computational Complexity 1998, pages 24–33, 1998.

[17] R. L. Goodstein. Logic-free formalisations of recursive arithmetic. Mathe- matica Scandinavica, 2:247–261, 1954.

[18] A. Grzegorczyk. Some classes of recursive functions. Rozprawy Matematy- czne, 4:1–45, 1953.

[19] Hans Hermes. Enumerability, Decidability, Computability. Springer-Verlag, 1969.

[20] Peter G. Hinman. Recursion-theoretic Hierarchies. Perspectives in math- ematical logic. Springer-Verlag, 1978.

[21] John E. Hopcroft and Jeffrey D. Ullman. Introduction to Automata Theory, Languages, and Computation. Addison-Wesley, 1979.

[22] Stefan Kahrs. The primitive recursive functions are recursively enumerable. University of Kent at Canterbury, Department of Computer Science, 200X.

[23] Stephan Cole Kleene. Introduction to . North-Holland, 1952. Reprinted by Ishi press, 2009.

[24] Stephen C. Kleene and Emil L. Post. The upper semi-lattice of degrees of recursive unsolvability. Ann. of Math. (2), 59:379–407, 1954.

[25] Stephen Cole Kleene. Recursive predicates and quantifiers. Transactions of the American Mathematical Society, 53(1):41–73, 1943.

[26] Stephen Cole Kleene. Arithmetical predicates and function quantifiers. Transactions of the American Mathematical Society, 79(1):312–340, 1955.

[27] Ming Li and Paul Vit´anyi. An Introduction to Kolmogorov Complexity and Its Applications. Springer, third edition, 2008.

[28] A. R. Meyer and D. M. Ritchie. The complexity of loop programs. Pro- ceedings of 22nd National Conference of the ACM, pages 465–469, 1967.

49 [29] A. R. Meyer and D. M. Ritchie. Computational complexity and program structure. IBM Research Report RC 1817, 1967. [30] Robert Moll. Complexity classes of recursive functions. PhD in Mathe- matics, Massachusetts Institute of technology, 1973. [31] Yiannis N. Moschovakis. On primitive recursive algorithms and the great- est common divisor function. Theoretical Computer Science, 301(3):1–30, 2003. [32] Piergiorgio Odifreddi. Classical Recursion Theory – The Theory of Func- tions and Sets of Natural Numbers. Studies in Logic and the Foundations of Mathematics. Elsevier North Holland, first edition, 1989. Second im- pression. [33] Iain Phillips. Recursion theory. In S. Abramsky, D.M. Gabbay, and T.S.E. Maibaum, editors, Handbook of Logic in Computer Science, volume 1, pages 79–187. Oxford University Press, 1992. [34] . A note on primitive recursive functions. Proceedings of the American Mathematical Society, 6(4):667–670, 1955. [35] Julia Robinson. Recursive functions of one variable. Proceedings of the American Mathematical Society, 9:815–820, 1968. [36] Raphael Robinson. Primitive recursive functions. Bull. Amer. Math. Soc., 53(10):925–942, 1947. [37] Raphael Robinson. Primitive recursive functions II. Proceedings of the American Mathematical Society, 6:663–666, 1955. [38] Hartley Rogers. Theory of Recursive Functions and Effective Computabil- ity. MIT Press Cambridge, MA, 1987. Third printing (1992). [39] Daniel Severin. Unary primitive recursive functions. Journal of Symbolic Logic, 73(4):1122–1138, 2008.

0 [40] Jakob Grue Simonsen. The Π2-completeness of most of the properties of rewriting systems you care about (and productivity). In Ralf Treinen, editor, RTA, volume 5595 of Lecture Notes in Computer Science, pages 335–349. Springer, 2009. [41] Istv´anSzalkai. On the algebraic structure of primitive recursive functions. Z. Math. Logik Grundlagen Math., 31:551–556, 1985. [42] Pierre Valarcher. Autour du concept d’algorithme: intensionnalit´e, compl´etude algorithmique, programmation et mod`eles de calcul; suivi de: fonctions bool´eennes et cryptographie. Habilitation `aDiriger des Recherches, Universit´eParis Est Cr´eteil,2010. [43] Lou van den Dries. Generating the greatest common divisor, and limi- tations of primitive recursive algorithms. Foundations of Computational Mathematics, 3(3):297–324, 2003.

50 [44] Ann Yasuhara. Recursive Function Theory and Logic. Computer Science And Applied Mathematics. Academic Press, 1971.

51