# Why does the following contradiction arise in Lagrangian Formalism?

If we look at the Lagrange's equation

$\frac{d}{dt}(\frac{\partial L}{\partial \dot{q_i}})- \frac{\partial L}{\partial q_i}=0$

It is clear that Lagrangian is invariant under a Transformation $L \rightarrow L + \frac{dF (q_i,t)}{dt}$

because $\frac{\partial \dot{F}(q_i,t)}{\partial \dot{q_i}} = \frac{\partial F}{\partial q}$

But when we look at the action,

$A=\int L{dt}$,

A transformation of the kind $L \rightarrow L + \frac{dF(q_i, \dot{q_i}, t)}{dt}$ would leave the extrema of action invariant and hence the equations of motion should also be invariant(according to the principle of least action) because the total time derivative of $F$ would contribute just a constant.

So under what kind of transformation are equations of motion invariant? $L \rightarrow L + \frac{dF (q_i,t)}{dt}$ or $L \rightarrow L + \frac{dF(q_i, \dot{q_i}, t)}{dt}$

I mean what kind of function should F be? Is it allowed to have explicit dependence on $\dot{q_i}$?

The Euler-Lagrange equation holds for Lagrangians that depend on at most first order derivatives of $q$. But when we take the transformation: $$L' = L+\frac{dF(q,\dot q,t)}{dt}$$ we find that our new Lagrangian now has a dependence on the second order derivative of $q$: $$L' = L+\frac{dF(q,\dot q,t)}{dt} = L+\frac{\partial F}{\partial q}\frac{dq}{dt}+\frac{\partial F}{\partial \dot q}\frac{d\dot q}{dt}+\frac{\partial F}{\partial t}$$ $$= L+\frac{\partial F}{\partial q}\dot q+\frac{\partial F}{\partial \dot q}\ddot q+\frac{\partial F}{\partial t}$$ and so the new Lagrangian now depends on $\ddot{q}$. The only way to avoid the new Lagrangian depending on $\ddot{q}$ is to demand that $$\frac{\partial F}{\partial \dot q} = 0$$ which brings us back to the case where $F$ depends only on $q$ and $t$.