I was working on a real analysis problem that goes as follows: Show that, for an arbitrary function $g:\mathbb R\to\mathbb R$ it is always true that $g(A\cap B)\subseteq g(A)\cap g(B)$. See, I ended up proving that this statement is true, but that's not what I'm confused about. What I'm confused about is how a proof for the opposite direction is false. I'm about to do some certified $BS^{tm}$ and prove that $g(A) \cap g(B)\subseteq g(A\cap B)$. Suppose some $g(x)\in g(A)\cap g(B)$. Then $g(x) \in g(A)$ and $g(x)\in g(B)$. It must follow that $x\in A$ and $x\in B$ by the definition of $g(A)$ and $g(B)$. So $x\in A\cap B$. However, this would imply that $g(x)\in g(A \cap B)$ by the definition of $g(A\cap B)= \{ g(x) \mid x \in A \cap B \}$. So $g(A) \cap g(B)\subseteq g(A \cap B)$.
Of course, this proof clearly has to be wrong, since that would imply the sets are equal (we assume that the correct direction for the subset is proven, although I didn't show the proof here). However, a previous problem showed that there are sets $A$ and $B$ that make this wrong for certain functions. My question is where my $BS^{tm}$ proof of the other direction went wrong. I know the proof shown can't work, but I can't see the flaw.
Edit: apologies for the problematic mathjax, I'm still getting the hang of this.