The notion of equality when considering composition of functions When going through some (very introductory) calculus homework I was given the function $f(x) = \frac{x}{1+x}$ and asked to find the composition $(f\circ f)(x)$ and then find its domain. Substituting, we find that $$(f\circ f)(x)= \frac{\frac{x}{1+x}}{1+\frac{x}{1+x}}$$ The domain is then found by solving $\frac{x}{1+x} = -1$ and to find that the composition is undefined at $-\frac{1}{2}$. It is also, of course, undefined at $-1$. Thus our domain is $\{x \in \mathbb{R} \mid x \neq -\frac{1}{2} $ and $x \neq -1$}. My question comes from noticing that if we take the algebra further we find that $$(f\circ f)(x)= \frac{\frac{x}{1+x}}{1+\frac{x}{1+x}} = \frac{x}{2x+1}$$ The domain is still surely unchanged. However, suppose I never did this problem and for some reason I simply desired to write down the function $\frac{x}{2x+1}$ on a sheet of paper and find its domain. I would find that it is defined for all reals except $-\frac{1}{2}$. (Wolfram alpha also verifies this). This would then imply that $$(f\circ f)(x)= \frac{\frac{x}{1+x}}{1+\frac{x}{1+x}} \neq \frac{x}{2x+1}$$ since the domain of the two functions is unequal. Couldn't we also work backwards from $\frac{x}{2x+1}$ in the following manner? $$\frac{x}{2x+1} = \frac{\frac{x}{1+x}}{\frac{1+2x}{1+x}} = \frac{\frac{x}{1+x}}{\frac{1+x}{1+x} + \frac{x}{1+x}} = \frac{\frac{x}{1+x}}{1 + \frac{x}{1+x}}$$ This is the function we orignally found the domain for. Did I some how just remove a point from the domain by just doing algebraic manipulations?
My guess is perhaps there are two (or more?) notions of equality going on here. One notion would perhaps be the idea of two functions $f$ and $g$ being "formally" equivalent if $f$ can be algebraically manipulated to $g$ and vice versa. The other notion would be the more intuitive one where two functions are equal if they have the same domain and map the elements of the domain to the same points in the codomain.
Thanks.

Essentially, the only time you may multiply the fraction by $\frac{x+1}{x+1}$ is if $x\ne-1$, or else you'd be multiplying by $\frac00$, which doesn't make sense in this context.
It is, however, an applicable standard technique in calculus to evaluate the limit as $x\to1:$
$$\underbrace{\lim_{x\to-1}\frac{\frac x{1+x}}{1+\frac x{1+x}}=\lim_{x\to-1}\frac x{2x+1}}_{\text{the expressions under the limit are equal for any $x\in \mathbb{R} \smallsetminus \{-1,-\frac12\}$}}=1$$
To put this into words, $(f\circ f)(x)$ approaches $1$ as $x$ approaches $-1$.  The approach is to algebraically remove any $1/(x+1)$ by multiplying everything through by $(x+1)$, which is what you did.
