Let $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]$?

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:

  1. $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$.
  2. $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$.
  3. $r\in(c,q)$. This is similar to case 2.

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.