Composition of functions: if $f(x) = |x-2|, x \in [2,4]$, what is $f(f(x))$? If $f(x) = |x-2| , x\in ]2,4[$  , then $f(f(x)) = ?$


*

*a) $-x$

*b) $4-x$

*c) $x-4$

*d) $x$

My turn :$$D_f= ]2,4[ , f(x) = x -2$$
To do the composition we need $$2<|x+2|<4 , x\in ]0,4[$$
Then the domain of the composition is $$]2,4[$$
Then
$$f(f(x)) = |x-2| -2 = x -4$$ 
Is my solution correct?
 A: For $x\in]2,4[$, it is $x-2\in]0,2[$, so $x-2>0$ and
$$
x-2=|x-2|.\tag{1}
$$
Hence, $|x-2|-2\in]-2,0[$, so $|x-2|-2<0$, this is
$$
|x-2|-2=-||x-2|-2|.\tag{2}
$$
You can compose $f(f(x))=||x-2|-2|$ on any interval of $\mathbb R$ and, for $(2)$ and $(1)$, in $]2,4[$ we have:
\begin{align}
||x-2|-2|&=-(|x-2|-2)\\
         &=-|x-2|+2\\
         &=-(x-2)+2\\
         &=-x+2+2=-x+4.\\
\end{align}
I was puzzled in the beginning, but the answer is b): $4-x$.
Image:

(Wolfram|Alpha agrees :))
A: You can think of this like applying two "transformations". 
The first time the function is applied, since f(x) > 0 for the given set of values, the function is effectively x - 2. Now, consider the range of that function. It is [0, 2]. This is because the function is linear and hence, we can just plug in the endpoints of the set. This is the first mapping of the set of values: [2, 4] -> [0, 2].
When we apply the function a second time, we will be able to see that the absolute value is important. (It is important to notice that the range of the first function becomes the domain of the second function.) For instance, when we apply the function a second time, we get f(0) = |0-2| = |-2| = 2. When we plug the other endpoint in, we get 0. This means that the function has not "rebounded" yet and the values that we have are just one branch of the V that characterizes absolute value functions. This means that the second mapping or "transformation" is also linear. To determine the actual function, you just need to play with the value a little and you can determine the resulting function. For a more concrete approach, notice that we have two points (the endpoints). The two points are (0, 2) and (4, 0). Using basic algebra, we can easily see that the function is 4 - x.
