Gibbs' inequality (non-negativity of KL divergence)
Provedgibbs_inequalityGibbs' inequality (equivalently, the non-negativity of Kullback-Leibler divergence), in elementary finite form. Let be two probability distributions on a finite set (, ), and suppose is positive wherever is (so the ratio is well-defined and finite on the support of ). Then
with equality exactly when . Equivalently, .
This is one of the two or three most-used inequalities in information theory: it underlies the fact that entropy is maximized by the uniform distribution, the data-processing inequality, and — as used in the entropy method in combinatorics (Spencer's partial coloring lemma) — the subadditivity of Shannon entropy for a pair of jointly distributed random variables, .
The proof is elementary: for each with , the standard bound applied at gives ; summing over the support of and using closes the inequality.
Formalization Note The hypothesis that does not vanish on the support of is necessary: without it, could be at a point where , and under Lean's junk-value convention would make the elementary per-term bound false there.
import Mathlib
open Finset
variable {γ : Type*} [Fintype γ]theorem gibbs_inequality (p q : γ → ℝ)
(hp0 : ∀ x, 0 ≤ p x) (hq0 : ∀ x, 0 ≤ q x)
(hpq : ∀ x, p x ≠ 0 → q x ≠ 0)
(hpsum : ∑ x, p x = 1) (hqsum : ∑ x, q x = 1) :
∑ x ∈ univ.filter (fun x => p x ≠ 0), p x * Real.log (q x / p x) ≤ 0 := by sorry