Proving convexity of a function is a local property Let $I$ be an open interval of $\mathbb R$. Let $\varphi:I\to\mathbb R$ be a continuous function such that $\forall x\in I$, there is an open interval $V(x)\subset I$ containing $x$ such that $\varphi$ is convex on $V(x)$. Is it true that $\varphi$ is convex on $I$? What about if we remove the continuity hypothesis?
It's tempting to say that for any $x\in I$, $\exists y\in I$, $V(x)\cap V(y)\neq\emptyset$ and so $\varphi$ is convex on $V(x)\cup V(y)$ since in this case $V(x)\cup V(y)$ is convex. In that case, we get that $\varphi$ is convex on $\bigcup_{x\in I}V(x)=I$. The problem is I dont know if we can necessarily find such a $y$. Furthermore, we don't use the fact that $\varphi$ is continuous at all, which feels weird. But then on the other hand, I don't really know how to get from the local convexity to convexity without using a similar reasoning. Any help on this question would be greatly appreciated.
 A: I think this is simple enough, and that the continuity of $\phi$ is not needed. Let $c\in(a,b)$. By the hypothesis, there are $c^{-},c^{+}$ with $a \lt c^{-} \lt c \lt c^{+} \lt b$ such that $\phi$ is convex on $[c^{-},c^{+}]$. Now, let
