TITLE: Why is $\displaystyle\int_{x=-\infty}^{x=\infty} f(x) \delta(x) \, \mathrm{d}x = f(0)$?
QUESTION [5 upvotes]: I understand that $\delta(x)=0$ whenever $x \ne 0$ and that $\displaystyle\int_{x=-a}^{x=b}  \delta(x) \, \mathrm{d}x = 1 \space$ $\forall\, a,b \gt 0$ and also that $\displaystyle\int_{x=-\infty}^{x=\infty}  \delta(x-a) \, \mathrm{d}x = 1$. 
But I see no justification that $\color{blue}{\displaystyle\int_{x=-\infty}^{x=\infty} f(x) \delta(x) \, \mathrm{d}x = f(0)}$ for any arbitrary function $f(x)$.
I'm asking this question because the formula marked blue was given to me in response to this previous related question asked by me. But every-time I search the internet for an explanation of its derivation all I get is the same formula stated without proof. Hence, could someone please prove and/or explain the origin of the formula marked blue?
Thank you.

REPLY [8 votes]: You can define the delta function, as folows: 
Define
$$
\delta_a(x) = 
\begin{cases}
1/a & |x|\leq a/2\\
0 & \text{otherwise.}
\end{cases}
$$
So we see that this function defines a box of width $a$ and height $1/a$, so that 
$$
\int_{\mathbb{R}} \delta_a(x)\;dx=1,\quad\forall a\in\mathbb{R}_{>0}.
$$
We can now think of taking the limit as $a\to0⁺$, whereas our box tends to something infinitely thin and infinitely tall but still with total area $1$. In that case we also have 
$$
\lim_{a\to\,0⁺}\delta_a(x) = 0, \quad\forall x\neq0.
$$
Let's take the condition
$$
\int_{\mathbb{R}} \delta(x)f(x)\;dx = f(0)
$$
as the definition of the delta function, and let's see whether $\lim_{a\to0⁺}\delta_a(x)=\delta(x)$. For any (integrable) $f$ we have
$$
\int_{-\infty}^\infty \delta_a(x)f(x)\;dx=\int_{-a/2}^{a/2} \delta_a(x)f(x)\;dx=\frac{1}{a}\int_{-a/2}^{a/2} f(x)\;dx,
$$
Where we have used that $\delta_a(x)=1/a$ on $[-a/2,a/2]$ and $0$ elsewhere.
Now by the mean-value theorem we have that there exists a number $\mu(a)\in[-a/2,a/2]$, such that $f(\mu(a))$ is the mean-value of $f$ on $[-a/2,a/2]$. The result is that we can write
$$
\int_{-a/2}^{a/2} f(x)\;dx=f\big(\mu(a)\big)\int_{-a/2}^{a/2}dx= af\big(\mu(a)\big),
$$
which in turn gives us
$$
\int_{-\infty}^\infty \delta_a(x)f(x)\;dx=f\big(\mu(a)\big).
$$
Taking the limit as $a\to0⁺$, we see that $\mu(a)$, being confined to the interval $[-a/2,a/2]$, which tends to the singleton $\{0\}$ as $a$ tends to $0⁺$, must also go to $0$, and hence, assuming continuity of $f$, we have
$$
\int_{-\infty}^\infty \lim_{a\to\,0⁺}\,\delta_a(x)f(x)\;dx=\lim_{a\to\,0⁺}\int_{-\infty}^\infty \delta_a(x)f(x)\;dx=\lim_{a\to0⁺}f\big(\mu(a)\big)=f(0).
$$
As desired.