Let $f: S \to \mathbb{R}$, where $S \subset \mathbb{R}$. Prove that the preimage under $f$ of any open set is open $\implies$ preimage under $f$ of any closed set is closed. My approach: Take $U \subset \mathbb{R}$ closed (ie $U = [a, b]$). Then $U = (a, b) \cup ${$a, b$}$ \implies$ By assumption $f^{-1}(U \setminus ${$a, b$}$)$ is open in $S$ since $U \setminus ${$a, b$} is open $\implies$ $f^{-1}(U) \setminus f^{-1}(${$a, b$}$)$ is open in $S$ $\implies$ $S \setminus \big(f^{-1}(U) \setminus f^{-1}(${$a, b$}$) \big )$ is closed in $S$ $\implies \big(S \setminus (f^{-1}(U)\big) \cap \big (S\setminus f^{-1}(${$a, b$}$)\big)$ is closed in $S$.
I need to show that $S \setminus f^{-1}(U)$ is open in S. However I am not sure how to proceed after the last step above. Any help would greatly be appreciated.