Alphabeta Math
Pipeline-generated
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.

✓ 11 results · all verified · 0 also independently AI-judged
Every result on this page is machine-checked by a proof checker and read in full and owner-audited; the judge is an additional, independent cross-model AI review of the proofs. The 11 not AI-judged were verified by owner audit (typically over a confirmed judge false positive), not failures.

Prefix Codes and Finite Lossless Coding

1 · Prerequisites

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 qi/Q, a public maximum block length N, and fixed length-n frames with known source model and outer frame count. Its integer registers are sized from N and Q; no constant-word-width streaming or approximate-frequency guarantee is claimed.

3 · Logical flowchart

4 · Definitions, theorems and proofs

DefinitionDefinition: Literature-sourcedProof: Not applicableOpen item page →

Finite discrete sources and product blocks

Definition

A finite discrete source is an integer m≥1 and a probability vector p=(p1,…,pm) on the alphabet X=[m]={1,…,m} such that pi>0 for every i. 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 X is the source support. In particular, the one-symbol source has m=1 and p1=1.

For n≥1, a block of length n is a word xn=(x1,…,xn)∈Xn. Its product probability is pn(xn):=∏t=1npxt. Finite distributivity gives ∑xn∈Xnpn(xn)=(∑i=1mpi)n=1, so pn is again a probability vector and has full support. When coding blocks, use lexicographic order on Xn; listing its mn words in that order identifies the block alphabet with [mn] for the code conventions below. Blocks are the only memoryless-source objects used on this page.

LemmaStatement: Literature-sourcedProof: AI-adaptedprecheck passOpen item page →

Nonnegativity of finite relative entropy with a positive reference

Statement

Let p=(pi)i=1m and q=(qi)i=1m be probability vectors with qi>0 for every i. Then D(p∥q)≥0, with equality if and only if p=q.

Facts & Assumptions

Given: Probability vectors p,q on [m], with qi>0 for every i.

[F1]

Finite distributions, entropy, divergence, and stochastic matrices: D(p∥q)=∑i:pi>0piln⁡(pi/qi) when no positive coordinate of p is paired with a zero coordinate of q.

[F2]

Information units and logarithm-base convention: ln⁡ denotes the natural logarithm log⁡ of the library's natural-logarithm definition.

[F5]

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 1/t.

[A1]

qi>0 for all i, so the finite relative entropy in [F1] is defined by its displayed finite sum.

Proof

1.1F2F3F4F5F6givenchoosealgebra

If t=1, then ln⁡t=t−1=0. Otherwise let a=min⁡{1,t} and b=max⁡{1,t}. By [F2] and [F3], ln⁡ is continuous on [a,b]; by [F5], it is differentiable on (a,b) with derivative 1/u. Applying [F6] gives c∈(a,b) with ln⁡t−ln⁡1=(t−1)/c, so ln⁡t=(t−1)/c by [F4]. If t>1, then c>1; if 0<t<1, then 0<c<1 and t−1<0. In either case (t−1)/c<t−1. Thus ln⁡t≤t−1, with equality only at t=1.

2.1F1A1step 1.1givenalgebra∎

Let S={i:pi>0}. By [F1], [A1], and step 1.1 applied to qi/pi for each i∈S, D(p∥q)=−∑i∈Spiln⁡(qi/pi)≥∑i∈S(pi−qi)=1−∑i∈Sqi≥0. If D(p∥q)=0, both inequalities are equalities. Equality in the last requires qi=0 outside S, and [A1] then forces S=[m]. Equality in the first requires each nonnegative gap from step 1.1, multiplied by pi>0, to vanish; hence qi/pi=1 for every i. Conversely p=q gives D(p∥q)=0 by [F1].

DefinitionDefinition: Literature-sourcedProof: Not applicableOpen item page →

Base-two entropy of a finite source

Definition

For a finite source p of Finite discrete sources and product blocks, define its base-two Shannon entropy, measured in bits, by H2(p):=H(p)ln⁡2=−∑i=1mpilog⁡2pi. Here H(p)=−∑ipiln⁡pi 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 log⁡2t=ln⁡(t)/ln⁡2. Substituting this identity termwise and using ∑ipi=1 gives the displayed equality. Every pi is positive by the source convention, so no zero-term convention is needed here.

DefinitionDefinition: Literature-sourcedProof: Not applicableOpen item page →

Finite binary source codes, extension, and expected length

Definition

