# Piece-wise density function

I know that when your are given a piece-wise density function such as: $$f(x) = \begin{cases} 4x, & 0< x\leq \frac{1}{2} \\ 4-4x, & \frac{1}{2}< x\leq1 \\ 0, & \text{ otherwise} \end{cases}$$

The distribution function would be: $$F(x) = \begin{cases} \int\limits_{0}^{x}4x\, dx, & 0< x\leq \frac{1}{2} \\ \int\limits_{0}^{\frac{1}{2}}4x\, dx + \int\limits_{\frac{1}{2}}^{x}4-4x\, dx, & \frac{1}{2}< x\leq1 \end{cases}$$

However, I do not quite understand why for $$\frac{1}{2}< x\leq1$$ the distribution function is: $$\int\limits_{0}^{\frac{1}{2}}4x\, dx + \int\limits_{\frac{1}{2}}^{x}4-4x\, dx$$

I would appreciate if someone could explain the logic behind this.

In general, the CDF of a density $f(x)$ defined on $\mathbb{R^+}$ is given by \begin{align} F(x)=\int_{0}^x f(s) ds \end{align} using your definition of $f$, i.e. \begin{align} \begin{cases} 4x, & 0< x\leq \frac{1}{2} \\ 4-4x, & \frac{1}{2}< x\leq1 \\ 0, & \text{ otherwise} \end{cases} \end{align} we get for $x \in [0.5,1]$ due to the additivity of the integral \begin{align} F(x)=\int_{0}^x f(s) ds &= \int_0^{0.5}f(s)ds + \int_{0.5}^x f(s) ds \\ &=\int_0^{0.5}4s\,ds + \int_{0.5}^x 4-4s\, ds \end{align} which one could of course simplify even further.
Note, that in your definition for $F(x)$ you are using $x$ in the second integral as upper bound and argument There you might use $s$ for the argument as I did to avoid confusion.