Use the continuous convention . Let . Applying the allowed logarithm inequality to for gives
Hence . Equality forces . Since every is strictly positive, this makes the entire alphabet. Equality in every weighted logarithm inequality then forces for every . Conversely makes every summand zero. Thus
This is Gibbs inequality for relative entropy, with zero probabilities in the first argument handled explicitly.
Fix the channel matrix . The mixed input induces the mixed output . The concavity of information entropy implies
For completeness, the difference is by Gibbs inequality, including zero coordinates with the usual conventions.
On the other hand, conditional output entropy is linear in the input law:
Subtracting gives the concavity of mutual information in the input distribution:
This makes maximizing mutual information over the input probability simplex a concave optimization problem: a local maximum is global. It also justifies averaging input distributions over channel symmetries when searching for an optimum, since symmetry averaging cannot lower the achieved mutual information. The channel itself is held fixed throughout.
For a finite joint distribution, the mutual information is
Zero-probability terms contribute zero. It measures the reduction in uncertainty about one variable upon observing the other.
A discrete memoryless channel has discrete input/output alphabets and a fixed transition matrix . Over successive uses it obeys
Thus the output at a use depends on that input and no other channel history. Its channel capacity is
in bits per use for base-two logarithms. On finite alphabets the maximum exists by continuity on the probability simplex; for more general discrete alphabets one uses a supremum.
Given an output of positive probability, the ideal observer chooses a symbol maximizing the posterior:
Ties may be broken arbitrarily, and the choice at an impossible output does not matter. This is maximum a posteriori decoding. It minimizes conditional error at each , because a deterministic decision is correct with probability ; a randomized decision is a weighted average of these success probabilities and cannot exceed their maximum.
Write . Then . Applying the two cases from part (b) to the posterior distribution gives
Average with respect to the output law to obtain the conditional entropy upper bound on minimum decoding error:
This is an upper bound on the optimum error probability; it does not hold for arbitrary deliberately poor decoding rules.
For the nontrivial case , every and
The probability ordering makes . At a dyadic number, choose the terminating binary expansion followed by zeros. Let be the first bits of , and let
be its binary cylinder interval.
Suppose and were a prefix of . Since , the numbers and would have the same first bits, so both would lie in . In particular . But
a contradiction. A later word cannot be a shorter prefix of an earlier word because the lengths are nondecreasing; equal-length coincidences were also excluded. Thus the cumulative Shannon code is a prefix code.
The ceiling inequalities give
Multiply by and sum to obtain
For a one-symbol deterministic source the displayed construction assigns the empty word and gives . This zero-bit convention is valid when the number of source emissions is supplied separately. It is not an unframed uniquely decodable code: concatenating different numbers of empty words gives the same bit string. If positive-length unframed words are required, the shortest deterministic code has length , so the strict upper bound requires the nontrivial-source assumption.
Put and let be the largest length. Expanding sums over all strings of source symbols, where is the total code length. By unique decodability, the concatenations of length in this sum are all distinct, so there are at most of them. Since ,
Taking th roots and sending to infinity proves the Kraft–McMillan inequality
Now is a probability distribution. With base-two logarithms, Gibbs inequality gives
Terms with contribute zero. Therefore
The normalization by is important: the raw numbers need not sum to one.
A binary code assigns a finite bit string to each source symbol. Use nonempty codewords for an unframed variable-length stream. The code is uniquely decodable if no two distinct finite sequences of source symbols produce the same concatenated bit string. It is a prefix-free code if no codeword is an initial segment of a different codeword.
To prove unique decoding of a prefix code, suppose two concatenations agree. Their first codewords both begin the same bit string, so the shorter is a prefix of the longer. The prefix condition forces the first codewords to be equal. Cancel them and repeat. Since the codewords are nonempty, this process ends with both symbol sequences exhausted at the same time; otherwise a nonempty remainder could not equal the empty string. Hence the source sequences agree.
The code is not a prefix code, since is a prefix of . Nevertheless it is uniquely decodable: decode from the right. A final forces the last codeword to be , whereas a final forces it to be . Removing that final word recursively gives a unique parsing. Thus the converse fails.
Let record whether the second stage erased the symbol, and write its output as . The erasure marker is outside the original output alphabet, so is determined by . Independence makes independent of both and the first output . The chain rule for mutual information therefore gives
The erased branch gives zero information because its output is constant; the unerased branch has exactly the original joint input-output law. Maximizing over the same input distributions gives
This includes and . It is the capacity after independent output erasure; input-dependent erasure would not justify the independence step.
Let the probability of the first input be . The two equal output probabilities are , and the third is . Writing for the binary entropy function, the output entropy is , while the conditional entropy is . Therefore
The derivative with respect to is
and the second derivative is in the interior. Thus the unique stationary point is the global maximum. It occurs at , so
The capacity itself is . The maximization is over , not over arbitrary output distributions; keeps the feasible outputs explicit.
For finite-valued variables, mutual information is
Terms of zero joint probability are zero. A discrete memoryless channel has fixed transition probabilities on finite alphabets, and conditional on an input sequence its outputs are independent with the product law . Its channel capacity is
bits per channel use. The maximum is over all input distributions, with the transition law held fixed.
Suppose every sum of two distinct probabilities exceeds every third probability. If an optimal code were not a block code, part (b) gives two deepest sibling leaves at depth and a leaf at depth . Replace the sibling pair by a leaf labelled , and replace the former leaf by two children labelled . The resulting tree is still a prefix tree, and other word lengths are unchanged. The change in expected length is
Here . This contradicts optimality. Thus every optimal code is a block code.
Conversely, suppose distinct satisfy . Starting with the complete length- code, arrange as a sibling pair, which is possible by permuting the source labels. Its parent at depth does not contain . Label that parent , and split the old leaf into children . This gives lengths for , for , and otherwise, with expected length
If the optimal mean length is below , no optimal code can be a block code: any injective binary block code for symbols has length at least . If the optimal mean is , the constructed non-block code itself is optimal. In either case there is an optimal non-block code. This proves the reverse implication, including the equality case, and hence the strict inequality in the criterion is necessary.
Every internal node of an optimal binary prefix tree has two children. If one had only one child, remove that one-edge detour from all descendant words. Prefix-freeness is preserved and at least one positive-probability word becomes shorter, strictly lowering the expected length. Thus the tree is full.
Take a leaf at maximum depth . Its sibling exists because the tree is full. That sibling cannot be an internal node, since a descendant would be deeper than . Hence it is another leaf at depth , and the corresponding codewords differ only in their final bit. This is the deepest sibling property of an optimal prefix code.
A finite full binary tree satisfies Kraft equality, , by dividing mass equally down each branch from the root. If all lengths were at least , with at least one strictly greater, that sum would be less than , a contradiction. Since the code is not a block code, the alternative that all lengths equal is excluded. Therefore some word has length below . Also a longest word must have length above : if all lengths were at most and some shorter, the Kraft sum would exceed one.