A binary word is a finite sequence of symbols from {0,1}. The set {0,1}∗ includes the empty word ε, and {0,1}+ is the set of nonempty binary words. A binary source code for the finite source X=[m] is a function C:X→{0,1}+. Its codeword length is ℓi:=∣C(i)∣≥1.

The extension C∗:X∗→{0,1}∗ maps the empty source word to ε and maps i1⋯in to C(i1)⋯C(in). The code is uniquely decodable if C∗ is injective, including comparisons between source words of different lengths. Its expected length for source law p is Lp(C):=∑i=1mpiℓi.

DefinitionDefinition: Literature-sourcedProof: Not applicableOpen item page →

Binary prefix codes and their code trees

Definition

A binary code C is a prefix code if it is nonsingular and no codeword C(i) is a proper prefix of a different codeword C(j). A word u is a proper prefix of v when v=uw for some nonempty binary word w. Nonsingular means C(i)≠C(j) whenever i≠j.

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 0 or 1. 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.

TheoremStatement: Literature-sourcedProof: AI-adaptedprecheck passOpen item page →

McMillan inequality for finite binary uniquely decodable codes

Statement

Let C be a finite binary uniquely decodable code with lengths ℓi. Then ∑i=1m2−ℓi≤1.

Facts & Assumptions

Given: A finite source alphabet [m], a binary code C, and injectivity of its concatenation extension C∗.

[F1]

Finite binary source codes, extension, and expected length: Unique decodability means that the concatenation extension C∗ is injective on all finite source words, and every codeword is nonempty.

[F2]

Integer part: for every real x there is exactly one integer m with m≤x<m+1: For every real x, the integer part ⌊x⌋ satisfies ⌊x⌋≤x<⌊x⌋+1.

Proof

1.1F1givenalgebra

Put K:=∑i=1m2−ℓi and λ:=max⁡iℓi. For each integer k≥1, expand Kk=∑(i1,…,ik)∈[m]k2−(ℓi1+⋯+ℓik). For each total length s, let Nk,s count the tuples with ℓi1+⋯+ℓik=s. Their concatenated codewords are distinct by [F1] and each is a binary word of length s, of which there are exactly 2s because each of the s positions has two choices; hence Nk,s≤2s.

2.1step 1.1algebra

Since every ℓi≥1, the only possible totals satisfy k≤s≤kλ, so there are k(λ−1)+1 possible integer values of s. Grouping step 1.1 by s gives Kk=∑s=kkλNk,s2−s≤k(λ−1)+1. Therefore K≤(k(λ−1)+1)1/k for every k.

3.1F2step 2.1assume-contrachoosealgebradischarge-contradiction∎

Suppose K>1, set ϵ=K−1>0, and put a=λ−1≥0. By [F2], the integer k:=⌊1+2a/ϵ2⌋+1 satisfies k>1+2a/ϵ2 and k≥2, so k(k−1)ϵ2/2>ak. The binomial theorem gives Kk=(1+ϵ)k≥1+kϵ+(k2)ϵ2>1+ak, contradicting step 2.1, which gives Kk≤ak+1. Hence K≤1.

DefinitionDefinition: Literature-sourcedProof: Not applicableOpen item page →

Ideal-real arithmetic interval coding for a fixed block

Definition

Fix a finite full-support source p=(p1,…,pm), its symbol order 1<⋯<m, and a public block length n≥1. The ideal-real arithmetic interval of the empty prefix is [0,1). If a prefix has interval [a,b) and the next symbol is i, assign the extended prefix the half-open subinterval [a+(b−a)∑j<ipj, a+(b−a)∑j≤ipj). 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 xn has width w=∏t=1npxt=pn(xn)∈(0,1].

Use the base-two logarithm convention of Information units and logarithm-base convention. Its positive denominator and the strict increase of ln⁡ from Order, continuity, range, and the product, quotient, and reciprocal laws for the natural logarithm make log⁡2 strictly increasing; Change of base and inversion of the positive-base real exponential gives log⁡2(2u)=u and 2log⁡2x=x. Every floor is the integer part specified by Integer part: for every real x there is exactly one integer m with m≤x<m+1.

For a completed block xn, let I(xn)=[a,b) be its resulting interval, put w=b−a, and define r=⌊−log⁡2w⌋,s=r+2,k=⌊2sa+b2⌋. The dyadic cell represented by an s-bit index k is Js,k:=[k2−s,(k+1)2−s). The ideal-real codeword is the s-bit binary representation of k, with leading zeros. Each encoding frame contains exactly one length-n source block; the decoder knows p and n. A stream uses an externally known number of such frames. No finite-register or finite-precision implementation is specified by this definition.

