Inverse set functions identities For my analysis 1 class, I have to solve this problem:

Let $f:A\rightarrow B$ be a function and let $A_1,A_2\subseteq A$ and $B_1,B_2\subseteq B$.
(c) Prove that $f^{-1}(B_1\setminus B_2)=f^{-1}(B_1)\setminus f^{-1}(B_2)$
(d) Provide an example such that $f(A_1 \setminus A_2) \neq f(A_1)\setminus f(A_2)$. Provide a condition on $f$ that implies that $f(A_1\setminus A_2)=f(A_1)\setminus f(A_2)$

MY SOLUTION
(c)
$$\begin{align}
\text{Let } x\in f^{-1}(B_1\setminus B_2)\, &\iff f(x)\in B_1\setminus B_2 \\ 
                &\iff \, f(x)\in B_1 \text{ and } f(x) \notin B_2 \\
                &\iff \, x\in f^{-1}(B_1) \text{ and } x\notin f^{-1}(B_2) \\
                &\iff \, x\in f^{-1}(B_1)\setminus f^{-1}(B_2)
\end{align}$$
After doing question (c) and seeing question (d), I thought I could do a similar proof to prove that $f(A_1\setminus A_2)=f(A_1)\setminus f(A_2)$:
$$\begin{align}
\text{Let } f(x)\in f(A_1\setminus A_2)\, &\iff x\in A_1\setminus A_2 \\ 
                &\iff \, x\in A_1 \text{ and } x \notin A_2 \\
                &\iff \, f(x)\in f(A_1) \text{ and } f(x)\notin f(A_2) \\
                &\iff \, f(x)\in f^{-1}(A_1)\setminus f^{-1}(A_2)
\end{align}$$
But I realized while writing my proof that, from arrow 2 to arrow 3, there was a mistake because if I take $f(x)=x^2$, $A_1=\{x<0\}$ and $A_2=\{x>0\}$, it's not true that $\left[x\in A_1 \text{ and } x \notin A_2\right] \, \iff \, \left[f(x)\in f(A_1) \text{ and } f(x)\notin f(A_2)\right]$ (because $f(A_1)=f(A_2)$). So I was wondering why there should be a condition on $f$ for (d) but none on $f^{-1}$ for (c).
Thanks in advance for your answers.
 A: The same issue arises already with your first claim: $$f(x)\in f(A_1\setminus A_2)\, \implies x\in A_1\setminus A_2.$$
Or more simply: $f(x)\in f(A_1)\, \implies x\in A_1, $ since the error in your thinking is not to do with set difference, it seems to me.
Why should information about the location of $f(x)$ (necessarily) help you locate $x$? Your example of $x \mapsto x^2$ is a useful one here. Note that it is a "two-to-one" mapping.
But a more dramatic example is $f(x) = \tan x,$ letting $A_1 = [0,\pi/4].$ So if I tell you $f(x)\in f(A_1)$, this says simply that $0 \leqslant f(x) \leqslant 1$.
But this in no way makes it safe to conclude $0 \leqslant x \leqslant \pi/4$. (Look at the graph of tangent if you do not see this.)
Whatever condition we provide to fix part (d) must outlaw functions like tangent and $x^2$. (Or at least require us to restrict their domains.)
Your proof for part (c) is valid, so no extra condition is needed. In fact the proof of (c) uses nothing other than the definition of set difference and the definition of a statement of the form $x\in f^{-1}(B_1)$.
