How statement and proof provenance work
The first chip identifies the source of the statement or construction; the second identifies the source of its local proof or verification.
- Literature-sourced: the exact statement appears in a cited source; only wording and notation differ.
- AI-adapted: a semantically identical restatement of literature-sourced material, modulo indexing, notation, and boundary cases adopted by the library.
- AI-generated: a genuinely novel statement formulated by AI, with no source for the claim itself.
These labels describe origin, not correctness: citations and verification chips remain separate evidence.
Prefix Codes and Finite Lossless Coding
1 · Prerequisites
- Absolute and Conditional Convergence; Rearrangement; Products
- Binary Operations, Monoids, Groups and Subgroups
- Compactness in Metric Spaces
- Completeness, Completion, and Uniform Continuity
- Construction of the Natural Numbers
- Construction of the Real Numbers via Cauchy Sequences
- Construction of the Real Numbers via Dedekind Cuts
- Continuity, IVT, EVT, and Uniform Continuity
- Countability and Uncountability
- Decidable, Recognizable, and Enumerable Languages
- Finite Counting, Factorials and Binomial Coefficients
- Finite Probability Spaces and Random Variables
- Finite-Alphabet Entropy and Divergence
- Formal Languages, Encodings, and Decision Problems
- Foundations of the Real Numbers for Analysis
- Kolmogorov Complexity and Algorithmic Randomness
- Limits of Real Functions
- limsup, liminf, and Subsequential Limits
- Linear Recurrences and Rational Generating Functions
- Metric Spaces
- Monotone Functions, Discontinuities, and Continuity Sets
- Monotone Sequences, Bolzano-Weierstrass, and Cauchy Completeness
- Order, Zorn's Lemma, and the Axiom of Choice
- Power and sample size
- Power Series and Real-Analytic Functions
- Properties of the Integral and the Working FTC
- Quantum Communication and Fingerprinting
- Relations, Functions, and Quotients
- Roots, Rational Powers, and Classical Inequalities
- Sequences and Limits
- Sequences and Series of Functions; Uniform Convergence
- Series: Convergence and the Nonnegative Tests
- Suprema and Infima
- The Derivative and the Mean Value Theorems
- The Exponential Function
- The Logarithm and General Powers
- The Riemann Integral: Definition and Integrability
- The ZFC Axioms and the Basic Set Constructions
- Topology of ℝ
- Turing Machines, Configurations, and Computation
- Vector Spaces, Linear Subspaces, Span and Direct Sums
2 · Summary
This page develops finite binary lossless coding for a finite full-support source. It defines code extensions, unique decodability, prefix codes, and binary code trees; proves the binary Kraft criterion and McMillan inequality; and establishes Shannon and Huffman length bounds. Entropy is recorded in nats by the existing finite-distribution interface and converted explicitly to bits for code lengths.
The arithmetic-coding section separates the ideal-real interval construction from an exact finite-register block coder. The latter assumes positive rational frequencies , a public maximum block length , and fixed length- frames with known source model and outer frame count. Its integer registers are sized from and ; no constant-word-width streaming or approximate-frequency guarantee is claimed.
3 · Logical flowchart
4 · Definitions, theorems and proofs
Finite discrete sources and product blocks
Definition
A finite discrete source is an integer and a probability vector on the alphabet such that for every . Here a probability vector has nonnegative entries summing to one, as in Finite distributions, entropy, divergence, and stochastic matrices; the strict positivity convention means that is the source support. In particular, the one-symbol source has and .
For , a block of length is a word . Its product probability is Finite distributivity gives , so is again a probability vector and has full support. When coding blocks, use lexicographic order on ; listing its words in that order identifies the block alphabet with for the code conventions below. Blocks are the only memoryless-source objects used on this page.
Nonnegativity of finite relative entropy with a positive reference
Statement
Let and be probability vectors with for every . Then , with equality if and only if .
Facts & Assumptions
Given: Probability vectors on , with for every .
Finite distributions, entropy, divergence, and stochastic matrices: when no positive coordinate of is paired with a zero coordinate of .
Information units and logarithm-base convention: denotes the natural logarithm of the library's natural-logarithm definition.
Order, continuity, range, and the product, quotient, and reciprocal laws for the natural logarithm: The natural logarithm is continuous on .
The natural logarithm has derivative 1/x and equals the integral from 1 to x of 1/t: The natural logarithm is differentiable for positive inputs and has derivative .
The mean value theorem, as the case of Cauchy's: for continuous on with and differentiable on there is with : A continuous function on , differentiable on , has a point where its derivative equals its average rate of change.
for all , so the finite relative entropy in [F1] is defined by its displayed finite sum.
Proof
If , then . Otherwise let and . By [F2] and [F3], is continuous on ; by [F5], it is differentiable on with derivative . Applying [F6] gives with , so by [F4]. If , then ; if , then and . In either case . Thus , with equality only at .
Let . By [F1], [A1], and step 1.1 applied to for each , . If , both inequalities are equalities. Equality in the last requires outside , and [A1] then forces . Equality in the first requires each nonnegative gap from step 1.1, multiplied by , to vanish; hence for every . Conversely gives by [F1].
Base-two entropy of a finite source
Definition
For a finite source of Finite discrete sources and product blocks, define its base-two Shannon entropy, measured in bits, by Here is the finite Shannon entropy in natural units from Finite distributions, entropy, divergence, and stochastic matrices. By Information units and logarithm-base convention, information quantities use natural logarithms by default and . Substituting this identity termwise and using gives the displayed equality. Every is positive by the source convention, so no zero-term convention is needed here.
Finite binary source codes, extension, and expected length
Definition
A binary word is a finite sequence of symbols from . The set includes the empty word , and is the set of nonempty binary words. A binary source code for the finite source is a function . Its codeword length is .
The extension maps the empty source word to and maps to . The code is uniquely decodable if is injective, including comparisons between source words of different lengths. Its expected length for source law is
Binary prefix codes and their code trees
Definition
A binary code is a prefix code if it is nonsingular and no codeword is a proper prefix of a different codeword . A word is a proper prefix of when for some nonempty binary word . Nonsingular means whenever .
The code tree is the finite rooted trie whose vertices are all prefixes of codewords, whose root is , and whose edges append one bit, labeled or . Since the code is prefix-free, its codewords are exactly the leaves; unused branches are absent. A binary word path from the root records its successive edge labels.
McMillan inequality for finite binary uniquely decodable codes
Statement
Let be a finite binary uniquely decodable code with lengths . Then
Facts & Assumptions
Given: A finite source alphabet , a binary code , and injectivity of its concatenation extension .
Finite binary source codes, extension, and expected length: Unique decodability means that the concatenation extension is injective on all finite source words, and every codeword is nonempty.
Integer part: for every real there is exactly one integer with : For every real , the integer part satisfies .
Proof
Put and . For each integer , expand . For each total length , let count the tuples with . Their concatenated codewords are distinct by [F1] and each is a binary word of length , of which there are exactly because each of the positions has two choices; hence .
Since every , the only possible totals satisfy , so there are possible integer values of . Grouping step 1.1 by gives . Therefore for every .
Suppose , set , and put . By [F2], the integer satisfies and , so . The binomial theorem gives , contradicting step 2.1, which gives . Hence .
Ideal-real arithmetic interval coding for a fixed block
Definition
Fix a finite full-support source , its symbol order , and a public block length . The ideal-real arithmetic interval of the empty prefix is . If a prefix has interval and the next symbol is , assign the extended prefix the half-open subinterval This subdivision is performed exactly over the real numbers.
Each subdivision multiplies the interval width by the positive probability of the next symbol. Thus a completed block has width .
Use the base-two logarithm convention of Information units and logarithm-base convention. Its positive denominator and the strict increase of from Order, continuity, range, and the product, quotient, and reciprocal laws for the natural logarithm make strictly increasing; Change of base and inversion of the positive-base real exponential gives and . Every floor is the integer part specified by Integer part: for every real there is exactly one integer with .
For a completed block , let be its resulting interval, put , and define The dyadic cell represented by an -bit index is . The ideal-real codeword is the -bit binary representation of , with leading zeros. Each encoding frame contains exactly one length- source block; the decoder knows and . A stream uses an externally known number of such frames. No finite-register or finite-precision implementation is specified by this definition.
Since , the logarithm conventions above give and hence . The interval midpoint lies in , so the integer-part property gives ; the stated -bit representation therefore exists.
Every finite binary prefix code is uniquely decodable
Statement
Every binary prefix code for a finite source is uniquely decodable.
Facts & Assumptions
Given: A finite source and a binary prefix code .
Finite binary source codes, extension, and expected length: Codewords are nonempty finite binary words, and unique decodability means injectivity of the concatenation extension on all finite source words.
Binary prefix codes and their code trees: Distinct codewords are nonempty, nonsingular, and no codeword is a proper prefix of another.
Proof
Among two distinct codewords that are initial segments of the same binary word, one would be a prefix of the other: compare their lengths, since the shorter initial segment agrees with the initial part of the longer. By [F2], at most one codeword can be an initial segment of any binary word.
To parse a word in the range of , repeatedly take its unique initial codeword from step 1.1 and remove it. Each removal shortens the unread finite word because codewords are nonempty by [F1]; the process therefore reaches the empty word after finitely many removals. At every stage the next codeword is forced, so the resulting source word is unique; the empty output is produced only by the empty source word. Thus is injective, which is unique decodability by [F1].
Binary Kraft criterion for finite positive codeword lengths
Statement
For a finite list of positive integers , there is a binary prefix code on having codeword lengths if and only if
Facts & Assumptions
Given: A finite source alphabet and positive integer lengths .
Kraft inequality and effective prefix-code allocation: Every prefix-free set satisfies ; conversely, a computably enumerable request list with total weight at most one admits an effective prefix-free allocation of the requested lengths.
Finite binary source codes, extension, and expected length: A binary code assigns a nonempty finite binary word to each source symbol.
Binary prefix codes and their code trees: A binary prefix code is nonsingular and no codeword is a proper prefix of another.
Proof
If a prefix code has lengths , its finite set of codewords is prefix-free by [F3]. Apply the first assertion of [F1] to that set; the codewords are distinct by nonsingularity, so its Kraft sum is exactly .
Suppose . Enumerate the finite request list in increasing order of ; this is a computable enumeration, and the requested lengths are positive by hypothesis. The converse in [F1] allocates distinct prefix-free binary words of those lengths. Assign the word allocated to request as . Their positive lengths make a binary source code by [F2]. Distinctness gives nonsingularity and prefix-freeness gives [F3], so the requested binary prefix code exists.
Deterministic binary Huffman coding
Definition
Input: A finite full-support source as in Finite discrete sources and product blocks, with the symbols ordered .
Output: A binary prefix code on these symbols.
If , return the one-bit codeword .
If , make one active leaf for each source symbol , with weight and serial number . Repeatedly do the following while more than one node is active:
- Order active nodes lexicographically by (weight, serial number), using the ordinary order on real weights and then integer serials.
- Remove the first two nodes. Make a new parent whose left child is the first removed node and whose right child is the second, whose weight is their sum, and whose serial is the next unused integer.
- Insert this parent among the active nodes.
When one root remains, label every left edge and every right edge . The codeword for symbol is the edge-label sequence on the path from the root to its original leaf. The order by serial number fixes all ties and fixes the bit orientation. The same merge rule applies to any finite active list of positive weights carrying distinct serial numbers; the source input initializes the serials as , and each new parent receives a fresh serial.
For each , the algorithm executes exactly merges because each merge decreases the number of active nodes by one. The returned tree is finite. The next theorem proves the code is prefix-free and optimal; no complexity bound is asserted.
Ideal-real interval coding is prefix-free and lossless
Statement
For fixed and , the code in Ideal-real arithmetic interval coding for a fixed block is injective and prefix-free on the lexicographically ordered block alphabet . Its codeword length for is at most . Thus an -block is recovered uniquely, and concatenated frames of this fixed block length are uniquely parsed.
Facts & Assumptions
Given: A finite full-support source , a fixed block length , and the ideal-real interval and codeword construction.
Finite discrete sources and product blocks: for every .
Ideal-real arithmetic interval coding for a fixed block: If a prefix has interval and the next symbol is , the extended prefix receives the half-open interval determined by the cumulative sums of .
Binary prefix codes and their code trees: A binary code is prefix-free when it is nonsingular and no codeword is a proper prefix of another.
Information units and logarithm-base convention: For , and the denominator is positive.
Order, continuity, range, and the product, quotient, and reciprocal laws for the natural logarithm: is strictly increasing.
Change of base and inversion of the positive-base real exponential: For , , and for .
Integer part: for every real there is exactly one integer with : For every real , .
Ideal-real arithmetic interval coding for a fixed block: For a final interval width , the code uses , , and the dyadic cell with index .
Proof
At every prefix, the child intervals are disjoint half-open intervals whose union is the parent interval, because the cumulative probabilities increase from to . Induction on prefix length therefore shows that the length- intervals partition , and multiplying the successive width factors gives by [F1].
By [F8], put and . Since , [F4] and [F5] give , so [F7] gives and . The same facts show that is strictly increasing, and [F6] gives ; therefore . Thus the cell width satisfies . If is the midpoint of , then by step 1.1. By [F7], is an integer; since , it satisfies and has an -bit representation. Its cell contains and lies within distance of it; hence it is contained in the interior of .
Distinct blocks have disjoint source intervals by step 1.1. Their nonempty dyadic cells from step 2.1 are therefore disjoint. If one emitted bit word were a prefix of another, its dyadic cell would contain the other's cell, contradicting disjointness. Thus the codewords are distinct and prefix-free by [F3]; the unique interval containing a received code cell identifies its block, and prefix-freeness parses concatenated fixed- frames.
By [F7] and [F8], , so the emitted length is by step 1.1 and [F1]. This proves the pointwise bound without converting ideal-real interval arithmetic into a finite-register procedure.
Exact finite-register arithmetic coding for rational block sources
Definition
Configuration and frame model. The shared model consists of positive integers , their total , the rational source , and a maximum frame length . Fix a frame length with . At configuration time compute by successive multiplications, then initialize and and repeat , while . The resulting is the least integer with ; it is fixed for every frame using this configuration. Every frame is exactly one -symbol block; the decoder knows . A complete stream contains a specified finite number of such frames, supplied by an outer frame count. The arithmetic coder adds no end marker.
Register size. With fixed by the configuration above, Endpoint, width, frequency, and cumulative-frequency registers have bits; the output index has at most bits. One -bit temporary register stores intermediate products, numerators, denominators, and sums. The symbol-position counter uses bits and the range/output-length counter uses bits. All arithmetic is exact integer addition, multiplication, comparison, and floor division; no floating-point rounding or register growth during a frame is allowed.
Encoder. Put and . For an input block , initialize and . For , set and update After the updates, search the finite list and retain the largest satisfying . Set and Emit the -bit binary representation of , padded on the left with zeros; its dyadic cell is from Ideal-real arithmetic interval coding for a fixed block.
Decoder. For fixed , generate the finite codebook by applying the encoder to every block in and build its binary trie. For one frame, read payload bits along this trie until a leaf is reached and return its block; reject an invalid path or a path not reaching a leaf within bits. For a stream, repeat this operation exactly times and then stop. The next theorem proves that the generated codebook is prefix-free and that every encoded frame reaches exactly one leaf.
The configured register widths are finite for each fixed rational model and cap . They grow when a new configuration with a larger or is installed; no constant-word-width streaming guarantee is claimed.
Shannon bounds for finite binary codes
Statement
Let be a finite full-support source and let be its entropy in bits. Every finite binary uniquely decodable code satisfies . If , the binary prefix code with lengths (called a Shannon code) has expected length strictly less than . If , the one-bit codeword has length .
Facts & Assumptions
Given: A finite full-support source and a finite binary code .
Finite discrete sources and product blocks: , , and .
Finite binary source codes, extension, and expected length: , and is uniquely decodable exactly when its finite-word concatenation extension is injective.
McMillan inequality for finite binary uniquely decodable codes: Every finite binary uniquely decodable code has .
Nonnegativity of finite relative entropy with a positive reference: For finite probability vectors with , .
Binary Kraft criterion for finite positive codeword lengths: Positive integer lengths are realized by a binary prefix code whenever their Kraft sum is at most one.
Order, continuity, range, and the product, quotient, and reciprocal laws for the natural logarithm: is strictly increasing and .
Order, continuity, range, and the product, quotient, and reciprocal laws for the natural logarithm: For positive , , , and .
Change of base and inversion of the positive-base real exponential: for every real .
Ceilings give the least positive integer meeting a real threshold: is an integer and .
Integer part: for every real there is exactly one integer with : For every real , .
Proof
Let be uniquely decodable and set . By [F3] and [F4], . Define ; then is a positive probability vector.
Suppose . Full support gives , so [F8] and [F9] give . By [F12], is a positive integer and . Thus by [F11]; since is strictly increasing by [F8] and [F9], this gives and hence . By [F6] there is a binary prefix code with these lengths.
By [F2], [F3], [F5], [F7], [F8], and [F10], using the logarithm product and quotient laws for the integer powers in , . Since , [F9] gives , so . Divide by from [F8] and use [F2] to obtain .
By [F12] and [F13], if then , so . Therefore the Shannon code in step 1.2 satisfies . If , then by [F1], so by [F2] and [F8]–[F9]; the codeword is a prefix code of length one.
The deterministic Huffman code is prefix-optimal
Statement
For every finite full-support source, the algorithm Deterministic binary Huffman coding terminates, returns a binary prefix code, and minimizes among all binary prefix codes on the same alphabet. For a one-symbol source it returns the one-bit codeword , which is optimal among codes with nonempty codewords.
Facts & Assumptions
Given: A finite full-support source and the deterministic algorithm Deterministic binary Huffman coding.
Finite discrete sources and product blocks: The alphabet has symbols, every source weight is positive, and .
Binary prefix codes and their code trees: The code tree is the finite trie of codeword prefixes, and a prefix code has distinct codeword leaves with no codeword a proper prefix of another.
Finite binary source codes, extension, and expected length: Every codeword is nonempty and .
Binary Kraft criterion for finite positive codeword lengths: A finite positive integer length list with Kraft sum at most one is realized by a binary prefix code.
Deterministic binary Huffman coding: Order active nodes lexicographically by (weight, serial number), using the ordinary order on real weights and then integer serials.
Deterministic binary Huffman coding: Remove the first two nodes. Make a new parent whose left child is the first removed node and whose right child is the second, whose weight is their sum, and whose serial is the next unused integer.
Deterministic binary Huffman coding: If , return the one-bit codeword .
Proof
If , the algorithm returns by [F7]. Every codeword is nonempty by [F3], so every one-symbol code has expected length at least ; the returned code is prefix-free by [F2] and attains that value.
Suppose . Every merge removes two nodes and adds one, so the active count decreases by exactly one; after merges there is one root. Each original symbol remains one leaf, and the only new nodes are internal parents by [F6]. Distinct leaves cannot lie on one root-to-leaf path, so their path words are distinct and neither is a prefix of another. Every path has positive length because the root is internal. Thus [F2] gives a binary prefix code.
An optimal prefix code exists. For every integer , by induction: it holds at , and . Thus [F4] applied to the length list gives a finite prefix code, since its Kraft sum ; let its cost be . Any code with cost at most has for every , because and all summands in are nonnegative. Only finitely many positive integer length vectors satisfy these bounds, and at least one is realized. A least cost among those realized vectors exists and is a global minimum because every code outside the set has cost greater than .
For an active list of size two and total weight one, the algorithm merges its two nodes into a root with two leaves, giving lengths and cost . Every binary source code has nonempty words by [F3], so every competing prefix code has both lengths at least one and cost at least the sum of the weights, namely by [F1]. Thus the size-two case is optimal.
Suppose the active list has size and assume as induction hypothesis that every sequence of minimum-weight merges on a positive normalized list of size with distinct serials gives an optimal code.
In an optimal code tree, no internal vertex has exactly one child: contracting its sole edge preserves the leaves and their incomparability, so [F2] still gives a prefix code, while every codeword below the vertex loses one bit. At least one symbol is below it by the trie definition, and its positive weight by [F1] makes the expected length strictly smaller, a contradiction. Hence every internal vertex has two children. Choose a leaf of maximal depth . Its sibling cannot be internal, since that sibling would have a descendant leaf deeper than ; it is therefore another leaf at depth .
The first selected pair gives a reduced list of size with positive weights summing to one and distinct serials. Its subsequent merges are minimum-weight choices by [F5] and [F6]. The induction hypothesis in step 1.5 therefore makes the reduced tree optimal for its weights.
Let be the two symbols selected by the algorithm for its first merge; [F5] and [F6] make them two symbols of least weight. Place them at a sibling pair of leaves at depth without increasing cost. If is currently at depth and a symbol of weight occupies the chosen depth- leaf, swapping them changes the two cost terms from to , a difference . Then place in the sibling leaf by the same calculation, since its current occupant has weight at least . Relabeling leaves preserves the prefix property; the original code was optimal, so the resulting code is still optimal.
Contract the two sibling leaves labeled to one leaf with weight . The contracted tree is a prefix code on the reduced alphabet and its cost is the original cost minus , since both leaf depths decrease by one. Conversely, expanding any reduced prefix code by replacing the codeword for with its two children labeled preserves the prefix property and increases cost by . Therefore contraction sends an optimal original code to an optimal reduced code, and expanding an optimal reduced code gives an optimal original code.
By step 4.1, expansion of that reduced tree is optimal for the original weights. The algorithm terminates and returns a prefix code by step 1.2; the base case step 1.4 and the induction step prove its optimality for every .
Ideal-real arithmetic coding is within two bits per block
Statement
For an ideal-real arithmetic code of a length- block from source ,
Facts & Assumptions
Given: The product block law , the pointwise bound of the ideal-real interval theorem, and the entropy definition .
Ideal-real interval coding is prefix-free and lossless: for every block.
Proof
Take the expectation of the pointwise inequality in [F1] under ; finite summation gives .
By [F2], [F4], and [F5], . For each coordinate , summing over blocks with gives , so has law . Linearity of the finite expectation and [F3] then give . Substitute in step 1.1.
The rational finite-register arithmetic code is prefix-free and lossless
Statement
For every configured rational model and fixed frame length in Exact finite-register arithmetic coding for rational block sources, let be the codeword assigned to by the encoder and put . The codebook on the lexicographically ordered block alphabet assigns each block a distinct binary word with and . The codebook on is prefix-free, and the decoder returns exactly . The configuration-time computation of terminates. The encoder uses exactly symbol updates, its bounded integer search terminates, and the decoder reads at most payload bits per frame without overflow.
Facts & Assumptions
Given: Positive integer frequencies , total , maximum frame length , fixed frame length , and the encoder/decoder in Exact finite-register arithmetic coding for rational block sources.
Finite discrete sources and product blocks: A block probability is .
Binary prefix codes and their code trees: A binary code is prefix-free when it is nonsingular and no codeword is a proper prefix of another.
Exact finite-register arithmetic coding for rational block sources: The integer endpoint update is and ; the codeword uses , , and .
Order, continuity, range, and the product, quotient, and reciprocal laws for the natural logarithm: The natural logarithm is strictly increasing.
Change of base and inversion of the positive-base real exponential: for every real .
Integer part: for every real there is exactly one integer with : For every real , .
Ceilings give the least positive integer meeting a real threshold: For every real , is an integer with .
Exact finite-register arithmetic coding for rational block sources: The endpoint, width, frequency, and cumulative-frequency registers have bits; the output index has at most bits; the temporary register has bits; the counters have the stated ceiling-logarithm widths.
Proof
After symbols, the scaled interval for the prefix is . At it is , so the claim holds. If it holds at , symbol occupies the subinterval beginning after the parent lower endpoint and of width ; the widths sum to the parent width because . Thus the update [F3] gives the claimed child interval. At it is with , so after division by its width is by [F1].
The search in [F3] finds with : is admissible since , and , so the largest admissible is at most . Hence . The selected dyadic cell has width . Its index is the floor of times the interval midpoint ; therefore the cell contains that midpoint and extends by at most to either side. Since is smaller than half the source-interval width, the cell lies inside the source interval. Also the midpoint is in , so [F7] gives and its -bit representation exists.
Length- source intervals partition by step 1.1, and step 2.1 places each nonempty emitted dyadic cell inside its own interval. Thus cells for distinct blocks are disjoint. A proper-prefix relation between emitted words would make one dyadic cell contain the other, which contradicts disjointness. The codewords are distinct and prefix-free by [F2]. A trie leaf therefore identifies one block, so the decoder returns exactly the encoded block.
Since , [F4], [F5], and [F6] give ; [F4] and [F8] give by step 1.1. Thus the payload length is at most . Also and , so and . At configuration, computing takes multiplications. The doubling loop for terminates because for every positive integer (by induction), and its first with is least. The encoder performs updates, tests at most values of , and emits at most bits; the decoder's trie traversal reads at most that many bits and outputs symbols. Since , , so each and fits its -bit register; also , so their -bit registers suffice. By [F9], if and , then and . Applying the increasing logarithm facts [F4]–[F6] gives and , so the counters hold counts up to and output lengths up to . By [F10], the numerator is at most , so the temporary register suffices; the denominator and scale also fit it. All other products in the interval update are at most . Hence every loop terminates and no configured per-frame register overflows.
Huffman expected length is within one bit of entropy
Statement
Let be the code returned by Deterministic binary Huffman coding for a finite full-support source . If , then If , then and .
Facts & Assumptions
Given: A finite full-support source and its deterministic Huffman code .
The deterministic Huffman code is prefix-optimal: The deterministic Huffman procedure returns a binary prefix code minimizing among all binary prefix codes on the same alphabet.
Every finite binary prefix code is uniquely decodable: Every binary prefix code is uniquely decodable.
Shannon bounds for finite binary codes: Every finite binary uniquely decodable code has expected length at least , and for a binary prefix code exists with expected length strictly less than .
Deterministic binary Huffman coding: For , the algorithm returns .
Proof
Suppose . By [F1], is a prefix code; [F2] makes it uniquely decodable. Apply the lower bound in [F3] to obtain .
The upper-bound construction in [F3] is a prefix code on the same source. Since minimizes expected length among prefix codes by [F1], its length is no larger than that constructed code, hence .
If , then by the source definition and by [F4], [F6], and [F7]. The returned codeword has length one by [F5], so .
The finite-register rational coder is within two bits per block
Statement
For the rational source and length- frames of Exact finite-register arithmetic coding for rational block sources,
Facts & Assumptions
Given: A product source block , its rational frequencies, and the pointwise length bound of the finite-register coding theorem.
The rational finite-register arithmetic code is prefix-free and lossless: for every block.
Proof
Take the expectation of [F1] under the finite product law [F2], obtaining .
By [F2], [F4], and [F5], . For each coordinate , summing over blocks with gives , so has law . Linearity of finite expectation and [F3] then give . Substitute in step 1.1.
5 · Examples, counterexamples and false statements
None yet.