G¨odel& Recursivity

JACQUES DUPARC

BˆatimentInternef CH - 1015 Lausanne

[email protected] Jacques.Duparc@epfl.ch 2 Contents

Introduction 7

I Recursivity 9

Recursivity 11

1 Towards Turing Machines 11 1.1 Deterministic Finite Automata ...... 11 1.2 Nondeterministic Finite Automata ...... 12 1.3 Regular Expressions ...... 16 1.4 Non-Regular Languages ...... 19 1.5 Pushdown Automata ...... 20 1.6 Context-Free Grammar ...... 22

2 Turing Machines 27 2.1 Deterministic Turing Machines ...... 27 2.2 Non-Deterministic Turing Machines ...... 32 2.3 The Concept of Algorithm ...... 35 2.4 Universal ...... 36 2.5 The Halting Problem ...... 40 2.6 Turing Machine with Oracle ...... 40

3 Recursive Functions 47 3.1 Primitive Recursive Functions ...... 47 3.2 Variable Substitution ...... 52 3.3 Bounded Minimisation and Bounded Quantification ...... 53 3.4 Coding Sequences of Integers ...... 55 3.5 Partial Recursive Functions ...... 57 4 CONTENTS Introduction

Introduction 7

The basic requirements for this course are contained in the ”Mathematical Logic” course. Among other things, you should have a clear understanding of each of the following: first order language, signature, terms, formulas, theory, proof theory, models, completeness theorem, compactness theorem, L¨owenheim-Skolem theorem. It makes no sense to take this course without this solid background on first order logic.

The title of the course is ”G¨odeland Recursivity” but it should rather be ”Recursivity and G¨odel”since that is the way we are going to go through these topics

(1) Recursivity

(2) G¨odel’sincompleteness theorems (there are two of them)

Recursivity is at the heart of computer science, it represents the mathematical side of what computing is like. It is related to arithmetics and to proof theory. G¨odel’sincompleteness theorems are concerned with number theory (arithmetics) which itself lies at the core of mathematics. They contradict the commonly shared idea that everything that is true can be proved. It ruins the plan, for every mathematical statement ϕ to either prove it or disprove it (by proving ϕ). G¨odel’sfirst incompleteness theorem says that there exists a formula ϕ from number theory such that neither ϕ nor ϕ is provable. More precisely, it says that in Peano Arithmetics (which is a first order axiomatization of arithmetics) there exists a formula ϕ that cannot be proved nor disproved, and if we were to add this formula to Peano Arithmetics, one would find a second one that would not be provable nor disprovable inside their first extension of Peano Arithmetics. And if this new formula would be added again, we could find a third one and so on and so forth. To put it differently, if we want to extend Peano Arithmetics to a larger theory which is complete in the sense that it proves or disproves any given formula, there would not have any understanding of this theory, we would not get hold of it, for it would not be recursive, meaning that we would not have any efficient way of figuring out whether a given closed formula is part of the theory or not (not provable from the theory, but simply part of the theory!). This is precisely where the notion of recursivity plays a crucial role. One does not have the right comprehension of G¨odel’sincompleteness theorems without a proper understanding of what recursivity is like. The formula that we will construct (the one that is not provable nor disprovable in Peano Arith- metics) is rather odd. There is no chance that one might tumble over such a formula during the usual mathematical practice. However, since G¨odel’sincompleteness theorem was proved, there have been several examples of real arithmetic mathematical formulas that are not provable nor disprovable in Peano Arith- metics, although the are formulated in the language of arithmetics. A good example of such a formula is the one related to Goodstein sequences (1944). A Goodstein m m m sequence is of the form Gp0q,Gp1q,Gp2q,..., etc, where m is a positive integer. It is defined the following way (we take m “ 4 as an example, the general case being obtained by replacing 4 m m m Gp0q “ 4 by Gp0q “ m and gathering the other values Gp1q,Gp2q, etc the same way): 8 EPFL G¨odel& Recursivity

4 2 ˝ Gp0q “ 4 write 4 in hereditary base 2: 4 “ 2 replace all 2’s by 3’s, then subtract 1: 33 “ 26

4 2 1 0 ˝ Gp1q “ 26 write 26 in hereditary base 3: 26 “ 2 ¨ 3 ` 2 ¨ 3 2 ¨ 3 replace all 3’s by 4’s, then subtract 1: 2 ¨ 42 ` 2 ¨ 412 ¨ 40 ´ 1 “ 41

4 2 1 0 ˝ Gp2q “ 41 write 41 in hereditary base 4: 41 “ 2 ¨ 4 ` 2 ¨ 4 2 ¨ 4 replace all 4’s by 5’s, then subtract 1: 2 ¨ 52 ` 2 ¨ 512 ¨ 50 ´ 1 “ 60

4 ˝ Gp3q “ 60 ... etc

4 402653209 Amazingly, Gpnq increases until n reaches the value 3 ¨ 2 where it reaches the maximum of 3 ¨ 2402653210 ´ 1, it stays there for the next 3 ¨ 2402653209 steps then starts its final descent and eventually reaches 0. m Amazingly, for every integer m, the Goodstein sequence pGpnqqnPN is ultimately constant with value 0, i.e. lim Gm “ 0. nÑ8 pnq However this statement which is easily formalizable in the language of arithmetics is not provable in Peano Arithmetics (Kirby and Paris 1982). It requires a stronger theory to be proved (for instance record order arithmetics). G¨odel’ssecond incompleteness theorem than says that mathematics cannot prove its own con- sistency (unless it is inconsistent in which case it can prove its own consistency for it can prove everything). More precisely, in any recursive extension J of Peano Arithmetics, the formula ”ConspJq” (which is a formula from number theory that asserts that there is no proof of K from J) is not provable unless J is inconsistent i.e.

IfJ&c thenJ&c ConspJq

We will present three different approaches:

˝ Computer Science ÝÑ Turing Machine (one of the abstract model of computer)

k ˝ Number Theory ÝÑ Recursive functions which are particular functions N Ñ N Part I

Recursivity

Chapter 1

Towards Turing Machines

The whole chapter is highly inspired by Michael Sipser’s book: “Introduction to the Theory of Computation” [31]. It is a dashing introduction to the notions of Finite Automata, PushDown Automata, Turing Machines.

We also recommend “Introduction to , languages, and computation” by John E. HopcroftHopcroft, John E., Rajeev MotwaniMotwani, Rajeev et Jeffrey D. UllmanUllman, Jef- frey D. [19]; “Computational complexity” by Christos H. PapadimitriouPapadimitriou, Christos H. [26] and “A mathematical introduction to logic” by Herbert B. Enderton Enderton, Herbert B. [8].

1.1 Deterministic Finite Automata

We will see that any finite automaton can be regarded as a rudimentary Turing machine: a Turing machine that never writes anything and only goes one direction.

Definition 1 A deterministic finite automaton (DFA) is a 5-tuple pQ, Σ, δ, q0,F q, where (1) Q is a finite set called the states,

(2) Σ is a finite set called the alphabet,

(3) δ : Q ˆ Σ ÝÑ Q is the transition function,

(4) q0 P Q is the initial state, and (5) F Ď Q is the set of accepting states.1

We denote by Σăω (or equivalently by Σ˚) the set of finite words on Σ and by ε the empty sequence.

1Accept states sometimes are called final states. 12 EPFL G¨odel& Recursivity

ăω Definition 2 A DFA “ pQ, Σ, δ, q0,F q on an alphabet Σ accepts the word w P Σ if and A only if

˝ either w “ ε (the empty sequence) and q0 P F

˝ or w “ xa0, . . . , any with each ai P Σ, and there is a sequence of states r0, . . . , rn`1 such that:

‚ r0 “ q0

‚@ i ă n, δpri, aiq “ ri`1

‚ rn`1 P F .

Notation 3 Given any DFA , A p q “ tw P Σăω : w is accepted by u . L A A p q denotes the language accepted by . L A A Definition 4 Any language recognised by some deterministic finite automata (DFA) is called regular.

Example 5 The following DFA recognises the language p q “ tw1 | w P t0, 1uăωu of all A L A the words of 0’s and 1’s that end with a 1.

0 1

q0 q1 1

0

1.2 Nondeterministic Finite Automata

Given any alphabet Σ, we both assume that ε R Σ holds and write Σε for Σ Y tεu.

Definition 6 A nondeterministic finite automaton (NFA) is a 5-tuple pQ, Σ, δ, q0,F q, where

(1) Q is a finite set of states,

(2) Σ is a finite alphabet,

(3) δ : Q ˆ Σε ÝÑ pQq is the transition function, P Recursivity 13

(4) q0 P Q is the initial state, and

(5) F Ď Q is the set of accepting states.

ăω Definition 7 Let “ pQ, Σ, δ, q0,F q be an NFA and w P Σ . We say that accepts w if N N and only if

˝ either w “ ε the empty sequence and q0 P F

˝ or w can be written as w “ xa0, . . . , any with each ai P Σε, and there is and a sequence of states r0, . . . , rn`1 such that:

‚ r0 “ q0

‚@ i ă n, ri`1 P δpri, aiq,

‚ rn`1 P F .

Example 8 The following NFA recognises the language p q “ tw1 | w P t0, 1uăωu of all N L N the words of 0’s and 1’s that end with a 1.

0, 1

1 q0 q1

Proposition 9 Every NFA has an equivalent DFA. i.e. given any NFA there exists some N DFA such that D p q “ p q. L N L D

Proof of Proposition 9: Given any NFA “ xQ, Σ, δ, q0,F y, we build some DFA “ 1 1 1 1 N D xQ , Σ, δ , q0,F y that recognises the same language. (1) Q1 “ pQq P (2) For S Ď Q and a P Σ we set

ε˚aε˚ δ1pS, aq “ tq1 P Q | Dq P S q ÝÝÝÝÑ q1u

ε˚aε˚ where q ÝÝÝÝÑ q1 stands for the existence of a path in the graph of that goes through N exactly one edge labelled with ”a”, the others being labelled with ”ε”.

1 (3) q0 “ tq0u 14 EPFL G¨odel& Recursivity

(4) F 1 “ tS Ď Q | S X F ‰ Hu.

% 9

Definition 10 Let A and B be languages. We define the regular operations union, concatena- tion, and star as follows.

˝ Union: A Y B “ tx | x P A or x P Bu.

˝ Concatenation: A ˝ B “ txy | x P A and y P Bu.

˚ ˝ Star: A “ tx1x2 . . . xk | k ě 0 and each xi P Au.

Theorem 11 Regular languages are closed under union, concatenation and star.

Proof of Theorem 11: Let 1 “ pQ1, Σ, ∆1, q1,F1q, 2 “ pQ2, Σ, ∆2, q2,F2q be two NFAs N N recognising respectively A1 and A2.

1 N N2

