Interactive learning companion

Executable Gödel Encodings

A structural guide to the paper Executable Gödel Encodings: A Verified Runtime for Logical Syntax. This version is designed to help you learn the architecture of the mathematics: what each construction does, what depends on what, and why the runtime interpretation emerges.

The central idea

Syntax becomes executable numerical data

The paper starts with ordinary inductive syntax—terms and formulas—then gives those objects numerical representations. Once encoded, transformations of syntax can be simulated by arithmetic operations on codes, while Lean verifies the correspondence.

Terms & formulas
Gödel codes
Verified transformations
Executable logic runtime
Question to keep in mind

Where does the “runtime” enter?

Not merely when a number represents a formula. The runtime interpretation appears when encoded syntax can be decoded, transformed, re-encoded, and verified as part of an executable procedure.

Learning objective

See the dependency structure

Diagonalization depends on substitution. Arithmetic substitution depends on encoding and decoding. Encoding depends on inductively defined syntax. The paper is therefore a layered construction, not a collection of independent results.

Paper roadmap
Formal syntax. Define finite syntax trees for terms and formulas.
Gödel encoding. Map those trees injectively into natural numbers and decode valid codes.
Substitution. Define structural transformations recursively on syntax.
Arithmetic simulation. Perform the same transformation at the code level by decode → transform → re-encode.
Diagonalization. Use encoded substitution to construct self-reference.
Runtime interpretation. Reinterpret the machinery as a verified execution layer for rule engines, DSLs, and compilers.
Definition 2.1

Terms

Term ::= var(n) | zero | succ(t) | add(t₁,t₂)

Because this is inductive, every term is a finite syntax tree. Structural recursion is therefore available automatically as the natural way to define transformations.

Definition 2.2

Formulas

Formula ::= t₁ = t₂ | ¬φ | φ₁ ∧ φ₂ | ∀xₙ φ

Formulas are built from terms and logical constructors. The same tree structure later makes recursive substitution possible.

Why this matters

The syntax tree is the first computational object

Before Gödel numbers appear, the syntax is already executable data. Lean's inductive definitions give a finite object that programs can traverse. Gödel encoding then supplies a second representation of that same structure.

Encoding

Term → Nat

godel : Term → Nat

def godel : Term → Nat :=
Encodable.encode

The code is determined by syntactic structure.

Decoding

Nat → Option Term

decodeTerm : Nat → Option Term

def decodeTerm : Nat → Option Term :=
Encodable.decode

Decoding is partial because an arbitrary natural number need not be a valid code.

The key invariant

Round-trip correctness

decodeTerm (godel t) = some t

This is stronger than saying “we assigned numbers.” It establishes a machine-checked correspondence between the structural object and its code.

Worked example from the paper

Structural substitution

Original term
add(var(0), zero)
Replacement
succ(zero)
Theorem 4.3

Basic substitution law

substTerm(x, s, var(x)) = s
Structural recursion

Why recursion appears naturally

The definition follows the constructors of the term. A variable is inspected directly; successor recurses into one child; addition recurses into both children.

Definition 5.1

Code-level substitution

The paper's central computational move is to perform syntactic substitution through numerical representations.

encoded term + encoded formula
decode
structural substitution
re-encode
Correctness

Theorem 5.2

codeSubst(x, godel(s), godelF(φ))
= godelF(substFormula(x,s,φ))
Interpretation

Two representations, one transformation

The left side performs the operation through codes. The right side performs it structurally and then encodes. Their equality is the verified bridge between arithmetic and syntax.

Self-reference

Why diagonalization needs everything before it

A formula can only be made to refer to its own code after syntax can be encoded and substitution can be represented arithmetically.

formula φ(x)
Gödel code
encoded substitution
self-reference
Diagonal lemma

Theorem 6.1

∃ ψ, ψ ↔ φ(⌜ψ⌝)

For every formula with one free variable, a sentence exists that says of itself what φ says of its code.

Gödel sentence

Choose φ(x) := ¬Prov(x)

G ↔ ¬Prov(⌜G⌝)

This produces the familiar self-referential sentence: G says that G is not provable.

Important distinction: the computational contribution of the paper is not merely the classical statement of diagonalization. It is the executable infrastructure—encoded syntax plus verified substitution—that makes the construction algorithmic inside Lean.
Clickable dependency map

Main results

Click each theorem to see what it depends on and what it enables.

Theorem 3.1 — Injectivity of Gödel encoding
depends on inductive syntax + Lean's canonical Encodable instance.
enables distinct syntax has distinct numerical representation.
Theorem 3.2 — Round-trip correctness
depends on encoding + decoding.
enables verified recovery of syntax from its valid code.
Theorem 4.3 — Basic substitution property
depends on recursive definition of substitution.
enables confidence that the structural operation has the intended variable-replacement behavior.
Theorem 5.2 — Correctness of arithmetic substitution
depends on round-trip correctness + structural substitution + formula encoding.
enables arithmetic operations on codes to simulate syntactic transformation.
Theorem 6.1 — Diagonal Lemma
depends on arithmetic representation of substitution.
enables construction of self-referential sentences.
Theorem 8.1 — Gödel incompleteness result as stated in the paper
depends on provability predicate + diagonal lemma + assumptions on the formal system.
enables the paper's transition from executable self-reference to the classical incompleteness discussion.
Definition 11.1

Gödel runtime representation

The paper abstracts the construction into three ingredients:

1. encoding
2. decoding
3. verified code operations

The third ingredient is decisive: operations on codes must simulate structural transformations on the original expressions.

Compiler view

Syntax as executable data

Substitution, rewriting, normalization, and related compiler transformations can be understood as operations over encoded logical structures, with Lean supplying correctness proofs.

Why this is more than Gödel numbering

Representation becomes infrastructure

The paper's software interpretation is that the encoding is a runtime layer connecting symbolic rules to verified executable transformations.

A question for further study

What is the invariant being preserved?

At each layer, the same syntactic meaning is represented differently: first as a tree, then as a number, then as a transformed number, and finally again as syntax. The correctness theorems certify that the numerical computation agrees with the intended structural computation. That viewpoint is a useful doorway into the later idea of semantic invariance.