If $f$ is uniformly continuous on two sets, show that $f$ is also uniformly continuous on the union of two given sets

So my next question is again about uniform continuity. Can you give me hints, or (better) give the solution of the following exercise? Thank you very much :-)

Given two subsets $A$ and $B$ of $\mathbb R$ with $A$ bounded from above (i.e., having an upper bound) and $B$ bounded from below (i.e., having a lower bound), where $\sup A = \inf B$ and $\sup A \in A\cap B$

(1) Prove that $A\cap B = \{\sup A\}.$

Now, take $A$ and $B$ as above. Let $f : \mathbb R \rightarrow \mathbb R$ and assume that $f$ is uniformly continuous on $A$ and on $B$.

(2) Prove that f is uniformly continuous on $A \cup B.$

My try:

(1) Let $x \in A\cap B$. Because $\sup A = \inf B,$ $\inf B \le x \le \sup A$ implies $x = \sup A$. I chose $x$ arbitrary, so $ A\cap B = \sup A$

(2) ???


The definition says $\forall\varepsilon>0\ \exists\delta>0\cdots\cdots\cdots\cdots$. To prove that a function is uniformly continuous, you need to find $\delta$ as a function of $\varepsilon$ and prove that it's small enough. You know you've got $\delta_1$ that's small enough on one set and $\delta_2$ that's small enough on the other. Which one is smaller might depend on $\varepsilon$. However $\min\{\delta_1,\delta_2\}$ will be small enough on both sets.

Later note, per comments: Let's make $\delta_A$ small enough so that if $x,y\in A$ and $|x-y|<\delta_A$ then $|f(x)-f(y)|<\varepsilon/2$, and if $x,y\in B$ and $|x-y|<\delta_B$ then $|f(x)-f(y)|<\varepsilon/2$.

Let $\delta=\min\{\delta_A,\delta_B\}$.

If $x,y\text{ both}\in A$ or $\text{both}\in B$, and $|x-y|<\delta$ that does it, as above.

If $x\in A$ and $y\in B$, then the distances from $x$ to the boundary point $b$, and from $y$ to $b$, are less than $\delta$, so $$|f(x)-f(y)| \le|f(x)-f(b)|+|f(b)-f(y)|<\frac\varepsilon2+\frac\varepsilon2=\varepsilon.$$

So in all cases, $|x-y|<\delta$ implies $|f(x)-f(y)|<\varepsilon$.