Picking up this material from
Li,Yuan-Chuan;Yeh,Cheh-Chih, Some characterizations of convex functions,Computers & Mathematics with Applications
: Volume $59$, Issue $1$, January $2010$, Pages $327-337$
Definition : Let $\Omega \subset X$ be a subset of a normed linear space $X$. A function $f : X \to \mathbb R$ is called locally convex on $\Omega$ if for all $x \in \Omega$ there exists $x \in U_x \subset \Omega$ open (relative to $\Omega$) such that $f$ is convex on $U_x$. That is, for all $y_1,y_2 \in U_x, \lambda \in [0,1]$,$$
f(\lambda y_1 + (1-\lambda)y_2) \leq \lambda f(y_1)+(1-\lambda)f(y_2)
$$
Note that we did not insist that $\Omega$ is convex, but the domain of $f$ is $X$ so the definition still makes sense. For a given $y_1,y_2 \in \Omega$, we call the statement above as the convexity condition for $y_1,y_2$. That is, the convexity condition for $y_1,y_2$ is true if the convexity definition holds for all $\lambda \in [0,1]$.
Of course, a function $f : X \to \mathbb R$ is called convex if the convexity condition holds for all $y_1,y_2 \in \Omega$, not merely those restricted to a neighborhood of some point.
Theorem : Every locally convex function on a convex subset $\Omega \subset X$ is also convex.
Proof : We will first prove the statement when $X = \mathbb R$ and $\Omega=I$ is an interval (and hence a convex set).
Start with the following idea : if $I$ can be broken into two convex parts which intersect, then it should be convex as well, so let's prove this.
- Claim : If $a,b \in I, a <b$ are such that $f$ is convex is $I_R = I \cap [a,\infty)$ and on $I_L = I \cap (-\infty,b]$ then $f$ is convex on $I$.
Proof of claim : If $a$ or $b$ is an endpoint of $I$ then we are clearly done since either $I_L$ or $I_R$ will equal $I$.
Note that convex functions are automatically continuous on the interior of an interval (this was mentioned in a comment, and can be proved "graphically" by sandwiching the graph of the convex function on a neighborhood of a point between chords of reducing slope, or using the result I proved here as a consequence of left and right derivatives existing at every interior point).
Let $x<y \in I$. If either of $x,y \geq a$ or $x,y \leq b$ are true then either $x,y \in I_R$ or $x,y \in I_L$. Hence, the convexity condition is satisfied for $x,y$. We will then assume that $x<a$ and $y>b$ now.
Now, suppose that $x<z<y$. Either $x<z<a,a<z<b$ or $b<z<y$ must be true : note that $z=a,z=b$ are possible, but these can be handled by continuity of $f$.
We handle $a<z<b$ first.
Note that $x<a<z<b<y$. Thus we can find $r,s \in (0,1)$ such that $a = rx+(1-r)z$ and $z = sa+(1-s)y$. This implies that $$
z = sa+(1-s)y = s(rx+(1-r)z) +(1-s)y = tx+(1-t)y
$$
where $t = \frac{sr}{1-s(1-r)}$. As $a,z,y \in I_R$ and $x,a,z \in I_L$, we get by convexity of $f$ in each of these regions, $$
f(z) \leq sf(a) + (1-s)f(y) \leq s(rf(x)+(1-r)f(z)) - (1-s)f(y)
$$
From here, taking the $f(z)$ to the other side and making $f(z)$ the subject of the inequation leads to $f(z) \leq tf(x)+(1-t)f(y)$, as desired.
We now handle $b<z<y$. The case $x<z<a$ is similarly handled. Now, $x<a<b<z<y$ so there exist $r,s,t \in (0,1)$ such that $$
z = rb+(1-r)y,b = sa+(1-s)y,a=tx+(1-t)b
$$
Now, as an exercise similar to the one in the previous case, one can easily see that $z = tx+(1-t)y$ where $$
t = \frac{rst}{1-s(1-t)}
$$
Finally, using convexity for $b<z<y \in I_R, a<b<y \in I_R,x<a<b \in I_L$ and putting those conditions together, it is easy to see that $f(z) \leq tf(x) + (1-t)f(y)$ as desired.
As I mentioned earlier, the third case is clear. The result is now complete. $\blacksquare$
- Use this claim to show that if $f : \mathbb I \to \mathbb R$ is locally convex then $f$ is convex, where $I$ is an interval.
Fix $z \in I$ not an endpoint. Let $d := \sup\{y \in [z,b] : f \text{ is convex on } I \cap [z,y]\}$. We claim that $d$ is an endpoint of $I$. Clearly $d \neq z$ by local convexity at the point $z$.
If not, then by local convexity at $d$ we have an $r>0$ such that $f$ is convex on $(d-r,d+r) \subset I$, and because $d$ is the supremum, $f$ is convex on $[z,d)$. Now, let $I' = [z,d+r)$. Then, $f$ is convex on $I'\cap [z,\infty)$ and on $I' \cap (-\infty,d]$ where $d>z$. By the claim, $f$ is convex on $I'$, a contradiction to $d$ being the supremum.
It follows that $d$ is an endpoint of $I$. In other words, we have shown that $f$ is convex on $I \cap [z,+\infty)$. A very similar argument but moving in the other direction shows that for any $z'>z \in I$ which is not an endpoint, $f$ is convex on $I \cap (-\infty,z']$. As $z'>z$, the claim finishes off the proof and $f$ is convex on $I$.
- For general normed linear spaces
This follows from the convexity of $\Omega$ and the fact that convexity is essentially a phenomena restricted to functional behavior on one-dimensional line segments.
Let $y_1,y_2 \in \Omega$ be given, and let $f$ be locally convex on $\Omega$. As $\Omega$ is convex, $f$ is also locally convex on every point joining the line segment between $y_1$ and $y_2$, which lies entirely in $\Omega$. Call this line segment $L$.
Let $g(t) = f(ty_1+(1-t)y_2)$ for $t \in [0,1]$. We claim that $g$ is locally convex on $[0,1]$. Indeed, let $t \in [0,1]$ be given. By definition, $z = tx+(1-t)y$ has a neighborhood $U_z \subset \Omega$ in which $f$ is convex. By definition of a neighborhood in a normed linear space, $U_z$ also contains part of the line segment $L$, and corresponding to the values of $t'$ such that $t'y_1+(1-t')y_2$ fall in that part, there is a neighborhood of $t$ in $[0,1]$ over which $g$ is convex. Thus, $g$ is locally convex.
By our previous results, $g$ is convex. This obviously implies that $g(t) \leq tg(0)+(1-t)g(1)$ for any $t \in [0,1]$. If $z = tx+(1-t)y$ then $g(t)=f(z)$ and $tg(0)+(1-t)g(1) = tf(x)+(1-t)f(y)$. Hence, we are done.
Concerning the main question, maybe is easier to prove the converse: if a continuous function $\varphi : I \to \mathbb{R}$ is not convex, then there is a point $z \in I$ such that for every $\varepsilon>0$ the function $\varphi$ restricted to $(z-\varepsilon,z+\varepsilon)$ is not convex. Anyway, I don't know how to choose $z$ in a smart way.
– Motticoz Feb 22 '23 at 19:24