Solution (source code)

= Solution

When $r=p'$, write the differential expression in divergence form,
$$
\widetilde L y=(py')'+qy.
$$
Two integrations by parts give the <Lagrange identity for a Sturm-Liouville operator>:
$$
\langle f,\widetilde Lg\rangle-\langle\widetilde Lf,g\rangle
=\left[p(fg'-f'g)\right]_a^b.
$$
The $q$ terms cancel because $q$ is real. Hence the exact boundary criterion, in the sense of <self-adjointness> defined in the question, is
$$
\boxed{\left[p(fg'-f'g)\right]_a^b=0\quad\text{for every admissible pair }f,g.}
$$
At regular endpoints, all separated homogeneous conditions of the following type satisfy it:
$$
\alpha_a y(a)+\beta_a p(a)y'(a)=0,\qquad
\alpha_b y(b)+\beta_b p(b)y'(b)=0,
$$
with real coefficients, not both zero at either endpoint. The allowed value-and-flux pairs at an endpoint are proportional, so their <determinant> $p(fg'-f'g)$ vanishes. This includes <Dirichlet boundary conditions>, <Neumann boundary conditions>, <Robin boundary conditions> and arbitrary mixtures of these at the two ends.

Coupled conditions can also work: periodic conditions $y(b)=y(a)$ and $p(b)y'(b)=p(a)y'(a)$ make the two endpoint expressions equal; simultaneous minus signs give the antiperiodic case. Thus requiring each endpoint term separately to vanish is sufficient, but not necessary.

More generally, for regular endpoints set $Y=(y(a),y(b))^{\mathsf T}$ and $N=(-p(a)y'(a),p(b)y'(b))^{\mathsf T}$. All maximal homogeneous self-adjoint <boundary conditions> can be written $AY+BN=0$ with real two-by-two <matrices> satisfying $\operatorname{rank}(A\ B)=2$ and $AB^{\mathsf T}=BA^{\mathsf T}$. If an endpoint is singular, the relevant limiting boundary form and admissible domain must instead be specified; the assumption $p>0$ only in the interior does not itself fix those endpoint limits.