Pinned article: Introduction to the OurBigBook Project

Welcome to the OurBigBook Project! Our goal is to create the perfect publishing platform for STEM subjects, and get university-level students to write the best free STEM tutorials ever.
Everyone is welcome to create an account and play with the site: ourbigbook.com/go/register. We belive that students themselves can write amazing tutorials, but teachers are welcome too. You can write about anything you want, it doesn't have to be STEM or even educational. Silly test content is very welcome and you won't be penalized in any way. Just keep it legal!
We have two killer features:
  1. topics: topics group articles by different users with the same title, e.g. here is the topic for the "Fundamental Theorem of Calculus" ourbigbook.com/go/topic/fundamental-theorem-of-calculus
    Articles of different users are sorted by upvote within each article page. This feature is a bit like:
    • a Wikipedia where each user can have their own version of each article
    • a Q&A website like Stack Overflow, where multiple people can give their views on a given topic, and the best ones are sorted by upvote. Except you don't need to wait for someone to ask first, and any topic goes, no matter how narrow or broad
    This feature makes it possible for readers to find better explanations of any topic created by other writers. And it allows writers to create an explanation in a place that readers might actually find it.
    Figure 1.
    Screenshot of the "Derivative" topic page
    . View it live at: ourbigbook.com/go/topic/derivative
  2. local editing: you can store all your personal knowledge base content locally in a plaintext markup format that can be edited locally and published either:
    This way you can be sure that even if OurBigBook.com were to go down one day (which we have no plans to do as it is quite cheap to host!), your content will still be perfectly readable as a static site.
    Figure 5. . You can also edit articles on the Web editor without installing anything locally.
    Video 3.
    Edit locally and publish demo
    . Source. This shows editing OurBigBook Markup and publishing it using the Visual Studio Code extension.
  3. https://raw.githubusercontent.com/ourbigbook/ourbigbook-media/master/feature/x/hilbert-space-arrow.png
  4. Infinitely deep tables of contents:
    Figure 6.
    Dynamic article tree with infinitely deep table of contents
    .
    Descendant pages can also show up as toplevel e.g.: ourbigbook.com/cirosantilli/chordate-subclade
All our software is open source and hosted at: github.com/ourbigbook/ourbigbook
Further documentation can be found at: docs.ourbigbook.com
Feel free to reach our to us for any help or suggestions: docs.ourbigbook.com/#contact