I need help with this proof I'm writing. The problem is from the "mathematical background" section of a book in automata theory and formal languages. Let $f: A \to B$ be a function, then prove that if $X$ and $Y$ are subsets of $B$, then we have $f^{-1}(X - Y) = f^{-1}(X)-f^{-1}(Y)$.
Here is what I have so far. Let $x \in f^{-1}(X - Y)$, then there exists $y \in X-Y$ such that $f(x) = y$. Notice that $y \in X$ and also $y \notin Y$. Since $y \in X$ we have that $f(x) \in X$ and thus $x \in f^{-1}(X)$. Next we have to prove that $x \notin f^{-1}(Y)$ and to do this suppose for contradiction that $x \in f^{-1}(Y)$, then that would mean that $f(x) \in Y$ and thus that $y \in Y$, a contradiction, thus, we can conclude that $x \in f^{-1}(X)$ and $x \notin f^{-1}(Y)$ thus $x \in f^{-1}(X)-f^{-1}(Y)$, which means that $f^{-1}(X - Y) \subseteq f^{-1}(X)-f^{-1}(Y)$.
My main doubts about this first half is on the proof by contradiction part, mostly because I feel it's not necessary, I tried doing a direct proof, concluding directly from $y \notin Y$ that $f(x) \notin Y$ and thus $x \notin f^{-1}(Y)$, but that feels like too much of a leap in logic, hence why I decided to go with proof by contradiction, what do you guys think?
To prove the other way, let $x \in f^{-1}(X)-f^{-1}(Y)$, then $x \in f^{-1}(X)$ and $x \notin f^{-1}(Y)$, this means that $f(x) \in X$ and $f(x) \notin Y$. Then $f(x) \in X-Y$ and lastly that means that $x \in f^{-1}(X - Y)$, concluding the proof that $f^{-1}(X)-f^{-1}(Y) \subseteq f^{-1}(X - Y)$ and thus concluding the proof that $f^{-1}(X)-f^{-1}(Y) = f^{-1}(X - Y)$
So is my proof ok? Are there section that need more clarification or more explanation? Or is it ok like this?
I am not seeing anything wrong in your derivation. However, you could have compacted the proof by writing straightforward:
$$x\in f^{-1}(X\setminus Y) \iff f(x) \in X\setminus Y\iff f(x)\in X~\wedge ~f(x)\notin Y\iff x\in f^{-1}(X)~\wedge~x\notin f^{-1}(Y)\iff x\in f^{-1}(X)\setminus f^{-1}(Y).$$