The inverse image of the image of $X$

I'm working on some exercises in Bert Mendelson's Introduction to Topology book in the first chapter and there's this question about functions:

If $f:A\rightarrow B$ is injective, then for every subset $X\subset A$, $f^{-1}(f(X)) = X$.

Here's my attempt at a proof which doesn't use the fact that $f$ is injective, which I know must be wrong because I can find a counterexample for which this will not hold if $f$ is not injective:

$\it{Proof}:$ We want to show that $f^{-1}(f(X))\subset X$. Let $x\in f^{-1}(f(X))$. Then, by definition, we have that

$$f^{-1}(f(X)) = \{a | f(a)\in f(X)\}$$ $$\implies f(x)\in f(X)$$ $$\implies x\in X \text{ since } f(X) = \{f(b) | b\in X\}$$

I already proved that $X\subset f^{-1}(f(X))$ for a more general case (i.e $f$ is not injective). As you can see, I didn't use the fact that $f$ is injective, so I'm sure I'm making a mistake somewhere. Any pointers as to where that mistake is?

Thanks!

The problem here is in the line $$x\in X\text{ since } f(X)=\{f(b)|b\in X\}$$ Consider the set $X=(0,2)\subset\mathbb{R}$ and the function $f=x^2:(0,2)\to(0,4).$
Now let $x=-1.$ Now clearly $f(-1)=1\in f(X)$, but $x\not\in X$.
All you have shown up to that point that there exists an $x$ which shares an image with something in $X$.
• Yes, I see! I was rewriting the proof just now and I believe this is the point where I have to use the injectivity of $f$. Since $f$ is injective there will only be one such $x$ that is in $X$ as a consequence of $f(x)\in f(X)$. Clearly, for $f = x^{2}$ this is not the case since $x^2$ is not injective. Am I correct? Commented Apr 15, 2015 at 4:18
• Exactly. The injectivity lets you pick out the point that maps to $f(x)$ as opposed to a point.