Proof of $f^{-1}(B_{1}\setminus B_{2}) = f^{-1}(B_{1})\setminus f^{-1}(B_{2})$

I want to prove the following equation:

$$ f^{-1}(B_{1}\setminus B_{2}) = f^{-1}(B_{1})\setminus f^{-1}(B_{2}) $$

Is this a valid proof? I am not sure, because at one point I am looking at $f(x) \in B_1$, but then $x \in f^{-1}(B_1)$ could be actually some different points.

$$\begin{align*} x \in f^{-1}(B_{1}\setminus B_{2}) &\iff f(x) \in B_{1}\setminus B_{2} \\ &\iff f(x) \in B_{1} \land f(x) \notin B_{2} \\ &\iff x \in f^{-1}(B_{1}) \land x \notin f^{-1}(B_{2}) \\ &\iff x \in f^{-1}(B_{1})\setminus f^{-1}(B_{2}) \end{align*}$$


Solution 1:

Throughout your proof, $x$ is a given element of the domain of $f$; it doesn't matter that $f^{-1}(B_1)$, or $f^{-1}(B_2)$, or even $f^{-1}(f(x))$, could have more elements.

To help you see why your argument is correct, I'll rewrite your proof but with the domain of the function $f$, and with the "initialization" of the "variable" $x$, more explicit:

Theorem: Let $A$ and $B$ be sets, and consider a function $f:A\to B$. Let $B_1\subseteq B$ and $B_2\subseteq B$ be any subsets. Then we have $$f^{-1}(B_1\setminus B_2)=f^{-1}(B_1)\setminus f^{-1}(B_2).$$ Proof: For any given $x\in A$, we have $$\begin{align*} x\in f^{-1}(B_1\setminus B_2) & \iff f(x)\in B_1\setminus B_2\\ &\iff f(x)\in B_1\land f(x)\notin B_2\\ &\iff x\in f^{-1}(B_1)\land x\notin f^{-1}(B_2)\\ &\iff x\in f^{-1}(B_1)\setminus f^{-1}(B_2) \end{align*}$$ and therefore, since they comprise the same elements of $A$, $$f^{-1}(B_1\setminus B_2)=f^{-1}(B_1)\setminus f^{-1}(B_2).$$