How can we composite two piecewise functions?

Let say $$f(x) := \left\{\begin{array}{l l}x+1 & \text{ if } -2\leq x<0 \\ x-1 & \text{ if }0\leq x\leq 2\end{array}\right.$$ How can we find out $f\circ f$?


Solution 1:

Hint: First, verify that $f(x) \subset [-2,2]$ to be sure that the composition $f \circ f$ is well defined. Then you should carefully separate the cases. Here's an example for the first steps:

If $-2 \leq x < 0$ then $f(x) = x+1$ and so $f(x) < 0$ for $-2 \leq x < -1$, it follows that $f\circ f(x) = ((x+1)+1)$ for $-2 \leq x < -1$. Now if $-2 \leq x < 0$ then $f(x) = x+1$ and so $f(x) \geq 0$ for $-1 \leq x < 0$ thus ... Can you continue from here?

EDIT: To be more precise, let $y = f(x)$, then

$$f \circ f(x) = f(y) = \left\{\begin{array}{l l}y+1 & \text{ if } -2\leq y<0 \\ y-1 & \text{ if }0\leq y\leq 2\end{array}\right.=\left\{\begin{array}{l l}f(x)+1 & \text{ if } -2\leq f(x)<0 \\ f(x)-1 & \text{ if }0\leq f(x)\leq 2\end{array}\right.$$ So we have to separate the cases when $-2\leq f(x)<0$ and $0\leq f(x)\leq 2$. By definition of $f$ we know that $f(x) < 0$ for every $x \in [-2,-1)$ and $x \in [0,1)$. In particular this implies that if $x \in [-2,-1)$, then $f(x) = x+1 < 0$ and thus $$f \circ f(x) = f(x)+1 = (x+1)+1 = x+2.$$ Stays to study the case $x \in [0,1)$ and $f(x) \geq 0$.