Suppose I begin with the time-independent Schrodinger equation $$ \left(-\frac{1}{2m}\partial_x^2 + V(x)\right)\psi_n(x) = E_n\psi_n(x), $$ ordinarily we specify the function $V$ and then solve for a set of eigenfunctions and eigenvalues. And just to be slightly more general, we do the same thing with Sturm-Liouville equations, which I'll write in terms of the momentum operator and an extra function $U$, $$ \left(\hat{p} U(\hat{x}) \hat{p} + V(\hat{x})\right)\psi_n = E_n\psi_n.$$
Now nothing is stopping us from defining a new Hamiltonian operator with the same eigenvectors but different arbitrary eigenvalues $\lambda_n$,
$$\hat{H}\psi_n = \lambda_n \psi_n$$ Under what conditions can this eigenvalue equation for the new Hamiltonian be represented as a (not-necessarily second order) differential equation in $x$ with the same eigenfunctions? In other words when does $\hat{H}$ belong to the operator algebra generated by $\hat{x}$ and $\hat{p}$?
I see if I define the new eigenvalues by some $n$-independent function $f$ of the original eigenvalues $\lambda_n = f(E_n)$, I can come up with a new differential equation, but does this exhaust the possibilities?