Let Y be a function of the random variable X as follows: $$ Y= \left\{ \begin{aligned} X, & \quad X\ge 0 \\ X^2,& \quad X\le0 \end{aligned} \right. $$ compute $f_{Y}{(y)}$ in terms of $f_{X}{(x)}$, where $f_{X}{(x)}=\frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}x^2}$
I use total probability formula to derive an equation: $$ P(Y\le y) =P(Y\le y | X \ge 0)P(X\ge 0) + P(Y\le y | X \le 0)P(X \le 0) $$ Then: $$ P(Y\le y) = P(X \le y | X \ge 0)P(X\ge 0) + P(X^2 \le y | X \le 0)P(X\le 0) $$
Finally I derive cumulative distribution function $F_{Y}{(y)}$, and obtain $f_{Y}{(y)}$ from it.
However, my answer is not correct. I think the problem may lie in above two steps, so I was wondering if maybe anyone could point me out what is wrong with above two equitations?
Note that, for $x\geq0$: $$[Y\le x]=[-\sqrt{x}\le X\le x]$$ Hence: $$F_Y(x)=F_X(x)-F_X(-\sqrt{x})$$ Differentiating: $$f_Y(x)=f_X(x)+\frac1{2\sqrt{x}}f_X(-\sqrt{x})$$ Now substitute.