General equation for the change of variable (random variables' functions) I have learned that for monotonic functions, one can obtain the formula for the pdf of a random variable, by using the following:
$$f_Y(y) = \left| \frac{dx}{dy}\right|f_X(x)$$
where $x$ is $g^{-1}(y)$ and $Y=g(X)$
Then I have the following in my notes: "the most general equation for change of variables (includes non-monotonic functions)":
$$f_Y(y) = \int_{-\infty}^{+\infty}\delta (g(x)-y)f_X(x)dx$$
I am not quite sure where that formula comes from, and why it holds. And how would I evaluate it... Do you have some examples perhaps? I don't know how I would evaluate that integral. I know that:
$$\int_{-\infty}^{+\infty}\delta (x-x_0) dx=1$$
and that
$$\int_{-\infty}^{+\infty}g(x) \delta(x-x_0) dx=g(x_0)$$
 A: I've never worked with dirac delta function, but here is my stab at it.
Under the stipulations given here, let $h(x) = g(x)-y$, then $h'(x) = g'(x)$, and
\begin{align*}
f_Y(y) &= \int_{-\infty}^{\infty}\delta (h(x))f_X(x)dx\\
&= \int_{-\infty}^\infty\sum_i \frac{\delta(x-x_i)}{|h'(x_i)|}f_X(x)\,dx\\
&= \sum_i\int_{-\infty}^\infty \frac{\delta(x-x_i)}{|h'(x_i)|}f_X(x)\,dx\\
&= \sum_i\frac{1}{|h'(x_i)|}f_X(x_i)\tag{$\star$},
\end{align*}
where $i$ is such that $x_i$ is a root of $h(x)$.
This $(\star)$ is the many-to one formula and is particularly useful when we have to make a many-to-one transform. For example, say $X\sim \text{unif}(-1,1)$, and I would like to find the density of $Y = X^2$. Notice that over $(-1,1)$, $Y$ is not one-to-one but two-to-one. Thus we apply the many-to-one formula. $X = \pm \sqrt Y$, and 
$$f_Y(y)=\frac{f_X(-\sqrt y)}{\left|\frac{dy}{dx}\right|_{-\sqrt y}}+\frac{f_X(\sqrt y)}{\left|\frac{dy}{dx}\right|_{\sqrt y}} = \frac{1/2}{|2(-\sqrt y)|}+\frac{1/2}{|2\sqrt y|} = \frac{1}{2\sqrt y}.$$
As a final note, I'm sure 
$$f_Y(y) = \int_{-\infty}^{\infty}\delta (g(x)-y)f_X(x)dx$$
covers more case when the stipulations I mentioned earlier are not met, but I wouldn't know about it
