ArticleslgStudy

mathematics

Shannon's source coding theorem

Shannon's source coding theorem is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Shannon's source coding theorem rather than just read about it. In short: In information theory, Shannon's source coding theorem (or noiseless coding theorem) establishes the statistical limits to possible data compression for data whose source is an independent identically distributed random variable, and the operational meaning of the Shannon entropy. Named after Claude Shannon, the source coding theorem shows that, in the limit, as the length of a stream of independent and identically…

Shannon's source coding theorem — main illustration
Shannon's source coding theorem — illustration

Key takeaways

  • Shannon's source coding theorem belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Shannon's source coding theorem to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Shannon's source coding theorem from memory before moving on to harder problems.

Reference excerpt

In information theory, Shannon's source coding theorem (or noiseless coding theorem) establishes the statistical limits to possible data compression for data whose source is an independent identically distributed random variable, and the operational meaning of the Shannon entropy. Named after Claude Shannon, the source coding theorem shows that, in the limit, as the length of a stream of independent and identically-distributed random variable (i.i.d.) data tends to infinity, it is impossible to compress such data such that the code rate (average number of bits per symbol) is less than the Shannon entropy of the source, without it being virtually certain that information will be lost. However, it is possible to get the code rate arbitrarily close to the Shannon entropy, with negligible probability of loss. The source coding theorem for symbol codes places upper and lower bounds on the minimal possible expected length of codewords as a function of the entropy of the input word (which is viewed as a random variable) and of the size of the target alphabet. Note that for data that exhibits more dependencies (whose source is not an i.i.d. random variable), the Kolmogorov complexity, which quantifies the minimal description length of an object, is more suitable to describe the limits of data compression. Shannon entropy takes into account only frequency regularities, while Kolmogorov complexity takes into account all algorithmic regularities, so in general the latter is smaller. On the other hand, if an object is generated by a random process in such a way that it has only frequency regularities, entropy is close to complexity with high probability (Shen et al. 2017).

Statements Source coding is a mapping from (a sequence of) symbols from an information source to a sequence of alphabet symbols (usually bits) such that the source symbols can be exactly recovered from the alphabet symbols (lossless source coding) or recovered within some distortion (lossy source coding). This is one approach to data compression.

Source coding theorem In information theory, the source coding theorem (Shannon 1948) informally states that (MacKay 2003, p. 81, Cover 2006, Chapter 5):

N i.i.d. random variables, each with entropy H(X), can be compressed into more than N H(X) bits with negligible risk of information loss, as N → ∞; but conversely, if they are compressed into fewer than N H(X) bits, it is virtually certain that information will be lost.

The coded sequence of length NH(X) represents the compressed message in a biunivocal way, under the assumption that the decoder knows the source. From a practical point of view, this assumption is not always true. Consequently, when the entropy encoding is applied, the transmitted message may need to include information characterizing the source, usually inserted at the beginning of the transmitted message.

Source coding theorem for symbol codes Let Σ1, Σ2 denote two finite alphabets and let Σ∗1 and Σ∗2 denote the set of all finite words from those alphabets respectively. Suppose that X is a random variable taking values in Σ1 and let f be a uniquely decodable code from Σ∗1 to Σ∗2 where |Σ2| = a. Let S denote the random variable given by the length of codeword f(X). If f is optimal in the sense that it has the minimal expected word length for X, then (Shannon 1948): H(X)log2a≤𝔼[S]<H(X)log2a+1, where 𝔼 denotes the expected value operator.

Proof: source coding theorem Given X is an i.i.d. source, its time series X1, ..., Xn is i.i.d. with entropy H(X) in the discrete-valued case and differential entropy in the continuous-valued case. The Source coding theorem states that for any ε > 0, i.e. for any rate H(X) + ε larger than the entropy of the source, there is large enough n and an encoder that takes n i.i.d. repetition of the source, X1:n, and maps it to n(H(X) + ε) binary bits such that the source symbols X1:n are recoverable from the binary bits with probability of at least 1 − ε. Proof of Achievability. Fix some ε > 0, and let

