Pasting Lemma

Theorem
Let $X$ and $Y$ be topological spaces.

Let $A$ and $B$ be open in $X$.

Let $f: A \to Y$ and $g: B \to Y$ be continuous mappings that agree on $A \cap B$.

Then the mapping $f \cup g : A \cup B \to Y$ is continuous where $(f \cup g)(x) = f(x)$ if $x \in A$ and $(f \cup g)(x) = g(x)$ if $x \in B$.

Proof

 * $f \cup g$ is well-defined:

To show this, it suffices to check that $f \cup g$ maps any $x \in A \cap B$ to a single value in $Y$. Well, if $x \in A \cup B$, then by definition $f \cup g$ maps $x$ to the value $f(x) \in Y$ because $x \in A$ and to the value $g(x) \in Y$ because $x \in B$. But by hypothesis $f(x) = g(x)$; so indeed $f \cup g$ maps $x$ to a unique value in $Y$.


 * $f \cup g$ is continuous:

To show continuity, we show that $(f \cup g)^{-1}(U)$ is open in $A \cup B$ for every open $U$ in $Y$. Observe first that $(f \cup g)^{-1}(U) = f^{-1}(U) \cup g^{-1}(U)$. For if $x \in (f \cup g)^{-1}(U) \subseteq A \cup B$, then $(f \cup g)(x) \in U$; but if $x \in A$, then $f(x) = (f \cup g)(x) \in U$ i.e. $x \in f^{-1}(U)$ or if $x \in B$, then $g(x) = (f \cup g)(x) \in U$ i.e. $x \in g^{-1}(U)$. In both cases, $x \in f^{-1}(U) \cup g^{-1}(U)$. Conversely if $x \in f^{-1}(U) \cup g^{-1}(U)$, then without loss of generality consider the case of $x \in f^{-1}(U) \subseteq A$; in this case $(f \cup g)(x) = f(x) \in U$ so that $x \in (f \cup g)^{-1}(U)$.

Having established that $(f \cup g)^{-1}(U) = f^{-1}(U) \cup g^{-1}(U)$, note that by continuity of $f$ and $g$, we have that $f^{-1}(U)$ is open in $A$ and $g^{-1}(U)$ is open in $B$. So there are an open sets $P$ and $Q$ of $X$ such that $f^{-1}(U) = P \cap A$ and $g^{-1}(U) = Q \cap B$. Since $A$ and $B$ are open in $X$ and intersections of open sets are open, this implies that $f^{-1}(U)$ and $g^{-1}(U)$ are open in $X$. Furthermore, note that $P \cap A$ and $Q \cap B$ are both subsets of $A \cup B$. Hence, $f^{-1}(U) = f^{-1}(U) \cap (A \cup B)$ and $g^{-1}(U) = g^{-1}(U) \cap (A \cup B)$. Thus, $$ (f \cup g)^{-1}(U) = f^{-1}(U) \cup g^{-1}(U) = (f^{-1}(U) \cup g^{-1}(U)) \cap (A \cup B) $$ demonstrating that $(f \cup g)^{-1}(U)$ is open in the subspace topology of $A \cup B$.