Q:

Why can't we prove that $X= f^{-1}(f(X))$ in general?

Let $f:A \rightarrow B$ be a map. Let $X \subseteq A$, $Y \subseteq B$.
I saw this result that states $X \subseteq f^{-1}(f(X))$.
Well to prove that I said the following:

Let $x \in X$. By definition, $f(x) \in f(X)$. Again, by definition, $x \in f^{-1}(f(X))$. Hence $X \subseteq f^{-1}(f(X))$.

I already try a few examples of the other inclusion, i.e., $f^{-1}(f(X)) \subseteq X$ and indeed is false (we can see for example the quadratic function).
But my doubt is why can't we say the following:

Let $x \in f^{-1}(f(X))$. By definition, $f(x) \in f(X)$. Again by definition, $x \in X$.

It seems that there is something wrong with the definitions that I'm missing. What is my mistake here?
Thank you!

A:

If $f(x)\in f(X)$ then you can only conclude that there is some $u\in X$ such that $f(x)=f(u)$. If $f$ is injective (on $X$), that is enough to conclude that $x=u$ and thus $x\in X$. But if $f$ is not injective, you cannot conclude that.
The function $x\mapsto x^2$ is a good example indeed.

