ages

Countability, enumerating programs, and the limits of logic

One of the simplest observations in both logic and computability theory turns out to have surprisingly strong consequences: any formal language or programming language uses a finite alphabet, and every formula or program is a finite string over that alphabet.

That immediately means there are only countably many formulas and countably many programs. By contrast, the set of all subsets of the natural numbers N\mathcal{N} has cardinality 2N2^{\mathcal{N}}, which is uncountable. From this cardinality mismatch alone, we already know that most decision problems cannot be solved by any program, and most number-sets cannot be expressed by any formula in a logical system.

Trivial incompleteness from counting alone

In a formal system Σ\Sigma over a finite alphabet, the set of all expressions E\mathcal{E} is countable. Every number-set A⊆NA \subseteq \mathcal{N} that we might want to express or represent needs a predicate H∈HH \in \mathcal{H} assigned to it.

Because H\mathcal{H} is countable while 2N2^{\mathcal{N}} is uncountable, there is no surjection from predicates to number-sets. It immediately follows that some number-sets are neither expressible nor representable in Σ\Sigma.

The exact same counting argument holds for decision problems. Each decision problem corresponds to a subset of N\mathcal{N} (its characteristic function f:N→{0,1}f : \mathcal{N} \to \{0, 1\}), so there are uncountably many decision problems, yet only countably many Turing machines or programs. Most decision problems therefore have no algorithm at all.

Enumerating programs and the universal machine

Counting tells us that uncomputable problems exist, without pointing to a concrete one. To construct a specific undecidable problem, we actually use the fact that programs are countable and list them in an enumeration:

Φ0,Φ1,Φ2,…\Phi_0, \Phi_1, \Phi_2, \dots

Here Φx\Phi_x denotes the xx-th computable partial function. A key property of an admissible enumeration is given by the Enumeration Theorem: the enumeration itself contains a universal function Φz\Phi_z (which abstracts the concept of a universal Turing machine) such that for all x,y∈Nx, y \in \mathcal{N}:

Φz(x,y)={Φx(y)if Φx(y)↓↑if Φx(y)↑\Phi_z(x, y) = \begin{cases} \Phi_x(y) & \text{if } \Phi_x(y) \downarrow \\ \uparrow & \text{if } \Phi_x(y) \uparrow \end{cases}

In code terms, universal(x, y) enumerates programs until it finds the xx-th program Φx\Phi_x and then simulates it on input yy.

Diagonalizing over the enumeration: the Halting Problem

Once all computable functions sit in a countable list Φ0,Φ1,…\Phi_0, \Phi_1, \dots, we can apply Cantor’s diagonal argument directly to that list. Consider the function:

g(x)={1if Φx(x)↓0if Φx(x)↑g(x) = \begin{cases} 1 & \text{if } \Phi_x(x) \downarrow \\ 0 & \text{if } \Phi_x(x) \uparrow \end{cases}

Suppose for contradiction that gg is computable. Then the following partial function Ψ\Psi is also computable:

Ψ(x)={1if g(x)=0↑if g(x)=1\Psi(x) = \begin{cases} 1 & \text{if } g(x) = 0 \\ \uparrow & \text{if } g(x) = 1 \end{cases}

Because Ψ\Psi is computable, it must appear somewhere in our countable enumeration, meaning there is some index x0x_0 with Φx0≃Ψ\Phi_{x_0} \simeq \Psi. Now evaluate Φx0\Phi_{x_0} on its own index x0x_0:

  • Φx0(x0)=1  ⟺  g(x0)=0  ⟺  Φx0(x0)↑\Phi_{x_0}(x_0) = 1 \iff g(x_0) = 0 \iff \Phi_{x_0}(x_0) \uparrow
  • Φx0(x0)↑  ⟺  g(x0)=1  ⟺  Φx0(x0)↓\Phi_{x_0}(x_0) \uparrow \iff g(x_0) = 1 \iff \Phi_{x_0}(x_0) \downarrow

Both cases contradict themselves. Since the only assumption we made was that gg is computable, gg is not computable, and it immediately follows that the general Halting Problem Halt(x,y)\text{Halt}(x, y) is undecidable.

Recursive vs. recursively enumerable sets

Even when a set of natural numbers A⊆NA \subseteq \mathcal{N} cannot be decided outright, we can sometimes still enumerate its elements with a program. This splits problems into two distinct classes:

  1. Recursive (decidable). There exists a total computable characteristic function ff such that f(x)=1f(x) = 1 if x∈Ax \in A and f(x)=0f(x) = 0 otherwise.
  2. Recursively enumerable (r.e.). Either A=∅A = \emptyset or there exists a total computable function gg whose range is AA, i.e. A=R(g)={z∣∃x.  g(x)=z}A = R(g) = \{ z \mid \exists x.\; g(x) = z \}.

An equivalent characterization of r.e. sets is semi-decidability: there exists a computable partial function hh such that A=D(h)={x∣h(x)↓}A = D(h) = \{ x \mid h(x) \downarrow \} (returning 1 if x∈Ax \in A and diverging otherwise).

To see why r.e. and semi-decidable are the same:

  • If A=R(g)A = R(g) is r.e., we build h(x)h(x) by testing g(0)=xg(0) = x, g(1)=xg(1) = x, and so on until a match is found. If x∉Ax \notin A, h(x)h(x) simply diverges.
  • Conversely, if A=D(h)A = D(h) is non-empty (pick some k∈Ak \in A), we cannot just run h(0),h(1),…h(0), h(1), \dots sequentially because a single diverging input would block everything after it. Instead we use dovetailing, defining g(y)g(y) via a pairing function π(x,n)\pi(x, n) that returns xx if h(x)h(x) halts within nn steps and kk otherwise.1

This leads directly to Post’s Theorem:

If both II and its complement Iˉ\bar{I} are recursively enumerable, then II is recursive.

The proof is completely constructive. Let I=R(g)I = R(g) and Iˉ=R(g′)\bar{I} = R(g'). To decide whether x∈Ix \in I, we interleave the two enumerations: check g(0)=xg(0) = x, then g′(0)=xg'(0) = x, then g(1)=xg(1) = x, then g′(1)=xg'(1) = x, and so on. Because R(g)∩R(g′)=∅R(g) \cap R(g') = \emptyset and R(g)∪R(g′)=NR(g) \cup R(g') = \mathcal{N}, xx is guaranteed to appear in one of the two lists in finite time, making the resulting characteristic function total and computable.

As an immediate consequence, if a set AA is r.e. but not recursive (such as the Halting set), then its complement Aˉ\bar{A} cannot even be r.e.

How this mirrors logic

The exact same split between countable syntax and what can be enumerated appears in first-order logic:

  • Proofs are enumerable. Because derivations in first-order sequent calculus (LK) are finite trees over a finite alphabet, we can enumerate all valid proofs. That makes the set of valid first-order formulas recursively enumerable (semi-decidable). By Church’s theorem it is not recursive, so by Post’s Theorem the set of invalid first-order formulas is not even r.e.
  • Countable syntax cannot pin down uncountable semantics. Even though a first-order theory Γ\Gamma has only countably many sentences, the upward Löwenheim-Skolem Theorem shows that if Γ\Gamma has an infinite model, it automatically has uncountably infinite models as well.2

In both logic and computability theory, the same structural constraint keeps resurfacing: our descriptions (formulas, proofs, programs) live in a countable syntactic world, while the semantic objects we try to capture (models, subsets of N\mathcal{N}, program behaviors) are vastly larger.