Since 0<w≤1, the logarithm conventions above give r≥0 and hence s≥2. The interval midpoint lies in [0,1), so the integer-part property gives 0≤k<2s; the stated s-bit representation therefore exists.

LemmaStatement: Literature-sourcedProof: AI-adaptedprecheck passOpen item page →

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 C.

[F1]

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.

[F2]

Binary prefix codes and their code trees: Distinct codewords are nonempty, nonsingular, and no codeword is a proper prefix of another.

Proof

1.1F2given

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.

2.1F1F2step 1.1givenalgebra∎

To parse a word in the range of C∗, 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 C∗ is injective, which is unique decodability by [F1].

TheoremStatement: Literature-sourcedProof: AI-adaptedprecheck passOpen item page →

Binary Kraft criterion for finite positive codeword lengths

Statement

For a finite list of positive integers ℓ1,…,ℓm, there is a binary prefix code on [m] having codeword lengths ℓi if and only if ∑i=1m2−ℓi≤1.

Facts & Assumptions

Given: A finite source alphabet [m] and positive integer lengths ℓi.

[F1]

Kraft inequality and effective prefix-code allocation: Every prefix-free set D⊆{0,1}∗ satisfies ∑w∈D2−∣w∣≤1; conversely, a computably enumerable request list with total weight at most one admits an effective prefix-free allocation of the requested lengths.

[F2]

Finite binary source codes, extension, and expected length: A binary code assigns a nonempty finite binary word to each source symbol.

[F3]

Binary prefix codes and their code trees: A binary prefix code is nonsingular and no codeword is a proper prefix of another.

Proof

1.1F1F3given

If a prefix code has lengths ℓi, 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 ∑i2−ℓi≤1.

2.1F1F2F3givenconstruct∎

Suppose ∑i2−ℓi≤1. Enumerate the finite request list (i,ℓi) in increasing order of i; 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 i as C(i). Their positive lengths make C a binary source code by [F2]. Distinctness gives nonsingularity and prefix-freeness gives [F3], so the requested binary prefix code exists.

AlgorithmAlgorithm: Literature-sourcedProof: Not applicableOpen item page →

Deterministic binary Huffman coding

Definition

Input: A finite full-support source (m,p) as in Finite discrete sources and product blocks, with the symbols ordered 1,…,m.

Output: A binary prefix code CH on these symbols.

If m=1, return the one-bit codeword CH(1)=0.

If m≥2, make one active leaf for each source symbol i, with weight pi and serial number i. Repeatedly do the following while more than one node is active:

  1. Order active nodes lexicographically by (weight, serial number), using the ordinary order on real weights and then integer serials.
  2. 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.
  3. Insert this parent among the active nodes.

When one root remains, label every left edge 0 and every right edge 1. The codeword for symbol i 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 1,…,m, and each new parent receives a fresh serial.

For each m≥2, the algorithm executes exactly m−1 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.

TheoremStatement: Literature-sourcedProof: AI-adaptedprecheck passOpen item page →

Ideal-real interval coding is prefix-free and lossless

Statement

For fixed p and n, the code in Ideal-real arithmetic interval coding for a fixed block is injective and prefix-free on the lexicographically ordered block alphabet Xn. Its codeword length for xn is at most −log⁡2pn(xn)+2. Thus an n-block is recovered uniquely, and concatenated frames of this fixed block length are uniquely parsed.

Facts & Assumptions

Given: A finite full-support source p, a fixed block length n≥1, and the ideal-real interval and codeword construction.

[F1]

Finite discrete sources and product blocks: pn(xn)=∏t=1npxt>0 for every xn∈Xn.

[F2]

Ideal-real arithmetic interval coding for a fixed block: If a prefix has interval [a,b) and the next symbol is i, the extended prefix receives the half-open interval determined by the cumulative sums of p1,…,pm.

[F3]

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.

[F4]

Information units and logarithm-base convention: For b>1, log⁡bx=ln⁡x/ln⁡b and the denominator is positive.

[F6]

Change of base and inversion of the positive-base real exponential: For b>0, b≠1, log⁡b(bu)=u and blog⁡bx=x for x>0.

[F7]