Union We need an NFA such that recognises a string if and only if 1 or 2 recognises N N N N it. By working nondeterministically, the automaton is allowed to split into two copies: N we construct in such a way that 1 and 2 work in parallel at the same time. We N N N assume Q1 X Q2 “H and q0 R Q1 Y Q2. Define “ pQ, Σ, ∆, q0,F q where N

(1) Q “ tq0u Y Q1 Y Q2.

(2)∆ Ă Q ˆ Σε ˆ Q is defined by: pp, s, rq P ∆ if and only if one of the following is true

(a) p “ q0 (b) p, r P Q1 (c) p, r P Q2 s “ ε pp, s, rq P ∆1 pp, s, rq P ∆2. r P tq1, q2u

(3) F “ F1 Y F2. Recursivity 15

The machine splits immediately into two copies of itself, which work exactly as 1 and N 2. It accepts a string if and only if at least one of the two main copies ends up in an N accepting state, i.e. in F1 or in F2, i.e. if and only if 1 or 2 accept it. N N

"

"

N

Concatenation Here we need an NFA that accepts a word w if and only if w can be broken N into two pieces: a prefix and a suffix w “ wpws such that wp is accepted by 1 and ws N is accepted by 2. We set q1 as the initial state and let the machine read the same way N 1 would do. Any time that 1 finds itself in an accepting state, we want to non- N N N deterministically start reading as if it were 2 but still remaining a copy of itself: so we N make it split any time it comes to some final state of 1. The reason is that we want N to be able to check longer sub-strings as well, because it might be the case that the first prefix that is found to be accepted by 1 corresponds to a suffix that is rejected by 2, N N while there is a longer prefix which is also accepted by 1 that yields a suffix which is this N time also accepted by 2. Formally, we define ∆ by: pp, s, rq P ∆ if and only if one of the N following is true

(1) p, r P Q1 (2) p, r P Q2 (3) p P F1 pp, s, rq P ∆1 pp, s, rq P ∆2 s “ ε r “ q2

The third condition guarantees the splitting. Finally, we set the accepting set to be F “ F2. 16 EPFL G¨odel& Recursivity

" "

" "

N

Star Here the machine should be able to check if a word w can be broken into a finitely N many pieces w “ w1w2 ¨ ¨ ¨ wk, each of them being accepted by 1. So has to read w1 N N as if it were 1, and when it finds itself in an accepting state, it needs to start all over N again and read w2 and so on and so forth. The construction is similar to the one of the concatenation, but since A˚ contains the empty string, we want to accept ε. So we just 1 N add an initial state q0 which is also an accepting state, and from where the initial state of 1 is reached by an ε move. % 11 N

"

"

"

N 1.3 Regular Expressions

Definition 12 We say that R is a regular expression if R is of one the following form:

(1) a (for some a P Σ) (3) H (5) R1 ˝ R2

˚ (2) ε (4) R1 Y R2 (6) R1 where R1 and R2 are regular expressions.

The expression ε represents the language containing a single sequence, namely, the empty se- quence, whereas H represents the language that doesn’t contain any sequence. Notice that Recursivity 17

(1) R ˝ H “ H ˝ R “H (2) H˚ “ tεu.

Definition 13 Let R be a regular expression. We define by induction its associated language LpRq as follows:

(1) Lpaq “ tau (4) LpR1 Y R2q “ LpR1q Y LpR2q

(2) Lpεq “ tεu (5) LpR1 ˝ R2q “ LpR1q ˝ LpR2q

˚ ˚ (3) LpHq “ H (6) LpR1 q “ LpR1q .

Theorem 14 A language L is regular if and only if there exists a regular expression R such that L “ LpRq.

Proof of Theorem 14:

(Ñ) (1) Lpaq “ tau (4) LpR1 Y R2q “ LpR1q Y LpR2q

(2) Lpεq “ tεu (5) LpR1 ˝ R2q “ LpR1q ˝ LpR2q

˚ ˚ (3) LpHq “ H (6) LpR1 q “ LpR1q

(ð) (1) We go from some n-states DFA to some n ` 2-states Generalized-NFA:

(a) we add (A) an initial state “s” (B) an accepting state “a” ε (C) a transition a ÝÑ q0 ε (D) a transition q ÝÑ a (each accepting state q ‰ a)

(b) we reduce the set of accepting states to tau.

(2) We go from some k`1`2-states Generalized-NFA 2 to some k`2-states Generalized- NFA by removing one state from the original automaton: qrip R ts, au and for each states qin R ta, qripu and qout R ts, qripu we set the new transition to be:

˚ RinÑrip ˝ pRripÑripq ˝ RripÑout Y RinÑout qin ÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÑ qout

where RinÑrip, RripÑrip, RripÑout and RinÑout denote the following transitions:

2an NFA whose transitions are labelled with regular expressions. 18 EPFL G¨odel& Recursivity

RinÑrip RripÑout (a) qin ÝÝÝÝÝÑ qrip (c) qrip ÝÝÝÝÝÝÑ qout

RripÑrip RinÑout (b) qrip ÝÝÝÝÝÑ qrip (d) qin ÝÝÝÝÝÑ qout.

(3) We end up with a 2-states (“s” and “a”) Generalized-NFA with a single transition of R the form s ÝÑ a. The regular expression R gives the solution.

Example 15

0 s 0 "

1 1

" 0, 1 a 0, 1 (a) (b) " s 0 s

