Let $\dot x = f(x)$ be an ODE, where $f: U\to \mathbb{R}^n$, and $U\subset \mathbb{R}^n$ is open. Then I know that a first integral is a function $H: U\to \mathbb{R}^n$ so that $H(\varphi(t,x_0))=const$ for every solution $\varphi(t,x_0)$ of the ODE.
My notes prove that $\nabla H \cdot f = 0 \Rightarrow H$ is a first integral.
My question is whether the reciprocal is true, that is, if $H$ is a first integral does it satisfy $\nabla H \cdot f = 0$? I cannot find any clues online.
My notes say that this is true for a planar complex polynomial system, that is, $n=2$ and $f(x,y)=\big(P(x,y),Q(x,y)\big)$, where $P,Q$ are polynomials. Is this true for an $n-$dimensional polynomial system? How about for an arbitrary function $f$?
Thank you very much!
Indeed,$$ 0=\frac{d}{dt}H(\varphi(t,x_0))\Big|_{t=0}=\nabla H(\varphi(t,x_0))\Big|_{t=0}\cdot \frac{d}{dt}\varphi(t,x_0)\Big|_{t=0}=\nabla H(x_0)\cdot f(x_0), $$ since $$ \frac{d}{dt}\varphi(t,x_0)=f(\varphi(t,x_0)). $$