A relative entropy (Kullback–Leibler divergence) is an extended real number DKL(P∥Q) associated to two probability measures P and Q on the same measurable space, defined (when P is absolutely continuous with respect to Q) by
DKL(P∥Q)=∫log(dQdP)dP,
where dQdP is the Radon–Nikodym derivative (see the Radon–Nikodym theorem). If P is not absolutely continuous with respect to Q, one sets DKL(P∥Q)=+∞.
In the discrete case with mass functions p,q on a countable set, this becomes
DKL(P∥Q)=x∑p(x)logq(x)p(x),
with the convention that terms with p(x)=0 contribute 0, and any x with p(x)>0 and q(x)=0 forces DKL(P∥Q)=+∞. Relative entropy is always nonnegative by Gibbs' inequality, equals 0 iff P=Q (in the appropriate sense), and is not symmetric in general. It is related to other discrepancy notions such as total variation distance (for example via Pinsker's inequality).