# What does a symmetry that changes the Lagrangian by a total derivative do to the Hamiltonian $H$?

I) *Disclaimer.* As a purist, I disapprove of the common praxis to call the implication
$$ \tag{1} \{Q,H\}+\frac{\partial Q}{\partial t}~=~0 \qquad\Rightarrow\qquad \frac{dQ}{dt}~\approx~0.$$
for a 'Hamiltonian version of Noether's theorem', cf. my Phys.SE answers here & here. My reason is that the implication (1) is merely a trivial consequence of Hamilton's equations, nothing more.

II) Instead, a 'Hamiltonian version of Noether's theorem' should refer to quasi-symmetries of a *Hamiltonian action*
$$ S_H[q,p] ~:=~ \int \! dt ~ L_H(q,\dot{q},p,t), \tag{2}$$
and their corresponding conservation laws. Here $L_H$ is the so-called *Hamiltonian Lagrangian*
$$ L_H(q,\dot{q},p,t) ~:=~\sum_{i=1}^n p_i \dot{q}^i - H(q,p,t). \tag{3}$$

III) It is a misunderstanding that *all that fuss about total derivatives [...] disappears in the Hamiltonian framework.* The Hamiltonian version allows for the Hamiltonian action to only be invariant up to boundary terms (i.e. a so-called quasi-symmetry) just like in the standard Lagrangian formulation of Noether's theorem. See also this related Phys.SE post.

I suppose I figured out the "answer" to my very vague question, although the other answers here are also helpful. The "Hamiltonian Lagrangian" is

$$ L = p_i \dot q_i - H. $$ Say we have a conserved charge $Q$, that is $$ \{Q, H\} = 0. $$ If we make the tiny symmetry variation $$ \delta q_i = \frac{\partial Q}{\partial p_i} \hspace{1cm} \delta p_i = - \frac{\partial Q}{\partial q_i} $$ then \begin{align*} \delta L &= - \frac{\partial Q}{\partial q_i} \dot q_i - p_i \frac{d}{dt} \Big( \frac{\partial Q}{\partial p_i} \Big) + \{ H, Q\} \\ &= - \frac{\partial Q}{\partial p_i} \dot q_i - \dot p_i \frac{\partial Q}{\partial p_i} + \frac{d}{dt} \Big( p_i \frac{\partial Q}{\partial p_i} \Big) \\ &= \frac{d}{dt} \Big( p_i \frac{\partial Q}{\partial p_i} - Q\Big) \end{align*}

So we can see that $L$ necessarily changes by a total derivative. When the quantity $p_i \frac{\partial Q}{\partial p_i} - Q = 0$, the total derivative is $0$. This happens when the conserved quantity is of the form $$ Q = p_i f_i(q). $$ Note that in the above case, $$ \delta q_i = f_i(q) $$ That is, symmetry transformations which do not "mix up" the $p$'s with the $q$'s have no total derivative term in $\delta L$.

The reason we don't talk about "changing the Hamiltonian by a total derivative" is because symmetries and conservation laws are usually handled differently in the Hamiltonian picture.

In Hamiltonian mechanics, any function $f$ on phase space generates a flow on phase space, i.e. a one-parameter family of canonical transformations $(q, p) \to (\tilde{q}(\alpha), \tilde{p}(\alpha))$. The induced rate of change of any other phase space function $g$ is $$\frac{dg}{d\alpha} = \{g, f\}.$$ In particular, the Hamiltonian itself generates time translation, $$\frac{dg}{dt} = \{g, H\}.$$ The statement that $Q(q, p)$ is a conserved quantity is simply $$\{Q, H\} = 0.$$ That is, the time evolution generated by $H$ doesn't change the value of $Q$. The key is that this is equivalent, by the antisymmetry of the Poisson bracket, to $\{H, Q\} = 0$, which states that the canonical transformations generated by $Q$ don't change the values of $H$.

Thus, given an infinitesimal canonical transformation that keeps $H$ the same, its generator is a conserved quantity. This is the closest thing to Noether's theorem you'll usually see in Hamiltonian mechanics. Since it refers to only $H$, not the integral of $H$, there's no need to talk about keeping $H$ invariant up to a total derivative -- it just has to be invariant, period. (But also see Qmechanic's answer, about an action-like formulation where it does appear.)