0⇤1(0 1)⇤ 1(0 1)⇤ [ [ a a (c) (d)

An other example with an automaton a bit more complicated.

Example 16

(a) 0

1 0

1 0

1

(b) Recursivity 19

0

1 s 0 a " " 1 0 " 1

(c)

00 1 0 [ s " a 01 10 0 [ 1 "

11

(d)

0(00 1)⇤ s [ a

0(00 1)⇤01 b (10 0)(00 1)⇤ " [ [ [ [ [

(10 00)(00 1)⇤01 11 [ [ [ (e)

0(00 1)⇤01 b (10 00)(00 1)⇤01 11 ⇤ (10 0)(00 1)⇤ " 0(00 1)⇤ [ [ [ [ [ [ [ [ [ s [ a

% 14

1.4 Non-Regular Languages

Notice that any finite word on Σ can be coded by an integer, so that there are only 0 many ℵ regular languages. But there are 2ℵ0 many languages for there are as many as the number of subsets of N. Hence most languages are not regular!

Theorem 17 (Pumping Lemma) If A is a , then there is a number p (the pumping length) where, if s is any sequence in A of length at least p, then s may be divided into three pieces, s “ xyz, satisfying the following conditions: 20 EPFL G¨odel& Recursivity

(1) for each i ě 0, xyiz P A,

(2) |y| ą 0, and

(3) |xy| ď p

Proof of Theorem 17: Let be any DFA such that p q “ A. Set p to be the number of states A L A of . Let s be accepted by . Then s may be broken into three pieces: s “ xyz. Such that the A x A y path q0 ÝÑ q never visits twice the same state. The path q ÝÑ q visits twice the state q but none u of the others twice. This holds since for every word u of length at least p every path q1 ÝÑ q2 in visits at least twice the same state. A y

x z

% 17

m m Example 18 The language t0 1 | n P Nu is not regular. m m By contradiction, assume there exists some DFA “ pQ, Σ, δ, q0,F q which recognises t0 1 | A p p n P Nu. We consider p “ |Q| the number of states of . the word 0 1 is accepted by . By A A the previous Pumping Lemma there exist x, y and z such that 0p1p “ xyz and

i m m (1) for each i ě 0, xy z P t0 1 | n P Nu, (2) |y| ą 0, and

(3) |xy| ď p

But since |xy| ď p, it turns out that xy P 0˚ and z P 0˚1˚. Therefore, for each integer i ą 1 we have xyi P 0˚, hence xyiz contains too many 0’s compared to 1’s: a contradiction.

1.5 Pushdown Automata

Definition 19 A (PDA) is a 6-tuple pQ, Σ, Γ, δ, q0,F q, where Q, Σ, Γ and F are all finite sets, and Recursivity 21

(1) Q is the set of states, (2) Σ is the input alphabet, (3) Γ is the stack alphabet,

3 (4) δ : Q ˆ Σε ˆ Γε ÝÑ pQ ˆ Γεq is the transition function , P (5) q0 P Q is the initial state, and (6) F Ď Q is the set of accepting states.

Definition 20 A pushdown automaton M “ pQ, Σ, Γ, δ, q0,F q computes as follows. It accepts input w if w can be written as w “ w1w2 . . . wm, where each wi P Σε and sequences of states ˚ r0, r1, . . . , rm P Q and sequences s0, s1, . . . , sm P Γ exist that satisfy the next three conditions. The sequences si represent the sequence of stack contents that M has on the accepting branch of the computation.

(1) r0 “ q0 and s0 “ ε. This condition testifies that M starts out properly: both in the initial state and with an empty stack.

(2) For i “ 0, . . . , m ´ 1, we have pri`1, bq P δpri, wi`1, aq, where si “ at and si`1 “ bt for ˚ some a, b P Γε and t P Γ . This condition states that M moves properly according to the state, stack, and next input symbol.

(3) rm P F . This condition states that an accepting state occurs right at the end of the reading of the input. (1) One step of a computation:

a b e e c c ri ri ri+1 ri+1

w1w2w3 wi 1wiwi+1 wm w1w2w3 wi 1wiwi+1 wm ··· ··· ··· ···

(2) The special case where a “ ε and b P Γ (the PDA “pushes” b to the top of the stack)

e c ri ri+1

w1w2w3 wi 1wiwi+1 wm ··· ···

3 For a deterministic version, replace PpQ ˆ Γεq by Q ˆ Γε. 22 EPFL G¨odel& Recursivity

(3) The special case where a P Γ and b “ ε (the PDA “pops off” a from the top of the stack)

a e e c c ri ri ri+1 ri+1

w1w2w3 wi 1wiwi+1 wm w1w2w3 wi 1wiwi+1 wm ··· ··· ··· ···

m m Example 21 (1) The language t0 1 | n P Nu is recognised by a PDA.

", " !? 0, " 0 !

1, 0 " ! ", " ?! 1, 0 " !

(2) The language t0i1j2k | i, j, k ě 0 and i “ j or i “ ku is recognizable by a PDA, however it is not recognizable by a deterministic PDA.

1, 0 " 2, " " ! ! 0, " 0 ! ", ?!? , " " " ! ", " !? ", " ! " ", " " ", ! ?!?

1, " " 2, 0 " ! !

1.6 Context-Free Grammar

Definition 22 A context-free grammar is a 4-tuple pV, Σ,R,Sq, where

(1) V is a finite set whose elements are called variables, Recursivity 23

(2) Σ is a finite set, disjoint from V . Its elements are called terminals,

(3) R is a finite set of rules. Each rule is a couple of the form pξ, uq where ξ P V and u P pV Y Σq˚.

(4) S P V is the initial variable.

If u, v and w are sequences of variables and terminals, and A Ñ w is a rule of the grammar, we say that uAv yields uwv (written uAv ñ uwv). We write u ñ˚ v if u “ v or if a sequence u1, u2, . . . , uk exists for k ą 0 and

u ñ u1 ñ u2 ñ ... ñ uk ñ v.

The language generated by the grammar is tw P Σ˚ | S ñ˚ wu.

Example 23 Consider pV, Σ,R,Sq the context-free grammar where V “ tS, Bu,Σ “ t0, 1, 7u and R is the following set of production rules:

˝ S ÝÑ 0S1 ˝ S ÝÑ B ˝ B ÝÑ 7

n n This grammar generates the language t0 71 | n P Nu.

Theorem 24 A language is recognised by a PDA if and only if it is context-free.

Proof of Theorem 24:

(ð) Get a context-free grammar. The Pushdown P works as follows:

(1) Places a marker symbol “K” and the start variable on the stack. (2) Repeat: (a) If the top stack is a variable A it selects non-deterministically one of the rules for A and substitutes A by the string on the right hand side of the rule. (b) If the top stack is a terminal symbol a, it reads the next input symbol from the input and compares it to a. If they don’t match, rejects (for this branch of non-deterministic). If they do, repeat. (c) If the top of stack is the symbol “K” enters the accepting state (If a letter from the input must be read, it rejects).

(ñ) We start from a PDA and construct P an equivalent one such that

(1) P has a single accepting state qacc. (2) It empties its stack before accepting 24 EPFL G¨odel& Recursivity

(3) Each transition either pushes a symbol onto the stack or pops one off, but does not do both at the same time so that the the content of the stack never stays put.

From P “ pQ, Σ, Γ, δ, q0, tqacc.uq we construct G.

(1) V “ tApq | p, q P Qu, (2) Σ is unchanged,

(3) the start variable is Aq0, qacc.. (4) The set of rule R is:

(a) For each p, q, r, s P Q, t P Γ and a, b P Σε if δpp, a, εq contains pr, tq and δps, b, tq contains pq, εq put the rule Apq Ñ a Arsb in R. (b) For each p, q, r P Q put the rule Apq Ñ AprArq in R. (c) For each p P Q put the rule App Ñ ε in R.

Why is the language recognised by P is the one derived by G?

(ñ) If w is accepted by P , then there exists a computation that accepts it. This compu- tation goes from q0 ÝÑ qacc.. It determines one derivation.

(ð) Any successful derivation induces an accepting computation.

% 24 Every regular language is context-free. But many languages are neither regular nor context-free.

Theorem 25 (Pumping Lemma for Context-Free Languages) If A is a context-free lan- guage, then there is a number p (the pumping length) where, if s is any sequence in A of length at least p, then s may be divided into five pieces, s “ vwxyz, satisfying the following conditions:

(1) for each i ě 0, vwixyiz P A,

(2) |wy| ą 0, and

(3) |wxy| ď p

Proof of Theorem 25: See Theorem 2.19 in [31]. We first fix a grammar. Then we concentrate on getting a derivation tree4 large enough so that there is one path – from the root to some leaf – that visits twice the same variable T . For this, if k is the number of variables in the grammar, we need a tree of height at least k ` 1. We take m to be the maximum number of symbols in the right hand side of a rule 5, and take n “ maxp2, mq. Every word of height at least nk`1 that is generated by this grammar has a derivation tree with at least one branch whose length is ě k ` 1. We set p “ nk`1.

4notice that in a derivation tree every leaf is a terminal symbol, and very other node is a variable. 5k is the maximum number of immediate successors of a node in the derivation tree. Recursivity 25

Take any word u generated by this grammar such that |u| ď p holds. Consider the smallest – in terms of nodes – derivation tree that produces u, and consider a node T which repeats only once and such that there is no other variable that repeats in the subtree induced by this node. The whole derivation tree is described below:

S

T

T

v w x y z

Notice that |wxy| ď p holds, because the subtree induced by T has never twice the same variable (except for T itself which appears only twice). Hence every branch on this subtree has length at most k ` 1, which guarantees that wxy has length at most p “ nk`1.

Notice also that |wy| ą 0 because otherwise, we would have w “ y “ ε. But then the derivation tree below would also produce the same word which would contradict the minimality of the one we chose.

S

T

x

v z

We also clearly have, for each i ě 0, vwixyiz P A:

S

T

T

T v w y z

w x y

% 25 26 EPFL G¨odel& Recursivity

Example 26 The following language is not context-free:

n n n ta b c | n P Nu.

Towards a contradiction we assume that this language is context-free so that there exists some integer p that verifies the conditions of Theorem 25. We consider the word u “ 0p1p2p P A. By Theorem 25, there exist words v, w, x, y, z such that u “ vwxyz and

(1) vwixyiz P A (@i ě 0) (2) |wy| ą 0, and (3) |wxy| ď p

Since |wxy| ď p holds, this word cannot contain all three letters 0,1 and 2. We distinguish two different cases:

(1) if wxy P 0˚1˚, then z P 1˚2˚. Therefore for each i ą 1 vwixyiz contains either more 0’s than 2’s or 1’s than 2’s.

(2) if wxy P 1˚2˚, then v P 0˚1˚. Therefore for each i ą 1 vwixyiz contains either more 1’s than 0’s or 2’s than 0’s. Chapter 2

Turing Machines

A Turing Machine (TM) is a general model of computation. It consist in an infinite tape and a tape head that can read, write and move around. It can both read the content of the tape and write on it. The read-write head can move both to the left and to the right. The tape is infinite. There are special states for rejecting and accepting which both take immediate effect.

Control

1 0 1 0 0 1 t t t t t

2.1 Deterministic Turing Machines

Definition 27 A (deterministic) TM is a 7-tuple pQ, Σ, Γ, δ, q0, qacc., qrej.q where Q, Σ, Γ are all finite sets and

(1) Q is the set of states,

(2) Σ is the alphabet not containing the blank symbol, \,

(3) Γ is the tape alphabet where \P Γ and Σ Ď Γ

(4) δ : Q ˆ Γ ÝÑ Q ˆ Γ ˆ tL, Ru is the transition function

(5) q0 is the initial state

(6) qacc. is the accepting state

(7) qrej. is the rejecting state 28 EPFL G¨odel& Recursivity

Clearly qacc. and qrej. must be different states.

Notice that the head cannot move off the left hand end of the tape. If δ says so, it stays put. A configuration of a TM is a snapshot: it consists in the actual control state (q), the position of the head and what is written on the tape (w). To indicate the position of the head we consider the word w0 which is located to the left of the head and slice the tape content w into the w0w1 “ w. This means that the head is actually positioned on the first letter of w1. Strictly speaking the content of the tape is an infinite word:

w \\\ ...... \\ ... but we forget about the infinite suffix \\\ .... We then write w0qw1 to say that

˝ the tape content is w0w1 \\\ ...

˝ the head is positioned on the first letter of w1 \\\ ...

˝ the actual control state is q.

ăω The initial configuration on input w P Σ is q0w. An halting configuration is

˝ either an accepting configuration of the form w0qacc.w1,

˝ or a rejecting configuration of the form w0qrej.w1.

Given any two configurations C,C1 we write C ñ C1 (for C yields C1 in one step) if there exist a, b, c P Γ, and u, v P Γ˚ such that

1 ˝ either C “ uaqibv, C “ uqjacv and δpqi, bq “ pqj, c, Lq,

1 ˝ or C “ uaqibv, C “ uacqjv and δpqi, bq “ pqj, c, Rq.

Definition 28 A TM accepts input w if there is a sequence of configuration C0,...,Ck such that

(1) C0 “ q0w

(2) Ci yields Ci`1 (for any 0 ă i ă k)

(3) Ck is an accepting configuration.

Definition 29 The set of all words accepted by a TM is the language it recognises: M p q “ tw P Σ˚ | accepts wu. L M M Recursivity 29

Example 30 A Turing machine that recognises tw7w | w P t0, 1u˚u – where w is the mirror of w (for instance 001011 “ 110100). pQ, Σ, Γ, δ, q0, qacc., qrej.q where

(1) Q “ tq0, qremember 0 look for \ go right, qremember 1 look for \ go right, qwrite 0, qwrite 1, qlook for \ go left, qstep rightu

(2)Σ “ t0, 1u

(3)Γ “ t0, 1, \u

(4) δ : Q ˆ Γ ÝÑ Q ˆ Γ ˆ tL, Ru is defined by

pq0, \q ÝÑ qacc. pq0, 0q ÝÑ pqremember 0 look for \ go right, \,Rq pq0, 1q ÝÑ pqremember 1 look for \ go right, \,Rq pqremember 0 look for \ go right, \q ÝÑ pqwrite 0, \,Lq pqremember 0 look for \ go right, 0q ÝÑ pqremember 0 look for \ go right, 0,Rq pqremember 0 look for \ go right, 1q ÝÑ pqremember 0 look for \ go right, 1,Rq pqremember 1 look for \ go right, \q ÝÑ pqwrite 1, \,Lq pqremember 1 look for \ go right, 0q ÝÑ pqremember 1 look for \ go right, 0,Rq pqremember 1 look for \ go right, 1q ÝÑ pqremember 1 look for \ go right, 1,Rq pqwrite 0, \q ÝÑ qrej. pqwrite 0, 0q ÝÑ pqlook for \ go left, \,Lq pqwrite 0, 1q ÝÑ qrej. pqwrite 1, \q ÝÑ qrej. pqwrite 1, 0q ÝÑ qrej. pqwrite 1, 1q ÝÑ pqlook for \ go left, \,Lq pqlook for \ go left, \q ÝÑ pqstep right, \,Rq pqlook for \ go left, 0q ÝÑ pqlook for \ go left, 0,Lq pqlook for \ go left, 1q ÝÑ pqlook for \ go left, 1,Lq pqstep right, \q ÝÑ qacc. pqstep right, 0q ÝÑ pqremember 0 look for \ go right, \,Rq pqstep right, 1q ÝÑ pqremember 1 look for \ go right, \,Rq 30 EPFL G¨odel& Recursivity

If we rename the states :

q0 ; q0 qremember 0 look for \ go right ; q1 qremember 1 look for \ go right ; q2 qwrite 0 ; q3 qwrite 1 ; q4 qlook for \ go left ; q5 qstep right ; q6 the transition function becomes:

pq0, \q ÝÑ qacc. pq3, 1q ÝÑ qrej. pq0, 0q ÝÑ pq1, \,Rq pq4, \q ÝÑ qrej. pq0, 1q ÝÑ pq2, \,Rq pq4, 0q ÝÑ qrej. pq1, \q ÝÑ pq3, \,Lq pq4, 1q ÝÑ pq5, \,Lq pq1, 0q ÝÑ pq1, 0,Rq pq5, \q ÝÑ pq6, \,Rq pq1, 1q ÝÑ pq1, 1,Rq pq5, 0q ÝÑ pq5, 0,Lq pq2, \q ÝÑ pq4, \,Lq pq5, 1q ÝÑ pq5, 1,Lq pq2, 0q ÝÑ pq2, 0,Rq pq6, \q ÝÑ qacc. pq2, 1q ÝÑ pq2, 1,Rq pq6, 0q ÝÑ pq1, \,Rq pq3, \q ÝÑ qrej. pq6, 1q ÝÑ pq2, \,Rq pq3, 0q ÝÑ pq5, \,Lq

Definition 31 A language L is Turing recognizable if there exists a TM such that M L “ p q. L M Proposition 32 Turing Machines with bi-infinite tapes are equivalent to Turing machines.

Proof of Proposition 32: Left as an exercise. % 32

Proposition 33 2 stack Pushdown automata are equivalent to Turing machines.

Proof of Proposition 33: Left as an exercise. % 33

Definition 34 A Decider is a TM that halts on all inputs. Recursivity 31

Definition 35 A language is Turing decidable iff there exists a Decider that recognises it.

Turing recognizable is also called recursively enumerable (r.e. for short) and Decidable is also called recursive.

Example 36 A Decider for tanbncn | n P wu:

˝ Scan the input from left to right to be sure that it is a member of a˚b˚c˚ and reject if it isn’t.

˝ Return the head to the left and change one c into an x, then one b into x, then one a into x. Go back to the first blank \. Repeat again until the tape is only composed of x, in which case accept. Otherwise reject.

Definition 37 A k tape TM is the same as a TM except that is composed of k tapes: 1 ,. . . , k , with k independent heads so that the transition function becomes

δ : Q ˆ Γk ÝÑ Q ˆ Γk ˆ tL, Ruk

Notice that a configuration of a k-tape Turing machine is of the form

u qv , u qv , ...... , u qv 1 1 2 2 k k . ´ 1 2 k ¯

Proposition 38 Given any TM there exist

(1) an equivalent TM with a bi-infinite tape,

(2) a multi-tape TM,

(3) a multi-tape with bi-infinite tapes TM.

Proof of Theorem 38: Left as an exercise. % 38

Theorem 39 Every multi-tape TM has an equivalent single tape TM.

Proof of Theorem 39: Let be a multi-tape TM. We will describe a TM that recognises M S the same language. Let pw1, w2, . . . , wkq be the input of on its k tapes. The corresponding M input of will be 7w17w27 ... 7wk7, where 7 does not belong to the alphabet of . To simulate a S M single move of , scans its tape from the first 7 which marks the left-hand end, to the k ` 1th M S 7 (which marks the right-hand end) replacing each letter a right after the 7 symbol (except for the k ` 1th one) bya ˆ to indicate the position of the heads. Then makes a second pass to S 32 EPFL G¨odel& Recursivity

update the tapes according to ’s transition functions. If at any point moves one of the M S virtual heads to the right onto a 7, this action signifies that has moved the corresponding M head onto the previously unread blank portion of that tape. So writes a blank symbol on this S tape cell and shifts the tape contents from this cell until the rightmost 7, one unit to the right. Then it continues the simulation as before.

1 0 1 t t t M 1 1 0 0 1 t t t t

1 0 0 0 t t t t

] 1 0ˆ 1 ] 1 1 0 0 1ˆ ] 1 0 0 0 ] t t t t b S % 39

2.2 Non-Deterministic Turing Machines

Definition 40 A non-deterministic TM (NTM) is the same as a deterministic TM except for the transition function which is of the form: δ : Q ˆ Γ ÝÑ pQ ˆ Γ ˆ tL, Ruq. P The computation of a (deterministic) TM is a sequence of configurations

C0 ùñ C1 ùñ ... ùñ Ck ùñ ... that may be finite or infinite. It accepts the input if this sequence is finite and the last configuration is an accepting one. The computation of a non-deterministic TM is no more a sequence of configurations but a tree whose nodes are configurations. This tree may have both infinite and finite branches. The machine accepts the input if and only if there exists some branch that is finite and whose leaf is an accepting configuration. Recursivity 33

Theorem 41 For every NTM there exists a deterministic TM that recognises the same lan- guage.

Proof of Theorem 41:

1 0 1 0 t t t

2 0 1 1 1 0 t t t t M 3 1 4 2 1 3 4 6 2 1 7 1 4 2 1 2 t t t t t

We consider a 3-tape ( 1 , 2 and 3 ) deterministic TM to simulate a NTM : M N ˝ (1) 1 is the input tape, (2) 2 is the simulation tape, and (3) 3 is the address tape.

˝ Initially, 1 contains the input w and 2 and 3 are empty.

˝ 1 always keeps the input w. So the content of 1 is never modified.

˝ 2 simulates on one – initial segment of a – branch of its non-deterministic computation N tree.

˝ 3 contains a finite word which corresponds to a succession of non deterministic choices. For instance the word 132 stands for: among the non-deterministic options choose the first one for the first transition, the third one for the second and the second one for the third. This means that we consider k P N to be maxtCardpδpq, γqq | q P Q, γ P Γu

and for each | q P Q, γ P Γ we fix a total ordering of δpq, γq. Words on 3 all belong to t1, 2, . . . , ku˚. Moreover, during the running time, the content of 3 changes over and over again until the machine accepts. This series gives rise to an enumeration of the infinite k-ary tree in a breadth-first search. This means it enumerates all words in t1, 2, . . . , ku˚ along the following well-ordering:

|u| ă |v| u ă v ðñ or |u| “ |v| and u ălexic. v 34 EPFL G¨odel& Recursivity

Which gives:

ε, 1, 2, . . . , k, 11, 12,..., 1k, 21, 22,..., 2k, ...... , k1, k2, . . . , kk, 111, 112,..., 11k,......

˝ At first, Copies the content of 1 (= the input w) to 2 . M ˝ It then uses 2 to simulate with input w on the branch b of its non-deterministic N computation which is lodged on 3 . In case the word b does not correspond to a real computation1 or if the simulation of on 2 either reaches the rejecting state or does not N reach any halting state at all, then erases completely 2 , replaces b on 3 with its the M immediate ă-successor, and starts all over again – by copying 1 on 2 and simulating N on 2 in accordance with the series of choices recorded on 3 .

% 41

Proposition 42

˝ Recursive languages are closed under union, intersection and complementation.

˝ Recursively enumerable languages are closed under union and intersection.

Proof of Proposition 42: Left as an exercise. % 42

Definition 43 An enumerator is a TM. We say that it enumerates a language if the result L of its computation (possibly infinite) is of the form

w0 \ w1 \ w2 \ ... \ wn \ wn`1 \ ...... where twi | i P Nu “ . L We say that a language is “recursively enumerable” if there is an enumerator that enumerates L . L Theorem 44 A language is Turing Recognizable if and only if it is recursively enumerable.

Proof of Theorem 44:

˚ (ñ) from we build that enumerates p q. Fix a recursive enumeration psiqi of Σ . M E L M PN (1) Repeat the following for i “ 1, 2, 3,...

(2) Run for i steps on each input s1, s2, . . . , si M (3) If any computation accepts, print out the corresponding sj.

1 this is the case for instance if from the initial configuration q0w there are only two control states non- deterministically available, whereas the word on 3 reads 3 .... Recursivity 35

(ð) From we build : on input w: run , and every time outputs some word v, find out E M E E whether v “ w or not, and accept if they are the same.

% 44

Proposition 45 For any infinite L Ď Σ˚,

there exits an enumerator that prints out E $ u0 \ u1 \ u2 \ ...... \ ui \ ui`1 \ ...... ’ ’ ’ L “ tui | i P Nu ’ ’ L is Turing decidable ðñ ’ $ ’ ’ and &’ ’ such that ’ ’ ’ &’ |u| ă |v| ’ ’ i ă j ùñ or ’ ’ $ ’ ’ |u| “ |v| and u ălexic. v. ’ ’ & ’ ’ ’ ’ Proof of Proposition 45: Left as an% exercise. % % % 45

2.3 The Concept of Algorithm

In 1900, Hilbert gave a list of the main mathematical problems of the time [17, 18]. The 10th one was the following: given a Diophantine equation with any number of unknown quantities, and with rational integral numerical coefficients, can we derive a process according to which it can be determined in a finite number of operations whether the equation admits a rational integer solution? This corresponds to the intuitive notion of an algorithm. Proving that such an algorithm does not exist requires a formal definition of the notion of “algorithm”. The “Church- Turing thesis” states that the informal notion of an algorithm corresponds exactly to the notion of a λ-calculus formula or equivalently to a Turing machine. In 1970, Yuri Matijasevic proved2 that the 10th problem of Hilbert is undecidable [23]: assuming that the notation P px1, . . . , xnq stands for a polynomial with integer coefficients, then there is no decider for n tP px1, . . . , xnq | Dpa1, . . . anq P N P pa1, . . . , anq “ 0u.

Definition 46 A “coding” is a rule for converting a piece of information into another object. Given any non empty sets E,F , a coding is a one-to-one (total) function

1 1 c : E ÝÝÑ´ F.

2this is combined work of Martin Davis, Yuri Matiyasevich, Hilary Putnam and Julia Robinson 36 EPFL G¨odel& Recursivity

1´1 Example 47 E “ t0, 1u˚, F “ N and c : E ÝÝÑ F is a coding defined by:

2 cpwq “ 1w p= the word “1w” read in base 2q.

Definition 48 Given any two non-empty finite sets A, B, a partial function f : A˚ ÝÑ B˚ is “Turing computable” if and only if there exists a Turing machine f such that M ˝ on inputs w R dompfq: it never halts,

2 ˝ on inputs w P dompfq: it halts in configuration “qacc.u with u “ fpwq.

Remarks 49

(1) Given any finite alphabet Σ, and any TM whose alphabet is Σ, there exists a Turing ˚ ˚ M computable coding: c :Σ ÝÑ t0, 1, \u and a TM c with tape alphabet t0, 1, \u such M that accepts w if and only if c accepts cpwq. M M (2) Every regular language is decidable because a DFA is nothing but a deterministic TM that always goes right.

(3) Every Context-free language is decidable, because any PDA can be easily simulated by some equivalent non-deterministic TM.

(4) We have the following strict inclusions of languages.

Regular Ĺ Context-Free Ĺ Decidable Ĺ Turing Recognizable. “ “ Recursive Recursively Enumerable

In computer science, a programming language is said be “Turing complete” or “universal if it can be used to simulate any single-tape Turing machine. Examples of Turing-complete programming languages include:

˝ Ada ˝ C++ ˝ Java ˝ Pascal

˝ C ˝ Common Lisp ˝ Lisp ˝ Prolog, etc.

2.4

If we compare a Turing Machine with a computer, on one hand the TM seems much better because it can compute for ever without any chance to breakdown and it has an infinitely large storage facility. But on the other hand, a TM seems to be more of a computer with a single Recursivity 37

software program, whereas a computer can run different programs. A computer resemble more of a Turing machine with finite capacity but, a Turing machine that we can modify by changing its transition function – every program is like a new transition function for the machine. How are we going to address this issue, since we claimed that a Turing machine is an abstract model of computation ? This answer to this is the Universal Turing Machine. It is a machine that can work just like any other machine provided that we feed it with the right code of the machine. We will employ Turing machines to obtain:

(1) a languages that is Turing recognizable but not decidable3,

(2) a language that is not Turing recognizable.

From now on, we only consider Turing Machines with fixed alphabets Σ “ t0, 1u, Γ “ t0, 1, \u. Any such TM is of the form:

“ xtq0, q1, . . . , qku, t0, 1u, t0, 1, \u, δ, q0, qacc., qrej.y M Where δ is the description of the transition function of : M

δ “ tpq3, 0, q1, 1,Rq, pq8, 1, q4, 0,Lq, pq3, 0, q3, 0,Lq,...... u

The description of such a machine is a finite sequence M over some finite alphabet A:

x, y,q, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, c, e, j, r,., 0, 1, \,L,R, t, u, p, q,, “ A. ! ) Since CardpAq ă 28 we can code any letter l P A by a sequence of eight 0’s and 1’s, i.e we take any 1-1 mapping C : A ÝÑ t0, 1ur8s and we define a Turing computable coding

c : A˚ ÝÑ t0, 1u˚ by cpa0 . . . apq “ Cpa0qˆCpa1qˆCpa2qˆ...ˆCpapq. We denote by x y the code of , i.e. M M x y “ cp q. M M Clearly, the following language is decidable:

tx y : is a TMu. M M 3in other words: a non-recursive recursively enumerable language. 38 EPFL G¨odel& Recursivity

Proposition 50 (Universal Turing Machine) There exists a Turing machine4 such that U on each input of the form vw P t0, 1u˚,

if v “ x y for some Turing machine5 , then works as on input w. M M U M Notice that for any word u P t0, 1u˚, if there is a prefix of u which is the code of a Turing Machine, then this prefix is unique 6. Therefore, in case a word u P t0, 1u˚ can be decomposed into u “ x yw for some Turing machine , this decomposition is then unique. M M This means for instance that

˝ never stops if never stops on input w, U M ˝ stops with the word w1 written on its tape and rejects if stops on input w in a U M rejecting configuration with the word w1 written on its tape,

˝ stops with the word w1 written on its tape and accepts if stops on input w with the U M word w1 written on its tape

(1) on 1 the input x yw is inserted. It will never be modified during the rest of the compu- M tation. Then copies the code of U (a) the transition function of – xδy – on 2 ; M 7 (b) the initial state of – xq0y – on 3 ; M 8 (c) the accepting state of – xqacc.y – on 4 ; M 9 (d) the rejecting state of – xqrej.y – on 5 . M (2) It then uses 6 to simulate on input w: for each step of M M

(a) reads a letter – say 0 – on 6 , and U (b) using the code of the actual state – say xq3y – on 3 , looks in 2 for the code of the U corresponding transition – say xpq3, 0, q1, 1,Rqy – and then

(c) verifies that the code of the new state – here xq1y – is different from the content of U 4 and 5 (otherwise if it corresponds to the content of 4 it means that it is xqacc.y, and accepts right away, and if it corresponds to the content of 5 it means it is U xqrej.y, in which case rejects). U 4 working on alphabets ΣU “ t0, 1u and ΓU “ t0, 1, \u 5 also working on alphabets ΣU “ t0, 1u and ΓU “ t0, 1, \u 6this comes from the fact the last letter of a word that defines a TM is y. Therefore, reading u from left to right by blocks of eight 0’s or 1’s, the first block that corresponds to xyy marks the end of the wanted prefix. 7later on this tape will store the code of the actual state that M is on. 8the content of 4 will never be modified in the future. 9the content of 5 will never be modified in the future. Recursivity 39

(d) If the new state is different from both qacc. and qrej. – in our example q1 is different from both qacc. and qrej. – replaces on 6 the letter it just read with the new one U – here it replaces 0 by 1 – and still on tape 6 it makes the move indicated – here it goes right – and finally,

(e) replaces on 3 the code of the old state by the new one – here it replaces xq3y by U xq1y.

1 1 0 1 1 1 0 U

2 1 1 0 1 1 1 1 0 0

3 1 0 0 0 1 1 1 0

4 1 0 0 0 0 0 0 1

5 1 0 0 0 1 1 1 0

6 1 1 0 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 t t

M 1 1 0 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 t t

% 50 40 EPFL G¨odel& Recursivity

2.5 The Halting Problem

Proposition 51 The following language is Turing recognizable but not decidable:

tx yw P t0, 1u˚ | is a TM and accepts wu. M M M Proof of Proposition 51: Towards a contradiction we assume there exists a Decider that D decides this language. We build a Turing machine which works the following way: H on input w

˝ if accepts ww, then does not halt. D H ˝ if rejects ww, then accepts. D H Notice that

accepts x y ðñ rejects x yx y ðñ does not accept x y. H H D H H H H % 51

Proposition 52 The following language is Turing recognizable but not decidable:

tx y P t0, 1u˚ | is a TM and halts on the empty inputu. M M M Proof of Proposition 52: Left as an exercise. % 52

Corollary 53 The following languages are not recursively enumerable:

˝t 0, 1u˚ r tx y P t0, 1u˚ | is a TM and halts on the empty inputu M M M ˝t 0, 1u˚ r tx yw P t0, 1u˚ | is a TM and accepts wu M M M Proof of Corollary 53: Left as an exercise. % 53

2.6 Turing Machine with Oracle

A Turing machine with an oracle is one finite object (a Turing machine suitable for any oracle: an almost regular 2-tape Turing Machine) plus one infinite object so that this TM can have access to an infinite amount of information – which a normal one never does.

Definition 54

(1) An oracle is any subset O Ď N. Recursivity 41

(2) An oracle-compatible-Turing machine (o-c-TM) is a 2-tape Turing machine similar to any 2-tape Turing machine except that it only reads but never writes on tape 2 :

“ pQ, Σ, Γ, δ, q0, qacc., qrej.q O

(3) An oracle-compatible-Turing machine equipped with the oracle O, on input word w P Σ˚ O (in short an oracle TM O on word w P Σ˚) is nothing but the TM whose initial O O configuration is

q0w , q0χO ´ 1 2 ¯

ω where χO P t0, 1u is the infinite word

χOp0qχOp1qχOp2q ...... χOpnqχOpn ` 1q ...... defined by 1 if n P O

χOpnq “ $ and ’ & 0 if n R O. ’ %’ This means that on tape 2 the whole characteristic function of the oracle is already available once the machine starts. So that the machine is granted access to all of this ”external” infor- mation: it knows which integers belong to O and which do not. For instance, in case O is the set of all integers n such that:

(1) n reads “ 1x yw ” in the decimal numeral system, M (2) is a TM that halts on input w; M then O may be able to decide the Halting Problem. Of course this does not lead to a contra- O diction since there is no chance that such a Turing machine 10 ever sees its own code onto tape 2 (although the code of – or the code of an equivalent TM – does show on 2 ). O O O 1 1 1 0 1 1 1 1 t t

2 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0

10we are talking about OO and not just O! 42 EPFL G¨odel& Recursivity

Example 55 Let O Ď N be the set of all the codes of Turing machines that halt on the empty input:

2 O “ t1x y P N | is a TM and halts on the empty inputu. M M M We describe an oracle-compatible-TM that, once equipped with the oracle O, decides the O language tx y P t0, 1u˚ | is a TM and halts on the empty inputu. M M M The machine O works this way: O (1) on input w P t0, 1u˚, the TM O checks whether w is the code of a TM O if it is not the case it rejects right away. Otherwise,

2 (2) it computes n “ 1x y , then checks on tape 2 whether χ pnq “ 1 – in which case it M O accepts – or χOpnq “ 0 – in which case it rejects.

˚ Notation 56 ˝ Given any language L Ď t0, 1u , we write OpLq Ď N for the set

2 OpLq “ 1w ´ 1 P N | w P L . ! ) ˚ ˝ Given any subset O Ď N, we write p q Ď t0, 1u for the language L O ˚ 2 p q “ w P t0, 1u N | 1w ´ 1 P O . L O ! )

So OpLq is the oracle associated with the language L, and p q is the language associated with L O the oracle O. Notice that the oracle for the empty language is the empty set: OpHq “H.

Proposition 57 Given any L Ď t0, 1u˚, and any oracle Turing machine OpLq : O ˝ p OpLq q is recursively enumerable, and moreover L O ˝ if OpLq is an oracle Decider11, then p OpLq q is recursive. O L O Proof of Proposition 57: Left as an exercise. % 57

11meaning that OOpLq halts on every input. Recursivity 43

Definition 58 Given any A, B Ď N,

B A is “Turing reducible” to B if there exists an oracle Decider that computes χA. D Or equivalently: B is an oracle Decider DM for all o-c-TM there exists an o-c-TM M such that $ and M D ’ &’ B “ A . L DM L M ’ ` ˘ ` ˘ Notation 59 Given any A, B Ď N, we write %

˝ A ďT B if A is Turing reducible to B,

˝ A ”T B if A ďT B and B ďT B,

˝ A ăT B if A ďT B but B ­ďT B.

Notice that we have

˝ A ďT A

˝p A ďT B and B ďT Cq ùñ A ďT C

˝ A ”T B ðñ B ďT A

So that ”T is an equivalence relation.

Examples 60 Given any language L Ď t0, 1u˚,

(1) OpLq ”T OpLAq,

(2) if L is recursive, then OpLq ”T H,

(3) If L is not recursive, then H ăT OpLq. (4) ” . OpLq T O L pOpLqq ´ ¯

Proposition 61

˚ (1) p q Ď t0, 1u | O ďT H is the class ec. of all recursive languages. L O R ! ) 44 EPFL G¨odel& Recursivity

˚ (2) p q Ď t0, 1u | O ďT Halt Ě . . (= the class of all r.e. languages). L O R E !Where Halt stands for the set) of codes of Turing machines that halt on the empty input:

Halt “ Optx yPt0,1u˚| is a TM and halts on the empty inputuq. M M M Proof of Proposition 61: Left as an exercise. % 61

Definition 62 (jump operator) Given any subset A Ď N, the “jump” of A (denoted A1) is

1 A “ A . O x yPt0,1u˚| is an o-c-TM and halts on the empty input M M M ´! )¯ Proposition 63 Given any A Ď N,

1 A ăT A .

1 1 1 Proof of Proposition 63: We decompose A ăT A into first A ďT A , then A ­ďT A.

1 A1 (A ďT A ) Given any o-c-TM we need to find an o-c-TM such that decides mem- M N N bership in A . is defined such that: on input w P t0, 1u˚: L M N A1 (1) computes` ˘ the code of an o-c-TM w that works just like except that when N K M it starts on the empty tape, it begins with writing down the input w on the working tape, and then proceeds exactly as with the exception that instead of eventually M reaching the rejecting state, it reaches an ever lasting loop. A1 A (2) Then checks wether w halts on the empty tape. N K 1 (a) If it does not, then A rejects w. 1N (b) If it does, then A accepts w. N 1 1 (A ­ďT A) Towards a contradiction, we assume that A ďT A holds. So that given any o-c- 1 TM there exists some o-c-TM such that A decides membership in A . We M N N L M choose to be the o-c-TM that does the following on input w P t0, 1u˚: ´ ¯ M (1) if w “ x y for some o-c-TM , then N N (a) computes the code of an o-c-TM w that works the same as except that M K N (A) it never reaches the rejecting state but it rather enters a loop instead. (B) When it starts on the empty tape, it first write down the input w on the working tape, and then proceeds exactly as . 1 N (b) Then A makes use of its oracle to check whether A halts on the empty input M Kw or not. 1 (A) If it does halt, then A accepts w. N Recursivity 45

1 (B) If it does not halt, then A rejects w. M (2) if for all o-c-TM , w ‰ x y, then we don’t care what it does. N N

1 So, assume now there exists some o-c-TM such that A decides membership in A . N N L M It is enough to consider the input w “ x y to see that ´ ¯ N 1 A accepts x y ðñ A does not halt on the empty word x y M N K N ðñ A either never stops or stops and rejects x y. N N 1 Which contradicts that A decides membership in p A q since we have N L M 1 x y P p A q ðñ x y R p Aq. N L M N L N

% 63

Corollary 64 The following strict ordering between jumps is satisfied:

n n`1 ω ω`1 1 2 2 ¨ ¨ ¨ 1 2 ¨ ¨ ¨ 1 2 ¨ ¨ ¨ 2 ¨ ¨ ¨ 1 H ăW H ăW H ăW ... ăW H ăW H ăW ... ăW H ăW H ăW .... hkkikkj hkkikkj hkkikkj hkkikkj where pn`mqpn`m`1q k “ 2 ω 2 ¨ ¨ ¨ 1 $ and k PH ðñ ’ hkkikkj ’ n &’ m PH2 ¨ ¨ ¨ 1 . ’ hkkikkj ’ %’ Proof of Corollary 64: Left as an exercise. % 64 46 EPFL G¨odel& Recursivity Chapter 3

Recursive Functions

p Recursive functions are functions from N to N. We will show that they have a strong relation with the Turing computable ones. We define the set of recursive functions by induction. For this purpose, for any integer p, we p p p denote by NpN q the set of all mappings of the form N ÝÑ N. Notice that N is a notation for the set of all mappings ti P N | i ă pu ÝÑ N. When p “ 0, the set ti P N | i ă pu becomes 0 ti P N | i ă 0u “ H. Thus the set N only contains one element: the empty function whose 0 graph is H. Therefore the set of all mappings of the form N ÝÑ N contains all mappings that assign one integer to the empty function: f : tHu ÝÑ 0 ÝÑ “ N n P . N N H ÝÑ n N " ˇ * ˇ p 0q ˇ So, as may be expected, mappings in N N are identified withˇ elements of N.

3.1 Primitive Recursive Functions

Definition 65

th p projection: If i is any integer such that 1 ď i ď p holds, the i projection πi is the function p of NpN q defined by p πi px1, . . . , xpq “ xi 1 successor: S P NN is the successor function . p pq p nq p pq composition: Given f1, . . . , fn P N N and g P N N , the composition h “ gpf1, . . . , fnq P N N is defined by hpx1, . . . , xpq “ g f1px1, . . . , xpq, . . . , fnpx1, . . . , xpq ÝÑ ÝÑ ÝÑ We often make use the notation x for` px1, . . . , xpq so that for instance g˘ f1p x q, . . . , fnp x q stands for g f px , . . . , x q, . . . , f px , . . . , x q . 1 1 p n 1 p ` ˘ 1Spnq “ n ` 1. ` ˘ 48 EPFL G¨odel& Recursivity

p p`2 p`1 recursion: Given g P NpN q and h P NpN q, there exists a unique f P NpN q such that for all ÝÑ p x P N and y P N satisfies (1) fpÝÑx , 0q “ gpÝÑx q

(2) fpÝÑx , y ` 1q “ h ÝÑx , y, fpÝÑx , yq

We say f is defined by` recursion on˘ both g (for the initial step) and h (for the successor steps).

Definition 66 The set of primitive recursive ( rim. ec) functions is the least that P R (1) contains:

p p pq ÝÑ (a) All constants N ÝÑ N (all i P N N s.t. ip x q “ i – any i, p P N). p (b) All projections πi (any p P N, any 1 ď i ď p) (c) The successor function S P NN.

(2) and is closed under

(a) composition (b) recursion

We set up these functions in a hierarchy pRnqnPN:

(1) R0 is the set of all functions in (1)(a),(1)(b) and (1)(c).

2 (2) Rn`1 is the closure of Rn under (2)(a) and (2)(b). Clearly R “ Rn. nP ďN

Example 67

(1) Addition: px, yq ÝÑ x ` y We have: x ` 0 “ x (3.1) x ` py ` 1q “ px ` yq ` 1. " Formally: 1 addpx, 0q “ π1pxq 3 (3.2) # addpx, y ` 1q “ S π3 x, y, addpx, yq . ´ ` ˘¯ 2 Rn`1 “ Rn Y th obtained by composition on the basis of functions in Rnu Y th obtained by induction on the basis of functions in Rnu. Recursivity 49

(2) Multiplication: px, yq ÝÑ x ¨ y We have x ¨ 0 “ 0 (3.3) x ¨ py ` 1q “ x ¨ y ` x. " Formally:

multpx, 0q “ 0pxq 3 3 (3.4) # multpx, y ` 1q “ add π3 x, y, multpx, yq , π1 x, y, multpx, yq . ´ ` ˘ ` ˘¯ (3) Exponentiation: x ÝÑ nx We have n0 “ 1 (3.5) nx`1 “ nx ¨ n. " Formally: expnp0q “ 1 2 (3.6) # expnpx ` 1q “ mult π2 x, expnpxq , n . ´ ` ˘ ¯ (4) Factorial: x ÝÑ x! We have 0! “ 1 (3.7) px ` 1q! “ x! ¨ px ` 1q. " Formally: factp0q “ 1 2 2 (3.8) $ factpx ` 1q “ mult π2 x, factpxq ,S π1 x, factpxq . & ˆ ˙ ` ˘ ´ ` ˘¯ %

2 Example 68 We define ´9 P NpN q by

x ´9 y “ x ´ y if x ą y, “ 0 otherwise. " 2 We show that ´9 P NpN q belongs to rim. ec by first showing that : x ÝÑ x ´9 1 belongs to P R rim. ec. P R 0 ´9 1 “ 0 (3.9) px ` 1q ´9 1 “ x " 50 EPFL G¨odel& Recursivity

Formally: 0 ´9 1 “ 0pxq 2 (3.10) px ` 1q ´9 1 “ π x, x ´9 1 " 1 x ´9 0 “ x ` ˘ (3.11) x ´9 py ` 1q “ x ´9 y ´9 1 " Formally: ` ˘ 1 x ´9 0 “ π1pxq 3 (3.12) # x ´9 py ` 1q “ π3 x, y, x ´9 y ´9 1 ´ ` ˘¯

p Definition 69 A set A Ď N is primitive recursive ( rim. ec) if its characteristic function p pq P R (χA P N N ) is primitive recursive.

Example 70

(1) The set H is rim. ec since χ “ 0 is rim. ec. P R H P R (2) The set N is rim. ec since χ “ 1 is rim. ec. P R N P R

(3) The set ă “ tpx, yq | x ă yu is rim. ec. χă px, yq “ 1 ´9 p1 ´9 py ´9 xqq. N P R N

Definition 71

p p (1) pDf , fq is a partial function N ÝÑ N if f is a mapping Df ÝÑ N where Df Ď N .

p p (2) pDf , fq is a total function N ÝÑ N if Df “ N holds.

p Definition 72 A partial function f : N ÝÑ N is “Turing Computable” (TC) if there exists a TM such that on the input px1, x2, . . . , xpq: M

(1) if fpx1, . . . , xpq is not defined, then never stops; M ÝÑ (2) if px1, . . . , xpq P Df , stops with fp x q written on the tape. M p Proposition 73 Given any partial function f : N ÝÑ N,

ÝÑ ÝÑ f is Turing Computable ðñ Gf “ x , fpxq | x P Df is Turing Recognizable. ` ˘ ( Proof of Proposition 73: Recursivity 51

ÝÑ (ñ) From that computes f it is immediate to build that recognises Gf . On input p x , yq M N it simulates if stops it compares fpxq with y: if they compare it accepts. M M

ÝÑ (ð) From that recognises Gf , we build that computes f as follows, on input x repeatedly N M for i “ 1, 2, 3,... it recursively simulates on pÝÑx , 0q, pÝÑx , 1q, pÝÑx , 2q,..., pÝÑx , iq for i many N steps. If accepts pÝÑx , nq, then prints out the value n. N M % 73

p Corollary 74 Given any function f : N ÝÑ N,

f is both total and Turing Computable ùñ Gf is recursive (decidable).

Proof of Corollary 74: Left as an immediate exercise. % 74

p`1 p`1 Gf P N Gf P N

p f P NpN q total TC recursive decidable

p f P NpN q partial TC recursively enumerable Turing recognizable

Remark 75 All functions in R0 are total and Turing computable. By induction on n, it is easy to show that all functions in Rn are also total and Turing computable. Therefore

˝ All rim. ec functions are total and Turing computable. P R ˝ All graphs of rim. ec functions are recursive P R Even though the class of all rim. ec functions is included in the class of total and turing P R computable functions, the inverse inclusion does not hold3.

3 p 2q see exercise on the Ackermann function A P N N defined by n ` 1 if m “ 0, Apm, nq “ Apm ´ 1, 1q if m ą 0 and n “ 0, $ & A m ´ 1,Apm, n ´ 1q if m ą 0 and n ą 0. Apm, nq is fast growing. For instance% 3`¨ 1019728 ą Ap4, 2q ą˘ 2 ¨ 1019728. 52 EPFL G¨odel& Recursivity

3.2 Variable Substitution

Proposition 76 (Prim. Rec is closed under variable substitution) p p If f P NpN q, is rim. ec, then given any σ : t1, . . . , pu ÝÑ t1, . . . , pu, the function g P NpN q P R defined by

gpx1, . . . , xpq “ fpxσp1q, . . . , xσppqq is also rim. ec. P R

Proof of Proposition 76: The result is proved for all g P Rn by induction on n. Left as an exercise. % 76

k p kq Proposition 77 If A Ď N is rim. ec and f1, . . . , fn P N N are rim. ec then P R P R ÝÑ p ÝÑ ÝÑ t x P N | pf1p x q, . . . , fnp x qq P Au is rim. ec. P R ÝÑ p ÝÑ ÝÑ Proof of Proposition 77: Set B “ t x P N | pf1p x q, . . . , fnp x qq P Au. We have ÝÑ ÝÑ ÝÑ χBp x q “ χA f1p x q, . . . , fnp x q . ´ ¯ % 77

p Example 78 If f, g P NpN q are rim. ec, then the following sets are also rim. ec: P R P R (1) tÝÑx | fpÝÑx q ą gpÝÑx qu (2) tÝÑx | fpÝÑx q “ gpÝÑx qu (3) tÝÑx | fpÝÑx q ă gpÝÑx qu.

p p Proposition 79 If A, B Ď N are rim. ec then A Y B,A X B,A r B, A∆B and N r A are P R all rim. ec. P R Proof of Proposition 79:

χAYB “ 1 ´9 1 ´9 pχA ` χBq χ “ χ ¨ χ AXB A ` B ˘ χArB “ χA ¨ 1 ´9 χB

χA∆B “ 1 ´9 `χA ¨ χB˘ ¨ 1 ´9 1 ´9 χA ¨ 1 ´9 χB ˆ ˙ χAc `“ 1 ´9 χA. ˘ ´` ˘ ` ˘¯

% 79 Recursivity 53

p pN q p Proposition 80 (Case study) If f1, . . . , fn`1 P N and A1,...,An P N are all rim. ec, p P R then g P NpN q defined by: ÝÑ ÝÑ f1p x q if x P A1 ÝÑ ÝÑ f2p x q if x P A2 r A1 $ ÝÑ ÝÑ ’ f3p x q if x P A3 r pA1 Y A2q ’ . . . ÝÑ ’ . . . gp x q “ ’ . . . ’ ÝÑ ÝÑ &’ fip x q if x P Ai r pA1 Y A2 Y ... Y Ai´1q ...... ’ ’ f pÝÑx q if ÝÑx R pA Y ... Y A q ’ n`1 1 n ’ ’ is also rim. ec. % P R

A 80 Proof of Proposition 80: g “ f1 ¨ χA1 ` f2 ¨ χpA2rA1q ` ... ` fn`1 ¨ χ . % A1YA2Y...YAn ` ˘ Corollary 81 sup(x1, . . . , xn) and inf(x1, . . . , xn) are rim. ec. P R Proof of Corollary 81: Left as an exercise. % 81

p p`1 Proposition 82 f P NpN q is rim. ec, then g, h P NpN q below are rim. ec: P R P R t“y g “ fpx1, . . . , xp, tq, t“0 ÿ t“y h “ fpx1, . . . , xp, tq. t“0 ź Proof of Corollary 82: Left as an exercise(both are easily defined by induction). % 82

3.3 Bounded Minimisation and Bounded Quantification

p 1 p`1 Proposition 83 (Bounded minimisation) If A Ď N ` is rim. ec, then f P NpN q P R defined below is also rim. ec: P R 0 if @t ď z pÝÑx , tq R A, fpÝÑx , zq “ the least t ď z such that pÝÑx , tq P A otherwise. " fpÝÑx , zq is denoted by µt ď z pÝÑx , tq P A. 54 EPFL G¨odel& Recursivity

Proof of Proposition 83: f is defined by: fpÝÑx , 0q “ 0 y“z ÝÑ ÝÑ $ fp x , zq if χAp x , yq ě 1 y 0 ’ $ “ ’ yř“z ’ ’ ÝÑ ÝÑ ’ fpÝÑx , z ` 1q “ ’ z ` 1 if χAp x , yq “ 0 and p x , z ` 1q P A ’ ’ y“0 & ’ & yř“z`1 ’ ÝÑ ’ ’ 0 if χAp x , yq “ 0. ’ ’ y“0 ’ ’ ’ ’ ř %’ %’ % 83

Proposition 84 (Prim. Rec closed under bounded quantification) The set of all rim. ec p 1 P R predicates is closed under bounded quantification: i.e. If A Ď N ` is rim. ec, then P R ˝ tpÝÑx , zq : Dt ď z pÝÑx , tq P Au˝ tp ÝÑx , zq : @t ď z pÝÑx , tq P Au are both rim. ec. P R Proof of Proposition 84: Set

˝ B “ tpÝÑx , zq : Dt ď z pÝÑx , tq P Au, ˝ C “ tpÝÑx , zq : @t ď z pÝÑx , tq P Au.

We have

t“z t“z ÝÑ ÝÑ ÝÑ ÝÑ ˝ χBp x , zq “ 1 ´9 p1 ´9 χAp x , tqq, ˝ χC p x , zq “ χAp x , tqq. t“0 t“0 ř ś % 84

Example 85

˝t 2n : n P Nu is rim. ec It is defined by recursion P R

χp0q “ 0 χ “ 1 ´9 χ " pn`1q pnq

2 x ˝ The mapping P NpN q px, yq ÝÑ defined below is rim. ec: y P R „  x “ 0 if y “ 0 y $ „  x “ integer part of otherwise. &’ y %’ Recursivity 55

Formally x “ 0 if y “ 0 y $ „  & “ µt ď x y ¨ pt ` 1q ą x otherwise. ˝ px, yq | y divides x %P rim. ec: P R ( x χpx, yq “ 1 ´9 x ´9 y ¨ . y ˜ ˆ „ ˙ ¸

˝ Prime “ tx P N | x is a prime numberu P rim. ec: P R x ą 1 $ ’ and ’ ’ ’ x P Prime ðñ ’ y “ 1 ’ ’ or & $ @y ď x y “ x ’ ’ ’ ’ or ’ & ’ y does not divide x. ’ ’ ’ ’ ’ %th % ˝ Π: N ÝÑ N defined by Π pnq “ n ` 1 prime number P rim. ec. P R Π p0q “ 2 Π pn ` 1q “ µz ď pΠ pnq! ` 1q z ą Π pnq and z P Prime. "

3.4 Coding Sequences of Integers

We define rim. ec functions that allow to treat finite sequences of integers as integers. P R Every sequence xx1, . . . , xpy will be “coded” by a single integer αppx1, . . . , xpq. And from this single integer αppx1, . . . , xpq one will be able to recover the elements of the original sequence by having rim. ec functions βp that verify P R i

p βi αppx1, . . . , xpq “ xi. ´ ¯

1 2 p N Proposition 86 For every non zero p P N there exists rim. ec functions βp , βp , . . . , βp P N P R 56 EPFL G¨odel& Recursivity

p pq and αp P N N such that p 1´1 and onto αp : N ÐÝÝÝÝÝÝÝÝÑ N $ ’ and ’ &’ ´1 1 p α pxq “ β pxq, . . . , βp pxq . ’ p p ’ ’ ` 1 ˘ Proof of Proposition 86: We start% by defining α1 “ β1 “ id. Then we move on to px ` yq ¨ px ` y ` 1q α2px, yq “ ` y. 2 This is obtained by looking at the following picture and noticing that

(1) α2px, yq “ α2px ` y, 0q ` y, and

(2) α2px ` y, 0q “ 1 ` 2 ` ¨ ¨ ¨ ` px ` yq

1 2 x ` y 1 “ 2 ` ` ` ` ¨ ¨ ¨ ` ` . ˜ x ` y x ` y ´ 1 1 ¸

0,4

14 19

0,3 1,3 2,3

9 13 18

0,2 1,2 2,2 3,2

5 8 12 17

0,1 1,1 2,1 3,1 4,1 2 4 7 11 16

0,0 1,0 2,0 3,0 4,0 5,0 0 1 3 6 10 15

We have

1 (1) β2 pnq “ µx ď n Dt ď n α2px, tq “ n 2 (2) β2 pnq “ µy ď n Dt ď n α2pt, yq “ n. Recursivity 57

1 2 p´1 p p`1 Then we define αp`1, βp`1, βp`1, ...... , βp`1 , βp`1 and βp`1 by induction on p P N:

˝ αp`1px1, . . . , xp, xp`1q “ αp x1, . . . , xp´1, α2pxp, xp`1q 1 1 ` ˘ ˝ βp`1 “ βp ; 2 2 ˝ βp`1 “ βp ;

. . p´1 p´1 ˝ βp`1 “ βp ; p 1 p ˝ βp`1 “ β2 ˝ βp ;

p`1 2 p ˝ βp`1 “ β2 ˝ βp .

% 86

Example 87 A different way of coding sequences of integers:

cpεq “ 1 cpx , . . . , x q “ Π p0qx0`1 ¨ Π p1qx1`1 ¨ ¨ ¨ Π ppqxp`1. " 0 p From n P Nrt0u we recover the sequence xx0, . . . , xpy such that cpx0, . . . , xpq “ n by considering 2 the rim. ec function d P NpN q which yields the exponents of the prime numbers: P R dpi, nq “ µx ď n Π piqx`1 does not divide n.

3.5 Partial Recursive Functions

We recall that p p (1) pdomf , fq is a partial function N ÝÑ N if f is a mapping domf ÝÑ N where domf Ď N . p p (2) pdomf , fq is a total function N ÝÑ N if domf “ N holds.

We say that f is undefined on x – or fpxq is undefined – if x R domf . pdomĎ pq p We use the notation f P N N to signify that pdomf , fq is a partial function N ÝÑ N whose domain is domf . dom p Notice that for any two partial functions f, g P Np ĎN q:

domf “ domg f “ g holds ðñ and $ & @x fpxq “ gpxq. % 58 EPFL G¨odel& Recursivity

pdomĎ pq pdomĎ nq Definition 88 (composition) Given f1, . . . , fn P N N and g P N N , the composi- p pq tion h “ gpf1, . . . , fnq P N N is defined by ÝÑ x R domfi 1ďiďp $ $ č ’ hpÝÑx q is undefined iff ’ ’ ’ or otherwise ’ ’ ’ &’ ’ &’ ÝÑ ÝÑ ’ f1p x q, . . . , fnp x q R domg. ’ ’ ’ ’ ÝÑ %’ ` ÝÑ ˘ÝÑ ÝÑ ’ hp x q is defined otherwise and hp x q “ g f1p x q, . . . , fnp x q . ’ ’ ’ ` ˘ % “ g f1px1, . . . , xpq, . . . , fnpx1, . . . , xpq ` ˘ dom p dom p`2 Definition 89 (recursion) Given g P Np ĎN q and h P Np ĎN q, there exists a unique pdomĎ p`1q ÝÑ p f P N N such that for all x P N and y P N: (1) ÝÑ ÝÑ fp x , 0q is undefined if x R domg and $ ÝÑ ÝÑ ÝÑ & fp x , 0q is defined otherwise with fp x , 0q “ gp x q. (2) % ÝÑ p x , yq R domf

$ ÝÑ $ ’ fp x , y ` 1q is undefined if ’ or ’ ’ ’ &’ ’ ÝÑ ÝÑ ’ x , y, fp x , yq R domh. &’ ’ ’ and%’ ` ˘ ’ ’ ÝÑ ÝÑ ÝÑ ÝÑ ’ otherwise fp x , y ` 1q is defined and fp x , y ` 1q “ h x , y, fp x , yq . ’ ’ %’ ` ˘ dom p`1 dom p Definition 90 (minimization) Given f P Np ĎN q, we define g P Np ĎN q by: gpÝÑx q “ µy fpÝÑx , yq “ 0. Notice that fpÝÑx , zq is defined! $ @z ă y $ and ’ ’ ÝÑ ÝÑ ’ & fp x , zq ą 0 gp x q “ y ðñ ’ ’ &’ ’ % and ’ ÝÑ ’ fp x , yq “ 0. ’ ’ %’ Recursivity 59

Definition 91 (partial recursive functions) The set of partial recursive ( ) functions is PR the least that

(1) contains:

p p pq ÝÑ (a) All constants N ÝÑ N (all i P N N s.t. ip x q “ i – any i, p P N). p (b) All projections πi (any p P N, any 1 ď i ď p) (c) The successor function S P NN.

(2) and is closed under

(a) composition (b) recursion (c) minimisation.

Our next goal is to show that a function f is in if and only if it is Turing computable. One PR direction is easy, the other one is more involved. One side effect of our proof will show that every partial recursive function can be obtained by applying the minimisation at most once.

Lemma 92 Every partial recursive function is Turing computable.

dom p Proof of Lemma 92: We need to show that given any p P N r t0u and any f P Np ĎN q there exists some Turing machine that computes f. This means that on input pn1, . . . , npq it stops M in configuration qacc.fpn1, . . . , npq if pn1, . . . , npq P domef, and it never stops otherwise. Of course, we need to fix a certain representation of both integers and finite sequence of integers. For simplicity, let us say that the integers are represented in base-ten and the sequences as pn1, . . . , npq so that the input alphabet is

Σ “ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, p, q,, . ! ) So, for instance a TM computes Add if on input word “p385, 218q” it returns the word “603”. We do the proof by induction on the number of operation among

˝ composition ˝ recursion ˝ minimisation

dom p that are necessary to obtain f P Np ĎN q on the basis of

˝ all constants ˝ all projections ˝ the successor function.

(1) It is quite obvious that

dom p ˝ if f P Np ĎN q is constant, then there exists some basic TM that computes it. p ˝ Every projection πi (any 1 ď i ď p) is also trivially computable. 60 EPFL G¨odel& Recursivity

˝ The successor function is clearly computable as well.

p pdomĎN q (2) (a) Assume f1, . . . , fn P N are computed respectively by f1 ,..., fn and g P pdomĎ nq p Mpq M N N is computed by g. Then f “ gpf1, . . . , fnq P N N is computed by f M M which works as follows: ÝÑ on input x “ pn1, . . . , npq: ÝÑ successively for each i :“ 1,..., n f simulates f on input x , if f stops M M i M i with some output mi it stores mi.

(In case all simulation of machines f ,..., f do stop) f finally simulates g M 1 M n M M on input pm1, . . . , mnq.

It is clear that if either

ÝÑ ÝÑ ÝÑ (A) x R domfi or (B) f1p x q, . . . , fnp x q R domg, 1ďiďn č ´ ¯

then f never stops. M In the opposite case, f stops with the right answer. M pdomĎ pq pdomĎ p`2q (b) Assume g P N N and h P N N are computed respectively by g and M h. Then f defined by recursion: M (A) fpÝÑx , 0q “ gpÝÑx q (B) fpÝÑx , y ` 1q “ h ÝÑx , y, fpÝÑx , yq

is computed by f which works as follows: M ` ˘ ÝÑ ÝÑ ˝ on input p x , 0q it simply simulates g on input x , and ÝÑ M ÝÑ ˝ on input p x , n ` 1q f first simulates g on input x which gives – in case the M M machine stops! – fpÝÑx , 0q. Then ÝÑ ÝÑ recursively for i :“ 0,..., n f simulates h on x , i, fp x , iq which yields M M – in case the machine stops! – fpÝÑx , i ` 1q. ` ˘ ÝÑ It is clear that f brings the result if and only if every step fp x , iq (i :“ 0, . . . , n`1) M is defined. Otherwise it simply never stops. pdomĎ p`1q ÝÑ (c) Assume g P N N is computed by g. We design f that on input x M M computes µy gpÝÑx , yq “ 0. ÝÑ set i :“ 0 f simulates g on input p x , iq. If g stops and outputs the value of M M M gpÝÑx , iq, ÝÑ ˝ if gp x , iq “ 0 f stops and outputs i, ÝÑ M ˝ if gp x , iq ‰ 0, f starts over again with i :“ i ` 1. M ÝÑ Notice that f stops and outputs n “ µy gp x , yq “ 0 if and only if M ÝÑ ˝@ i ď n p x , iq P domg, Recursivity 61

