Show that the function $f : A \cup B \to Y, \quad x \mapsto \begin{cases} g(x), &x\in A \\h(x), &x\in B\end{cases}$ is continuous. Good evening, I'm doing Problem III.2.13 from textbook Analysis I by Amann.



Could you please verify if my proof look fine or contains logical gaps/errors? Any suggestion is greatly appreciated. Thank you so much!

My attempt:

Lemma: For $a \in (A -B)$, there is $r_a>0$ such that $B \cap \mathbb B_X(a,r_a) = \emptyset$. Similarly, for $b \in (B-A)$, there is $r_b>0$ such that $A \cap \mathbb B_X(b,r_b) = \emptyset$.



*

*For $a \in (A-B)$ and $r>0$
Then there is $r_1 > 0$ such that $g[\mathbb B_A(a,r_1)] \subseteq \mathbb B(g(a),r) =\mathbb B(f(a),r)$. Let $r_2 = \min \{r_1,r_a\}$. We have $(B \cap \mathbb B_{X}(a,r_2)) \subseteq (B \cap \mathbb B_{X}(a,r_a)) = \emptyset$ by Lemma. As such, $$\begin{aligned}\mathbb B_{A \cup B}(a,r_2) &= (A \cup B) \cap \mathbb B_{X}(a,r_2) &&= (A \cap \mathbb B_{X}(a,r_2)) \cup (B \cap \mathbb B_{X}(a,r_2))\\ &= \mathbb B_{A}(a,r_2) \cup \emptyset &&= \mathbb B_{A}(a,r_2)\end{aligned}$$ and consequently $$f[\mathbb B_{A \cup B}(a,r_2)] = f[\mathbb B_{A}(a,r_2)] = g[\mathbb B_{A}(a,r_2)] \subseteq g[\mathbb B_{A}(a,r_1)] \subseteq \mathbb B(f(a),r)$$ As such, $f$ is continuous at $a \in (A-B)$.


*For $b \in (B-A)$ and $r>0$
With a similar reasoning, we obtain $f$ is continuous at $b \in (B-A)$.


*For $c \in (A \cap B)$ and $r>0$
Then there are $r_1,r_2 > 0$ such that $$g[\mathbb B_A(c,r_1)] \subseteq \mathbb B(g(c),r) = \mathbb B(f(c),r)$$ and $$h[\mathbb B_B(c,r_2)] \subseteq \mathbb B(h(c),r) = \mathbb B(f(c),r)$$ Let $r_3 = \min \{r_1,r_2\}$. We have $$\begin{aligned}\mathbb B_{A \cup B}(c,r_3) &=(A \cup B) \cap \mathbb B_{X}(c,r_3) &&= (A \cap \mathbb B_{X}(c,r_3)) \cup (B \cap \mathbb B_{X}(c,r_3)) \\&= \mathbb B_{A}(c,r_3) \cup \mathbb B_{B}(c,r_3) &&\subseteq \mathbb B_{A}(c,r_1) \cup \mathbb B_{B}(c,r_2)\end{aligned}$$ and consequently $$\begin{aligned}f[\mathbb B_{A \cup B}(c,r_3)] &\subseteq f[\mathbb B_{A}(c,r_1) \cup \mathbb B_{B}(c,r_2)] &&= f[\mathbb B_{A}(c,r_1)] \cup f[\mathbb B_{B}(c,r_2)] \\ &= g[\mathbb B_{A}(c,r_1)] \cup h[\mathbb B_{B}(c,r_2)] &&\subseteq \mathbb B(f(c),r) \cup \mathbb B(f(c),r) \\ &= \mathbb B(f(c),r)\end{aligned}$$  As such, $f$ is continuous at $c \in (A\cap B)$.
 A: From @amsmath, I present my attempt in which I work with sequence here. It would be great if someone helps me verify it. Thank you so much!

My attempt:
Let $(x_k)$ be a sequence in $A \cup B$ such that $x_k \to x$ as $k \to \infty$.
Case 1: $A$ contains finitely many terms of $(x_k)$
Then $B$ contains infinitely many terms of $(x_k)$. Let $N = 1+\max \{k \in \mathbb N \mid x_k \in A\}$. Then $x_{k+N} \in B$ and thus $f(x_{k+N})= h(x_{k+N})$ for all $k$. It follows from $B$ is closed that $x = \lim_{k \to \infty} x_k = \lim_{k \to \infty} x_{k+N} \in B$, so $f(x)=h(x)$. We have $\lim_{k \to \infty} f(x_k) = \lim_{k \to \infty} f(x_{k+ N}) = \lim_{k \to \infty} h(x_{k+ N}) \overset{(\star)}{=} h(\lim_{k \to \infty} x_{k+ N}) =$ $h(x) = f(x)$. As such, $f$ is continuous at $x$.
$(\star)$ is due to the fact that $h$ is continuous.
Case 2: $B$ contains finitely many terms of $(x_k)$
We obtain the same result with a similar reasoning.
Case 3: $A$ and $B$ each contains infinitely many terms of $(x_k)$
We define $\mu,\nu: \mathbb N \to \mathbb N$ recursively by $$\begin{aligned}&\mu_0 = \min \{k \in \mathbb N \mid x_k \in A\}, && \mu_{n+1} = \min \{k \in \mathbb N \mid x_k \in A \, \text{and} \, k > \mu_n\} \\ &\nu_0 = \min \{k \in \mathbb N \mid x_k \in B\}, && \nu_{n+1} = \min \{k \in \mathbb N \mid x_k \in B \, \text{and} \, k > \nu_n\} \end{aligned}$$
By construction, $(x_{\mu_k})$ and $(x_{\nu_k})$ are subsequences of $(x_k)$. Moreover, $f(x_{\mu_k}) = g(x_{\mu_k})$ and $f(x_{\nu_k}) = h(x_{\nu_k})$ for all $k$. Because $\lim_{k \to \infty} x_k = x$ and $A,B$ are closed, $\lim_{k \to \infty} x_{\mu_k} = x \in A$ and $\lim_{k \to \infty} x_{\nu_k} = x \in B$. Because $g,h$ are continuous, $\lim_{k \to \infty} f(x_{\mu_k}) = \lim_{k \to \infty} g(x_{\mu_k}) = g(x) = f(x)$ and $\lim_{k \to \infty} f(x_{\nu_k}) = \lim_{k \to \infty} h(x_{\nu_k}) = h(x) = f(x)$.
For $\epsilon > 0$, there is $N \in \mathbb N$ such that $|f(x_{\mu_k})- f(x)| < \epsilon$ and $|f(x_{\nu_k})- f(x)| < \epsilon$ for all $k \ge N$. Let $M = \max \{\mu_N,\nu_N\}$. It follows that $|f(x_k) - f(x)| < \epsilon$ for all $k \ge M$. As such, $\lim_{k \to \infty} f(x_k) = f(x)$. Hence $f$ is continuous at $x$.
