I've been trying to better understand the proof of the LOTUS when the function $g$ between two scalar random variables $X$ and $Y=g(X)$ is not one-to-one.
I have followed two methods to show it (reported below). They use different writings to express the pdf $p_Y$ of $Y$ in terms of the pdf $p_X$ of $X$, which seem to be in disagreement.
Specifically, how can
$$p_Y(y)=\int p_X(x)\delta(y-g(x))dx$$
from here, working for $g$ that are not necessarily one-to-one, and
$$p_Y(y)=p_X(g^{-1}(y))|\frac{dg^{-1}}{dy}(y)|$$
from here
be in agreement?
If I take $g$ one-to-one in the first equation I get $$ p_Y(y)=... =\int p_X(x)\delta(g^{-1}(y)-x)dx = p_X(g^{-1}(y)), $$ where the Jacobian is missing.
I guess I am making some mistakes somewhere, but I can't figure out where.
Do you have any hints to help me out?
Method 1 for $g:\mathbb R\to \mathbb R$ is invertible.
Following Lotus Wikipedia, we exploit $dx=dy/g'(g^{-1}(y)$ which cancels out the Jacobian for the switch $p_Y \to p_X$ like so: $$ \begin{array}{rl} E_Y[Y] &= \int y p_Y(y) dy \\ &= \int y p_X(g^{-1}(y))\frac{d g^{-1}}{dx}(y) dy \\(p_Y\to p_X)\ &= \int y \frac{p_X(g^{-1}(y))}{g'(g^{-1}(y))} dy \\(dx=dy/g'(g^{-1}(y))\ &= \int y p_X(g^{-1}(y)) dy \\(y=g(x))\ &= \int g(x) p_X(x) dx = E_X[g(X)] \end{array} $$
Method 2 for $g:\mathbb R\to \mathbb R$ generic.
Following PDF Wikipedia, here the relation $p_Y(y)=\int p_X(x)\delta(y-g(x))dx$ is used $$ \begin{array}{rl} E_Y[Y] &= \int y p_Y(y) dy \\ &= \int y \{\int p_X(x)\delta(y-g(x))dx\} dy \\ &= \int p_X(x) \{\int y \delta(y-g(x)) dy\} dx \\ &= \int p_X(x) g(x) dx = E_X[g(X)] \end{array} $$