Why an Absolute Difference Has Two Branches
The distance between two measurements is often more useful than their signed difference. If \(Z=X-Y\), then \(D=|X-Y|=|Z|\) records the magnitude but discards the sign. Every positive value \(t\) of \(D\) can come from either \(Z=t\) or \(Z=-t\). Consequently, the density of \(D\) combines contributions from both sides of the distribution of \(Z\).
This is a many-to-one transformation: the two inputs \(t\) and \(-t\) map to the same output \(t\). At zero there is only one preimage, but a point mass at zero can arise if \(X=Y\) has positive probability. Independence and atomlessness rule out that equality mass; dependence does not.
Definition and Branch Formula
The phrase “for almost every” is appropriate because densities are defined only up to changes on sets of Lebesgue measure zero. The displayed integral for \(f_Z\) is finite for almost every \(z\), and is a density: the nonnegative integrand permits Tonelli’s theorem, and $$ \int_{-\infty}^{\infty}\int_{-\infty}^{\infty}f_X(x)f_Y(x-z)\,dx\,dz =\int_{-\infty}^{\infty} f_X(x)\left[\int_{-\infty}^{\infty}f_Y(x-z)\,dz\right]dx =1. $$
Proof. Independence gives the joint density \(f_X(x)f_Y(y)\) for \((X,Y)\). For any nonnegative measurable function \(h\), change variables from \((x,y)\) to \((x,z)\), where \(z=x-y\), so \(y=x-z\). The absolute Jacobian determinant is \(1\). Thus $$ E[h(Z)] =\int_{\mathbb R}\int_{\mathbb R}h(x-y)f_X(x)f_Y(y)\,dy\,dx =\int_{\mathbb R}h(z)\left[\int_{\mathbb R}f_X(x)f_Y(x-z)\,dx\right]dz. $$ This identifies the stated density of \(Z\). For any nonnegative measurable function \(q\), split the integral for \(E[q(|Z|)]\) into the positive and negative half-lines and substitute \(t=-z\) in the negative part: $$ E[q(D)] =\int_0^\infty q(t)f_Z(t)\,dt+\int_0^\infty q(t)f_Z(-t)\,dt =\int_0^\infty q(t)\bigl[f_Z(t)+f_Z(-t)\bigr]\,dt. $$ There is no remaining point mass at zero. Indeed, independence and the existence of a density for \(Y\) give $$ P(X=Y)=\int_{\mathbb R}P(Y=x)\,dF_X(x)=0, $$ since \(P(Y=x)=0\) for every fixed \(x\). Hence \(P(D=0)=0\), proving the result. \(\square\)
The branch formula can also be read directly from the change of variables \(t=|z|\): for \(t>0\), the inverse values are \(z=t\) and \(z=-t\), and each branch has derivative magnitude \(1\). The two density contributions therefore add; neither is multiplied by an extra factor of \(1/2\).
Worked Continuous Examples
Worked Example: Difference of Two Uniform Variables
Let \(X\) and \(Y\) be independent \(\operatorname{Uniform}(0,1)\) variables. Their densities equal \(1\) on \((0,1)\) and \(0\) elsewhere. For \(-1<z<1\), the integrand \(f_X(x)f_Y(x-z)\) equals \(1\) exactly where both \(x\in(0,1)\) and \(x-z\in(0,1)\).
If \(0<z<1\), the overlap is \(z<x<1\), of length \(1-z\); if \(-1<z<0\), its length is \(1+z\). Therefore $$ f_Z(z)= \begin{cases} 1-|z|,& |z|<1,\\ 0,& |z|\geq 1. \end{cases} $$ For \(0<t<1\), both branches contribute: $$ f_D(t)=f_Z(t)+f_Z(-t)=(1-t)+(1-t)=2(1-t). $$ Outside this interval the density is zero. The result integrates to \(1\), since \(\int_0^1 2(1-t)\,dt=1\). Also, \(P(D=0)=0\) by independence and atomlessness.
Worked Example: Absolute Difference of Two Standard Normals
Let \(X,Y\) be independent \(N(0,1)\) variables. Using their densities in the difference formula gives $$ f_Z(z)=\frac{1}{2\pi}\int_{-\infty}^{\infty} \exp\left[-\frac{x^2+(x-z)^2}{2}\right]dx. $$ Complete the square: \(x^2+(x-z)^2=2(x-z/2)^2+z^2/2\). Therefore $$ f_Z(z)=\frac{e^{-z^2/4}}{2\pi}\int_{-\infty}^{\infty}e^{-(x-z/2)^2}\,dx =\frac{1}{2\sqrt{\pi}}e^{-z^2/4}, $$ using \(\int_{\mathbb R}e^{-u^2}\,du=\sqrt{\pi}\). The density is symmetric, so for \(t>0\), $$ f_D(t)=f_Z(t)+f_Z(-t)=\frac{1}{\sqrt{\pi}}e^{-t^2/4}. $$ As a check, substituting \(u=t/2\) gives \(\int_0^\infty f_D(t)\,dt=(2/\sqrt{\pi})\int_0^\infty e^{-u^2}\,du=1\). There is no atom at zero.
When Atoms Are Present
A density describes only the part of a distribution that is absolutely continuous with respect to Lebesgue measure. If \(X\) or \(Y\) also has atoms, the law of \(D\) may have point masses as well as a density. In particular, equality can produce an atom at zero. For independent variables with arbitrary distributions, its probability is $$ P(D=0)=P(X=Y)=\sum_{a}P(X=a)P(Y=a), $$ where the sum is over locations that are atoms of both variables. To see this, condition on \(X\): \(P(X=Y)=\int P(Y=x)\,dF_X(x)\). The integrand is zero except at atoms of \(Y\), and only atoms of \(X\) at those same locations contribute. The sum may be finite or countable.
For a useful mixed-model formula, suppose each distribution consists only of a density and countably many atoms, with no other component: $$ P_X(dx)=f_X(x)\,dx+\sum_a p_a\delta_a(dx),\qquad P_Y(dy)=f_Y(y)\,dy+\sum_b q_b\delta_b(dy). $$ For \(t>0\), the absolutely continuous part of the law of \(D\) has density $$ g_D(t)=\int_{\mathbb R} f_X(x)f_Y(x-t)\,dx+ \int_{\mathbb R} f_X(x)f_Y(x+t)\,dx +\sum_a p_a\bigl[f_Y(a-t)+f_Y(a+t)\bigr] +\sum_b q_b\bigl[f_X(b-t)+f_X(b+t)\bigr]. $$ Each term corresponds to one continuous pairing: density with density, or an atom of one variable with the density of the other. Atom-atom pairings instead give discrete mass. At a location \(d\geq0\), their contribution is \(\sum_{a,b:\,|a-b|=d}p_aq_b\). Thus positive atoms are possible too; they are not part of \(g_D\). If distributions have singular-continuous components, further non-density components may occur, so this mixed-model formula does not cover them.
Worked Example: A Zero Atom and a Positive Atom
Let \(X\) have mass \(0.4\) at \(0\) and, with probability \(0.6\), be uniform on \((0,1)\). Let \(Y\), independently, have mass \(0.5\) at \(0\), mass \(0.2\) at \(2\), and, with probability \(0.3\), be uniform on \((0,1)\). We account for each pairing of components.
Both atoms: The pair \((X,Y)=(0,0)\) has probability \(0.4(0.5)=0.20\), giving an atom of \(D\) at \(0\). The pair \((0,2)\) has probability \(0.4(0.2)=0.08\), giving an atom at \(2\).
Both uniform components: Their combined probability is \(0.6(0.3)=0.18\). The absolute difference of two independent uniforms has density \(2(1-t)\) for \(0<t<1\), so this pairing contributes \(0.36(1-t)\) there.
One atom at zero and one uniform component: The \(X=0\), \(Y\)-uniform pairing has probability \(0.4(0.3)=0.12\) and contributes density \(0.12\) on \((0,1)\). The \(X\)-uniform, \(Y=0\) pairing has probability \(0.6(0.5)=0.30\) and contributes density \(0.30\) on \((0,1)\).
The atom at \(Y=2\) and the uniform component of \(X\): This pairing has probability \(0.6(0.2)=0.12\). If \(X\) is uniform on \((0,1)\), then \(D=2-X\) is uniform on \((1,2)\), so its density contribution is \(0.12\) there. Combining the contributions, the full law is $$ P(D=0)=0.20,\qquad f_D(t)= \begin{cases} 0.36(1-t)+0.42,&0<t<1,\\ 0.12,&1<t<2,\\ 0,&\text{otherwise}, \end{cases} \qquad P(D=2)=0.08. $$ The continuous mass is \(\int_0^1[0.36(1-t)+0.42]dt+\int_1^2 0.12\,dt=0.60+0.12=0.72\). Adding the atoms gives \(0.72+0.20+0.08=1\), as required.
Common Pitfall and Why the Distinction Matters
A common mistake is to say, “\(X\) and \(Y\) have densities, so \(P(X=Y)=0\),” without checking their joint structure. Marginal densities alone do not imply this: if \(X=Y\) is a single uniform random variable, both marginals have densities but \(P(X=Y)=1\). The correction is to state the needed condition. Independence and atomless marginals suffice for \(P(X=Y)=0\); a jointly absolutely continuous distribution also suffices. In the density derivation above, independence supplies a joint density. More generally, two independent atomless variables have no equality atom even if their distributions are not described by densities.
Another error is to use only \(f_Z(t)\) for \(t>0\). That omits cases where \(Z=-t\), even though they produce the same absolute difference. Conversely, adding the branches does not mean that an atom at zero should be doubled: zero has only one preimage, and its probability must be computed directly as \(P(X=Y)\). Keeping the density contributions and point masses separate is essential whenever a model has both continuous and discrete components.
Check Your Understanding
Use the branch formula and distinguish continuous density from point mass.
- If \(Z=X-Y\) has density \(f_Z\), what is the density of \(|Z|\) at a positive value \(t\)? Why are there two terms?
- For independent uniform \((0,1)\) variables, what is the density of their absolute difference on \(0<t<1\), and what is its integral?
- Can two dependent variables with densities satisfy \(P(X=Y)=1\)? Give a construction or explain why not.
- If independent \(X\) and \(Y\) both have an atom at \(a\), what contribution does that pair make to \(P(|X-Y|=0)\)?
- In the mixed example, why is the mass \(0.08\) at \(D=2\) not included in the displayed density?