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 has cardinality , 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 over a finite alphabet, the set of all expressions is countable. Every number-set that we might want to express or represent needs a predicate assigned to it.
Because is countable while is uncountable, there is no surjection from predicates to number-sets. It immediately follows that some number-sets are neither expressible nor representable in .
The exact same counting argument holds for decision problems. Each decision problem corresponds to a subset of (its characteristic function ), 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:
Here denotes the -th computable partial function. A key property of an admissible enumeration is given by the Enumeration Theorem: the enumeration itself contains a universal function (which abstracts the concept of a universal Turing machine) such that for all :
In code terms, universal(x, y) enumerates programs until it finds the -th program and then simulates it on input .
Diagonalizing over the enumeration: the Halting Problem
Once all computable functions sit in a countable list , we can apply Cantor’s diagonal argument directly to that list. Consider the function:
Suppose for contradiction that is computable. Then the following partial function is also computable:
Because is computable, it must appear somewhere in our countable enumeration, meaning there is some index with . Now evaluate on its own index :
Both cases contradict themselves. Since the only assumption we made was that is computable, is not computable, and it immediately follows that the general Halting Problem is undecidable.
Recursive vs. recursively enumerable sets
Even when a set of natural numbers cannot be decided outright, we can sometimes still enumerate its elements with a program. This splits problems into two distinct classes:
- Recursive (decidable). There exists a total computable characteristic function such that if and otherwise.
- Recursively enumerable (r.e.). Either or there exists a total computable function whose range is , i.e. .
An equivalent characterization of r.e. sets is semi-decidability: there exists a computable partial function such that (returning 1 if and diverging otherwise).
To see why r.e. and semi-decidable are the same:
- If is r.e., we build by testing , , and so on until a match is found. If , simply diverges.
- Conversely, if is non-empty (pick some ), we cannot just run sequentially because a single diverging input would block everything after it. Instead we use dovetailing, defining via a pairing function that returns if halts within steps and otherwise.1
This leads directly to Post’s Theorem:
If both and its complement are recursively enumerable, then is recursive.
The proof is completely constructive. Let and . To decide whether , we interleave the two enumerations: check , then , then , then , and so on. Because and , 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 is r.e. but not recursive (such as the Halting set), then its complement 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 has only countably many sentences, the upward Löwenheim-Skolem Theorem shows that if 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 , program behaviors) are vastly larger.