Integer part: for every real x there is exactly one integer m with m≤x<m+1: For every real y, ⌊y⌋≤y<⌊y⌋+1.

[F8]

Ideal-real arithmetic interval coding for a fixed block: For a final interval width w, the code uses r=⌊−log⁡2w⌋, s=r+2, and the dyadic cell with index k=⌊2s(a+b)/2⌋.

Proof

1.1F1F2giveninduction

At every prefix, the m child intervals are disjoint half-open intervals whose union is the parent interval, because the cumulative probabilities increase from 0 to 1. Induction on prefix length therefore shows that the length-n intervals partition [0,1), and multiplying the successive width factors gives ∣I(xn)∣=pn(xn)>0 by [F1].

2.1F4F5F6F7F8step 1.1algebra

By [F8], put w=∣I(xn)∣ and r=⌊−log⁡2w⌋. Since 0<w≤1, [F4] and [F5] give −log⁡2w≥0, so [F7] gives r≥0 and r≤−log⁡2w<r+1. The same facts show that log⁡2 is strictly increasing, and [F6] gives log⁡2(2u)=u; therefore 2−(r+1)<w≤2−r. Thus the cell width δ:=2−(r+2) satisfies δ<w/2. If c is the midpoint of I(xn), then 0≤c<1 by step 1.1. By [F7], k=⌊2sc⌋ is an integer; since 0≤c<1, it satisfies 0≤k<2s and has an s-bit representation. Its cell [kδ,(k+1)δ) contains c and lies within distance δ of it; hence it is contained in the interior of I(xn).

3.1F3F8step 1.1step 2.1

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-n frames.

4.1F1F7F8step 1.1algebra∎

By [F7] and [F8], r≤−log⁡2w, so the emitted length is s=r+2≤−log⁡2w+2=−log⁡2pn(xn)+2 by step 1.1 and [F1]. This proves the pointwise bound without converting ideal-real interval arithmetic into a finite-register procedure.

AlgorithmAlgorithm: Literature-sourcedProof: Not applicableOpen item page →

Exact finite-register arithmetic coding for rational block sources

Definition

Configuration and frame model. The shared model consists of positive integers q1,…,qm, their total Q=∑iqi, the rational source pi=qi/Q, and a maximum frame length N≥1. Fix a frame length n with 1≤n≤N. At configuration time compute P=QN by N successive multiplications, then initialize B=0 and T=1 and repeat B←B+1, T←2T while T<P. The resulting B is the least integer b≥0 with QN≤2b; it is fixed for every frame using this configuration. Every frame is exactly one n-symbol block; the decoder knows q1,…,qm,Q,N,n. A complete stream contains a specified finite number R of such frames, supplied by an outer frame count. The arithmetic coder adds no end marker.

Register size. With B fixed by the configuration above, Endpoint, width, frequency, and cumulative-frequency registers have B+1 bits; the output index has at most B+2 bits. One 2B+4-bit temporary register stores intermediate products, numerators, denominators, and sums. The symbol-position counter uses ⌈log⁡2(N+1)⌉ bits and the range/output-length counter uses ⌈log⁡2(B+3)⌉ 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 ci=∑j<iqj and D=Qn. For an input block xn=(x1,…,xn), initialize L=0 and W=1. For t=1,…,n, set r=n−t and update L←L+WcxtQr,W←Wqxt. After the n updates, search the finite list j=0,…,B and retain the largest u satisfying 2uW≤D. Set s=u+2 and k=⌊2s(2L+W)2D⌋. Emit the s-bit binary representation of k, padded on the left with zeros; its dyadic cell is Js,k from Ideal-real arithmetic interval coding for a fixed block.

Decoder. For fixed n, generate the finite codebook by applying the encoder to every block in [m]n 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 B+2 bits. For a stream, repeat this operation exactly R 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 N. They grow when a new configuration with a larger N or Q is installed; no constant-word-width streaming guarantee is claimed.

TheoremStatement: Literature-sourcedProof: AI-adaptedprecheck passOpen item page →

Shannon bounds for finite binary codes

Statement

Let p be a finite full-support source and let H2(p) be its entropy in bits. Every finite binary uniquely decodable code C satisfies Lp(C)≥H2(p). If m≥2, the binary prefix code with lengths ℓi=⌈−log⁡2pi⌉ (called a Shannon code) has expected length strictly less than H2(p)+1. If m=1, the one-bit codeword 0 has length 1=H2(p)+1.

Facts & Assumptions

