13. Kolmogorov Complexity

The shortest possible description of anything

Shannon entropy tells us the best possible compression for a source — a statistical process that generates symbols according to some probability distribution. But what about compressing a single, specific string? What is the absolute shortest description of this particular sequence of bits?

That question is the domain of Kolmogorov complexity, independently discovered by Ray Solomonoff (1960), Andrey Kolmogorov (1965), and Gregory Chaitin (1966). It's one of the most beautiful ideas in computer science — and one of the most frustrating, because it turns out to be uncomputable.

The Core Idea

Kolmogorov complexity of a string

The Kolmogorov complexity K(x) of a string x is the length of the shortest program (in some fixed programming language) that outputs x and then halts.

Consider two strings, each 1,000 characters long:

String A: 010101010101010101010101010101...  (01 repeated 500 times)
String B: 110100100001111110110101010001...  (digits of pi in binary)
String C: 01101100010011101000110100111001...  (truly random bits)
  • String A has very low Kolmogorov complexity. A short program generates it: print("01" * 500). Maybe 20 bytes of code.
  • String B also has low Kolmogorov complexity. Despite looking random, there are short programs that compute the digits of pi: print(binary(pi, 1000)). Maybe 50 bytes of code.
  • String C — if it's truly random — has high Kolmogorov complexity. There is no pattern, no shortcut, no formula. The shortest program is essentially print("01101100010011101000...") — it must contain the entire string as a literal. K(x) ≈ |x|.

This is the key distinction: Kolmogorov complexity measures the information content of a specific object, not a statistical source. A string is "random" in the Kolmogorov sense if and only if it cannot be compressed — its shortest description is about as long as the string itself.

Entropy vs Kolmogorov Complexity

Shannon entropy and Kolmogorov complexity both measure "information content," but from different angles:

Shannon Entropy Kolmogorov Complexity
Measures Average information per symbol from a source Information in a specific string
Input A probability distribution A single string
Computable? Yes — just calculate H = −∑ p log p No — provably uncomputable
Depends on The source's statistics The string's structure (patterns, regularities)
Practical use Designing optimal codes (Huffman, ANS) Theoretical limits, defining randomness

Where they diverge

Consider the first million digits of π. If you model them as independent random digits, Shannon entropy says each digit carries about 3.32 bits of information — maximum entropy, no compression possible. But Kolmogorov complexity says the string is highly compressible: a short program computing π is far smaller than a million digits.

Shannon entropy sees no statistical pattern (the digits of π pass all standard randomness tests). Kolmogorov complexity sees algorithmic pattern — the digits aren't random, they're computed by a simple formula.

Why It's Uncomputable

Here's the devastating result: there is no algorithm that, given a string x, computes K(x). The proof is elegant and uses the same diagonalization trick as the halting problem.

Berry's paradox, formalized

Suppose a program COMPUTE_K exists that computes K(x) for any string x. We build a new program:

function BERRY(n):
    for each string x in length order:
        if COMPUTE_K(x) >= n:
            print(x)
            halt

This program outputs the first string whose Kolmogorov complexity is at least n. But the program itself has a fixed size — call it c. So for large enough n, BERRY(n) is a program of length c + log(n) that outputs a string of complexity ≥ n. That means there's a short program (length c + log(n)) that outputs something that by definition has no short program (complexity ≥ n). Contradiction.

This isn't a limitation of current technology — it's a fundamental mathematical impossibility. No future algorithm, no quantum computer, no breakthrough in AI will ever compute Kolmogorov complexity in general.

The Invariance Theorem

One worry: the definition talks about "the shortest program in some fixed programming language." Doesn't the complexity change depending on the language?

Yes, but only by a constant. This is the invariance theorem:

Invariance theorem

For any two universal programming languages U1 and U2, there exists a constant c (that depends only on the languages, not on x) such that for all strings x:

|KU₁(x) − KU₂(x)| ≤ c

The constant c is just the size of a compiler/interpreter from one language to the other. If you have a short Python program that outputs x, you can always write a C program of length (that Python program) + (size of a Python interpreter in C) that does the same thing. The interpreter is a fixed overhead — it doesn't grow with x.

For long strings, this constant is negligible. So Kolmogorov complexity is essentially language-independent — it's a property of the string, not the formalism.

Incompressible Strings and Randomness

A string x is called incompressible (or Kolmogorov random) if K(x) ≥ |x| — its shortest description is about as long as the string itself.

How many incompressible strings exist?

A counting argument

