TITLE: Midpoint-Convex and Continuous Implies Convex
QUESTION [48 upvotes]: Given that $$f\left(\frac{x+y}{2}\right)\leqslant \frac{f(x)+f(y)}{2}~,$$
how can I show that $f$ is convex.
Thanks.  

Edit: I'm sorry for all the confusion. $f$ is assumed to be continuous on an interval $(a,b)$.

REPLY [2 votes]: Here is a sketch of the standard proof by contradiction: 
if $f$ is not convex, then continuity implies that there is an interval $[a',b']\subset (a,b)$ such that, if $g:[a',b']\to \mathbb R$ is defined by $$g(x)=f(x)-\frac{f(b')-f(a')}{b'-a'}(x-a')-f(a'),$$
then the  following is true:
$\tag 1 s:=\sup_{x\in [a',b']}\{g(x)\}>0$
$\tag 2 g(a')=g(b')=0$
$\tag 3 g \ \text{is midpoint convex}$
The motivation for this is that if $f$ is not convex then, by continuity,  the graph of $f$  must rise above a segment connecting the endpoints $(a',f(a'))$ and $(b',f(b'))$ 
Note that since $g$ is continuous and $[a',b']$ is compact, $s$ is actually attained by at least one $x\in [a',b'].$
Now, put $c=\inf \{x\in [a',b']: g(x)=s\}.$ Continuity of $g$ implies that $g(c)=s$ and $(2)$ implies that $a'<c<b'.$ Now choose $\delta>0$ small enough so that $c+\delta$ and $c-\delta$ are contained in $(a',b').$ Then, the definition of $c$ together with $(1)$ implies that $g(c-h)<g(c)$ and $g(c+h)\le g(c)$, and therefore that $g(c)>\frac{g(c-h)+g(c+h)}{2}$, which contradicts $(3).$