Question about domain of composition of functions? I am tutoring a student in precalculus and there was a question that I couldn't quite answer.
I know that the domain of $f \circ g$ is the domain of $g$, minus the points $z$ where $g(z)$ is not in the domain of $f$.
Now, in precalculus we often have functions such as $f(x) = \dfrac {1}{x+2}$ and  $g(x) = 1/x$. According to what I said above, the domain for $f \circ g$ is $\mathbb{R} - \{0, -\frac 12 \}$. But if we just compute the formula for $f\circ g$ directly, we get $\dfrac {x}{2x+1}$. Now, this function also gives us the restriction $x \not = -\frac 12$.
So it seems that, we still have to start with the domain of $g$, but then instead of finding the points $z$ where $g(z)$ is not in the domain of $f$, it seems like we can directly compute $f \circ g$ and compute the domain directly from there (after simplification). In fact, my tutee's professor even told the students to write this "fact" down. 
Is this really true, or can it fail? I really think it should fail in some cases, because I really don't see how you would ever prove it; "finding the domain of $f \circ g$ after simplification" is just a very ambiguous concept, so I can't even see where you would start to prove such a thing.
 A: It is false that you can find the domain of $f\circ g$ after simplifying the expression. Here is an example: take $g(x)=\sqrt{x}$ and $f(x)=x^2$. The domain of $f\circ g$ is $x\ge 0$ but after simplification you get $f\circ g(x)=x$ and it might seem that the domain is $\mathbb{R}$ which is false. The whole point is that an expression is not a function. In order to specify a function you need a domain. The domain of the composition is by definition the set of points in the domain of $g$ such that $g(x)$ is in the domain of $f$ to be able to apply both functions sequentially.
A: Actually, the formula for $f\circ g(x)$ is not what you give. The formula is
$$f\circ g(x) = f\Bigl(g(x)\Bigr) = f\left(\frac{1}{x}\right) = \frac{1}{\frac{1}{x}+2}.$$
For this formula to make sense, you need $x\neq 0$ and you need $\frac{1}{x}\neq -2$ (or $x\neq -\frac{1}{2}$); which gives the correct answer.
Why is that the formula? Because “$f\circ g$” means “do $g$ to $x$ first, then do $f$ to the result of that.” In this case, “do $g$ to $x$” means “take the reciprocal of $x$”. And “do $f$ to $u$” means “add two to $u$, then take the reciprocal.” so $f\circ g(x)$ means:


*

*First take the reciprocal of $x$; then

*Add two to that; and then

*Take the reciprocal of that result.


And this corresponds to
$$\frac{1}{\frac{1}{x}+2}$$
and not to $\frac{x}{2x+1}$. 
This all comes from our convention that if we give a function by a formula, but do not specify its domain, then we mean the domain to be the “natural domain”: the set of all numbers for which the formula makes sense. When you “simplify” the formula, you may be removing restrictions and thus changing the domain. So you would need to do something like this:
$$\begin{align*}
f\circ g(x) &= \frac{1}{\frac{1}{x}+2}\\
&= \frac{1}{\quad\frac{1+2x}{x}\quad} &\text{(1)}\\
&= \frac{x}{1+2x}, \quad x\neq 0 &\text{(2)}
\end{align*}$$
Notes:


*

*This is fine, because the natural domain of both expressions are the same.

*Here you need to include the restriction $x\neq 0$ in order to keep the domains the same. 

Note that $\frac{1}{\frac{1}{x}+2}$ is not the same function as $\frac{x}{1+2x}$, precisely because they have different domains. Similarly, the function
$$\frac{1}{\quad\frac{1}{x}\quad}$$
and the function $x$ are different, because they have different domains.
