This is a lengthier comment...
Is the first $f$ the same as the second, i.e. where is the $-\frac{i}{2}$ coming from? $\frac{1}{2}$? Is it the function in the second expression shifted by this number / does it come from permuting $X$ and $P$?
Is $p=-i\frac{\text{d}}{\text{d}x}$? What does real valued function mean here?
Does
$$\left(x\frac{\text{d}}{\text{d}x}\right)^n x^m
=\left(x\frac{\text{d}}{\text{d}x}\right)^{n-1} (x\ m\ x^{m-1})
=m\left(x\frac{\text{d}}{\text{d}x}\right)^{n-1} x^m
=m^n x^m$$
help?
Let $B=x\frac{\text{d}}{\text{d}x}$, so that $B^nx^m=m^n x^m$ and consider $H$ in the form $\beta(B)=\sum_n b_n B^n$. Collect all the powers of $-\frac{i}{2}$ in $b_0$, and notice that the real even powers $(-\frac{i}{2})^{2N}\phi(x)=\pm\frac{1}{4^N}\phi(x)$ are merely energy shifts in your equation.
Then
$$H\phi(x)=\left(\sum_n b_n B^n\right)\left(\sum_m\varphi_mx^m\right)=\sum_m\left(\sum_nb_nm^n\right)\varphi_mx^m=\sum_m\beta(m)\varphi_mx^m.$$
E.g. for $\phi(x)=Cx^k$, integrable in a box, you find $H\phi(x)=\beta(k)\phi(x)$.
If $\beta$ is periodic, e.g. $\beta(2)=\beta(5)$, then there are other solutions like $\phi(x)=C_1x^2+C_2x^5$ too.