Gödel Numbering

What this page does

This page demonstrates a classic Gödel numbering: each symbol in a logical formula is mapped to an integer code, shifted by +1 to ensure positivity, and used as the exponent of successive primes 2, 3, 5, 7, …. The product is the Gödel number ⟦ϕ⟧. Thanks to unique prime factorization, we can recover the exact formula from the number by reading those exponents back.

How to use: Type a formula, click Compute ⟦ϕ⟧ to see its number, or Decode ⟦ϕ⟧ to reconstruct a formula from a number. The “Prime Exponent Decomposition” table shows the factorization of the last computed number.

Prompt & Question

Teach the program a Gödel encoding scheme and answer:
Question. Compute the Gödel number ⟦ϕ⟧ for a given formula ϕ under the specified coding; also provide a “Reason Why” and run multiple “Check (harness)” tests.
Inputs. Data (alphabet & codes), Logic (encoding rules), and the formula ϕ.

Data (Alphabet & Codes)

Reserved logic symbols have small codes; any other character uses a generic rule so everything remains encodable.

Reserved symbols

SymbolCode c(·)

Generic rule

For any character χ not listed at left, use:

c(χ) = 1000 + codePoint(χ)

This guarantees a total, injective code over all Unicode symbols we might type.

Encoding function

E(χ) = c(χ) + 1

Adding 1 ensures exponents are ≥ 1 (we never use zero exponents).

Logic (Gödel Numbering)

Let p₁, p₂, … be the increasing sequence of primes.

Tokenize ϕ into σ₁…σₙ (normalize ASCII: !→¬, &→∧, |→∨, ->→→, <->→↔; ignore spaces).

Define the Gödel number: ⟦σ₁…σₙ⟧ = ∏i=1..n pᵢ ^ E(σᵢ).

Decoding: factor the number; the exponents are E(σᵢ)=c(σᵢ)+1. Subtract 1 and invert c.

Program

Encode a formula

ASCII synonyms allowed: ! → ¬, & → ∧, | → ∨, -> → →, <-> → ↔. Spaces are ignored.

Answer

Result will appear here…

Reason Why (mathematical English)

Let ϕ have token sequence σ₁…σₙ. Define ⟦ϕ⟧ := ∏i=1..n pᵢE(σᵢ), where E(σ)=c(σ)+1 and c(·) is injective. By the Fundamental Theorem of Arithmetic, every natural number has a unique prime factorization. Hence the exponent vector (E(σ₁), …, E(σₙ)) is uniquely determined by ⟦ϕ⟧. Subtracting 1 yields (c(σ₁), …, c(σₙ)), and because c is injective we recover the exact σ₁…σₙ. Therefore ϕ ↦ ⟦ϕ⟧ is injective and decoding is well-defined.

Compositionality. If τ is appended to ϕ, then ⟦ϕ·τ⟧ = ⟦ϕ⟧ · pn+1E(τ). This follows from multiplying by the next prime raised to the new symbol’s exponent.

Worked Example (reading the table)

After you click Compute ⟦ϕ⟧, the table below lists, for each position i, the i-th prime pᵢ, the corresponding exponent eᵢ, the recovered symbol, and its base code c(·) = eᵢ−1. Reading the symbols in order reconstructs the formula. If you change one symbol, only one exponent changes, so the product changes in exactly one prime component.

Prime Exponent Decomposition

From the last computed Gödel number; exponents eᵢ satisfy eᵢ = E(σᵢ) = c(σᵢ)+1.
#Prime pᵢExponent eᵢRecovered symbolc(·)

Check (harness) 1

Check (harness) 2

Check (harness) 3

Check (harness) 4

Check (harness) 5

Check (harness) 6

Check (harness) 7

Check (harness) 8