One textbook states the following
Another textbook states:
I can't reconcile the difference, nor can I understand how the two slightly different versions of the same theorem are compatible. One states that $f^{-1}(A)$ is open whenever $A \subset \mathbb{R}$ is open, while the other states $f^{-1}(A)$ is open relative to the domain whenever $A \subset \mathbb{R}$.
Please help me understand.


In the first definition, the domain is assumed to be all of $\mathbb{R}$. In the second definition, the domain is only assumed to be a subset of $\mathbb{R}$, i.e., it may be a proper subset of $\mathbb{R}$. If the domain is indeed a proper subset $S$ of $\mathbb{R}$, then the relevant topology is the subspace topology on $S$. In the subspace topology on $S$, a set may be open which is not open in $\mathbb{R}$. For example, take $S = \{0, 1\}$. Then in the subspace topology, both $\{0\}$ and $\{1\}$ are open, but they are clearly not open in $\mathbb{R}$. If we consider the function $f : S \to \mathbb{R}$ defined by $f(s) = 0$, we would incorrectly conclude that this function is discontinuous if we ignored the fact that the topology on our domain is the subspace topology and not the topology on $\mathbb{R}$.
So, the second definition is just a slightly more general version of the first, taking in account functions which might not be defined on all of $\mathbb{R}$.