Given: A finite full-support source p=(pi)i=1m and a finite binary code C.

[F1]

Finite discrete sources and product blocks: m≥1, pi>0, and ∑ipi=1.

[F2]

Base-two entropy of a finite source: H2(p)=H(p)/ln⁡2=−∑ipilog⁡2pi.

[F3]

Finite binary source codes, extension, and expected length: Lp(C)=∑ipiℓi, and C is uniquely decodable exactly when its finite-word concatenation extension is injective.

[F4]

McMillan inequality for finite binary uniquely decodable codes: Every finite binary uniquely decodable code has ∑i2−ℓi≤1.

[F5]

Nonnegativity of finite relative entropy with a positive reference: For finite probability vectors p,q with qi>0, D(p∥q)≥0.

[F6]

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.

[F7]

Finite distributions, entropy, divergence, and stochastic matrices: H(p):=−∑ipiln⁡pi and D(p∥q):=∑i:pi>0piln⁡(pi/qi) when qi>0.

[F8]

Information units and logarithm-base convention: log⁡2x=ln⁡x/ln⁡2, and ln⁡2>0.

[F10]

Order, continuity, range, and the product, quotient, and reciprocal laws for the natural logarithm: For positive x,y, ln⁡(xy)=ln⁡x+ln⁡y, ln⁡(x/y)=ln⁡x−ln⁡y, and ln⁡(1/x)=−ln⁡x.

[F11]

Change of base and inversion of the positive-base real exponential: log⁡2(2u)=u for every real u.

[F12]

Ceilings give the least positive integer meeting a real threshold: ⌈x⌉=−⌊−x⌋ is an integer and x≤⌈x⌉.

[F13]

Integer part: for every real x there is exactly one integer m with m≤x<m+1: For every real y, ⌊y⌋≤y<⌊y⌋+1.

Proof

1.1F3F4givenconstruct

Let C be uniquely decodable and set K:=∑i2−ℓi>0. By [F3] and [F4], K≤1. Define qi:=2−ℓi/K; then q is a positive probability vector.

1.2F1F6F8F9F11F12givenconstructalgebra

Suppose m≥2. Full support gives 0<pi<1, so [F8] and [F9] give −log⁡2pi>0. By [F12], ℓi=⌈−log⁡2pi⌉ is a positive integer and ℓi≥−log⁡2pi. Thus log⁡2(2−ℓi)=−ℓi≤log⁡2pi by [F11]; since log⁡2 is strictly increasing by [F8] and [F9], this gives 2−ℓi≤pi and hence ∑i2−ℓi≤1. By [F6] there is a binary prefix code with these lengths.

2.1F2F3F5F7F8F9F10step 1.1givenalgebra

By [F2], [F3], [F5], [F7], [F8], and [F10], using the logarithm product and quotient laws for the integer powers in qi, 0≤D(p∥q)=∑ipiln⁡(pi/qi)=−H(p)+(ln⁡2)Lp(C)+ln⁡K. Since K≤1, [F9] gives ln⁡K≤0, so H(p)≤(ln⁡2)Lp(C)+ln⁡K≤(ln⁡2)Lp(C). Divide by ln⁡2>0 from [F8] and use [F2] to obtain H2(p)≤Lp(C).

3.1F1F2F8F9F12F13step 1.2givenalgebra∎

By [F12] and [F13], if ma=⌊−a⌋ then ma≤−a<ma+1, so a≤−ma=⌈a⌉<a+1. Therefore the Shannon code in step 1.2 satisfies Lp(C)=∑ipi⌈−log⁡2pi⌉<∑ipi(−log⁡2pi+1)=H2(p)+1. If m=1, then p1=1 by [F1], so H2(p)=0 by [F2] and [F8]–[F9]; the codeword 0 is a prefix code of length one.

TheoremStatement: Literature-sourcedProof: AI-adaptedprecheck passOpen item page →

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 Lp(C) among all binary prefix codes on the same alphabet. For a one-symbol source it returns the one-bit codeword 0, which is optimal among codes with nonempty codewords.

Facts & Assumptions

Given: A finite full-support source (m,p) and the deterministic algorithm Deterministic binary Huffman coding.

[F1]

Finite discrete sources and product blocks: The alphabet has m≥1 symbols, every source weight pi is positive, and ∑ipi=1.

[F2]

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.

[F3]

Finite binary source codes, extension, and expected length: Every codeword is nonempty and Lp(C)=∑ipiℓi.

