title: Gibbs' inequality
text: # Gibbs' inequality
  
  In information theory, Gibbs' inequality is a statement about the information entropy of a discrete probability distribution. Several other bounds on the entropy of probability distributions are derived from Gibbs' inequality, including Fano's inequality. It was first presented by J. Willard Gibbs in the 19th century.
  
  ## Gibbs' inequality
  
  Suppose that
  
      $P=\{p_{1},\ldots ,p_{n}\}$
  
  is a discrete probability distribution. Then for any other probability distribution
  
      $Q=\{q_{1},\ldots ,q_{n}\}$
  
  the following inequality between positive quantities (since $p_i$ and $q_i$ are between zero and one) $holds:^{:68}$
  
      $-\sum _{i=1}^{n}p_{i}\log p_{i}\leq -\sum _{i=1}^{n}p_{i}\log q_{i}$
  
  with equality if and only if
  
      $p_{i}=q_{i}$
  
  for all i. Put in words, the information entropy of a distribution P is less than or equal to its cross entropy with any other distribution Q.
  
  The difference between the two quantities is the Kullback–Leibler divergence or relative entropy, so the inequality can also be $written:^{:34}$
  
      $D_{\mathrm {KL} }(P\|Q)\equiv \sum _{i=1}^{n}p_{i}\log {\frac {p_{i}}{q_{i}}}\geq 0.$
  
  Note that the use of base-2 logarithms is optional, and allows one to refer to the quantity on each side of the inequality as an "average surprisal" measured in bits.
  
  ## Proof
  
  For simplicity, we prove the statement using the natural logarithm (ln). Because
  
      $\log _{b}a={\frac {\ln a}{\ln b}},$
  
  the particular logarithm base b > 1 that we choose only scales the relationship by the factor 1 / ln b.
  
  Let $I$ denote the set of all $i$ for which $p_i$ is non-zero. Then, since $\ln x\leq x-1$ for all x > 0, with equality if and only if x=1, we have:
  
      $-\sum _{i\in I}p_{i}\ln {\frac {q_{i}}{p_{i}}}\geq -\sum _{i\in I}p_{i}\left({\frac {q_{i}}{p_{i}}}-1\right)$$=-\sum _{i\in I}q_{i}+\sum _{i\in I}p_{i}=-\sum _{i\in I}q_{i}+1\geq 0$
  
  The last inequality is a consequence of the $p_i$ and $q_i$ being part of a probability distribution. Specifically, the sum of all non-zero values is 1. Some non-zero $q_i,$ however, may have been excluded since the choice of indices is conditioned upon the $p_i$ being non-zero. Therefore, the sum of the $q_i$ may be less than 1.
  
  So far, over the index set $I$, we have:
  
      $-\sum _{i\in I}p_{i}\ln {\frac {q_{i}}{p_{i}}}\geq 0$,
  
  or equivalently
  
      $-\sum _{i\in I}p_{i}\ln q_{i}\geq -\sum _{i\in I}p_{i}\ln p_{i}$.
  
  Both sums can be extended to all $i=1,\ldots ,n$, i.e. including $p_{i}=0$, by recalling that the expression $p\ln p$ tends to 0 as $p$ tends to 0, and $(-\ln q)$ tends to $\infty$ as $q$ tends to 0. We arrive at
  
      $-\sum _{i=1}^{n}p_{i}\ln q_{i}\geq -\sum _{i=1}^{n}p_{i}\ln p_{i}$
  
  For equality to hold, we require
  
  * ${\frac {q_{i}}{p_{i}}}=1$ for all $i\in I$ so that the equality $\ln {\frac {q_{i}}{p_{i}}}={\frac {q_{i}}{p_{i}}}-1$ holds,
  * and $\sum _{i\in I}q_{i}=1$ which means $q_{i}=0$ if $i\notin I$, that is, $q_{i}=0$ if $p_{i}=0$.
  
  This can happen if and only if $p_{i}=q_{i}$ for $i=1,\ldots ,n$.
  
  ## Alternative proofs
  
  The result can alternatively be proved using Jensen's inequality, the log sum inequality, or the fact that the Kullback-Leibler divergence is a form of Bregman divergence. Below we give a proof based on Jensen's inequality:
  
  Because log is a concave function, we have that:
  
      $\sum _{i}p_{i}\log {\frac {q_{i}}{p_{i}}}\leq \log \sum _{i}p_{i}{\frac {q_{i}}{p_{i}}}=\log \sum _{i}q_{i}\leq 0$
  
  Where the first inequality is due to Jensen's inequality, and the last equality is due to the same reason given in the above proof.
  
  Furthermore, since $\log$ is strictly concave, by the equality condition of Jensen's inequality we get equality when
  
      ${\frac {q_{1}}{p_{1}}}={\frac {q_{2}}{p_{2}}}=\cdots ={\frac {q_{n}}{p_{n}}}$
  
  and
  
      $\sum _{i}q_{i}=1$
  
  Suppose that this ratio is $\sigma$, then we have that
  
      $1=\sum _{i}q_{i}=\sum _{i}\sigma p_{i}=\sigma$
  
  Where we use the fact that $p,q$ are probability distributions. Therefore, the equality happens when $p=q$.
  
  ## Corollary
  
  The entropy of $P$ is bounded $by:^{:68}$
  
      $H(p_{1},\ldots ,p_{n})\leq \log n.$
  
  The proof is trivial – simply set $q_{i}=1/n$ for all i.
  
  