The expectation of a r.v. times an indicator function which depends on the r.v. Suppose $X$ is a random variable, with mean zero, and finite variance.
I'm trying to understand how to think about the function
$$ K(t) = \mathbb{E}\left[X (1_{\{0\leq t \leq X\}} - 1_{\{X\leq t \leq 0\}})\right].$$
To make things more concrete, I'd like to show:
$$ \int_{-\infty}^\infty K(t) \,dt = \mathbb{E}\left[ X^2\right].$$
 A: $\begin{aligned}\int K\left(t\right)dt & =\int\int X\left(\omega\right)1_{\left\{ 0\leq t\leq X\left(\omega\right)\right\} }-X\left(\omega\right)1_{\left\{ X\left(\omega\right)\leq t\leq0\right\} }P\left(d\omega\right)dt\\
 & =\int_{0}^{\infty}\int X\left(\omega\right)1_{\left[0,X\left(\omega\right)\right]}\left(t\right)P\left(d\omega\right)dt+\int_{-\infty}^{0}\int-X\left(\omega\right)1_{\left[X\left(\omega\right),0\right]}\left(t\right)P\left(d\omega\right)dt\\
 & =\int\int_{0}^{\infty}X\left(\omega\right)1_{\left[0,X\left(\omega\right)\right]}\left(t\right)dtP\left(d\omega\right)+\int\int_{-\infty}^{0}-X\left(\omega\right)1_{\left[X\left(\omega\right),0\right]}\left(t\right)dtP\left(d\omega\right)\\
 & =\int X\left(\omega\right)\int_{0}^{\infty}1_{\left[0,X\left(\omega\right)\right]}\left(t\right)dtP\left(d\omega\right)+\int-X\left(\omega\right)\int_{-\infty}^{0}1_{\left[X\left(\omega\right),0\right]}\left(t\right)dtP\left(d\omega\right)\\
 & =\int X\left(\omega\right)^{2}1_{\left[0,\infty\right)}\left(X\left(\omega\right)\right)P\left(d\omega\right)+\int X\left(\omega\right)^{2}1_{\left(-\infty,0\right]}\left(X\left(\omega\right)\right)P\left(d\omega\right)\\
 & =\int X\left(\omega\right)^{2}P\left(d\omega\right)\\
 & =\mathbb{E}X^{2}
\end{aligned}$