$$
\Omega=\bigg\lbrace d\in [c^{-},b) \ \bigg| \ \phi \ \textrm{is convex on } [c^{-},d] \bigg\rbrace
$$
We have $[c^{-},c^{+}] \subseteq \Omega \subseteq [c^{-},b)$, so $\omega=\sup(\Omega)$ is $\leq b$, and further $\Omega=[c^{-},\omega)$.
In fact, we can show that $\omega=b$, by contradiction as follows. Suppose that $\omega \lt b$. By the hypothesis, there are $\omega^{-},\omega^{+}$ with $a \lt \omega^{-} \lt \omega \lt \omega^{+} \lt b$ such that $\phi$ is convex on $J=[\omega^{-},\omega^{+}]$.
Then $\frac{\omega^{-}+\omega}{2}\in [c^{-},\omega)=\Omega$, so $\phi$ is convex on $K=[c^{-},\frac{\omega^{-}+\omega}{2}]$. Now the interior of $J\cap K$ is nonempty (it contains a neighborhood of $\omega^{-}$), so by gluing, $\phi$ must be convex on $J\cup K=[c^{-},\omega^{+}]$. But then $\omega^{+}\in \Omega$, contradicting $\omega=\sup(\Omega)$. So $\omega=b$, and $\phi$ is therefore convex on $[c^{-},b)$.
A symmetrical argument shows that phi is convex on $(a,c^{+}]$. By gluing, $\phi$ is convex on $(a,b)$ as wished.
Appendix: Since there is a userin the comments who is skeptical about the gluing property, I add a proof for it :
Theorem(gluing property). Suppose a function $\phi$ is convex on two intervals $J,K$ of $\mathbb R$, and that $J\cap K$ has nonempty interior. Then $\phi$ is convex on $J\cup K$.
Proof. For $x_1\lt x_2\lt x_3$ define
$$
\Delta_{f}(x_1,x_2,x_3)=
(x_3-x_2)f(x_1)+(x_2-x_1)f(x_3)-(x_3-x_1)f(x_2)
$$
Notice that $f$ is convex an interval $I$ iff $\Delta_{f}(x_1,x_2,x_3)\geq 0$ for any $x_1\lt x_2\lt x_3\in I$.
Now, we have the purely algebraic identity
$$
a\Delta_{f}(x_1,x_2,x_5)=
b_1\Delta_{f}(x_1,x_2,x_3)+
b_2\Delta_{f}(x_2,x_3,x_4)+
b_3\Delta_{f}(x_3,x_4,x_5) \tag{1}
$$
where $a,b_1,b_2,b_3$ are the nonnegative numbers defined by
$$
\begin{array}{lcl}
a &=&(x_4-x_3)(x_3-x_2) \\
b_1&=&(x_4-x_3)(x_5-x_2) \\ 
b_2&=&(x_2-x_1)(x_5-x_3) \\ 
b_3&=&(x_2-x_1)(x_3-x_2)
\end{array}\tag{2}
$$
More generally, for an arbitrary number of points $x_1\lt x_2\lt \ldots \lt x_n$, it can be shown that any $\Delta_f(x_i,x_j,x_k)$ with $i\leq j\leq k$ can be written as a nonnegative linear combination of the $\Delta_f(x_t,x_{t+1},x_{t+2})$ for $i\leq t \leq j-2$ ; this can be shown by induction on $k-i$, starting with the trivial cases when some variables are equal. The formulas in (2) reflect this.
In particular, if the three deltas in the RHS of (1) are nonnegative, so is the $\Delta$ in the LHS.
Let us now show the theorem. Take $x_1 \lt x_2 \lt x_5$ in $J\cup K$ ; our goal is to show that $\Delta_{f}(x_1,x_2,x_5)\geq 0$.
If $x_1,x_2,x_5$ are all in $J$ or all in $K$, we are done by the hypothesis. So we can assume without loss that (say) $x_1,x_2\in J,x_5\in K$. Then we can find $x_3 \lt x_4\in J\cap K$ such that $x_2\lt x_3 \lt x_4 \lt x_5$. Applying (1) finishes the proof.
A: 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.
A: To prove the desired result directly, I find it easier to glue monotone functions, rather than convex ones.  (N.B. removing the continuity hypothesis doesn't do anything, as any convex function is continuous on the interior of its domain, thus $\phi$ is continuous on a neighborhood of every point and hence local convexity implies continuity everywhere.)
Since $\varphi$ is convex on some neighborhood of every point, it is right-differentiable everywhere.  Moreover, at any point $\bar{x} \in I$, the function $\partial_+ \varphi$ (i.e. the right derivative of $\varphi$) is monotone increasing on the open neighborhood $V(\bar{x})$.  To establish the claim, it then suffices to show that $\partial_+ \varphi$ is monotone on all of $I$.

Proof: Consider $\mathcal{I} = \{\textrm{relatively open intervals $\tilde{I}$ of } I : \partial_+ \varphi \vert_{\tilde{I}} \textrm{ is monotone}\}$, partially ordered by set-inclusion, $\subseteq$.  Given any chain $\{I_\lambda\}_{\lambda \in \Lambda}$ of elements of $\mathcal{I}$, clearly $\cup_\lambda I_\lambda \in \mathcal{I}$ is an upper bound for $\{I_\lambda\}_{\lambda \in \Lambda}$, thus by Zorn's lemma, there exist $\subseteq$-maximal elements of $\mathcal{I}$.  Suppose, toward a contradiction, that there exists a maximal element $I^* \in \mathcal{I}$, with $I^* \subsetneq I$.  Let $x^* \in \textrm{cl}(I^*) \setminus I^*$; without loss let $x^* = \sup I^*$.  By hypothesis, $\partial_+ \varphi \vert_{V(x^*)}$ is monotone, thus for all $x \in V(x^*) \cap I^*$, $\partial_+ \varphi(x) \le \partial_+ \varphi(x^*)$, and thus $\partial_+ \varphi(x) \le \partial_+ \varphi(x^*)$ for all $x \in I^*$ by monotonicity on $I^*$.  Similarly, for any $y > x^*$, $\partial_+ \varphi(x^*) \le \partial_+ \varphi(y)$, and hence $\partial_+ \varphi$ is monotone on $I^* \cup V(x^*)$.  Since without loss we may assume $V(x^*)$ is an open interval, this contradicts the maximality of $I^*$. Thus any maximal element of $\mathcal{I}$ equals $I$ itself, and $\varphi$ is convex, as desired.

To address the specific question about finding, for any $x$, a $y$ such that (i) $V(y) \not \subseteq V(x)$ and (ii) $V(x) \cap V(y)$ is non-empty, pick an arbitrary $x$ and let $\bar{x} \in I$, $\bar{x}> x$ be arbitrary.  Then the sets $\{V(y)\}_{y \in [x , \bar{x}]}$ are an open cover for $[x, \bar{x}]$.  Since $[x, \bar{x}]$ is compact, there exists a finite set of points $y_1,\ldots, y_N \in [x, \bar{x}]$ such that the $\{V(y_i)\}_{i=1}^N$ cover $[x, \bar{x}]$. Without loss, we can take this collection to be minimal, in the sense that we can throw out any $V(y_i)$ that is contained in any other $V(y_j)$.  We can also, without loss, let $y_1 = x$.  Then there is some $V(y_i)$ such that $V(y_i) \cap V(x) \neq \varnothing$ and $V(y_i) \not \subseteq V(x)$ or vice versa.
