Is this function continuous? Topology Let $X=\cup_{n\ge 1}A_n$ be a topological space and $f:X\to Y$ a map. Suppose each restriction of $f$ to $A_n$ is continuous. I think $f$ is continuous just by using definitions. Is this true though?
 A: Yes.  Suppose $U$ is open in $Y$.  Let's consider $f^{-1}(U)$.  The continuity of $f|_{A_n}$ for any $n$ implies $f^{-1}(U) \cap A_n$ is open for every $n$.
Since we can write $\displaystyle f^{-1}(U) = \bigcup_{k} \Big(f^{-1}(U) \cap A_k \Big)$, a union of open sets, we can conclude the preimage of $U$ is open.

Edit: In the above, I was assuming that $X$ is to be considered as a union of the $A_n$'s under the disjoint union topology.  If instead the $A_n$'s are inheriting the subspace topology from some pre-defined topology on $X$, then counterexamples exist.  For example:
Let $X = [-1, 1]$, which we can write as $[-1, 0] \cup (0, 1]$.  Let $f:X \rightarrow \mathbb{R}$ be defined as:
$\qquad \qquad \qquad \qquad f(x) = \begin{cases} 0 \text{ if } x \in [-1, 0] \\ 1/x \text{ if } x \in (0, 1] \end{cases}$
Notice that the restriction of $f$ to either $[-1, 0]$ or $(0, 1]$ is continuous, but $f$ as a whole is not continuous. In particular, $f^{-1} \Big((-1/2, 1/2)\Big)$ is not open in $X$.
A: Consider the real subspace $X=\cup_{n\in \mathbb N}A_n$ where  $A_1=\{0\}$ and $A_n=\{1/n\}$ for $1<n\in \mathbb N.$  Let $f(0)=0$ and $f(p)=1$ for $0\ne p\in X.$  Then $f|A_n$ is continuous for each $n$ but $f$ is not continuous.
Note: A function on $X$ is locally continuous iff every $p\in X$ has a nbhd $U_p$ such that $f|U_p$ is continuous. A function is continuous iff it is locally continuous. So if each $A_n$ were open in $X$ then $f$ would be continuous. In my example above, $A_1$ is not open in $X.$
