continuity of a function defined in pieces Frequently i have to prove in topology case by case that some functions defined in pieces are continous. I would like to solve the general case so that i don't have to prove it everytime in some particular cases.
Let $X$ and $Y$ be a Topological space. Let $X_1 \subseteq X$ and $X_2 \subseteq X$ be such that  $X_1\ne \emptyset $  ,  $X_2\ne \emptyset $ and  $X_1 \cup X_2 = X$  .
Let $ g: X_1 \to Y$ and $h: X_2 \to Y$ be continous functions such that $g(x)=h(x) \forall x \in X_1 \cap X_2$
When does the function $f:X \to Y$ defined by $f(x)=g(x) \forall x \in X_1$ and $f(x)=h(x) \forall x \in X_2$ is continous?
I don't think this is true in general but i suspect that to prove this fact i need something like a separable property on the domain. For example i think i need that for every point in $X_1$ that is not in $X_2$ i can find a neighbourhood (in $X$ ) of this point which is entirely contained in $X_1$ and vice versa. With this hypothesis i think i could prove that $f$ is continous in every point of $X$.
I would like to ask you if this intuition is right or if this statement is true in a more generale case.
 A: The statement holds for more general cases than requiring separability properties:
Indeed it is true when $X$ is a general topological space and it can be written as a union of open sets $U_\alpha$, with $\alpha \in I$ generic index set, for example. Moreover, there property holds even assuming closed sets, but with a little assumption more.

The map $f: X \rightarrow Y$ is continuous if $X$ can be written as the union of open sets $U_{\alpha}$ such that $f_{\big|U_{\alpha}}$ is continuous for each $\alpha$.

Proof: By hypothesis, we can write $X$ as a union of open sets $U_{\alpha}$, such that $f_{\big|U_{\alpha}}$ is continuous for each $\alpha$. Let $V$ be an open set in $Y$. Then
$$
f^{-1}(V) \cap U_{\alpha}=\left(f_{\big|U_{\alpha}}\right)^{-1}(V),
$$
because both expressions represent the set of those points $x$ lying in $U_{\alpha}$ for which $f(x) \in V$. Since $f_{\big|U_{\alpha}}$ is continuous, this set is open in $U_{\alpha}$, and hence open in $X$. But
$$
f^{-1}(V)=\bigcup_{\alpha}\left(f^{-1}(V) \cap U_{\alpha}\right),
$$
so that $f^{-1}(V)$ is also open in $X$.

The same condition holds even in the case $U_\alpha$ are closed, but here you need to require the family is locally finite. An indexed family of sets $\left\{A_{\alpha}\right\}$ is said to be locally finite if each point $x$ of $X$ has a neighborhood that intersects $A_{\alpha}$ for only finitely many values of $\alpha$.


With the notation above, if the family $\left\{A_{\alpha}\right\}$ is locally finite and each $A_{\alpha}$ is closed, then $f$ is continuous.

Proof: Let $B$ be a closed subset of $Y$. Then $A=f^{-1}(B)=\cup_{\alpha}\left(f_{\big|A_{\alpha}}\right)^{-1}(B)$ (this follows from the fact that $\cup_{\alpha} A_{\alpha}=X$ ). Suppose $x \notin A$. There is a neighborhood $U$ of $x$ such that it intersects only a finite number of sets in the collection: $A_{1}, \ldots, A_{n}$. For each $i=1, \ldots, n:\left(f_{\big|A_{i}}\right)^{-1}(B)=S_{i}$ is closed in $A_{i}$ and, therefore, closed in $X$ (as $A_{i}$ is closed). Moreover, $x \notin S_{i}$. Hence, there is a neighborhood $U_{i}$ of $x$ such that $U_{i} \cap S_{i}=\emptyset$. The intersection $U^{\prime}=U \cap \cap_{i} U_{i}$ is a neighborhood of $x$ such that $U^{\prime} \cap A=\emptyset$. We conclude that $A$ is closed.
