The notion of equality when considering composition of functions

Note that the notation $(f\circ f)(x)$ gives some intuitive notion that we are going to do $2$ different operations. The first will be to "feed" $x$ to $f$, and then "feed" $f(x)$ to $f$. Indeed we have $(f\circ f)(x) = f(f(x))$. We know that $f$ is not defined for $x = -1$ and therefore the inner $f$ in $f(f(x))$ cannot be "fed" $-1$. However, the outer $f$ is fed values from $f(x)$ and it just so happens that $f(x) = -1 \iff x = -\frac12$.

We can then proceed to write the algebraic manipulations you wrote assuming that $1+x \not= 0, \frac{x}{1+x} \not= -1$ given that otherwise you would be dividing by $0$.

On the other hand, starting from $\frac{1}{2x+1}$ one cannot write $$\frac{\frac{x}{1+x}}{\frac{1+2x}{1+x}}$$ if we don't explicitly state that $1+x\not=0$, otherwise you would be dividing by $0$. Therefore one can always do the algebraic manipulations, given that one carries the excluded points along.

Therefore, one finds $f(f(x))$ to be defined for $x\not\in \{-\frac12, -1\}$ and for the points where it is defined we have $f(f(x)) = \frac{1}{2x+1}$. Similarly, working backwards like you did, we get

$$\frac{\frac{x}{1+x}}{\frac{1+2x}{1+x}} = \frac{\frac{x}{1+x}}{1 + \frac{x}{1+x}}$$

except for the points $x = -\frac12, -1$ because we had to exclude them.

What is more, you are right when you say that two functions are equal if they have the same domain/codomain and if they map the same objects to the same images. Having that in mind, the functions $f(f(x))$ and $\frac1{2x+1}$ are not the same function, unless you restrict the second one to the points where we know $f(f(x))$ is well-defined.


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.


Have you studied set theory? One defines there a composition of two functions $f \colon A \to B$ and $g \colon B \to C$ as a function $g \circ f \colon A \to C$. In your case, the domain of $x / (1 + x)$ is $\mathbb R \setminus \{-1 \}$, but the codomain is $\mathbb R \setminus \{1\}$, so you can't compose $f$ with itself.

What have you done unconsciously here is a restriction of both domain and codomain. You should restrict them at least to $\mathbb R \setminus \{1, -1\}$, in order to be able to compose the functions.

Additionaly you must remove $-1/2$ from your domain, otherwise you will divide by zero when calculating $f(f(-1/2))$.