G&oum;del Numbering: Encoding Logic as Numbers

The first step in Gödel’s incompleteness proof was finding a way of taking logical statements and encoding them numerically. Looking at this today, it seems sort-of obvious. I mean, I’m writing this stuff down in a text file – that text file is a stream of numbers, and it’s trivial to convert that stream of numbers into a single number. But when Gödel was doing it, it wasn’t so obvious. So he created a really clever mechanism for numerical encoding. The advantage of Gödel’s encoding is that it makes it much easier to express properties of the encoded statements numerically.

Before we can look at how Gödel encoded his logic into numbers, we need to look at the logic that he used. Gödel worked with the specific logic variant used by the Principia Mathematica. The Principia logic is minimal and a bit cryptic, but it was built for a specific purpose: to have a minimal syntax, and a complete but minimal set of axioms.

The whole idea of the Principia logic is to be purely syntactic. The logic is expected to have a valid model, but you shouldn’t need to know anything about the model to use the logic. Russell and Whitehead were deliberately building a pure logic where you didn’t need to know what anything meant to use it. I’d really like to use Gödel’s exact syntax – I think it’s an interestingly different way of writing logic – but I’m working from a translation, and the translator updated the syntax. I’m afraid that switching between the older Gödel syntax, and the more modern syntax from the translation would just lead to errors and confusion. So I’m going to stick with the translation’s modernization of the syntax.

The basic building blocks of the logic are variables. Already this is a bit different from what you’re probably used to in a logic. When we think of logic, we usually consider predicates to be a fundamental thing. In this logic, they’re not. A predicate is just a shorthand for a set, and a set is represented by a variable.

Variables are stratified. Again, it helps to remember where Russell and Whitehead were coming from when they were writing the Principia. One of their basic motivations was avoiding self-referential statements like Russell’s paradox. In order to prevent that, they thought that they could create a stratified logic, where on each level, you could only reason about objects from the level below. A first-order predicate would be a second-level object could only reason about first level objects. A second-order predicate would be a third-level object which could reason about second-level objects. No predicate could ever reason about itself or anything on its on level. This leveling property is a fundamental property built into their logic. The way the levels work is:

  • Type one variables, which range over simple atomic values, like specific single natural numbers. Type-1 variables are written as a1, b1.
  • Type two variables, which range over sets of atomic values, like sets of natural numbers. A predicate, like IsOdd, about specific natural numbers would be represented as a type-2 variable. Type-2 variables are written a2, b2, …
  • Type three variables range over sets of sets of atomic values. The mappings of a function could be represented as type-3 variables: in set theoretic terms, a function is set of ordered pairs. Ordered pairs, in turn, can be represented as sets of sets – for example, the ordered pair (1, 4) would be represented by the set { {1}, {1, 4} }. A function, in turn, would be represented by a type-4 variable – a set of ordered pairs, which is a set of sets of sets of values.

Using variables, we can form simple atomic expressions, which in Gödel’s terminology are called signs. As with variables, the signs are divided into stratified levels:

  • Type-1 signs are variables, and successor expressions. Successor expressions are just Peano numbers written with “succ”: 0, succ(0), succ(succ(0)), succ(a1), etc.
  • Signs of any type greater than 1 are just variables of that type/level.

Now we can assemble the basic signs into formulae. Gödel explained how to build formulae in a classic logicians form, which I think is hard to follow, so I’ve converted it into a grammar:

 elementary_formula → signn+1(signn)
 formula → ¬(elementary_formula)
 formula → (elementary_formula) or (elementary_formula)
 formula → ∀ signn (elementary_formula)

That’s all that’s really included in Gödel’s logic. It’s enough: everything else can be defined in terms of combinatinos of these. For example, you can define logical and in terms of negation and logical or: (a ∧ b) ⇔ ¬ (¬ a ∨ ¬ b).

