g odel & recursivity - hec lausanne › logique › enseignement ›...
TRANSCRIPT
Godel & Recursivity
JACQUES DUPARC
Batiment InternefCH - 1015 Lausanne
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 Turing Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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, Lowenheim-Skolem theorem.
It makes no sense to take this course without this solid background on first order logic.
The title of the course is ”Godel and Recursivity” but it should rather be ”Recursivity and
Godel” since that is the way we are going to go through these topics
(1) Recursivity
(2) Godel’s incompleteness 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.
Godel’s incompleteness 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 ϕ).
Godel’s first 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 Godel’s incompleteness 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 Godel’s incompleteness 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
sequence is of the form Gmp0q, G
mp1q, G
mp2q, . . ., 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
G4p0q “ 4 by Gm
p0q “ m and gathering the other values Gmp1q, G
mp2q, etc the same way):
8 EPFL Godel & Recursivity
˝ G4p0q “ 4 write 4 in hereditary base 2: 4 “ 22
replace all 2’s by 3’s, then subtract 1: 33 “ 26
˝ G4p1q “ 26 write 26 in hereditary base 3: 26 “ 2 ¨ 32 ` 2 ¨ 312 ¨ 30
replace all 3’s by 4’s, then subtract 1: 2 ¨ 42 ` 2 ¨ 412 ¨ 40 ´ 1 “ 41
˝ G4p2q “ 41 write 41 in hereditary base 4: 41 “ 2 ¨ 42 ` 2 ¨ 412 ¨ 40
replace all 4’s by 5’s, then subtract 1: 2 ¨ 52 ` 2 ¨ 512 ¨ 50 ´ 1 “ 60
˝ G4p3q “ 60 . . . etc
Amazingly, G4pnq increases until n reaches the value 3 ¨ 2402653209 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.
Amazingly, for every integer m, the Goodstein sequence pGmpnqqnPN is ultimately constant with
value 0, i.e.
limnÑ8
Gmpnq “ 0.
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).
Godel’s second 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)
˝ Number Theory ÝÑ Recursive functions which are particular functions Nk Ñ 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 automata theory, 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 Godel & Recursivity
Definition 2 A DFA A “ pQ,Σ, δ, q0, F q on an alphabet Σ accepts the word w P Σăω if and
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,
LpAq “ tw P Σăω : w is accepted by Au .
LpAq denotes the language accepted by A.
Definition 4 Any language recognised by some deterministic finite automata (DFA) is called
regular.
Example 5 The following DFA A recognises the language LpAq “ tw1 | w P t0, 1uăωu of all
the words of 0’s and 1’s that end with a 1.
q0 q1 1
1
0
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ˆ Σε ÝÑ PpQq is the transition function,
Recursivity 13
(4) q0 P Q is the initial state, and
(5) F Ď Q is the set of accepting states.
Definition 7 Let N “ pQ,Σ, δ, q0, F q be an NFA and w P Σăω. We say that N accepts w if
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 N recognises the language LpN q “ tw1 | w P t0, 1uăωu of all
the words of 0’s and 1’s that end with a 1.
q0 q11
0, 1
Proposition 9 Every NFA has an equivalent DFA. i.e. given any NFA N there exists some
DFA D such that
LpN q “ LpDq.
Proof of Proposition 9: Given any NFA N “ xQ,Σ, δ, q0, F y, we build some DFA D “
xQ1,Σ, δ1, q10, F1y that recognises the same language.
(1) Q1 “ PpQq
(2) For S Ď Q and a P Σ we set
δ1pS, aq “ tq1 P Q | Dq P S qε˚aε˚ÝÝÝÝÑ q1u
where qε˚aε˚ÝÝÝÝÑ q1 stands for the existence of a path in the graph of N that goes through
exactly one edge labelled with ”a”, the others being labelled with ”ε”.
(3) q10 “ tq0u
14 EPFL Godel & 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: AYB “ 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 N 1 “ pQ1,Σ,∆1, q1, F1q, N 2 “ pQ2,Σ,∆2, q2, F2q be two NFAs
recognising respectively A1 and A2.
N1 N2
Union We need an NFA N such that N recognises a string if and only if N 1 or N 2 recognises
it. By working nondeterministically, the automaton N is allowed to split into two copies:
we construct N in such a way that N 1 and N 2 work in parallel at the same time. We
assume Q1 XQ2 “ H and q0 R Q1 YQ2. Define N “ pQ,Σ,∆, q0, F q where
(1) Q “ tq0u YQ1 YQ2.
(2) ∆ Ă Qˆ Σε ˆQ is defined by: pp, s, rq P ∆ if and only if one of the following is true
(a) p “ q0
s “ ε
r P tq1, q2u
(b) p, r P Q1
pp, s, rq P ∆1
(c) p, r P Q2
pp, s, rq P ∆2.
(3) F “ F1 Y F2.
Recursivity 15
The machine splits immediately into two copies of itself, which work exactly as N 1 and
N 2. It accepts a string if and only if at least one of the two main copies ends up in an
accepting state, i.e. in F1 or in F2, i.e. if and only if N 1 or N 2 accept it.
N
"
"
Concatenation Here we need an NFA N that accepts a word w if and only if w can be broken
into two pieces: a prefix and a suffix w “ wpws such that wp is accepted by N 1 and wsis accepted by N 2. We set q1 as the initial state and let the machine read the same way
N 1 would do. Any time that N 1 finds itself in an accepting state, we want N to non-
deterministically start reading as if it were N 2 but still remaining a copy of itself: so we
make it split any time it comes to some final state of N 1. The reason is that we want
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 N 1 corresponds to a suffix that is rejected by N 2,
while there is a longer prefix which is also accepted by N 1 that yields a suffix which is this
time also accepted by N 2. Formally, we define ∆ by: pp, s, rq P ∆ if and only if one of the
following is true
(1) p, r P Q1
pp, s, rq P ∆1
(2) p, r P Q2
pp, s, rq P ∆2
(3) p P F1
s “ ε
r “ q2
The third condition guarantees the splitting. Finally, we set the accepting set to be F “ F2.
16 EPFL Godel & Recursivity
N
"
""
"
Star Here the machine N should be able to check if a word w can be broken into a finitely
many pieces w “ w1w2 ¨ ¨ ¨wk, each of them being accepted by N 1. So N has to read w1
as if it were N 1, and when it finds itself in an accepting state, it needs to start all over
again and read w2 and so on and so forth. The construction is similar to the one of the
concatenation, but since A˚1 contains the empty string, we want N to accept ε. So we just
add an initial state q0 which is also an accepting state, and from where the initial state of
N 1 is reached by an ε move. % 11
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 Σ)
(2) ε
(3) H
(4) R1 YR2
(5) R1 ˝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
(2) Lpεq “ tεu
(3) LpHq “ H
(4) LpR1 YR2q “ LpR1q Y LpR2q
(5) LpR1 ˝R2q “ LpR1q ˝ LpR2q
(6) LpR˚1q “ 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
(2) Lpεq “ tεu
(3) LpHq “ H
(4) LpR1 YR2q “ LpR1q Y LpR2q
(5) LpR1 ˝R2q “ LpR1q ˝ LpR2q
(6) LpR˚1q “ 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:
qinRinÑrip ˝ pRripÑripq
˚ ˝ RripÑout Y RinÑoutÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÑ 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 Godel & Recursivity
(a) qinRinÑripÝÝÝÝÝÑ qrip
(b) qripRripÑripÝÝÝÝÝÑ qrip
(c) qripRripÑoutÝÝÝÝÝÝÑ qout
(d) qinRinÑoutÝÝÝÝÝÑ qout.
(3) We end up with a 2-states (“s” and “a”) Generalized-NFA with a single transition of
the form sRÝÑ a. The regular expression R gives the solution.
Example 15
(a)
1
0
0, 1(b)
1
0
0, 1"
"s
a
(c)
0"
s
a
1(0 [ 1)⇤
(d)
s
a
0⇤1(0 [ 1)⇤
An other example with an automaton a bit more complicated.
Example 16
(a)
1
0
0
0
1
1
(b)
Recursivity 19
1
0
0
0
1
1
"
"s a
"
(c)
0
1 "
s a"
00 [ 1
01 10 [ 0
11
(d)
s a
(10 [ 00)(00 [ 1)⇤01 [ 11
0(00 [ 1)⇤01 [ b
0(00 [ 1)⇤
(10 [ 0)(00 [ 1)⇤ [ "
(e)
s a
�0(00 [ 1)⇤01 [ b
��(10 [ 00)(00 [ 1)⇤01 [ 11
�⇤�(10 [ 0)(00 [ 1)⇤ [ "
�[�0(00 [ 1)⇤
�
% 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 regular language, 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 Godel & Recursivity
(1) for each i ě 0, xyiz P A,
(2) |y| ą 0, and
(3) |xy| ď p
Proof of Theorem 17: Let A be any DFA such that LpAq “ A. Set p to be the number of states
of A. Let s be accepted by A. Then s may be broken into three pieces: s “ xyz. Such that the
path q0xÝÑ q never visits twice the same state. The path q
yÝÑ q visits twice the state q but none
of the others twice. This holds since for every word u of length at least p every path q1uÝÑ q2 in
A visits at least twice the same state.
z
y
x
% 17
Example 18 The language t0m1m | n P Nu is not regular.
By contradiction, assume there exists some DFA A “ pQ,Σ, δ, q0, F q which recognises t0m1m |
n P Nu. We consider p “ |Q| the number of states of A. the word 0p1p is accepted by A. By
the previous Pumping Lemma there exist x, y and z such that 0p1p “ xyz and
(1) for each i ě 0, xyiz P t0m1m | 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 pushdown automaton (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,
(4) δ : Qˆ Σε ˆ Γε ÝÑ PpQˆ Γεq is the transition function3,
(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:
ri
aec
w1w2w3 · · · wi�1wiwi+1 · · · wm
ri+1ri
bec
w1w2w3 · · · wi�1wiwi+1 · · · wm
ri+1
(2) The special case where a “ ε and b P Γ (the PDA “pushes” b to the top of the stack)
ri
ec
w1w2w3 · · · wi�1wiwi+1 · · · wm
ri+1ri
bec
w1w2w3 · · · wi�1wiwi+1 · · · wm
ri+1
3For a deterministic version, replace PpQˆ Γεq by Qˆ Γε.
22 EPFL Godel & Recursivity
(3) The special case where a P Γ and b “ ε (the PDA “pops off” a from the top of the stack)
ri
aec
w1w2w3 · · · wi�1wiwi+1 · · · wm
ri+1ri
ec
w1w2w3 · · · wi�1wiwi+1 · · · wm
ri+1
Example 21 (1) The language t0m1m | n P Nu is recognised by a PDA.
1, 0 ! "
", " ! ?0, " ! 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 ! "
", " ! ?
0, " ! 0
",? ! ?
",? ! ?", " ! "
", "!" ", " ! "
1, " ! " 2, 0 ! "
2, " ! "
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
This grammar generates the language t0n71n | 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 Godel & 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:
T
S
T
x y zwv
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
zv
We also clearly have, for each i ě 0, vwixyiz P A:
T
S
T
x y zwv
T
T
x yw
S
z
T
ywv
% 25
26 EPFL Godel & Recursivity
Example 26 The following language is not context-free:
tanbncn | 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.
100 01 1
Control
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 Godel & 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,C 1 we write C ñ C 1 (for C yields C 1 in one step) if there exist
a, b, c P Γ, and u, v P Γ˚ such that
˝ either C “ uaqibv, C 1 “ uqjacv and δpqi, bq “ pqj , c, Lq,
˝ or C “ uaqibv, C 1 “ 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 M is the language it recognises:
LpMq “ tw P Σ˚ |M accepts wu.
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 Godel & 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.pq0, 0q ÝÑ pq1,\, Rq
pq0, 1q ÝÑ pq2,\, Rq
pq1,\q ÝÑ pq3,\, Lq
pq1, 0q ÝÑ pq1, 0, Rq
pq1, 1q ÝÑ pq1, 1, Rq
pq2,\q ÝÑ pq4,\, Lq
pq2, 0q ÝÑ pq2, 0, Rq
pq2, 1q ÝÑ pq2, 1, Rq
pq3,\q ÝÑ qrej.pq3, 0q ÝÑ pq5,\, Lq
pq3, 1q ÝÑ qrej.pq4,\q ÝÑ qrej.pq4, 0q ÝÑ qrej.pq4, 1q ÝÑ pq5,\, Lq
pq5,\q ÝÑ pq6,\, Rq
pq5, 0q ÝÑ pq5, 0, Lq
pq5, 1q ÝÑ pq5, 1, Lq
pq6,\q ÝÑ qacc.pq6, 0q ÝÑ pq1,\, Rq
pq6, 1q ÝÑ pq2,\, Rq
Definition 31 A language L is Turing recognizable if there exists a TM M such that
L “ LpMq.
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
´
u1qv1 , u2qv2 , . . . . . . , ukqvk
¯
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 M be a multi-tape TM. We will describe a TM S that recognises
the same language. Let pw1, w2, . . . , wkq be the input of M on its k tapes. The corresponding
input of S will be 7w17w27 . . . 7wk7, where 7 does not belong to the alphabet of M. To simulate a
single move of M, S scans its tape from the first 7 which marks the left-hand end, to the k`1th
7 (which marks the right-hand end) replacing each letter a right after the 7 symbol (except for
the k ` 1th one) by a to indicate the position of the heads. Then S makes a second pass to
32 EPFL Godel & Recursivity
update the tapes according to M’s transition functions. If at any point S moves one of the
virtual heads to the right onto a 7, this action signifies that M has moved the corresponding
head onto the previously unread blank portion of that tape. So S writes a blank symbol on this
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.
00 01 t t
01 1 t t t
0 01 1
t t t t
]]]] 1 1
t
10 01 1
t
00 01 t t t10 bt
M
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ˆ Γ ÝÑ PpQˆ Γˆ tL,Ruq.
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:
2434 2 24 t t t2
Mt t t t
t t t
t t
0 0
0 0
1
111
1
1 1 1 176
1
2
3
We consider a 3-tape ( 1 , 2 and 3 ) deterministic TM M to simulate a NTM 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 N on one – initial segment of a – branch of its non-deterministic computation
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 Godel & Recursivity
Which gives:
ε, 1, 2, . . . , k, 11, 12, . . . , 1k, 21, 22, . . . , 2k, . . . . . . , k1, k2, . . . , kk, 111, 112, . . . , 11k, . . . . . . . . . . . .
˝ At first, M Copies the content of 1 (= the input w) to 2 .
˝ It then uses 2 to simulate N with input w on the branch b of its non-deterministic
computation which is lodged on 3 . In case the word b does not correspond to a real
computation1 or if the simulation of N on 2 either reaches the rejecting state or does not
reach any halting state at all, then M erases completely 2 , replaces b on 3 with its the
immediate ă-successor, and starts all over again – by copying 1 on 2 and simulating Non 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 L if the result
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 L is “recursively enumerable” if there is an enumerator that enumerates
L.
Theorem 44 A language is Turing Recognizable if and only if it is recursively enumerable.
Proof of Theorem 44:
(ñ) from M we build E that enumerates LpMq. Fix a recursive enumeration psiqiPN of Σ˚.
(1) Repeat the following for i “ 1, 2, 3, . . .
(2) Run M for i steps on each input s1, s2, . . . , si
(3) If any computation accepts, print out the corresponding sj .
1this 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 E we build M: on input w: run E , and every time E outputs some word v, find out
whether v “ w or not, and accept if they are the same.
% 44
Proposition 45 For any infinite L Ď Σ˚,
L is Turing decidable ðñ
$
’
’
’
’
’
’
’
’
’
’
’
’
’
’
’
&
’
’
’
’
’
’
’
’
’
’
’
’
’
’
’
%
there exits E an enumerator that prints out
u0 \ u1 \ u2 \ . . . . . .\ ui \ ui`1 \ . . . . . . . . .
such that
$
’
’
’
’
’
’
’
’
’
&
’
’
’
’
’
’
’
’
’
%
L “ tui | i P Nu
and
i ă j ùñ
$
&
%
|u| ă |v|
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
tP px1, . . . , xnq | Dpa1, . . . anq P Nn 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
c : E1´1ÝÝÑ F.
2this is combined work of Martin Davis, Yuri Matiyasevich, Hilary Putnam and Julia Robinson
36 EPFL Godel & Recursivity
Example 47 E “ t0, 1u˚, F “ N and c : E1´1ÝÝÑ F is a coding defined by:
cpwq “ 1w2p= 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 Mf such that
˝ on inputs w R dompfq: it never halts,
˝ on inputs w P dompfq: it halts in configuration “qacc.u2 with u “ fpwq.
Remarks 49
(1) Given any finite alphabet Σ, and any TM M whose alphabet is Σ, there exists a Turing
computable coding: c : Σ˚ ÝÑ t0, 1,\u˚ and a TM Mc with tape alphabet t0, 1,\u such
that M accepts w if and only if Mc accepts cpwq.
(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
“
Recursive
Ĺ Turing Recognizable.
“
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
˝ C++
˝ Common Lisp
˝ Java
˝ Lisp
˝ Pascal
˝ Prolog, etc.
2.4 Universal Turing Machine
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:
M “ xtq0, q1, . . . , qku, t0, 1u, t0, 1,\u, δ, q0, qacc., qrej.y
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 xMy the code of M, i.e.
xMy “ cpMq.
Clearly, the following language is decidable:
txMy : M is a TMu.
3in other words: a non-recursive recursively enumerable language.
38 EPFL Godel & Recursivity
Proposition 50 (Universal Turing Machine) There exists a Turing machine4 U such that
on each input of the form vw P t0, 1u˚,
if v “ xMy for some Turing machine5 M, then U works as M on input w.
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 “ xMyw for some Turing machine M, this decomposition is then unique.
This means for instance that
˝ U never stops if M never stops on input w,
˝ U stops with the word w1 written on its tape and rejects if M stops on input w in a
rejecting configuration with the word w1 written on its tape,
˝ U stops with the word w1 written on its tape and accepts if M stops on input w with the
word w1 written on its tape
(1) on 1 the input xMyw is inserted. It will never be modified during the rest of the compu-
tation. Then U copies the code of
(a) the transition function of M – xδy – on 2 ;
(b) the initial state of M – xq0y – on 3 7;
(c) the accepting state of M – xqacc.y – on 4 8;
(d) the rejecting state of M – xqrej.y – on 5 9.
(2) It then uses 6 to simulate M on input w: for each step of M
(a) U reads a letter – say 0 – on 6 , and
(b) using the code of the actual state – say xq3y – on 3 , U looks in 2 for the code of the
corresponding transition – say xpq3, 0, q1, 1, Rqy – and then
(c) U verifies that the code of the new state – here xq1y – is different from the content of
4 and 5 (otherwise if it corresponds to the content of 4 it means that it is xqacc.y,
and U accepts right away, and if it corresponds to the content of 5 it means it is
xqrej.y, in which case U rejects).
4working on alphabets ΣU “ t0, 1u and ΓU “ t0, 1,\u5also working on alphabets ΣU “ t0, 1u and ΓU “ t0, 1,\u6this 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. – U replaces on 6 the letter it just read with the new one
– here it replaces 0 by 1 – and still on tape 6 it makes the move indicated – here it
goes right – and finally,
(e) U replaces on 3 the code of the old state by the new one – here it replaces xq3y by
xq1y.
U
0 01 1 1111 1 1 00 01 t t10 1
M
01 1 01 1
00 01 1 01 1
00 01 00 0 1
00 01 1 01 1
0
0 01 111 1 10
0 01 1 1111 1 1 00 01 t t10 10
4
5
6
1
2
3
% 50
40 EPFL Godel & Recursivity
2.5 The Halting Problem
Proposition 51 The following language is Turing recognizable but not decidable:
txMyw P t0, 1u˚ |M is a TM and M accepts wu.
Proof of Proposition 51: Towards a contradiction we assume there exists a Decider D that
decides this language. We build a Turing machine H which works the following way:
on input w
˝ if D accepts ww, then H does not halt.
˝ if D rejects ww, then H accepts.
Notice that
H accepts xHy ðñ D rejects xHyxHy ðñ H does not accept xHy.
% 51
Proposition 52 The following language is Turing recognizable but not decidable:
txMy P t0, 1u˚ |M is a TM and M halts on the empty inputu.
Proof of Proposition 52: Left as an exercise.
% 52
Corollary 53 The following languages are not recursively enumerable:
˝ t0, 1u˚ r txMy P t0, 1u˚ |M is a TM and M halts on the empty inputu
˝ t0, 1u˚ r txMyw P t0, 1u˚ |M is a TM and M accepts wu
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 :
O “ pQ,Σ,Γ, δ, q0, qacc., qrej.q
(3) An oracle-compatible-Turing machine O equipped with the oracle O, on input word w P Σ˚
(in short an oracle TM OO on word w P Σ˚) is nothing but the TM O whose initial
configuration is´
q0w , q0χO
¯
1 2
where χO P t0, 1uω is the infinite word
χOp0qχOp1qχOp2q . . . . . . χOpnqχOpn` 1q . . . . . . . . . . . .
defined by
χOpnq “
$
’
’
&
’
’
%
1 if n P O
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 “ 1xMyw ” in the decimal numeral system,
(2) M is a TM that halts on input w;
then OO may be able to decide the Halting Problem. Of course this does not lead to a contra-
diction since there is no chance that such a Turing machine 10 ever sees its own code onto tape
2 (although the code of O – or the code of an equivalent TM – does show on 2 ).
OO
0 00 01 10
1 111 1 101
2
t t
00 000 0 0 00 0 0 0 0
10we are talking about OO and not just O!
42 EPFL Godel & Recursivity
Example 55 Let O Ď N be the set of all the codes of Turing machines that halt on the empty
input:
O “ t1xMy2P N |M is a TM and M halts on the empty inputu.
We describe an oracle-compatible-TM O that, once equipped with the oracle O, decides the
language
txMy P t0, 1u˚ |M is a TM and M halts on the empty inputu.
The machine OO works this way:
(1) on input w P t0, 1u˚, the TM OO checks whether w is the code of a TM
if it is not the case it rejects right away. Otherwise,
(2) it computes n “ 1xMy2, then checks on tape 2 whether χOpnq “ 1 – in which case it
accepts – or χOpnq “ 0 – in which case it rejects.
Notation 56 ˝ Given any language L Ď t0, 1u˚, we write OpLq Ď N for the set
OpLq “!
1w2´ 1 P N | w P L
)
.
˝ Given any subset O Ď N, we write LpOq Ď t0, 1u˚ for the language
LpOq “!
w P t0, 1u˚N | 1w2´ 1 P O
)
.
So OpLq is the oracle associated with the language L, and LpOq is the language associated with
the oracle O.
Notice that the oracle for the empty language is the empty set: OpHq “ H.
Proposition 57 Given any recursive language L Ď t0, 1u˚, and any oracle Turing machine
OOpLq:
˝ LpOOpLqq is recursively enumerable, and moreover
˝ if OOpLq is an oracle Decider11, then LpOOpLqq is recursive.
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,
A is “Turing reducible” to B if there exists an oracle Decider DB that computes χA.
Or equivalently:
for all o-c-TM M there exists an o-c-TM DM such that
$
’
’
&
’
’
%
DBM is an oracle Decider
and
L`
DBM
˘
“ L`
MA˘
.
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
˝ pA ď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´
LpOpLqq¯.
Proposition 61
(1)!
LpOq Ď t0, 1u˚ | O ďT H)
is the class Rec. of all recursive languages.
44 EPFL Godel & Recursivity
(2)!
LpOq Ď t0, 1u˚ | O ďT Halt
)
Ě R.E . (= the class of all r.e. languages).
Where Halt stands for the set of codes of Turing machines that halt on the empty input:
Halt “ OptxMyPt0,1u˚|M is a TM and M halts on the empty inputuq.
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
A1 “ O´!
xMyPt0,1u˚|M is an o-c-TM and MAhalts on the empty input
)¯.
Proposition 63 Given any A Ď N,
A ăT A1.
Proof of Proposition 63: We decompose A ăT A1 into first A ďT A
1, then A1 ďT A.
(A ďT A1) Given any o-c-TM M we need to find an o-c-TM N such that NA1 decides mem-
bership in L`
MA˘
. N is defined such that: on input w P t0, 1u˚:
(1) NA1 computes the code of an o-c-TM Kw that works just like M except that when
it starts on the empty tape, it begins with writing down the input w on the working
tape, and then proceeds exactly as M with the exception that instead of eventually
reaching the rejecting state, it reaches an ever lasting loop.
(2) Then NA1 checks wether KAw halts on the empty tape.
(a) If it does not, then NA1 rejects w.
(b) If it does, then NA1 accepts w.
(A1 ďT A) Towards a contradiction, we assume that A1 ďT A holds. So that given any o-c-
TM M there exists some o-c-TM N such that NA decides membership in L´
MA1¯
. We
choose M to be the o-c-TM that does the following on input w P t0, 1u˚:
(1) if w “ xN y for some o-c-TM N , then
(a) M computes the code of an o-c-TM Kw that works the same as N except that
(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 N .
(b) Then MA1 makes use of its oracle to check whether KAw halts on the empty input
or not.
(A) If it does halt, then NA1 accepts w.
Recursivity 45
(B) If it does not halt, then MA1 rejects w.
(2) if for all o-c-TM N , w ‰ xN y, then we don’t care what it does.
So, assume now there exists some o-c-TM N such that NA decides membership in L´
MA1¯
.
It is enough to consider the input w “ xN y to see that
MA1 accepts xN y ðñ KAxN y
does not halt on the empty word
ðñ NA either never stops or stops and rejects xN y.
Which contradicts that NA decides membership in LpMA1q since we have
xN y P LpMA1q ðñ xN y R LpNAq.
% 63
Corollary 64 The following strict ordering between jumps is satisfied:
H ăW H1 ăW H2 ăW . . . ăW H
nhkkikkj
2 ¨ ¨ ¨ 1 ăW H
n`1hkkikkj
2 ¨ ¨ ¨ 1 ăW . . . ăW H
ωhkkikkj
2 ¨ ¨ ¨ ăW H
ω`1hkkikkj
2 ¨ ¨ ¨ 1 ăW . . . .
where
k P H
ωhkkikkj
2 ¨ ¨ ¨ 1 ðñ
$
’
’
’
’
&
’
’
’
’
%
k “ pn`mqpn`m`1q2
and
m P H
nhkkikkj
2 ¨ ¨ ¨ 1 .
Proof of Corollary 64: Left as an exercise.
% 64
46 EPFL Godel & Recursivity
Chapter 3
Recursive Functions
Recursive functions are functions from Np 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
denote by NpNpq the set of all mappings of the form Np ÝÑ N. Notice that Np 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
ti P N | i ă 0u “ H. Thus the set N0 only contains one element: the empty function whose
graph is H. Therefore the set of all mappings of the form N0 ÝÑ N contains all mappings that
assign one integer to the empty function:
N0 ÝÑ N “"
f : tHu ÝÑ NH ÝÑ n
ˇ
ˇ
ˇ
ˇ
n P N*
.
So, as may be expected, mappings in NpN0q are identified with elements of N.
3.1 Primitive Recursive Functions
Definition 65
projection: If i is any integer such that 1 ď i ď p holds, the ith projection πpi is the function
of NpNpq defined by
πpi px1, . . . , xpq “ xi
successor: S P NN is the successor function1.
composition: Given f1, . . . , fn P NpNpq and g P NpNnq, the composition h “ gpf1, . . . , fnq P NpN
pq
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`
f1px1, . . . , xpq, . . . , fnpx1, . . . , xpq˘
.
1Spnq “ n` 1.
48 EPFL Godel & Recursivity
recursion: Given g P NpNpq and h P NpNp`2q, there exists a unique f P NpNp`1q such that for allÝÑx P Np 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 (Prim. Rec) functions is the least that
(1) contains:
(a) All constants Np ÝÑ N (all i P NpNpq s.t. ipÝÑx q “ i – any i, p P N).
(b) All projections πpi (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) Rn`1 is the closure2 of Rn under (2)(a) and (2)(b).
Clearly
R “ď
nPNRn.
Example 67
(1) Addition: px, yq ÝÑ x` y
We have:"
x` 0 “ x
x` py ` 1q “ px` yq ` 1.(3.1)
Formally:#
addpx, 0q “ π11pxq
addpx, y ` 1q “ S´
π33
`
x, y, addpx, yq˘
¯
.(3.2)
2Rn`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
x ¨ py ` 1q “ x ¨ y ` x.(3.3)
Formally:
#
multpx, 0q “ 0pxq
multpx, y ` 1q “ add´
π33
`
x, y,multpx, yq˘
, π31
`
x, y,multpx, yq˘
¯
.(3.4)
(3) Exponentiation: x ÝÑ nx
We have"
n0 “ 1
nx`1 “ nx ¨ n.(3.5)
Formally:#
expnp0q “ 1
expnpx` 1q “ mult´
π22
`
x, expnpxq˘
, n¯
.(3.6)
(4) Factorial: x ÝÑ x!
We have"
0! “ 1
px` 1q! “ x! ¨ px` 1q.(3.7)
Formally:$
&
%
factp0q “ 1
factpx` 1q “ mult
ˆ
π22
`
x, factpxq˘
, S´
π21
`
x, factpxq˘
¯
˙
.(3.8)
Example 68 We define 9 P NpN2q by
"
x 9 y “ x´ y if x ą y,
“ 0 otherwise.
We show that 9 P NpN2q belongs to Prim. Rec by first showing that : x ÝÑ x 9 1 belongs to
Prim. Rec."
0 9 1 “ 0
px` 1q 9 1 “ x(3.9)
50 EPFL Godel & Recursivity
Formally:"
0 9 1 “ 0pxq
px` 1q 9 1 “ π21
`
x, x 9 1˘ (3.10)
"
x 9 0 “ x
x 9 py ` 1q “`
x 9 y˘
9 1(3.11)
Formally:#
x 9 0 “ π11pxq
x 9 py ` 1q “´
π33
`
x, y, x 9 y˘
¯
9 1(3.12)
Definition 69 A set A Ď Np is primitive recursive (Prim. Rec) if its characteristic function
(χA P NpNpq) is primitive recursive.
Example 70
(1) The set H is Prim. Rec since χH “ 0 is Prim. Rec.
(2) The set N is Prim. Rec since χN “ 1 is Prim. Rec.
(3) The set ăN“ tpx, yq | x ă yu is Prim. Rec. χăNpx, yq “ 1 9 p1 9 py 9 xqq.
Definition 71
(1) pDf , fq is a partial function Np ÝÑ N if f is a mapping Df ÝÑ N where Df Ď Np.
(2) pDf , fq is a total function Np ÝÑ N if Df “ Np holds.
Definition 72 A partial function f : Np ÝÑ N is “Turing Computable” (TC) if there exists a
TM M such that on the input px1, x2, . . . , xpq:
(1) if fpx1, . . . , xpq is not defined, then M never stops;
(2) if px1, . . . , xpq P Df , M stops with fpÝÑx q written on the tape.
Proposition 73 Given any partial function f : Np ÝÑ N,
f is Turing Computable ðñ Gf “ `
ÝÑx , fpxq˘
| ÝÑx P Df
(
is Turing Recognizable.
Proof of Proposition 73:
Recursivity 51
(ñ) From M that computes f it is immediate to build N that recognises Gf . On input pÝÑx , yq
it simulates M if M stops it compares fpxq with y: if they compare it accepts.
(ð) From N that recognises Gf , we build M that computes f as follows, on input ÝÑx repeatedly
for i “ 1, 2, 3, . . . it recursively simulates N on pÝÑx , 0q, pÝÑx , 1q, pÝÑx , 2q, . . . , pÝÑx , iq for i many
steps. If N accepts pÝÑx , nq, then M prints out the value n.
% 73
Corollary 74 Given any function f : Np ÝÑ N,
f is both total and Turing Computable ùñ Gf is recursive (decidable).
Proof of Corollary 74: Left as an immediate exercise.
% 74
Gf P Np`1 Gf P Np`1
f P NpNpq total TC recursive decidable
f P NpNpq 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 Prim. Rec functions are total and Turing computable.
˝ All graphs of Prim. Rec functions are recursive
Even though the class of all Prim. Rec functions is included in the class of total and turing
computable functions, the inverse inclusion does not hold3.
3see exercise on the Ackermann function A P NpN2q defined by
Apm,nq “
$
&
%
n` 1 if m “ 0,
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 Godel & Recursivity
3.2 Variable Substitution
Proposition 76 (Prim. Rec is closed under variable substitution)
If f P NpNpq, is Prim. Rec, then given any σ : t1, . . . , pu ÝÑ t1, . . . , pu, the function g P NpNpq
defined by
gpx1, . . . , xpq “ fpxσp1q, . . . , xσppqq
is also Prim. Rec.
Proof of Proposition 76: The result is proved for all g P Rn by induction on n. Left as an
exercise.
% 76
Proposition 77 If A Ď Nk is Prim. Rec and f1, . . . , fn P NpNkq are Prim. Rec then
tÝÑx P Np | pf1pÝÑx q, . . . , fnpÝÑx qq P Au
is Prim. Rec.
Proof of Proposition 77: Set B “ tÝÑx P Np | pf1pÝÑx q, . . . , fnpÝÑx qq P Au. We have
χBpÝÑx q “ χA
´
f1pÝÑx q, . . . , fnpÝÑx q
¯
.
% 77
Example 78 If f, g P NpNpq are Prim. Rec, then the following sets are also Prim. Rec:
(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.
Proposition 79 If A,B Ď Np are Prim. Rec then AYB,AXB,ArB, A∆B and NprA are
all Prim. Rec.
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
Proposition 80 (Case study) If f1, . . . , fn`1 P NpNpq and A1, . . . , An P Np are all Prim. Rec,
then g P NpNpq defined by:
gpÝÑx q “
$
’
’
’
’
’
’
’
’
’
’
&
’
’
’
’
’
’
’
’
’
’
%
f1pÝÑx q if ÝÑx P A1
f2pÝÑx q if ÝÑx P A2 rA1
f3pÝÑx q if ÝÑx P A3 r pA1 YA2q...
......
fipÝÑx q if ÝÑx P Ai r pA1 YA2 Y . . .YAi´1q...
......
fn`1pÝÑx q if ÝÑx R pA1 Y . . .YAnq
is also Prim. Rec.
Proof of Proposition 80: g “ f1 ¨ χA1 ` f2 ¨ χpA2rA1q ` . . .` fn`1 ¨ χ`A1YA2Y...YAn
˘A . % 80
Corollary 81 sup(x1, . . . , xn) and inf(x1, . . . , xn) are Prim. Rec.
Proof of Corollary 81: Left as an exercise.
% 81
Proposition 82 f P NpNpq is Prim. Rec, then g, h P NpNp`1q below are Prim. Rec:
g “
t“yÿ
t“0
fpx1, . . . , xp, tq,
h “
t“yź
t“0
fpx1, . . . , xp, tq.
Proof of Corollary 82: Left as an exercise(both are easily defined by induction).
% 82
3.3 Bounded Minimisation and Bounded Quantification
Proposition 83 (Bounded minimisation) If A Ď Np`1 is Prim. Rec, then f P NpNp`1q
defined below is also Prim. Rec:
fpÝÑx , zq “
"
0 if @t ď z pÝÑx , tq R A,
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 Godel & Recursivity
Proof of Proposition 83: f is defined by:$
’
’
’
’
’
’
’
’
’
’
&
’
’
’
’
’
’
’
’
’
’
%
fpÝÑx , 0q “ 0
fpÝÑx , z ` 1q “
$
’
’
’
’
’
’
’
’
&
’
’
’
’
’
’
’
’
%
fpÝÑx , zq ify“zř
y“0χApÝÑx , yq ě 1
z ` 1 ify“zř
y“0χApÝÑx , yq “ 0 and pÝÑx , z ` 1q P A
0 ify“z`1ř
y“0χApÝÑx , yq “ 0.
% 83
Proposition 84 (Prim. Rec closed under bounded quantification) The set of all Prim. Recpredicates is closed under bounded quantification: i.e. If A Ď Np`1 is Prim. Rec, then
˝ tpÝÑx , zq : Dt ď z pÝÑx , tq P Au ˝ tpÝÑx , zq : @t ď z pÝÑx , tq P Au
are both Prim. Rec.
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
˝ χBpÝÑx , zq “ 1 9 p1 9
t“zř
t“0χApÝÑx , tqq, ˝ χCpÝÑx , zq “
t“zś
t“0χApÝÑx , tqq.
% 84
Example 85
˝ t2n : n P Nu is Prim. Rec It is defined by recursion
"
χp0q “ 0
χpn`1q “ 1 9 χpnq
˝ The mapping P NpN2q px, yq ÝÑ
„
x
y
defined below is Prim. Rec:
$
’
&
’
%
„
x
y
“ 0 if y “ 0
“ integer part ofx
yotherwise.
Recursivity 55
Formally$
&
%
„
x
y
“ 0 if y “ 0
“ µt ď x y ¨ pt` 1q ą x otherwise.
˝
px, yq | y divides x(
P Prim. Rec:
χpx, yq “ 1 9
˜
x 9
ˆ
y ¨
„
x
y
˙
¸
.
˝ Prime “ tx P N | x is a prime numberu P Prim. Rec:
x P Prime ðñ
$
’
’
’
’
’
’
’
’
’
’
’
’
’
&
’
’
’
’
’
’
’
’
’
’
’
’
’
%
x ą 1
and
@y ď x
$
’
’
’
’
&
’
’
’
’
%
y “ 1
or
y “ x
or
y does not divide x.
˝ Π : N ÝÑ N defined by Π pnq “ n` 1th prime number P Prim. Rec."
Π p0q “ 2
Π pn` 1q “ µz ď pΠ pnq!` 1q z ą Π pnq and z P Prime.
3.4 Coding Sequences of Integers
We define Prim. Rec functions that allow to treat finite sequences of integers as integers.
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 Prim. Rec functions βpi that verify
βpi
´
αppx1, . . . , xpq¯
“ xi.
Proposition 86 For every non zero p P N there exists Prim. Rec functions β1p , β
2p , . . . , β
pp P NN
56 EPFL Godel & Recursivity
and αp P NpNpq such that
$
’
’
’
’
’
&
’
’
’
’
’
%
αp : Np 1´1 and ontoÐÝÝÝÝÝÝÝÝÑ N
and
α´1p pxq “
`
β1ppxq, . . . , β
pppxq
˘
.
Proof of Proposition 86: We start by defining α1 “ β11 “ id. Then we move on to
α2px, yq “px` yq ¨ px` y ` 1q
2` y.
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
“ 12
˜ 1
`
x` y
`
2
`
x` y ´ 1
` ¨ ¨ ¨ `
x` y
`
1
¸
.
0,4
0,3
0,2
0,0
0,1
1,3
1,2
1,0
1,1
3,2
3,0
3,1
2,3
2,2
2,0
2,1
4,0
4,1
5,0
0 1
2
5
9
14
4
8
13
3
7
12
18
6
11
17
10
16
15
19
We have
(1) β12pnq “ µx ď n Dt ď n α2px, tq “ n
(2) β22pnq “ µy ď n Dt ď n α2pt, yq “ n.
Recursivity 57
Then we define αp`1, β1p`1, β
2p`1, . . . . . . , β
p´1p`1 , β
pp`1 and βp`1
p`1 by induction on p P N:
˝ αp`1px1, . . . , xp, xp`1q “ αp`
x1, . . . , xp´1, α2pxp, xp`1q˘
˝ β1p`1 “ β1
p ;
˝ β2p`1 “ β2
p ;
...
˝ βp´1p`1 “ βp´1
p ;
˝ βpp`1 “ β12 ˝ β
pp ;
˝ βp`1p`1 “ β2
2 ˝ βpp .
% 86
Example 87 A different way of coding sequences of integers:
"
cpεq “ 1
cpx0, . . . , xpq “ Π p0qx0`1¨Π p1qx1`1
¨ ¨ ¨Π ppqxp`1.
From n P Nrt0u we recover the sequence xx0, . . . , xpy such that cpx0, . . . , xpq “ n by considering
the Prim. Rec function d P NpN2q which yields the exponents of the prime numbers:
dpi, nq “ µx ď n Π piqx`1 does not divide n.
3.5 Partial Recursive Functions
We recall that
(1) pdomf , fq is a partial function Np ÝÑ N if f is a mapping domf ÝÑ N where domf Ď Np.
(2) pdomf , fq is a total function Np ÝÑ N if domf “ Np holds.
We say that f is undefined on x – or fpxq is undefined – if x R domf .
We use the notation f P NpdomĎNpq to signify that pdomf , fq is a partial function Np ÝÑ Nwhose domain is domf .
Notice that for any two partial functions f, g P NpdomĎNpq:
f “ g holds ðñ
$
&
%
domf “ domg
and
@x fpxq “ gpxq.
58 EPFL Godel & Recursivity
Definition 88 (composition) Given f1, . . . , fn P NpdomĎNpq and g P NpdomĎNnq, the composi-
tion h “ gpf1, . . . , fnq P NpNpq is defined by
$
’
’
’
’
’
’
’
’
’
’
&
’
’
’
’
’
’
’
’
’
’
%
hpÝÑx q is undefined iff
$
’
’
’
’
’
’
&
’
’
’
’
’
’
%
ÝÑx Rč
1ďiďp
domfi
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˘
Definition 89 (recursion) Given g P NpdomĎNpq and h P NpdomĎNp`2q, there exists a unique
f P NpdomĎNp`1q such that for all ÝÑx P Np 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)$
’
’
’
’
’
’
’
’
’
’
&
’
’
’
’
’
’
’
’
’
’
%
fpÝÑx , y ` 1q is undefined if
$
’
’
’
’
&
’
’
’
’
%
pÝÑx , yq R domf
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˘
.
Definition 90 (minimization) Given f P NpdomĎNp`1q, we define g P NpdomĎNpq by:
gpÝÑx q “ µy fpÝÑx , yq “ 0.
Notice that
gpÝÑx q “ y ðñ
$
’
’
’
’
’
’
’
’
’
&
’
’
’
’
’
’
’
’
’
%
@z ă y
$
’
’
&
’
’
%
fpÝÑx , zq is defined!
and
fpÝÑx , zq ą 0
and
fpÝÑx , yq “ 0.
Recursivity 59
Definition 91 (partial recursive functions) The set of partial recursive (PR) functions is
the least that
(1) contains:
(a) All constants Np ÝÑ N (all i P NpNpq s.t. ipÝÑx q “ i – any i, p P N).
(b) All projections πpi (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 PR if and only if it is Turing computable. One
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.
Proof of Lemma 92: We need to show that given any p P N r t0u and any f P NpdomĎNpq there
exists some Turing machine M that computes f . This means that on input pn1, . . . , npq it stops
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
that are necessary to obtain f P NpdomĎNpq on the basis of
˝ all constants ˝ all projections ˝ the successor function.
(1) It is quite obvious that
˝ if f P NpdomĎNpq is constant, then there exists some basic TM that computes it.
˝ Every projection πpi (any 1 ď i ď p) is also trivially computable.
60 EPFL Godel & Recursivity
˝ The successor function is clearly computable as well.
(2) (a) Assume f1, . . . , fn P NpdomĎNpq are computed respectively by Mf1 , . . . ,Mfn and g P
NpdomĎNnq is computed by Mg. Then f “ gpf1, . . . , fnq P NpNpq is computed by Mf
which works as follows:
on input ÝÑx “ pn1, . . . , npq:
successively for each i :“ 1, . . . ,n Mf simulates Mfi on input ÝÑx , if Mfi stops
with some output mi it stores mi.
(In case all simulation of machines Mf1 , . . . ,Mfn do stop) Mf finally simulates Mg
on input pm1, . . . ,mnq.
It is clear that if either
(A) ÝÑx Rč
1ďiďn
domfi or (B)´
f1pÝÑx q, . . . , fnpÝÑx q
¯
R domg,
then Mf never stops.
In the opposite case, Mf stops with the right answer.
(b) Assume g P NpdomĎNpq and h P NpdomĎNp`2q are computed respectively by Mg and
Mh. Then f defined by recursion:
(A) fpÝÑx , 0q “ gpÝÑx q
(B) fpÝÑx , y ` 1q “ h`
ÝÑx , y, fpÝÑx , yq˘
is computed by Mf which works as follows:
˝ on input pÝÑx , 0q it simply simulates Mg on input ÝÑx , and
˝ on input pÝÑx , n` 1qMf first simulates Mg on input ÝÑx which gives – in case the
machine stops! – fpÝÑx , 0q. Then
recursively for i :“ 0, . . . ,n Mf simulates Mh on`
ÝÑx , i, fpÝÑx , iq˘
which yields
– in case the machine stops! – fpÝÑx , i` 1q.
It is clear that Mf brings the result if and only if every step fpÝÑx , iq (i :“ 0, . . . , n`1)
is defined. Otherwise it simply never stops.
(c) Assume g P NpdomĎNp`1q is computed by Mg. We design Mf that on input ÝÑx
computes
µy gpÝÑx , yq “ 0.
set i :“ 0 Mf simulates Mg on input pÝÑx , iq. If Mg stops and outputs the value of
gpÝÑx , iq,
˝ if gpÝÑx , iq “ 0 Mf stops and outputs i,
˝ if gpÝÑx , iq ‰ 0, Mf starts over again with i :“ i` 1.
Notice that Mf stops and outputs n “ µy gpÝÑx , yq “ 0 if and only if
˝ @i ď n pÝÑx , iq P domg,
Recursivity 61
˝ @i ă n gpÝÑx , iq ą 0 and
˝ gpÝÑx , nq “ 0.
% 92
62 EPFL Godel & 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 mathematique, tome 1 : Calcul
propositionnel; algebre de Boole; calcul des predicats, vol. 1. Dunod, Paris, 2003.
[5] Cori, R., Lascar, D., and Krivine, J.-L. P. Logique mathematique, tome 2 : Fonctions
recursives, theoreme de Godel, theorie des ensembles, theorie des modeles, 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. Einfuhrung in 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. Godel’s Theorem: 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 satze der principia mathematica und verwandter
systeme i. Monatshefte fur Mathematik 38, 1 (1931), 173–198.
64 EPFL Godel & 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 theoreme de Godel.
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 Godel’s theorems. Cambridge University Press, 2013.
[33] Smullyan, R. M. Godel’s incompleteness 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 Godel: A Source Book in Mathematical Logic, 1879-
1931. Harvard University Press, 1977.