p(x1,…,xn)=Pr⁡[X1=x1,⋯,Xn=xn]. The typical set, Aεn, is defined as follows:

Anε={(x1,⋯,xn) : |−1nlog⁡p(x1,⋯,xn)−Hn(X)|<ε}. The asymptotic equipartition property (AEP) shows that for large enough n, the probability that a sequence generated by the source lies in the typical set, Aεn, as defined approaches one. In particular, for sufficiently large n, P((X1,X2,⋯,Xn)∈Anε) can be made arbitrarily close to 1, and specifically, greater than 1−ε (See AEP for a proof). The definition of typical sets implies that those sequences that lie in the typical set satisfy:

2−n(H(X)+ε)≤p(x1,⋯,xn)≤2−n(H(X)−ε)

The probability of a sequence (X1,X2,⋯Xn) being drawn from Aεn is greater than 1 − ε. |Anε|≤2n(H(X)+ε), which follows from the left hand side (lower bound) for p(x1,x2,⋯xn). |Anε|≥(1−ε)2n(H(X)−ε), which follows from upper bound for p(x1,x2,⋯xn) and the lower bound on the total probability of the whole set Aεn. Since |Anε|≤2n(H(X)+ε),n(H(X)+ε) bits are enough to point to any string in this set. The encoding algorithm: the encoder checks if the input sequence lies within the typical set; if yes, it outputs the index of the input sequence within the typical set; if not, the encoder outputs an arbitrary n(H(X) + ε) digit number. As long as the input sequence lies within the typical set (with probability at least 1 − ε), the encoder does not make any error. So, the probability of error of the encoder is bounded above by ε. Proof of converse: the converse is proved by showing that any set of size smaller than Aεn (in the sense of exponent) would cover a set of probability bounded away from 1.

Proof: Source coding theorem for symbol codes For 1 ≤ i ≤ n let si denote the word length of each possible xi. Define qi=a−si/C, where C is chosen so that q1 + ... + qn = 1. Then

H(X)=−∑i=1npilog2pi≤−∑i=1npilog2qi=−∑i=1npilog2a−si+∑i=1npilog2C=−∑i=1npilog2a−si+log2C≤−∑i=1n−sipilog2a=𝔼Slog2a where the second line follows from Gibbs' inequality and the fifth line follows from Kraft's inequality:

C=∑i=1na−si≤1 so log C ≤ 0. For the second inequality we may set

si=⌈−logapi⌉ so that

−logapi≤si<−logapi+1 and so

a−si≤pi and

∑a−si≤∑pi=1 and so by Kraft's inequality there exists a prefix-free code having those word lengths. Thus the minimal S satisfies

𝔼S=∑pisi<∑pi(−logapi+1)=∑−pilog2pilog2a+1=H(X)log2a+1

Extension to non-stationary independent sources

Fixed rate lossless source coding for discrete time non-stationary independent sources Define typical set Aεn as:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Shannon's source coding theorem

Start with the simplest possible case. Write down what Shannon's source coding theorem claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Shannon's source coding theorem before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Shannon's source coding theorem ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Shannon's source coding theorem

In research
Shannon's source coding theorem appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Shannon's source coding theorem in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Shannon's source coding theorem is common in secondary-school and first-year university syllabi. It links to neighbouring topics Coding theory, Data compression, Information theory, so understanding it makes those chapters shorter.
In everyday life
Look for Shannon's source coding theorem outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Shannon's source coding theorem” →

How to study Shannon's source coding theorem in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Shannon's source coding theorem means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Shannon's source coding theorem out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Shannon's source coding theorem in simple terms?

In information theory, Shannon's source coding theorem (or noiseless coding theorem) establishes the statistical limits to possible data compression for data whose source is an independent identically distributed random variable, and the operational meaning of the Shannon entropy. Named after Claud…

Why does Shannon's source coding theorem matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Shannon's source coding theorem?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Shannon's source coding theorem.

Tags

  • Coding theory
  • Data compression
  • Information theory
  • Mathematical theorems in theoretical computer science
  • Presentation layer protocols

Keep exploring