Mechanical gauge transformation and energy conservation I'm studying lagrangian mechanics, and there's a property where you could obtain an equivalent lagrangian $\mathcal{L'}$ from $\mathcal{L}$ by adding a function which satisfies:
$$ \mathcal{L'}\rightarrow \mathcal{L}+\frac{df(q,t)}{dt}.$$
This lagrangian $L'$ would give rise to the same equations of motion.
My question comes when we study energy conservation of the system. For a system's energy to be conserved it is needed that $\mathcal{L}(q,\dot{q},t)=\mathcal{L}(q,\dot{q})$. But if we add a function $\frac{df(q,t)}{dt}$ time dependence would appear in $\mathcal{L'}$ and energy conservation would be broken. Does energy conservation depend on the lagrangian we use for describing the system?
 A: Strictly formally speaking, yes it does matter. Consider the minimal example
$L = p^2/2m + e^{-t^2}$. Clearly, the $e^{-t^2}$ doesn't do anything to the dynamics of the problem since it is a (time-dependent) constant, but it does provide a time-dependent "background energy". Therefore, strictly speaking this Lagrangian does not enjoy energy conservation.
In a typical physicist sense, however, we don't really care about the "background energy," but only about the "physical energy" of the particles. Therefore, if I were to only consider the kinetic energy of the particles, i.e. by transforming to the Lagrangian $L = p^2/2m$ which provides an equivalent action, that energy is indeed conserved.
A: Note a modified lagrangian need only reproduce the same laws of motion. Likely if the original lagrangian doesn't conserve energy, neither does the new one.
You get the equations of motion by taking the time derivative of the derivative of the lagrangian with respect to $\dot{q}$ then subtracting the derivative of the lagrangian with respect to $q$ and setting that equal to a weighted sum of "constraint forces", typically 0. The first term of this difference is unmodified if $f$ is independent of $\dot{q}$, which is the assumption for $f$.
The second term of the difference is just the gradient of the lagrangian. Taking the gradient and taking the time derivative commute, so if the gradient is constant in time or the gradient of the time derivative is zero, we have no change. So if $f$ is purely a function of time or purely a function of space, it won't contribute. The time derivative could in principle also be cancelled out by a constraint force.
More generally, we have this:Non-Uniqueness of the Lagrangian
