If $g$ is continuous and $A$ is a closed set and $A\subset \mathbb{R}$, then $g^{-1}(A)$ is closed 
Definition: Let $g$ be defined on all of $\mathbb{R}$. If $A$ is a subset of $\mathbb{R}$, define
$$g^{-1}(A)=\{ x\in\mathbb{R}:~ g(x)\in A\}$$

True or false:
If $g$ is continuous and $A$ is a closed set and $A\subset \mathbb{R}$, then $g^{-1}(A)$ is closed.
This problem is found from Understanding Analysis (Ex.4.4.12(d), by Abbott, Stephen). I found the answer from internet showing this statement is True. But can I use the following counter-example?
$$\begin{align} g(x)&=3x-1,~x\in[1/3,~2/3]\\
\\
g(x)&=1, ~~~~~~~~~~x\in (2/3,1)\\
\\
g(x)&=0,~~~~~~~~~~x\in(0,1/3)
\end{align}$$
So $A=[0,1]$ is closed. But $g^{-1}(A)=(0,1)$ is not closed.
 A: The function $g$ that you have described is not defined on all of $\Bbb R$. It is, in fact, only defined on $(0, 1)$. So this "counterexample" is not a counterexample to the given claim, because $g$ doesn't have the right form.
Here is the kicker, though: If we restrict ourselves to only looking at the domain of $g$, then the subset $g^{-1}(A) = (0, 1)$ (which happens to be all of the domain of $g$) then it is indeed closed.
Note that closedness is a property that subsets have in relation to an ambient space, not a property that a set has all by itself. And in relation to the ambient space $(0, 1)$, the subset $(0, 1)$ is closed. In relation to the ambient space $\Bbb R$, the subset $(0, 1)$ is not closed, but that's not relevant to our $g$.
So the theorem you qoute does hold in even more general circumstances, assuming you use the correct definition of "closed". But I suspect that a deepdive into relative topologies is not one of the immediate priorities of your math education. So for the moment, just make sure your functions have all of $\Bbb R$ as domain when you apply this result.