There are 2n binary strings of length n. How many can be compressed to fewer than n − k bits? At most 2n−k − 1 (because that's how many shorter programs exist). So at most a fraction 1/2k of all n-bit strings can be compressed by k or more bits.

Setting k = 1: at most half of all strings can be compressed by even one bit. Setting k = 10: at most 1 in 1024 strings can be compressed by 10 bits.

The vast majority of strings are incompressible. Randomness is the norm, not the exception. The strings we encounter in practice — text, images, code — are the rare, highly compressible exceptions.

This gives us a rigorous definition of randomness for individual strings. A string is random if and only if no algorithm can produce it from a significantly shorter description. No statistical test needed — no frequencies, no runs, no correlations. Just: can you compress it?

Connections to Compression

Kolmogorov complexity is the theoretical limit that real compressors approach but never reach:

  1. Every compressor is an upper bound. If gzip compresses a file to 3,000 bytes, then K(file) ≤ 3,000 + c (where c is the size of the gzip decompressor). The compressed file is a program — "run gzip -d on these bytes."

  2. No compressor achieves the bound. Since K is uncomputable, no algorithm can achieve optimal compression on all inputs. For any compressor, there exist strings where it performs far from K(x).

  3. Better compressors = tighter upper bounds. The history of compression — from Huffman to arithmetic to ANS — is the history of getting closer to K(x) on practical inputs, even though we can never reach it in general.

Compression as understanding

To compress something well, you need to understand it — to find its patterns, regularities, and structure. A compression algorithm is, in a deep sense, a theory of the data it compresses. Kolmogorov complexity says: the best possible compression is the best possible understanding.

The Minimum Description Length Principle

Kolmogorov complexity has a practical cousin: the Minimum Description Length (MDL) principle, used in statistics and machine learning.

The idea: when choosing between models that explain some data, prefer the model that gives the shortest total description: (model size) + (data encoded using the model).

Total description length = |model| + |data given model|
  • A very simple model (small |model|) might explain the data poorly (large |data given model|).
  • A very complex model (large |model|) might overfit — it memorizes the data instead of capturing patterns.
  • The best model balances the two — it captures genuine patterns without memorizing noise.

This is Occam's Razor formalized. And it connects directly to compression: the best model of the data is the one that compresses it most.

Algorithmic Probability

Solomonoff extended these ideas into algorithmic probability — a universal theory of prediction. The probability of a string x is:

P(x) = ∑ 2−|p| over all programs p that output x

Shorter programs contribute exponentially more probability. This means simple explanations (short programs) are overwhelmingly more likely than complex ones — a mathematical justification for Occam's Razor.

Solomonoff's theory is sometimes called the "ultimate" prediction framework: given all data seen so far, it assigns probabilities to all possible continuations, weighted by the complexity of the program that generates them. It's optimal in a precise sense — but, like Kolmogorov complexity, it's uncomputable. It exists as a theoretical ideal that practical prediction methods approximate.

Practical Echoes

Though K(x) itself is uncomputable, approximations are everywhere:

Application How it approximates K(x)
Normalized Compression Distance Uses gzip/bzip2 as K(x) approximations to measure similarity between strings, genomes, music, etc.
Minimum Description Length Model selection criterion that formalizes Occam's Razor
Lempel-Ziv complexity Counts the number of distinct patterns in a string — a computable lower bound on K(x)
Machine learning generalization Simpler models (shorter descriptions) tend to generalize better — this is Kolmogorov complexity's shadow over all of ML

The Normalized Compression Distance (NCD) is particularly elegant. To measure how similar two strings x and y are:

NCD(x, y) = (C(xy) - min(C(x), C(y))) / max(C(x), C(y))

where C(x) is the compressed size of x using any standard compressor. This has been used to build phylogenetic trees from DNA, classify music by genre, detect plagiarism, and cluster malware variants — all without any domain-specific knowledge. The compressor is the feature extractor.

The Halting Problem Connection

Kolmogorov complexity's uncomputability is deeply linked to the halting problem. In fact, the two are essentially the same impossibility wearing different hats:

  • Halting problem: Can you determine whether an arbitrary program halts?
  • Kolmogorov complexity: Can you determine the shortest program that produces a given output?

If you could compute K(x), you could solve the halting problem. If you could solve the halting problem, you could compute K(x) (just enumerate all programs, run them, and find the shortest one that outputs x — you'd need the halting oracle to know which ones terminate). They're equivalent impossibilities.

This means Kolmogorov complexity isn't just hard to compute — it's as hard as the hardest problems in all of mathematics. There exist strings whose complexity cannot be determined by any formal system (Chaitin's incompleteness theorem) — a result that strengthens Gödel's incompleteness theorems.

Key Takeaways

  • Kolmogorov complexity K(x) is the length of the shortest program that outputs x — the ultimate measure of a string's information content
  • Unlike Shannon entropy (which measures sources), Kolmogorov complexity measures individual strings
  • K(x) is uncomputable — no algorithm can determine the shortest description of an arbitrary string
  • The invariance theorem means K(x) is essentially language-independent
  • Most strings are incompressible — the compressible data we encounter daily is the rare exception
  • Every real compressor provides an upper bound on K(x); better compressors give tighter bounds
  • Practical approximations (NCD, MDL, LZ complexity) make these ideas useful despite uncomputability

Kolmogorov complexity tells us that perfect compression is impossible in general — but our practical compressors do remarkably well on the structured data we actually encounter. So far we've focused on lossless compression, where every bit is preserved. But what happens when we're willing to throw some bits away? That's the world of lossy compression.