Constructing differential equation from arbitrary Hamiltonian 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?
 A: After thinking about it, as long as the original eigenvalues are non-degenerate it should be possible to have the new Hamiltonian be represented by a differential equation of arbitrarily high order. The key is that the projection operators $P_n$ onto the eigenfunctions exist in the algebra generated by the original Hamiltonian $\hat{H_0}$.
For instance say the nth eigenvalue is $E_n=2$, and there are no other eigenvalues between 3 and 1. Then we can choose an indicator function $f_n(x)$ such that $f_n(2)=1$ but $f_n(x)=0$ if $x$ is less than 1 or greater than 3. Given sufficient continuity the Stone-Weierstrass theorem applies and we can represent $f$ by a polynomial basis
$$ f_n(x) =\sum_k c_{n,k} x^k.$$
Then the operator
$$ P_n \equiv  f_n(\hat{H}) = \sum_k c_{n,k} \hat{H_0}^k $$
will project onto the eigenfunction with eigenvalue 2. The details that this works even though we are dealing with infinite sums comes in the proofs of Gelfand duality.
Since the projectors are in the algebra generated by $\hat{H}_0$, the arbitrary Hamiltonian $\hat{H}$ is also in the algebra
$$H=\sum_{n} \lambda_n P_n=\sum_{n,k} \lambda_n c_{n,k}\hat{H_0}^k,$$
and since the original Hamiltonian can be expanded in terms of functions of $\partial_x$ and $x$, the Hamiltonian $\hat{H}$ also can, although now in general the differential equation will be of arbitrarily high order.
