Elementary inequality generalizing convexity of a function on a segment I am looking for a proof of the following statement which is known to be true as far as I heard.
Let $g\colon [a,b]\to \mathbb{R}$ be a smooth function. Assume that
$$b-a< \pi.$$
Assume also $$g(a)\geq 0,g(b)\geq 0,$$
$$g''+g\leq 0 \mbox{ on } [a,b].$$
Then $g\geq 0$ on $[a,b]$.
 A: Here's another argument using Sturm-Liouville theory.
Given $b - \pi < a \le x \le b$,
let
$$
  f(x) = \sin (x - b + \pi).
$$
Observe that $f > 0$ and $f'' + f = 0$ on $[a,b)$, $f(a) > 0$, $f(b) = 0$, and $f'(b) = -1$.
Since
\begin{align*}
 (fg'-f'g)' &= (g'' + g)f - (f''+f)g \le 0\\
  (fg'-f'g)(b) &= f(b)g'(b) - f'(b)g(b) = g(b) \ge 0,
\end{align*}
it follows that, on $[a,b]$,
$$
  fg' - f'g \ge 0.
$$
and therefore, on $[a,b)$,
\begin{align*}
  \left(\frac{g}{f}\right)' &= \frac{fg' - gf'}{f^2} \ge 0.
\end{align*}
Since
$$
  \frac{g(a)}{f(a)} \ge 0,
$$
it follows that, on $[a,b)$,
$$
  \frac{g}{f} \ge 0.
$$
A: Write $g=g^+-g^-$ in $[0,\ell]$, multiply $g''+g \le 0$ by $g^-$ (which vanishes at the the endpoints) and integrate. Then we get with $v=g^-$
$$
\int_0^l v'^2- \int_0^l v^2 \le 0.$$
Since the first eigenvalue of the Dirichlet laplacian in $[0,\ell]$ is $\pi^2/\ell^2 $ we have also
$$
\int_0^l v^2 \le \frac{\ell^2}{\pi^2} \int_0^l v'^2 $$ and then $v=g^-=0$, since $\ell <\pi$.
A: Suppose the contrary, so that $g(s)<0$ for some $s\in(a,b)$. Replacing now $a$ and $b$ by $\max\{t\in[a,s)\colon g(t)\ge0\}$ and $\min\{t\in(s,b]\colon g(t)\ge0\}$, respectively, we see that without loss of generality (wlog)
\begin{equation}
    g(a)=0=g(b). 
\end{equation}
Also, by a horizontal shift, wlog
\begin{equation}
    a=0,\quad b\in(0,\pi). 
\end{equation}
Let
\begin{equation}
    h:=-(g''+g)\ge0.
\end{equation}
Then
\begin{equation}
    G(t):=G_b(t):=g(t)\sin b=\sin t\,\int_0^b du\,h(u)\sin(b-u)
    -\sin b\,\int_0^t du\,h(u)\sin(t-u).
\end{equation}
We have to show that $G\ge0$ on $[0,b]$. Because the nonnegative function $h$ can be however closely approximated in $L^1$ by conical combinations of the indicators of intervals, wlog $h=1_{[c,d]}$ for some $c,d$ such that $0<c<d<b$, in which case
\begin{equation}
    G(t)=\sin t\, (\cos (b-d)-\cos (b-c))-\sin b\, (\cos (t-\max (c,\min (d,t)))-\cos (c-t)).
\end{equation}
So, if $0\le t\le c$, then $G(t)=\sin t\, (\cos (b-d)-\cos (b-c))\ge0$.
The case $d\le t\le b$ is similar, by the left-to-right symmetry.
It remains to consider the case when $c\le t\le d$. Then
\begin{equation}
    G''(t)=\sin t\, (\cos b\, (\cos c-\cos d)-\sin b\, \sin d)-\sin b \cos c\,\cos t
    =A\sin(t+C)=:f(t),
\end{equation}
where $A,C$ depend only on $b,c,d$. The function $f$ will be $\le0$ on the interval $[c,d]$ of length $<\pi$ iff $f(c)\le0$ and $f(d)\le0$. In our case, we have
\begin{equation}
    2f(c)=\sin (b-c-d)-\sin (b+c-d)-\sin (b-2 c)-\sin (b)
