Let $f$ be a real function and $aLet $f$ be a real function and $a<b<c<d$. If $f$ is convex on $[a,c]$ and $[b,d]$, then can we say $f$ is convex on $[a,d]$?
Below is my attempt. If we can show that when $x_1\in[a,b]$, $x_2\in [c,d]$,
then $$f(\theta x_1+(1-\theta)x_2)\le \theta f(x_1)+(1-\theta)f(x_2),\forall \theta\in(0,1)$$ the proof is done.
Let $x_3:=\theta x_1+(1-\theta)x_2$. It is equivalent to prove
$$\frac{f(x_3)-f(x_1)}{x_3-x_1}\le \frac{f(x_2)-f(x_3)}{x_2-x_3}.$$
When $x_3\in (b,c)$, we have
$$\frac{f(x_3)-f(x_1)}{x_3-x_1}\le \frac{f(c)-f(x_3)}{c-x_3}\le \frac{f(x_2)-f(x_3)}{x_2-x_3}.$$
However, when $x_3\in [a,b]\cup [c,d]$, the approach fails.
 A: Here is an elementary proof.
For any $p,q\in[a,d]$, denote by $L\left(p,q\right)$ the line segment joining $(p,f(p))$ and $(q,f(q))$. We shall prove that $(r,f(r))$ lies on or below $L(p,q)$ whenever $a\le p<r<q\le d$.
If $[p,q]\subseteq[b,d]$ or $[a,c]$, we are done because $f$ is convex on $[b,d]$ and $[a,c]$.
Suppose $p<b<c<q$. By replacing $f$ by $f(x)-\left[f(p)+\frac{f(q)-f(p)}{q-p}(x-p)\right]$, we may assume that $f(p)=f(q)=0$. If $(r,f(r))$ lies above $L(p,q,f)$, then $f(r)>0$. We will show that this leads to contradictions. There are three possibilities:

*

*$r\in[b,c]$. Since $f$ is convex on $[b,c]$, $(r,f(r))$ lies on or below $L(b,c)$. Therefore $\max\{f(b),f(c)\}\ge f(r)$. Assume that $f(b)\ge f(r)$ (the other case can be treated similarly). Then $f(b)\ge f(r)>0=f(p)$. Since $p<b\le r$, the point $(b,f(b))$ lies above $L(p,r)$, but this is a contradiction because $f$ is convex on $[a,c]\supseteq[p,r]\ni b$.

*$r\in(p,b)$. Since $p<r<b<c<q$ and $f$ is convex on $[a,c]$, we have $\frac{f(c)-f(b)}{c-b}\ge\frac{f(b)-f(p)}{b-p}\ge\frac{f(r)-f(p)}{r-p}>0$ and hence $f(c)>f(b)>0$. But then $(c,f(c))$ lies above $L(b,q)$, which is a contradiction because $f$ is convex on $[b,d]\supseteq[b,q]\ni c$.

*$r\in(c,q)$. This is similar to case 2.

A: The answer is YES. $f$ has right-hand (as well as left-hand) derivative at every point of $(a,c)$ and $(b,d)$ and $f'(t+)$ is increasing in each of these intervals. This implies that $f'(t+)$ is increasing in $(a,d)$. It follows also that $f(y)=f(x)+\int_x^{y}f'(t+)dt$ for $x <y$.  This is enough to say that $f$ is convex on $(a,d)$. Convexity on the closed interval $[a,d]$ is now easy to check.