[F4]

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.

[F5]

Deterministic binary Huffman coding: Order active nodes lexicographically by (weight, serial number), using the ordinary order on real weights and then integer serials.

[F6]

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.

[F7]

Deterministic binary Huffman coding: If m=1, return the one-bit codeword CH(1)=0.

Proof

technique · Induct on list size $m\ge2$: for every finite list of at least two positive weights with distinct serial numbers and total weight one, every sequence of minimum-weight merges, including every tie resolution, gives an optimal prefix code. The base case is size two; the one-symbol source is handled separately in step 1.1. A reduced list retains positive weights, total weight one, and distinct serials because each parent receives a fresh serial. The original source and each reduced active list are instances of this claim
1.1F2F3F7given

If m=1, the algorithm returns 0 by [F7]. Every codeword is nonempty by [F3], so every one-symbol code has expected length at least 1; the returned code is prefix-free by [F2] and attains that value.

1.2F2F6givenalgebra

Suppose m≥2. Every merge removes two nodes and adds one, so the active count decreases by exactly one; after m−1 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.

1.3F1F3F4givenchoosealgebra

An optimal prefix code exists. For every integer m≥1, m≤2m by induction: it holds at m=1, and 2m+1≥2m≥m+1. Thus [F4] applied to the length list (m,…,m) gives a finite prefix code, since its Kraft sum m2−m≤1; let its cost be L0. Any code with cost at most L0 has 1≤ℓi≤L0/pi for every i, because pi>0 and all summands in Lp 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 L0.

1.4F1F3F6givenbase

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 1,1 and cost 1. 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 1 by [F1]. Thus the size-two case is optimal.

1.5givenassume-hypih

Suppose the active list has size m≥3 and assume as induction hypothesis that every sequence of minimum-weight merges on a positive normalized list of size m−1 with distinct serials gives an optimal code.

2.1F1F2step 1.3algebra

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 d. Its sibling cannot be internal, since that sibling would have a descendant leaf deeper than d; it is therefore another leaf at depth d.

2.2F5F6step 1.5induction

The first selected pair a,b gives a reduced list of size m−1 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.

3.1F1F2F5F6step 2.1givenalgebra

Let a,b 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 d without increasing cost. If a is currently at depth e≤d and a symbol x of weight px≥pa occupies the chosen depth-d leaf, swapping them changes the two cost terms from pae+pxd to pad+pxe, a difference (pa−px)(d−e)≤0. Then place b in the sibling leaf by the same calculation, since its current occupant has weight at least pb. Relabeling leaves preserves the prefix property; the original code was optimal, so the resulting code is still optimal.

4.1F1F2F3step 3.1algebra

Contract the two sibling leaves labeled a,b to one leaf z with weight pz=pa+pb. The contracted tree is a prefix code on the reduced alphabet and its cost is the original cost minus pa+pb, since both leaf depths decrease by one. Conversely, expanding any reduced prefix code by replacing the codeword for z with its two children labeled a,b preserves the prefix property and increases cost by pa+pb. Therefore contraction sends an optimal original code to an optimal reduced code, and expanding an optimal reduced code gives an optimal original code.

5.1step 1.2step 4.1step 1.4step 2.2discharge-induction: step 2.2∎

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 m≥2.

CorollaryStatement: Literature-sourcedProof: AI-adaptedprecheck passOpen item page →

Ideal-real arithmetic coding is within two bits per block

Statement

For an ideal-real arithmetic code of a length-n block from source p, E[ℓ(Xn)]≤nH2(p)+2.

Facts & Assumptions

Given: The product block law pn, the pointwise bound of the ideal-real interval theorem, and the entropy definition H2(p).

[F1]

Ideal-real interval coding is prefix-free and lossless: ℓ(xn)≤−log⁡2pn(xn)+2 for every block.

[F2]

Finite discrete sources and product blocks: pn(xn)=∏t=1npxt.

[F3]

Base-two entropy of a finite source: H2(p)=−∑ipilog⁡2pi.

[F4]

Information units and logarithm-base convention: log⁡2t=ln⁡t/ln⁡2.

Proof

1.1F1F2givenalgebra

Take the expectation of the pointwise inequality in [F1] under pn; finite summation gives E[ℓ(Xn)]≤E[−log⁡2pn(Xn)]+2.

2.1F2F3F4F5step 1.1algebra∎

