## Gödel Numbering

### January 16, 2015

Gödel numbering is a system that assigns a natural number to each symbol and expression in a logical system, invented in 1931 by Kurt Gödel for the proofs of his incompleteness theorems. Consider the logical system where symbols are letters and expressions are words; for instance, the word PRAXIS consists of six symbols P, R, A, X, I, and S. Gödel numbering would assign numbers to the letters, say A=1 … Z=26, then assign each letter as the exponent of the next prime, so PRAXIS would be numbered 2^{16} × 3^{18} × 5^{1} × 7^{24} × 11^{9} × 13^{19} =

83838469305478699942290773046821079668485703984645720358854000640

The process is reversible; factor the Gödel number and decode the exponents.

Your task is to write functions that encode strings as Gödel numbers and decode Gödel numbers as strings. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Haskell:

Python:

Factor:

: >gödel ( str — n )

[ length nprimes ] keep [ 64 – ^ ] 2map product ;

: gödel> ( n — str )

group-factors values [ 64 + ] "" map-as ;

Implemented as a Python class that takes a sequence of symbols as a configuration parameter.

Example:

Also in Haskell, and similar to Francesco’s solution. This one uses the arithmoi package for the list of primes and the factorization function. I don’t shift the powers, so the resulting numbers are even larger.