˝@ i ă n gpÝÑx , iq ą 0 and ˝ gpÝÑx , nq “ 0.

% 92 62 EPFL G¨odel& Recursivity Bibliography

[1] Chiswell, I., and Hodges, W. Mathematical logic. Oxford University Press, 2007.

[2] Church, A. Introduction to Mathematical Logic. (Princeton Landmark in Mathematics. Princeton University Press, 1996.

[3] Cooper, S. B. Computability theory. CRC Press, 2004.

[4] Cori, R., Lascar, D., and Krivine, J.-L. P. Logique math´ematique,tome 1 : Calcul propositionnel; alg`ebre de Boole; calcul des pr´edicats, vol. 1. Dunod, Paris, 2003.

[5] Cori, R., Lascar, D., and Krivine, J.-L. P. Logique math´ematique,tome 2 : Fonctions r´ecursives,th´eor`emede G¨odel,th´eoriedes ensembles, th´eoriedes mod`eles, vol. 2. Dunod, Paris, 2003.

[6] Cutland, N. Computability: An introduction to recursive function theory. Cambridge university press, 1980.

[7] Ebbinghaus, H.-D., Flum, J., and Thomas, W. Einf¨uhrungin die mathematische Logik. Wissenschaftliche Buchgesellschaft Darmstadt, 1978.

[8] Enderton, H. B. A mathematical introduction to logic. Academic Press, 1972.

[9] Enderton, H. B. Computability Theory: An Introduction to Recursion Theory. Academic Press, 2010.

[10] Fitting, M. Incompleteness in the Land of Sets. College Publications, 2007.

[11] Franzen,´ T. G¨odel’sTheorem: an incomplete guide to its use and abuse. AK Peters, 2005.

[12] Godel,¨ K. Die vollstandigkeit der axiome des logischen funktionenkalkuls. Monatshefte fur Mathematik und Physik 37 (1930), 349–360.

[13] Godel,¨ K. Uber¨ formal unentscheidbare s¨atzeder principia mathematica und verwandter systeme i. Monatshefte f¨urMathematik 38, 1 (1931), 173–198. 64 EPFL G¨odel& Recursivity

[14] Grattan-Guinness, I. The search for mathematical roots, 1870-1940: logics, set theo- ries and the foundations of mathematics from Cantor through Russell to Godel. Princeton University Press, 2011.

[15] Hardy, G. H., and Wright, E. M. An Introduction to the Theory of Numbers. Oxford University Press, 1979.

[16] Hedman, S. A first course in logic: an introduction to model theory, proof theory, com- putability, and complexity. Oxford University Press Oxford, 2004.

[17] Hilbert, D. Mathematische probleme. Archiv der Mathematik und Physik,(3) 1 (1901), 44–63.

[18] Hilbert, D. Mathematical problems. Bull. Amer. Math. Soc 8 (1902), 437–479.

[19] Hopcroft, J. E., Motwani, R., and Ullman, J. D. Introduction to automata the- ory, languages, and computation. Addison-Wesley Publishing Co., Reading, Mass., 2001. Addison-Wesley Series in Computer Science.

[20] Kaye, R. Models of Peano arithmetic. Clarendon Press Oxford, 1991.

[21] Kleene, S. C. Introduction to Metamathematics. D. Van Nostrand Company, Inc., Prince- ton, New Jersey, 1952.

[22] Kleene, S. C. Mathematical Logic. John Wiley & Sons, 1967.

[23] Matiyasevich, Y. Hilbert’s tenth problem. MIT press, 1993.

[24] Nagel, E., Newman, J. R., Godel,¨ K., and Girard, J.-Y. Le th´eor`emede G¨odel. Editions´ du Seuil, 1989.

[25] Odifreddi, P. Classical recursion theory: The theory of functions and sets of natural numbers. North Holland, 1992.

[26] Papadimitriou, C. H. Computational complexity. John Wiley and Sons Ltd., 2003.

[27] Peter,´ R., and Foldes,¨ I. Recursive functions, vol. 80. Academic Press New York, 1967.

[28] Robinson, R. M. An essentially undecidable axiom system. In Proceedings of the inter- national Congress of Mathematics (1950), vol. 1, pp. 729–730.

[29] Rogers Jr, H. Theory of recursive functions and effective computability. MIT press, 1987.

[30] Shoenfield, J. R. Mathematical logic, vol. 21. Addison-Wesley Publishing Co., Reading, Mass., 1967.

[31] Sipser, M. Introduction to the Theory of Computation, vol. 2. Thomson Course Technology Boston, 2006. Recursivity 65

[32] Smith, P. An introduction to G¨odel’s theorems. Cambridge University Press, 2013.

[33] Smullyan, R. M. G¨odel’sincompleteness theorems. Oxford University Press New York, 1992.

[34] Smullyan, R. M. Diagonalization and self-reference. Clarendon press Oxford, 1994.

[35] Soare, R. I. The history and concept of computability. Studies in Logic and the Founda- tions of Mathematics 140 (1999), 3–36.

[36] Stillwell, J. Elements of number theory. Springer, 2003.

[37] van Heijenoort, J. From Freege to G¨odel:A Source Book in Mathematical Logic, 1879- 1931. Harvard University Press, 1977.