By [F2], [F4], and [F5], −log⁡2pn(Xn)=∑t=1n−log⁡2pXt. For each coordinate t, summing pn over blocks with xt=i gives pi(∑jpj)n−1=pi, so Xt has law p. Linearity of the finite expectation and [F3] then give E[−log⁡2pn(Xn)]=∑t=1nH2(p)=nH2(p). Substitute in step 1.1.

TheoremStatement: Literature-sourcedProof: AI-adaptedprecheck passOpen item page →

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 C(xn) be the codeword assigned to xn by the encoder and put ℓ(xn):=∣C(xn)∣. The codebook on the lexicographically ordered block alphabet [m]n assigns each block a distinct binary word with ℓ(xn)≤B+2 and ℓ(xn)≤−log⁡2pn(xn)+2. The codebook on [m]n is prefix-free, and the decoder returns exactly xn. The configuration-time computation of B terminates. The encoder uses exactly n symbol updates, its bounded integer search terminates, and the decoder reads at most B+2 payload bits per frame without overflow.

Facts & Assumptions

Given: Positive integer frequencies qi, total Q=∑iqi, maximum frame length N, fixed frame length 1≤n≤N, and the encoder/decoder in Exact finite-register arithmetic coding for rational block sources.

[F1]

Finite discrete sources and product blocks: A block probability is pn(xn)=∏t=1npxt.

[F2]

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.

[F3]

Exact finite-register arithmetic coding for rational block sources: The integer endpoint update is L←L+WcxtQn−t and W←Wqxt; the codeword uses u=max⁡{j≤B:2jW≤Qn}, s=u+2, and k=⌊2s(2L+W)/(2Qn)⌋.

[F4]

Information units and logarithm-base convention: log⁡2x=ln⁡x/ln⁡2, with ln⁡2>0.

[F6]

Change of base and inversion of the positive-base real exponential: log⁡2(2v)=v for every real v.

[F7]

Integer part: for every real x there is exactly one integer m with m≤x<m+1: For every real y, ⌊y⌋≤y<⌊y⌋+1.

[F8]

Order, continuity, range, and the product, quotient, and reciprocal laws for the natural logarithm: ln⁡(x/y)=ln⁡x−ln⁡y for positive x,y.

[F9]

Ceilings give the least positive integer meeting a real threshold: For every real x, ⌈x⌉ is an integer with x≤⌈x⌉.

[F10]

Exact finite-register arithmetic coding for rational block sources: The endpoint, width, frequency, and cumulative-frequency registers have B+1 bits; the output index has at most B+2 bits; the temporary register has 2B+4 bits; the counters have the stated ceiling-logarithm widths.

Proof

1.1F1F3giveninduction

After t symbols, the scaled interval for the prefix is [L,L+WQn−t). At t=0 it is [0,Qn), so the claim holds. If it holds at t−1, symbol i occupies the subinterval beginning WciQn−t after the parent lower endpoint and of width WqiQn−t; the widths sum to the parent width because ∑iqi=Q. Thus the update [F3] gives the claimed child interval. At t=n it is [L,L+W) with W=∏t=1nqxt, so after division by D=Qn its width is W/D=pn(xn)>0 by [F1].

2.1F1F3F7step 1.1givenalgebra

The search in [F3] finds u with 2uW≤D<2u+1W: j=0 is admissible since W≤Qn, and D/W≤Qn≤2B, so the largest admissible u is at most B. Hence 2−(u+1)<W/D≤2−u. The selected dyadic cell has width δ=2−(u+2)<W/(2D). Its index k is the floor of 2s times the interval midpoint (2L+W)/(2D); 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 [0,1), so [F7] gives 0≤k<2s and its s-bit representation exists.

3.1F2step 1.1step 2.1given

Length-n source intervals partition [0,1) 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.

4.1F3F4F5F6F8F9F10step 1.1step 2.1givenalgebra∎

