Gauge Symmetry of the Lagrangian My teacher told the following statement to me during office hours. Is it correct and if so, how could one go about proving it?

Given a material system subject to holonomic and smooth constraints whose Lagrangian is $L$ (we are assuming that it can be derived from a generalized potential rather than just a potential), then for a given function $g = g(\underline{q}, \underline{\dot q}, t)$:
\begin{equation*}
        \frac{d}{dt} \left( \frac{\partial g}{\partial \dot q_k} \right) - \frac{\partial g}{\partial q_k} = 0 \hspace{5mm} \iff \hspace{5mm} \exists f=f(\underline{q}, t): g = \frac{d}{dt} f
\tag{1}\end{equation*}

By straightforward computation one can prove the second implication ($\impliedby$) but I am having trouble with the other one. So far, by using the fact that
$$ \frac{\partial}{\partial \dot q_k} \left( \frac{d}{dt}f \right) = \frac{d}{dt} \left( \frac{\partial}{\partial \dot q_k} f \right) + \frac{\partial}{\partial q_k}f $$
and integrating with respect to time I have arrived to:
$$\frac{\partial}{\partial \dot q_k}f = Ct + D$$
where $C,D$ are constants of integration. However it does not seem right and it doesn't help me in showing that a primitive of $g$ with respect to time can not depend on lagrangian velocities.

Any comment or answer is much appreciated!
 A: Your teacher undoubtedly implicitly meant to say that eq. (1) for $g$ should hold for all (possible virtual) paths $t\mapsto q(t)$.  Then the trivial implication $\Longleftarrow$ is still true, while the non-trivial implication now $\Longrightarrow$ holds (as long as there are no topological obstructions) due to an algebraic Poincare lemma of the so-called bi-variational complex, see Ref. 1. For an elementary proof, see Ref. 2.
See also this related Phys.SE post.
References:

*

*G. Barnich, F. Brandt and  M. Henneaux, Local BRST cohomology in gauge theories, Phys. Rep. 338 (2000) 439, arXiv:hep-th/0002245.


*J.V. Jose and E.J. Saletan, Classical Dynamics: A Contemporary Approach, 1998; Section 2.2.2, p. 67.
A: Well, the non-trivial implication is in fact false.
Take $L = \dot{q}^2$ and $g(t,q, \dot{q}) := \dot{q}^3$ so that the E-L equations are $\frac{d\dot{q}}{dt}=0$.
We have
(1) $\frac{d\dot{q}}{dt}=0$ form the E-L equations.
(2) $\frac{d}{dt}\frac{\partial g}{\partial \dot{q}} - \frac{\partial g}{\partial q}= \frac{d\dot{q}}{dt} \frac{\partial^2g}{\partial \dot{q}^2} - 0=0$.
So there should exist $f=f(t,q)$ with $\frac{d}{dt}f(t,q)= \dot{q}^3$. In other words
$$\frac{\partial f}{\partial t}+ \frac{\partial f}{\partial q} \dot{q} = \dot{q}^3\:.$$
Since this must be valid for every $\dot{q}$ we conclude that $\frac{\partial f}{\partial t}=0$ and thus
$$\frac{\partial f}{\partial q} \dot{q} = \dot{q}^3\:.$$
But $\frac{\partial f}{\partial q}$ does not depend on $\dot q$ and thus, taking two derivatives in $\dot{q}$ on both sides we have
$$0= \dot{q}\:.$$
This is even false along to motions as the E-L equations permit $\dot{q}= constant \neq 0$.
Presumably, in your statement it is assumed that $g$ is linear (non-homogeneous possibly) in $\dot{q}^k$. In that case  both implicatios are locally true.