Next, we need to define the axioms of the system. In terms of logic the way I think of it, these axioms include both “true” axioms, and the inference rules defining how the logic works. There are five families of axioms.



  • First, there’s the Peano axioms, which define the natural numbers.
    1. ¬(succ(x1) = 0): 0 is a natural number, and it’s not the successor of anything.
    2. succ(x1) = succ(y1) ⇒ x1 = y1: Successors are unique.
    3. (x2(0) ∧ ∀ x1 (x2(x1) ⇒ x2(succ(x1)))) ⇒ ∀ x1(x2(x1)): induction works on the natural numbers.
  • Next, we’ve got a set of basic inference rules about simple propositions. These are defined as axiom schemata, which can be instantiated for any set of formalae p, q, and r.
       <li> <em>p &or; p &rArr; p</em></li>
       <li> <em>p &rArr; p &or; q</em></li>
       <li> <em>p &or; q &rArr; q &or; p</em></li>
       <li> <em>(p &rArr; q) &rArr; (p &or; r) &rArr; (q &or; r)</em></li>
  • Axioms that define inference over quantification. v is a variable, a is any formula, b is any formula where v is not a free variable, and c is a sign of the same level as v, and which doesn’t have any free variables that would be bound if it were inserted as a replacement for v.
    1. ∀ v (a) ⇒ subst[v/c](a): if formula a is true for all values of v, then you can substitute any specific value c for v in a, and a must still be true.
    2. (∀ v (b ∨ a)) ⇒ (b ∨ ∀ v (a))
  • The Principia’s version of the set theory axiom of comprehension: &exists; u (∀ v ( u(v) ⇔ a )).
  • <li> And last but not least, an axiom defining set equivalence:       <em>&forall; x<sub>i</sub> (x<sub>i+1</sub>(x<sub>i</sub>) &hArr; y<sub>i+1</sub>(y<sub>i</sub>)) &rArr; x<sub>i+1</sub> = y<sub>i+1</sub></em>   </li>

    So, now, finally, we can get to the numbering. This is quite clever. We’re going to use the simplest encoding: for every possible string of symbols in the logic, we’re going to define a representation as a number. So in this representation, we are not going to get the property that every natural number is a valid formula: lots of natural numbers won’t be. They’ll be strings of nonsense symbols. (If we wanted to, we could make every number be a valid formula, by using a parse-tree based numbering, but it’s much easier to just let the numbers be strings of symbols, and then define a predicate over the numbers to identify the ones that are valid formulae.)

    We start off by assigning numbers to the constant symbols:

    Symbols Numeric Representation
    0 1
    succ 3
    ¬ 5
    ( 11
    ) 13

    Variables will be represented by powers of prime numbers, for prime numbers greater that 13. For a prime number p, p will represent a type one variable, p2 will represent a type two variable, p3 will represent a type-3 variable, etc.

    Using those symbol encodings, we can take a formula written as symbols x1x2x3…xn, and encode it numerically as the product 2x13x25x2…pnxn, where pn is the nth prime number.

    For example, suppose I wanted to encode the formula: ∀ x1 (y2(x1)) ∨ x2(x1).

    First, I’d need to encode each symbol:

    1. “∀” would be 9.
    2. “x1“” = 17
    3. “(” = 11
    4. “y2” = 192 = 361
    5. “(” = 11
    6. “x1” = 17
    7. “)” = 13
    8. “∨” = 7
    9. “x2” = 172 = 289
    10. “(” = 11
    11. “x1” = 17
    12. “)” = 13
    13. “)” = 13

    The formula would thus be turned into the sequence: [9, 17, 11, 361, 11, 17, 13, 7, 289, 11, 17, 13, 13]. That sequence would then get turned into a single number 29 317 511 7361 1111 1317 1713 197 23289 2911 3117 3713 4113, which according to Hugs is the number (warning: you need to scroll to see it. a lot!):


    Next, we’re going to look at how you can express interesting mathematical properties in terms of numbers. Gödel used a property called primitive recursion as an example, so we’ll walk through a definition of primitive recursion, and show how Gödel expressed primitive recursion numerically.

    4 thoughts on “G&oum;del Numbering: Encoding Logic as Numbers

    1. David Furcy

      Thanks a lot for this series of posts.

      In your grammar, the productions for formula should be recursive and a base case should be added:
      formula rightarrow elementary_formula

      I am looking forward to the next post in the series.

    2. Anonymous

      I think your grammar needs to be modified.

      Rather than formula → ¬(elementary_formula), I think you want formula → ¬(formula). Similarly change the third and fourth productions, and add a production rule formula → elementary_formula.

      Otherwise, you can’t say make a formula like ¬(¬(…)).

    3. Craig Pennington

      Very cool. I once computed a number that was an instance of Goedel’s theorem VI. Hilarity ensued. (seriosuly, if anyone cares, I’ll share. I used a positional versus a exponential numbering technique to keep the size manageable.)

    4. Pingback: Finally: Gödel’s Proof of Incompleteness! | Good Math, Bad Math

    Leave a Reply