Since 2u≤D/W, [F4], [F5], and [F6] give u=log⁡2(2u)≤log⁡2(D/W); [F4] and [F8] give log⁡2(D/W)=−log⁡2(W/D)=−log⁡2pn(xn) by step 1.1. Thus the payload length s=u+2 is at most −log⁡2pn(xn)+2. Also W≥1 and D≤QN≤2B, so u≤B and s≤B+2. At configuration, computing P=QN takes N multiplications. The doubling loop for B terminates because 2P≥P for every positive integer P (by induction), and its first B with 2B≥P is least. The encoder performs n updates, tests at most B+1 values of j, and emits at most B+2 bits; the decoder's trie traversal reads at most that many bits and outputs n symbols. Since N≥1, Q≤QN≤2B, so each qi and ci fits its B+1-bit register; also L,W,D≤2B, so their B+1-bit registers suffice. By [F9], if bN=⌈log⁡2(N+1)⌉ and bB=⌈log⁡2(B+3)⌉, then bN≥log⁡2(N+1) and bB≥log⁡2(B+3). Applying the increasing logarithm facts [F4]–[F6] gives 2bN≥N+1 and 2bB≥B+3, so the counters hold counts up to N and output lengths up to B+2. By [F10], the numerator 2s(2L+W) is at most 2B+2⋅3⋅2B<22B+4, so the temporary register suffices; the denominator 2D and scale 2s also fit it. All other products in the interval update are at most D. Hence every loop terminates and no configured per-frame register overflows.

CorollaryStatement: Literature-sourcedProof: AI-adaptedprecheck passOpen item page →

Huffman expected length is within one bit of entropy

Statement

Let CH be the code returned by Deterministic binary Huffman coding for a finite full-support source p. If m≥2, then H2(p)≤Lp(CH)<H2(p)+1. If m=1, then H2(p)=0 and Lp(CH)=1.

Facts & Assumptions

Given: A finite full-support source p and its deterministic Huffman code CH.

[F1]

The deterministic Huffman code is prefix-optimal: The deterministic Huffman procedure returns a binary prefix code minimizing Lp(C) among all binary prefix codes on the same alphabet.

[F2]

Every finite binary prefix code is uniquely decodable: Every binary prefix code is uniquely decodable.

[F3]

Shannon bounds for finite binary codes: Every finite binary uniquely decodable code has expected length at least H2(p), and for m≥2 a binary prefix code exists with expected length strictly less than H2(p)+1.

[F4]

Base-two entropy of a finite source: H2(p)=−∑ipilog⁡2pi.

[F5]

Deterministic binary Huffman coding: For m=1, the algorithm returns CH(1)=0.

[F6]

Information units and logarithm-base convention: log⁡2t=ln⁡t/ln⁡2 with ln⁡2>0.

Proof

1.1F1F2F3given

Suppose m≥2. By [F1], CH is a prefix code; [F2] makes it uniquely decodable. Apply the lower bound in [F3] to obtain H2(p)≤Lp(CH).

2.1F1F3step 1.1algebra

The upper-bound construction in [F3] is a prefix code on the same source. Since CH minimizes expected length among prefix codes by [F1], its length is no larger than that constructed code, hence Lp(CH)<H2(p)+1.

3.1F4F5F6F7givenalgebra∎

If m=1, then p1=1 by the source definition and H2(p)=0 by [F4], [F6], and [F7]. The returned codeword has length one by [F5], so Lp(CH)=1.

CorollaryStatement: Literature-sourcedProof: AI-adaptedprecheck passOpen item page →

The finite-register rational coder is within two bits per block

Statement

For the rational source and length-n frames of Exact finite-register arithmetic coding for rational block sources, E[ℓ(Xn)]≤nH2(p)+2.

Facts & Assumptions

Given: A product source block Xn, its rational frequencies, and the pointwise length bound of the finite-register coding theorem.

[F1]

The rational finite-register arithmetic code is prefix-free and lossless: ℓ(xn)≤−log⁡2pn(xn)+2 for every block.

[F2]

Finite discrete sources and product blocks: pn(xn)=∏t=1npxt.

[F3]

Base-two entropy of a finite source: H2(p)=−∑ipilog⁡2pi.

[F4]

Information units and logarithm-base convention: log⁡2t=ln⁡t/ln⁡2.

Proof

1.1F1F2givenalgebra

Take the expectation of [F1] under the finite product law [F2], obtaining E[ℓ(Xn)]≤E[−log⁡2pn(Xn)]+2.

2.1F2F3F4F5step 1.1algebra∎

By [F2], [F4], and [F5], −log⁡2pn(Xn)=∑t=1n−log⁡2pXt. For each coordinate t, summing pn over blocks with xt=i gives pi(∑jpj)n−1=pi, so Xt has law p. Linearity of finite expectation and [F3] then give E[−log⁡2pn(Xn)]=nH2(p). Substitute in step 1.1.

5 · Examples, counterexamples and false statements

None yet.

Sources