Upload
vladimir-kulyukin
View
122
Download
0
Tags:
Embed Size (px)
Citation preview
Theory of Computation
Gödel Numbers
Vladimir Kulyukin
www.vkedco.blogspot.comwww.vkedco.blogspot.com
Outline
● Pairing Functions● Gödel Numbers● Gödel Coding & Decoding
Just a Thought on Why Natural Numbers are Natural
Every natural number in the universe is a program awaiting its computer. The program runs if and when its computer appears.
Theory of Program Compilation & Execution
● Programming languages are symbolic formalisms● If we can convert statements of symbolic formalisms into numbers (i.e., any
program P is associated with a unique number), we have the foundations of a mathematical theory of program compilation and program execution (interpretation)
● The gist of the theory is three-fold: ● Given a program P, there is a computable function C (Compiler) such that C(P) =
#(P); this is the compiler● Given #(P), there is a computable function RC (Reverse Compiler) such that
RC(#(P))= P; this function is the reverse compiler● Given a program P, there is a partially computable function VM that can execute
C(P); this is the operating system or the virtual machine
The Big Picture
GÖDEL Coder
GÖDEL Decoder
L Program Number Universal Program
Number
???
GÖDEL Coder = CompilerGÖDEL Decoder = Reverse CompilerUniversal Program = Operating System/VM/Interpreter
Pairing Functions
Pairing Functions
1221,
01122
1122,
yyx
y
yyx
x
x
x
Equation 8.1 (Ch. 3)
., tofor solution
unique a is therenumber, natural a a is If
zyxx, y
z
Equation 8.1 (Ch. 3)
2
12
1
2
112 .5
.1|2such that number largest theis s,other wordIn
.1z| 2max .4
).12(21z .3
).12(21, .2
, .1
x
x
x
d
d
x
x
z
yz
y
zx
x
y
yyx
zyx
Equation 8.1 (Ch. 3): Upper Bound for x & y
., Hence,
.1,1 Therefore,
.12211,
,1122, Since
zyzx
zyzx
yzyx
yzyxx
x
Example 1
.10111115225,0 :Check
.51112
011|2max
11122
10112210,
.10, Solve
0
yy
xx
y
yyx
yx
d
d
x
x
Example 2
.19120112222,2:Check
.251220122
220|2max
20122
191122,
.19, Solve
2
2
yyy
x
y
yyx
yx
d
d
x
x
Splitting Natural Numbers into
Left & Right Constituents
Equation 8.1 (Ch. 03)
.22,219;22,219
.55,010;05,010
:Examples
.,
.,
. , and :functions twodefines 8.1Equation
rrll
rrll
yyxrzr
xyxlzl
Nzzrzl
Lemma
recursive. primitive are and zrzl
Proof
. ,min)(
; ,min)(
Thus, .,,, then , If
yxzxzr
yxzyzl
zyzxyxzNz
zzy
zzx
Theorem 8.1 (Ch. 03)
zzrzzl
zzrzl
yyxrxyxl
zrzlx,y
, 4.
, 3.
,,, 2.
recursive primitive areThey 1.
:properties following thehave ,, functions The
Gödel Numbers
Background
● Kurt Gödel used of logic and set theory to formulate and understand the foundations of mathematics
● Gödel developed a technique to convert formal symbolic statements into natural numbers
● The technique was later called Gödel numbering
Kurt Gödel, 1906 - 1978
Gödel Numbers
n
ii
ain
n
ippaa
aa
i
1
th1
1
prime. theis where,,...,
as defined is sequence thisof number)-(Gnumber
Gödel The numbers. of sequence a be ,...,Let
Example
.5321,3,2
is sequence thisofnumber -G The
.2,3,1 sequence following thehave weSuppose
23123
32
11 ppp
Lemma
recursive. primitive is ,..., ,each For 1 naan
Proof
3. Ch. 6.2,Corollary
by recursive, primitive isfunction recursive primitive a of
product bounded thebecause recursive, primitive is
recursive. primitive is so recursive primitive is
recursive. primitive is
1
n
i
ai
ai
y
i
i
i
p
px
p
Note 1 on Theorem 8.2 (Ch. 3)
....11......
,..., because,0,0,,...,,...,
example,For number.-G its changing without sequence the
ofright the toszero' ofnumber any addcan wegeneral,In
02
01111
111
111
nnan
aan
aan
a
nnn
pppppppp
aaaaaannn
Note 2 on Theorem 8.2 (Ch. 3)
...75325323221
because 1, be to
defined is () sequenceempty theofnumber -G The
0000000000
Note 2 on Theorem 8.2 (Ch. 3)
.755322,1,018322,1
because,2,1,02,1
example,For
.......
because ,,...,,0,...,
general,In number.-G its changingwithout
sequence theofleft the toszero' addcannot We
21021
12011
11
11
nn a
naa
na
nn
ppppp
aaaa
Accessing Individual Elements of
Gödel Numbers
Motivation● We can map every natural number n into its Gödel number g ● Every n has a unique prime factorization, thus its g can be
construed as a sequence of powers of the prime factors of n● We can think of n as an array of numbers and, as with arrays
in other programming languages, we need access to their individual elements
● In our context, we would like to access those individual prime powers
Example
101
20
3
1000
11
100
2
10
1`
532]1,0,1[10
32]2,0[9
.238
7532[0,0,0,1]7
32[1,1]6
532[0,0,1]5
2[2]4
32[0,1] 3
2[1]2
Access Function for Gödel Numbers
.3;4;2
then,3,4,2 if example,For .1 ,function
recursive primitive a define want to We.,...,Let
321
1
xxx
xniax
aax
ii
n
Access Function for Gödel Numbers
. allfor ,00; allfor ,0 that Note
|min
0
1
ixx
xpx
i
ti
xti
Example 01
.2 so ,18|3 but 18;|3 ;18|3 ;18|3
and ;3 because ,218| min18
.1 so,18|2 but ;18|2 ;18|2
and 2; because ,118| min18
Then .322,118Let
3210
21
218
2
210
11
118
1
2122
11
t
pp
t
pp
pp
tttt
t
t
ttt
t
t
Example 02
3108
2108
Then .274323,2108Let
2
1
3222
11
pp
Access Function for G-Numbers: Implementation
// x is a natural number, compute (x)i
long GAccess(long x, long i) {
long p = computePrime(i); // compute i-th prime pi
for t from 0 upto x {
if ( pt does not divide x )
return t – 1;
}
}
Access Function for G-Numbers: Implementation
● The previous slide assumes that we represent G-Numbers as integers● This is a sensible choice, but only for small numbers● If we want to be generic, we can represent G-numbers as sequences of prime
powers, e.g. arrays, lists, etc. ● In this case, we can represent much larger values without actually having to
compute them● Access function becomes much easier, because we do not have to compute
primes or their powers
Lengths of Natural Numbers
Length of a Natural Number
● Since Gödel numbering and access functions give us techniques to split any natural number into its constituents
● Next question: how many constituents does a given natural number have if looked at as a G-number? In other words, how long is the number?
● How long is 20? How long is 7?
Length of a Natural Number: Definition
.010 ,definitionBy
number.-G ain power prime
zero-nonlast theofindex theis s,other wordIn
.0&0min
LtLt
i
xijjxxLt jxixi
How Long is Natural Number 20?
.320
.0...
.1
.1,0,253220
.?20
2054
3
102
Lt
xxx
x
x
Lt
How Long is Natural Number 7?
.47
.0
.1
.1,0,0,075327
.?20
765
4
1000
Lt
xxx
x
x
Lt
Just In Case You Are Not Confused Yet
20 > 7? Sure, but 7 is longer!
Gödel Coding & Decoding
Gödel Coder & Decoder● We will demonstrate that compilation (coding) and reverse
compilation (decoding) are both primitive recursive ● In other words:
Given an L program P, there is a primitive recursive function that maps P to its number #(P)
Given #(P), there is a primitive recursive function that maps #(P) to its source code P
Gödel Coder
● We need to solve three problems:● Problem 1: Mapping variables and labels to numbers● Problem 2: Mapping instructions to numbers● Problem 3: Mapping programs to numbers
Problem 1: Mapping Variables & Labels● We order the variables as follows: Y, X1, Z1, X2, Z2, X3, Z3, … ● We order the labels as follows: A1, B1, C1, D1, E1, A2, B2, C2,
D2, E2, A3, …● Let #(V) be the position of a variable in the variable ordering ● Let #(L) be the position of a label in the label ordering ● Note that the chosen orderings are arbitrary in the sense that
other orderings are possible
Examples of #(V) & #(L)
● We order the variables as follows: Y, X1, Z1, X2, Z2, X3, Z3, …
● We order the labels as follows: A1, B1, C1, D1, E1, A2, B2, C2, D2, E2, A3, …
● #(Y)=1, #(X1)=2, #(X3)=6, #(Z2)=5● #(B1)=2, #(A2)=6, #(C2)=8
Problem 2: Mapping Instructions to Numbers● There are four primitive instruction types in L: addition, subtraction,
self-assignment (no-op), conditional dispatch● There are three pieces of information we have to known in order to
map an instruction to a number: label or no label variable used in the instruction instruction type
Sub-Task 2: Assigning Numbers to Instruction Types
2# n typeinstructio be willThis // 0
2 n typeinstructio be willThis // 1
1 n typeinstructio be willThis // 1
0 n typeinstructio be willThis //
L GOTO LIF V
-VV
VV
VV
Problem 2: Mapping Instructions to Numbers
ninstructio in the used variable theofnumber theis .3
number n typeinstructio theis 2.
number label theis 1.
where,,,#Then n.instructio primitive a be Let
c
b
a
cbaILI
Problem 2: Mapping Instructions to Numbers
.22
case in this that Note .2then ,0! is if 7.
;2 then ,1 is if 6.
;1 then ,1 is if 5.
;0 then , is if .4
;1 then ,in used is variablea if .3
; then , label some with labeled is if 2.
;0 then unlabeled, is if 1.
where,,,#Then n.instructio primitive a beLet
L#b
L#b GOTO LIF VI
b-VVI
bVVI
bVV I
V#cIV
L#aLI
aI
cbaILI
Instruction Coding Example 01
Let I be X1 ← X1 + 1. What is #(I)?
Instruction Coding Example 01
.101111113221
111112222
111,1221,1,0#
Thus, 4.
;21 because ,111 3.
addition; is because ,1 .2
unlabeled; is because ,0 .1
where,,,# so ;111 is
10
0
I
X#X#c
Ib
Ia
cbaIXXI
Instruction Coding Example 02
Let I be [A1] X1 ← X1+1. What is #(I)?
Instruction Coding Example 02
.211112111112222
111,1221,1,1
11#,1,1##
,111 1 is Since
111
1
XAI
XXAI
Problem 3: Definition of #(P)
.1#,...,#,##
thenns,instructio primitive are ,...,, and
0 where,,...,, of consists that program a be Let
21
21
21
k
k
k
IIIP
LIII
kIIIP
Example of #(P)
1 GOTO 0 1 IF
111 1
program? thisofnumber theisWhat
AX
XXA
Example of #(P)
1#,##
Thus,
1 GOTO 0 1 IF is
111 1 is
21
2
1
IIP
AXI
XXAI
Example of #(P)
21111,1221,1,1 So,
11211# .3
1 2.
11# .1
where
,,,111 1## example, previous aBy
1
1
Xc
b
Aa
cbaXXAI
Example of #(P)
.46147112321
111112222
111,3221,3,0# Thus,
.111# .3
;32121# .2
;0 .1
where,,,1 GOTO 0! 1 IF##
30
02
2
I
Xc
Ab
a
cbaAXI
Example of #(P)
.1321]46,21[#
1 GOTO 0 1 IF
111 1
? program thisofnumber theisWhat
4621
P
AX
XXA
P
Back to The Big Picture
GÖDEL Coder
GÖDEL Decoder
L Program Number Universal Program
Number
???
The red arrows show the implemented tasks (program compilation): we now know how to map L programs to numbers.
Gödel Decoder
Gödel Decoder
● Problem 1: Obtain the source code number● Problem 2: Extract from the source code number the
numbers for individual instructions● Problem 3: Extract the source from each individual
instruction number
GÖDEL Decoder: Problem 1
.1##,...,#,#
isnumber code source theThus,
.1#,...,#,##
21
21
PIII
IIIP
k
k
Side Note: A Prime Factorization Algorithm// n is a natural number > 0, i is the prime counter, initially// set to 1. We need this algorithm to solve problem 2 of // Gödel DecodingFactors(n, i)
If n is prime then n is the factorization;If n is composite thenIf pi divides n then
add pi to the list of factors;Factors((n / pi), i);
If pi does not divide n ThenFactors(n, i+1)
Prime Factorization Algorithm: Example
2] 2, [2,return
2] [2,return
[2]return so prime a is 2
1) factors(2, to2 add so
4|2
1) factors(4, to2 add so
8|2
1)factors(8,
1
1
p
p
GÖDEL Decoder: Problem 2
number-G the
i.e., powers, prime oflist obtain the factors, prime oflist theFrom .3
factors prime oflist obtain the to,1,1nfactorsRun 2.
#,...,#,#1 isnumber code source theSo,
1#,...,#,# be Let 1.
21
21
k
k
IIIn
IIIP#n
Examples of Source Code Extraction
lyrespective 1, and 1,0,0, into compile that nsinstructiofour of consists P .3
1475321] 0, 0, [1,number -G the toconverted is [2,7] 2.
[2,7] returns ,1)factors(14 then 13, into compiles P If .1
3number into compilesn that instructio one of consists code source sP' .5
82[3]number -G the toconverted is ]2,2,2[ 4.
2] 2, [2, returns 1)factors(8, 3.
8 is Pfor number code source The 2.
7number into compiled is P program some Suppose 1.
1001
3
GÖDEL Decoder: Problem 3
ordering. variablein the 1 isposition
whose variableis in used variable theThus, . 3.
ordering. label in the 2 isposition
whoselabel is L whereL GOTO 0 ! V IF typeof is 2.4.
;2 if 1 - V V typeof is 2.3.
;1 if 1 V V typeof is 2.2.
;0 if V V typeof is 2.1.
Then . 2.
ordering. label in the
number label has Otherwise, unlabeled. is ,0 If . 1.
.,,#Let
number.-G in then instructioeach of code
source eextract th toneed wenumber,-G thehave that weNow
c
Iqrrc
b-
I
b I
b I
b I
qrlb
ql
IIaqla
cbaqI
#(P) P: GÖDEL Decoding Algorithm
recursive primitive are steps all that Note
3 stepin obtained
number-G theofelement each from code source eExtract th 4.
powers prime of sequence the
get i.e. factors, prime oflist thefromnumber -G Obtain the .3
1,1nFactorsRun 2.
#,...,#,#1 isnumber code source theSo,
;1#,...,#,# be Let 1.
21
21
k
k
IIIn
IIIP#n
GÖDEL Decoding Algorithm: Example1. Let #(P) = 199.2. The source code number = 199+1=200.3. The prime factorization of 200 is 233052. Thus, the G-number = [3,0,2].4. 3 = <2, <0, 0>>. So the label is B1, the instruction variable is Y and the type of instruction is self-assignment. Thus, first instruction is [B1] Y ← Y.5. 0 = <0, <0, 0>>. Thus, second instruction is Y ← Y.6. 2 = <0, <1, 0>>. Thus, third instruction is Y ← Y + 1.
GÖDEL Decoding Algorithm: Example
Let #(P) = 199. The source code number = 199+1=200. So, the source code of P is
[B1] Y ← Y
Y ← Y
Y ← Y + 1
Back To The Big Picture
GÖDEL Coder
GÖDEL Decoder
L Program Number Universal Program
Number
???
GÖDEL Coder = CompilerGÖDEL Decoder = Reverse CompilerUniversal Program = Operating System/VM/Interpreter
Reading Suggestions
● Ch. 03, Computability, Complexity, and Languages, 2nd Edition, by Davis, Sigal, Weyuker, Academic Press
● http://en.wikipedia.org/wiki/Kurt_Gödel