I found this function in an old math contest. $$ f(x)=\sqrt{x+2\sqrt{x-1}}+\sqrt{x-2\sqrt{x-1}},\space \space x\ge 1 $$ This function is identical to the piecewise function, $$ g(x) = \begin{cases} 2, & \text{if $1\le x\le 2$ } \\[2ex] 2\sqrt{x-1}, & \text{if $2\lt x$ } \end{cases}$$
I have proved the equality between $f(x)$ and $g(x)$. I would like to understand how the nested radicals produce an interval that is a constant function, and to able to create such functions with tailored characteristics.
HINT
Based on the comments of @labbhattacharjee and @JetfiRex, we can rearrange the expression as: \begin{align*} f(x) & =\sqrt{x + 2\sqrt{x-1}} + \sqrt{x - 2\sqrt{x-1}}\\\\ & = \sqrt{(\sqrt{x-1} - 1)^{2}} + \sqrt{(\sqrt{x-1} + 1)^{2}}\\\\ & = |\sqrt{x - 1} - 1| + |\sqrt{x - 1} + 1|\\\\ & = |\sqrt{x - 1} - 1| + \sqrt{x - 1} + 1 \end{align*}
whenever $x\geq 1$.
Can you take it from here?