\end{equation}
and hence $(f(c))'_d=-\sin c\, \sin (b-d)\le0$, so that $f(c)$ decreases in $d$. So, wlog $d=c$, in which case $f(c)=-\sin b\le0$. Thus, $f(c)\le0$ always, that is, for all $d\in[c,b]$.
Similarly, by the left-to-right symmetry, $f(d)\le0$, which completes the proof.
A: This is sometimes called a maximum principle "on thin domains". My answer below is technically equivalent to @Deane Yang's answer in this specific context, but the scope is more general so I thought I'd still give it a shot (in particular the argument applies to higher dimensions as well, see the comments below).
Note first that if the eliptic operator under consideration had nonnegative zeroth-order coefficient we could immediately conclude from the standard maximum principle that $-g''+g\geq 0$ implies $g\geq 0$, given that $g\geq 0$ on the boundaries. The problem here is of course that your operator
$$
\mathcal L[g]=-g''-g
$$
has negative zeorth-order coefficient, $c(x)\equiv -1$.

Here comes the trick now: assume that you can find some particular function $f(x)\geq C>0$ (up to the boundary) such that $\mathcal L[f]\geq 0$.
(The fact that you can find such a function relies on the thinness of the domain, I will come back to this later on. In your specific example you can take $f(x)=\sin(x-b+\pi)$ as in @Deane Yang's answer.)
Think then of $g$ as $uf$ for some $u$. (Here the strict positivity of $f$ is important so that $u$ is smooth enough, no funny business can arise from this change of variables)
Define then
$$
\tilde{\mathcal{L}}[u]:=\mathcal{L}[uf].
$$
Here you can compute expliticly $\mathcal L$, but the key is that in whole generality this new elliptic operator
$$
\tilde{\mathcal{L}}[u] =\Big(\mbox{1st & 2nd order}\Big) + \Big(\mathcal L[f]\Big) u
$$
always has a zeroth-order coefficient with the right sign, i-e $\tilde c(x)=\mathcal L[f](x)\geq 0$ .
Now if $g$ is a supersolution of $\mathcal L[g]\geq 0$ you have by definition that $u:=\frac{g}{f}$ is a supersolution of $\tilde{\mathcal L}[u]\geq 0$. Applying the usual maximum principle (with $\tilde c(x) \geq 0$) you conclude that $u\geq 0$, hence $g\geq 0$.

Comment 1: here you see that the key point is the existence of a well-chosen $f(x)$, which is not to be taken for granted.
The reason why you can actually find such a function is that your domain is small enough in terms of the lowest eigenvalue of the Dirichlet problem for the homogeneous problem, without zeroth-order terms: notice obviously that this mysterious function $f(x)=\sin(x-b+\pi)$ is indeed the principal eigenvalue of $-\frac{d^2}{dx^2}$ on the domain $(b-\pi,b)$ with zero boundary conditions. The trick is here that your domain $(a,b)\subset (b-\pi,b)$ is $b-a>0$ is small enough.
(This reminds me of a classical exercise in elliptic PDEs where one is asked to apply the Lax-Milgram theorem for operator whose zeroth-order term has the wrong sign, but not too large in modulus compared to the first eigenvalue, see also @Giorgio Metafune's answer)
Comment 2:
The trick works exactly the same in higher dimensions.
For example if you were working in two dimensions on an infinite but thin enough strip, then plugging in a well-chosen $\sin$ function depending only on the thin coordinate automatically gives a suitable $f$. I can't remember where I learnt this trick, and also I'm pretty sure that I also read somewhere a completely general statement that, regardless of the initial coefficients, sufficiently narrowing down the domain always gives a suitable $f$ (this is natural if one thinks of resonant frequencies: in the absence of zeroth-order terms, thinness in any direction of a given object/domain gives a high-pitch natural frequency, hence a large principal eigenvalue that can effectively dominate any zeroth-order coefficient that you might want to add to the free resonance).
The trick also works sometimes for nonlinear operators, but the "change of variables" to go from $g$ to $u$ can be very delicate to find, it's not just products and quotients anymore.
Comment 3: this is called "thin domains" because the argument is usually applied as above (in a systematic way, since thinness is a classical sufficient condition), but in fact everything relies on the existence of a "nice" $f$. So even in the broader context of not necessarily thin domains (balls, or whatever) one might get lucky by guessing the right $f$ (if any, of course!)
A: Another approach in the spirit of viscosity solutions/maximum principle:
Assume wlog $a>0$ and $b<\pi$. Let $I:=[a,b]$ and define
$$f(x):=\sin x,\quad g_\lambda:=g+\lambda f.$$
If $g=g_0<0$ somewhere on $I$, then we can then find $\lambda>0$ such that
$\min_I g_\lambda=0$ (observe that $f\ge c$ on $I$ for some $c>0$ and look at $\lambda\mapsto\min_I g_\lambda$).
But then $g_\lambda''\le g_\lambda''+g_\lambda\le 0$ on $I$, so $g_\lambda$ is concave. Since $g_\lambda>g$ is positive at the boundary of $I$, it must be positive on all of $I$, contradiction.
