# Where is the flaw in my proof that the union of two continuous functions is continuous?

Problem. Let $f:A\to\mathbb{R}$ be a continuous function on $A$ and $g:B\to\mathbb{R}$ be a continuous function on $B$ such that $A\cap B=\emptyset$. Let $h:A\cup B\to\mathbb{R}$ be defined by, $$h(x)=\begin{cases}f(x)& x\in A\\ g(x)& x\in B\end{cases}$$Is $h$ continuous on $A\cup B$?

Proof. Let $(x_n)_{n\ge1}$ be any sequence from $A\cup B$ converging to $c\in A\cup B$. Let us now form two subsequences of $(x_n)_{n\ge1}$, namely $(y_n)_{n\ge1}$ and $(z_n)_{n\ge1}$ such that $y_n\in A$ and $z_n\in B$ for all $n\in \mathbb{N}$.

Then clearly $(h(y_n))_{n\ge1}\to h(c)$ since $h(y_n)=f(y_n)$ for all $n\in\mathbb{N}$ and $(h(z_n))_{n\ge1}\to h(c)$ since $h(z_n)=g(y_n)$ for all $n\in\mathbb{N}$. Consequently $(h(x_n))_{n\ge1}\to h(c)$ and we are done.

But the problem is that when I told our professor about this proof he told me that there should be some other conditions. But the argument seems to work well. Where is the flaw (if any) in my argument?

• Consider $f(x) = -x$, $A = [-1;0]$, $g(x) = -x +1$, $B = (0;1]$. – Wojciech Karwacki Sep 20 '15 at 15:25
• As usual, the mistake happens the moment after you use the word "clearly". – 5xum Sep 20 '15 at 15:38

## 6 Answers

As is often the problem in mathematical proofs, there's an issue immediately after you write "clearly"; you only know that $(h(y_n))_{n\geq0} = (f(y_n))_{n\geq0}$, and we don't necessarily know what $(f(y_n))_{n\geq0}$ converges to (if at all!). By saying $h(y_n) \to h(c)$, you implicitly said that $f(y_n) \to f(c)$ but what if $c \in B$ (or neither $A$ nor $B$)?

• But $(f(y_n))_{n\ge1}$ is continuous on $A$. Doesn't this imply that $(f(y_n))_{n\ge1}$ is convergent? – user 170039 Sep 20 '15 at 15:37
• But we don't even know that $y_n$ converges in $A$. – Marcus M Sep 20 '15 at 15:46
• @user170039, think about this example: on the interval $A := (0,1)$, the sequence $y_n = \frac{1}{n}$ converges, i.e. $y_n \to 0$. Moreover, $f(x) = \frac{1}{x}$ is continuous on $A$, but $f(y_n) = n$ doesn't converge. – Marcus M Sep 20 '15 at 16:00
• It may be worth pointing out that the other thing that can go wrong is that one of the subsequences $y_n$ or $z_n$ could be finite. – Rob Arthan Sep 20 '15 at 18:44

Take $A = [-1, 0)$ and $B = [0, 1]$ and take $f(x) = -1$ and $g(x) = 1$, then your function $h$ is not continuous at $0$. Taking $x_n = -1/n$, $x_n \to 0$, but $h(x_n) \to -1 \neq h(0)$.

Your conjecture could be repaired in various ways. E.g., it is true if $A$ and $B$ are required to have disjoint closures. However, your line of proof would have to be that because $A$ and $B$ have disjoint closures, if $x_n$ is sequence in $A \cup B$ that converges to a point $x \in A$ (resp. $B$), then for all large enough $n$, $x_n \in A$ (resp. $x_n \in B$). I.e., one of your subsequences $y_n$ and $z_n$ would be finite.

The condition that $A$ and $B$ have disjoint closures, i.e., that $\overline{A}\cap\overline{B} = \emptyset$, can be relaxed to $A \cap \overline{B} = \overline{A} \cap B = \emptyset$. This weaker condition is necessary as well as sufficient: if either $A \cap \overline{B}$ or $\overline{A} \cap B$ is non-empty, then with $f$ and $g$ constant functions with different values, you get a counterexample.

Here is a counter-example. Take $$f(x)=0, g(x)=1, A=[0,1/2), B=[1/2,1].$$ Then $h$ is clearly not continuous at $1/2$.

Here's an exotic counter example which I think illustrates the problem nicely

Let $f: \mathbb{Q} \to \mathbb{R}$ by $f(x) = 0$, and $g: \mathbb{R} \setminus \mathbb{Q} \to \mathbb{R}$ by $g(x) = 1$. Then, $h = f\cup g$ is given by $$h(x) = \begin{cases} 1 & x \not\in \mathbb{Q}\\ 0 & x \in \mathbb{Q}\end{cases}$$ and $h$ is discontinuous everywhere!

To see why, let's consider the sequence $(x_n)_{n\ge 1}$ given by $x_{2n-1} = \frac{1}{n}$ and $x_{2n} = \frac{\sqrt{2}}{n}$. This sequence converges to $0$. At any even indexed term, $h(x_n) = g(x_n) = 1$, but at the odd indexed terms, $h(x_n) = f(x_n) = 0$. The problem occurs because there are infinitely many points of the sequence in each of $A$ and $B$. The sequence cannot converge to any number (in particular, it cannot converge to $h(0)$).

There are various ways to restrict either the domains of the functions or the functions themselves so that the result become true. For example, if we require that $\lim_{y \to x} f(y) = \lim_{y \to x} g(y)$ for every $x \in \overline{A} \cap \overline{B}$, the $h$ is continuous (and using Rob Arthan's observation in the last paragraph of his answer, we can weaken the requirement to the limits of $f$ and $g$ agreeing for any $x \in (\overline{A} \cap B) \cup (A \cap \overline{B})$).

• +1, I was just about to type this one in myself when I saw yours. – Lee Mosher Sep 20 '15 at 23:53

Suppose there are two constant functions: $f: (-\infty,0] \to \{0\}$ and $g: (0, \infty) \to \{1\}$. Can you see where your reasoning fails?

The problem is that you showed that 2 subsequences converge to the same limit, then concluded that the entire sequence converges to the same limit. If you want your proof to be valid, it should be shown for ALL subsequences. Cheers!

• I don't think even the OP's statement that each subsequence converges to $c$ is valid. – David K Sep 20 '15 at 19:36
• This part of the proof is actually correct; if two subsequences whose union is the entire sequence converge to the same limit, then the sequence does converge to that limit. It is a nice exercise to prove this if you are unfamiliar with it. – Eric Wofsey Sep 21 '15 at 2:21