What is $P(X=x)$ when $X\sim \text{Unif}(a,b)$? I'm trying to solve this excursive A stick of length 1 is broken in a random place that is U(0, 1). Let X be the length of the longer piece and let Y be the length of the shorter piece. in another way. The question:

A stick of length 1 is broken in a random place that is $\text{Unif}(0,1)$. Let $X$ be the point chosen on the steak and $Y$ be the length of the longer piece. Find $E(Y)$.

So we get:
$$
Y=\begin{cases}
1-X & X<0.5\\
X & X\geq0.5
\end{cases}
$$
Then we can say:
$$
\begin{align*}
E\left(Y\right)&=\int_{-\infty}^{\infty}y\cdot P\left(Y=y\right)dy\\&=\int_{0}^{1}y\cdot P\left(Y=y\right)dy=\int_{0}^{0.5}y\cdot P\left(Y=y\right)dy+\int_{0.5}^{1}y\cdot P\left(Y=y\right)dy\\&=\int_{0}^{0.5}y\cdot P\left(Y=y\right)dy+\int_{0.5}^{1}y\cdot P\left(Y=y\right)dy\\&=\int_{0}^{0.5}(1-x)\cdot P\left(X=x\right)dx+\int_{0.5}^{1}x\cdot P\left(X=x\right)dx\\&=\int_{0}^{0.5}(1-x)\cdot P\left(X=x\right)dx+\int_{0.5}^{1}x\cdot P\left(X=x\right)dx
\end{align*}
$$
I want to say $P(X=x)=1$ when $x\in[0,1]$. But is it true to say that $P(X=x)=\frac{1}{b-a}$ when $x\in[a,b]$?
 A: We can rewrite this in terms of $f_X(x)=1:$ \begin{align*}
\mathbb E(Y)&=\int_{-\infty}^\infty y\cdot f_X(x)dx=\int_0^{0.5}(1-x)(1)dx+\int_{0.5}^1x(1)dx\\
&= 0.75
\end{align*}
You don't have to deduce the pdf of $Y$ to get its expectation, as $Y$ is a function of $X$.
A: See the other answer for a direct method to get the expectation. Since you asked how to compute the pdf of y, here is one way, though not very intuitive.
$$\begin{split}Y=\begin{cases}1-X&X<.5\\X&X\ge.5\end{cases}\end{split}$$
For X<.5, you can write
$$\begin{split}Y&=|1-X-\frac 1 2|+\frac 1 2\\
&=|\frac 1 2 -X|+\frac 1 2\\
&=\left|\frac{1-2X}{2}\right|+\frac 1 2\\
&=\frac{|1-2X|+1}{2}\end{split}$$
and for X>.5 you can write
$$\begin{split}Y&=|X-\frac 1 2|+\frac 1 2\\
&=\left|\frac{2X-1}{2}\right|+\frac 1 2\\
&=\frac{|2X-1|+1}{2}\end{split}$$
Thus $$Y=\frac{|2X-1|+1}{2}\text{ for }0\le X\le1$$
and can take on the values $1 \ge Y\ge \frac 1 2$. The upper bound is achieved at X=0 or 1, and the lower bound is achieved at X=1/2.
$$F_Y(y)=P(Y\le y)\\...\\f_Y(y)=...$$
