In Data compression, particularly Universal source coding, we define the redundancy of a code with Codeword lengths l(x), and implied probability q(x)=2−l(x) (see Source coding theorem), as the difference between the expected length of the code (under the true Information source X distribution p) and the lower limit for the expected length:
R(p,q)=Ep[l(X)]−Ep[logp(X)1]
= ∑xp(x)(l(x)−logp(x)1)
=∑xp(x)(logq(x)1−logp(x)1)
=∑xp(x)logq(x)p(x)
=D(p∣∣q)
where q(x)=2−l(x) is the distribution that corresponds to the codeword lengths l(X), and D(⋅∣∣⋅) is the Relative entropy