First,
\begin{equation*}
(f\circ g)(x) = f\left(\frac{x+2}{1-x}\right)
= \frac{1}{\frac{x+2}{1-x}}
\end{equation*}
which is defined provided:
\(g(x) = \frac{x+2}{1-x}\) is defined. This requires \(x\neq 1\text{.}\)
\(\frac{x+2}{1-x} \neq 0\text{.}\) This requires \(x\neq -2\text{.}\)
Thus,
\begin{equation*}
(f\circ g)(x) = \frac{1-x}{x+2}, \quad x\neq -2,1.
\end{equation*}
It’s important to add these final conditions, because it would not be clear this is the domain from the final simplified expression.
Next,
\begin{equation*}
(g\circ f)(x) = g\left(\frac{1}{x}\right)
= \frac{\frac{1}{x}+2}{1-\frac{1}{x}}
\end{equation*}
which is defined provided:
\(f(x) = 1/x\) is defined. This requires \(x\neq 0\text{.}\)
\(1-\frac{1}{x} \neq 0\text{.}\) This requires \(x\neq 1\text{.}\)
Simplifying,
\begin{equation*}
(g\circ f)(x) = \frac{\frac{1}{x}+2}{1-\frac{1}{x}} \cdot \frac{x}{x} = \frac{1+2x}{x-1} \quad x\neq 0,1.
\end{equation*}
Finally, \((f\circ f)(x) = f\left(\frac{1}{x}\right) = \frac{1}{1/x}\) which is defined provided:
\(f(x) = 1/x\) is defined. This requires \(x\neq 0\text{.}\)
\(\frac{1}{x} \neq 0\text{.}\) This never happens.
Thus,
\begin{equation*}
(f\circ f)(x) = \frac{1}{1/x} = x, \quad x\neq 0.
\end{equation*}
Again, its essential to add the additional requirement \(x\neq 0\text{.}\)