# Proving invariance of Lagrange's equations under transformation of the form $L' = L + \dfrac{d}{dt}g(\mathbf{q},t)$

A problem in my classical mechanics textbook is stated as follows:

Show that if the Lagrangian $L(\mathbf{q},\dot{\mathbf{q}},t)$ is modified to $L'$ by any transformation of the form $$L' = L + \dfrac{d}{dt}g(\mathbf{q},t)$$ then Lagrange's equations remain unchanged.

I approched the problem as follows: $$\dfrac{d}{dt}\left(\dfrac{\partial L'}{\partial \dot{q}_j}\right)-\dfrac{\partial L'}{\partial q_j} =0$$ Since $g(\mathbf{q},t)$ is independent of $\dot{\mathbf{q}}$, this becomes: $$\dfrac{d}{dt}\left(\dfrac{\partial L}{\partial \dot{q}_j}\right)-\dfrac{\partial}{\partial q_j}\left(L+\dfrac{d}{dt}g(\mathbf{q},t)\right) =0$$ $$\dfrac{d}{dt}\left(\dfrac{\partial L}{\partial \dot{q}_j}\right)-\dfrac{\partial L}{\partial q_j} = \dfrac{\partial}{\partial q_j}\left(\dfrac{d}{dt}g(\mathbf{q},t)\right)$$ Which leaves us to prove that $$\dfrac{\partial}{\partial q_j}\left(\dfrac{d}{dt}g(\mathbf{q},t)\right) = 0$$

However, I seem to be unable to prove this. Did I make a mistake, or do I just fail to see how this can be proven?

Notice that $$\frac{dg}{dt} = \frac{\partial g}{\partial q}\dot{q}+\frac{\partial g}{\partial t} \, .$$ Hence \begin{eqnarray} \frac{d}{dt}\left(\frac{\partial L'}{\partial \dot{q}}\right)-\frac{\partial L'}{\partial q} &=& \frac{d}{dt}\left[\frac{\partial }{\partial \dot{q}}\left(L+\frac{\partial g}{\partial q}\dot{q}+\frac{\partial g}{\partial t}\right) \right]-\frac{\partial}{\partial q}\left(L+\frac{dg}{dt} \right) \\ &=& \frac{d}{dt}\left[\frac{\partial L}{\partial \dot{q}} \right] -\frac{\partial L}{\partial q} + \frac{d}{dt}\left[\frac{\partial}{\partial\dot{q}}\left(\frac{\partial g}{\partial q}\dot{q}\right) \right] -\frac{\partial}{\partial q}\left(\frac{dg}{dt} \right) \\ &=& \frac{d}{dt}\left[\frac{\partial L}{\partial\dot{q}} \right] -\frac{\partial L}{\partial q} + \frac{d}{dt}\left[\frac{\partial g}{\partial q} \right] -\frac{\partial}{\partial q}\left(\frac{dg}{dt} \right) \, . \end{eqnarray}