Data compression 2026-10-13
Data compression represents data using fewer bits than a specified original representation. The saving can reduce storage in a file system and reduce the number of bits sent through a communication channel. At a fixed transmission rate, fewer bits arrive sooner; this makes better use of a fixed transmission budget. Both the encoded data and the instructions needed to interpret them contribute to the size of a stored file.
There are two different promises. Lossless source coding preserves the original exactly: for an encoder and decoder , for every permitted input . Thus must be an injective function. Lossy compression allows to differ from , with the difference judged by an explicit criterion. A program or numerical record may require exact recovery; a preview image may tolerate altered pixels in return for fewer bits.
The appeal of lossless source coding is that repetition can be described rather than copied. Run-length encoding says "repeat this value twelve times"; a prefix code can give more frequent symbols shorter descriptions. These are distinct ways to exploit structure, and neither promises savings for every input. Image compression supplies especially visible examples of both lossless source coding and lossy compression.
Claude E. Shannon's 1948 paper made the role of probability distributions precise. For a memoryless classical information source with Shannon entropy bits per symbol, Shannon's source coding theorem bounds achievable average lengths; sufficiently long blocks allow exact codes to approach bits per symbol. This is a statement about a specified source and average lengths, not a promise to shorten every message.[ref]
Huffman coding Created 2026-09-24 Updated 2026-10-14
Huffman coding makes frequent symbols cheap to store by giving them short codewords, while allowing rare symbols longer codewords. For a known probability distribution on a finite alphabet with at least two positive-probability symbols, binary Huffman coding constructs a prefix code minimizing expected codeword length among binary prefix codes that encode one source symbol at a time. The objective is an average under that probability distribution; it does not promise to shorten every message. Encoder and decoder must agree on the resulting Huffman code. [ref]
The construction grows a binary tree from its leaves towards its root of a tree. Start with one leaf per symbol, weighted by its probability. Repeatedly join the two currently smallest weights beneath a new parent in a rooted tree, whose weight is their sum, and replace the pair by that subtree. Include newly formed subtrees when choosing the next pair. When one tree remains, label the two outgoing edges at every internal vertex with and ; the labels on the graph path from the root of a tree to a symbol give its codeword. This is a greedy algorithm: each step makes a locally cheapest merge, yet the result is an optimal prefix code.
For a concrete example, use probabilities , , , . First join and , creating weight . The remaining weights are for , for the subtree, and for . Join the two weights to make , then join with that subtree to make . The merge weights are therefore . Each merge adds one bit to every codeword below it, so their sum is the expected codeword length: bits per source symbol. The diagram fixes the edge labels to produce the Huffman code used below.
Figure 1.
Huffman merges for probabilities 0.4, 0.3, 0.2, 0.1 and their binary codewords
. Details.
The useful insight is that choosing short codewords is a resource allocation problem: the prefix code condition constrains the available codeword lengths through the Kraft inequality. Huffman coding solves this one-symbol problem exactly for the supplied probability distribution. For repeated emissions of a memoryless classical information source, the same Huffman code can be applied symbol by symbol. More general compression can exploit dependencies or encode groups of symbols; the one-symbol optimality statement does not compare all such methods.
Unique decipherability makes the map from to the concatenated binary string injective. Entropy is unchanged by an injective relabelling, and memorylessness gives independence, hence
Given , the string has at most possibilities. The entropy bound for finite alphabets therefore gives . Averaging,
The random length cannot simply be discarded: it can also carry information. Let be the maximum codeword length, finite since the alphabet is finite. Since is a function of and takes at most values,
Divide by and let . This proves . The conclusion also covers a deterministic source; the source's lowercase in its final expectation denotes the random source letter.
Use base-two logarithms throughout, so classical rates are measured in bits and quantum compression rates in qubits. A memoryless classical information source is a sequence of independent and identically distributed random variables on a finite alphabet , with fixed probability mass function . A length- word has probability , and the one-symbol Shannon entropy is , with .
For , the typical set is
This is weak typicality: it constrains the normalized self-information, not each empirical symbol count separately.
The typical sequence theorem gives the following three facts for fixed . The probability tends to one; each word in the set has probability between and ; and, once the set has probability at least ,
The concentration assertion follows from the weak law of large numbers applied to the iid information variables , whose finite-alphabet mean is . The probability bounds are the definition of typicality exponentiated. Summing the lower bound over the typical words and using total probability at most one proves the cardinality upper bound; summing the upper bound and using total typical probability at least proves the lower bound.
Fix and choose . Enumerate all words in and assign a distinct fixed-length binary index to each. Reserve one more index as a failure symbol for every atypical input. For all sufficiently large ,
so these indices can be transmitted using bits. The decoder inverts the typical-word enumeration; on the failure index it returns any fixed word. This describes both the compressor and decompressor, and its block error probability obeys
Its rate tends to bits per symbol. Thus every permits reliable fixed-rate compression, with no claim that atypical words are reconstructed correctly.
For the memoryless quantum information source, the average one-use density matrix is
Its trace is one and determinant , so its two eigenvalues are
The source-coding limit in Schumacher compression is the Von Neumann entropy of this average state: every larger qubit rate allows asymptotically faithful recovery of the emitted states, and a smaller rate cannot do so. Applying that limit gives
where is the binary entropy. The quantum typical subspace of has dimension about and carries asymptotically all source weight, which explains the compression rate. The entropy of the classical emission label is one bit; it is not the quantum rate because the two emitted pure states are nonorthogonal.
Typical sequence theorem Created 2026-10-14 Updated 2026-10-25
For a memoryless classical information source, the typical set consists of positive-probability words with . The weak law of large numbers applied to proves its probability tends to one. Every typical word has probability between and . Summing the lower bound gives the displayed cardinality upper bound; if the set has probability at least , summing the upper bound gives cardinality at least .
To compress at any rate , choose , assign one fixed-length binary index to each typical word, and reserve one additional index for all atypical words. At most bits suffice for all large . Decoding inverts the typical-word indices and makes an arbitrary output for the reserved index. The reconstruction error is at most the probability of the atypical set and tends to zero.