Solution (source code)

= Solution

For a time-independent <Hamiltonian operator> and a <Schrödinger picture> observable with no explicit time dependence, the <Heisenberg picture> operator is
$$
\boxed{O_H(t)=e^{iHt}O_Se^{-iHt}.}
$$
Differentiation gives $\dot O_H=iHO_H-iO_HH=i[H,O_H]$, so
$$
\boxed{[H,O_H]=-i\frac{dO_H}{dt}.}
$$
If $O_S$ itself depends explicitly on time, one must add $e^{iHt}(\partial_tO_S)e^{-iHt}$ to $\dot O_H$; the displayed commutator relation uses the usual convention of no explicit time dependence for the observable.