I am reading through Folland's Real Analysis: Modern Techniques and Their Applications, and they have the following proposition and proof:
Proposition: If $\{f_{j}\}$ is a sequence of $\bar{\mathbb{R}}$- valued measurable functions on $(X, \mathcal{M})$, then the functions:
$$g_{1}(x)=\sup_{j} f_{j}(x)$$ $$g_{2}(x)=\inf_{j} f_{j}(x)$$ are measurable.
Proof:
We have
$$g_{1}^{-1}((a,\infty])= \bigcup_{j=1}^{\infty} f_{j}^{-1}((a,\infty])$$ $$g_{2}^{-1}([-\infty,a))= \bigcup_{j=1}^{\infty} f_{j}^{-1}([-\infty,a))$$
Where the result follows from the fact that $g_{1}^{-1}((a,\infty])\in \mathcal{M}$ for all $a \in \mathbb{R} \iff g$ is measurable, and $g_{2}^{-1}([-\infty,a))\in \mathcal{M}$ for all $a \in \mathbb{R} \iff g$ is measurable.
I understand the last part of the proof, but how do we know $g_{1}^{-1}((a,\infty])= \bigcup_{j=1}^{\infty}f_{j}^{-1}((a,\infty])$ and $g_{2}^{-1}([-\infty,a))=\bigcup_{j=1}^{\infty} f_{j}^{-1}([-\infty,a))$? I would appreciate any help with this.