Gauge invariance of the Hamiltonian Consider a Lagrangian $L(x,\dot x,t)$ and a corresponding Hamiltonian $H=\dot xp-L$ where $p=\partial L/\partial \dot x$ which satisfies Hamilton's equations $$\frac{\partial H}{\partial x}=-\dot p$$ $$\frac{\partial H}{\partial p}=\dot x.$$ I'm trying to show that Hamilton's equations are unchanged by a gauge transformation of the Lagrangian $L'=L+ \frac{dF}{dt}$ where $F(x,t)$ is a function of the position and time only. I first expand the derivative of $F$ $$\frac{dF}{dt}=\frac{\partial F}{\partial t}+ \frac{\partial F}{\partial x}\dot x$$ the new conjugate momentum is $$p'=\frac{\partial L'}{\partial \dot x}=\frac{\partial L}{\partial \dot x}+\frac{\partial}{\partial \dot x} \frac{dF}{dt}=p+ \frac{\partial F}{\partial x}$$ and so $$\frac{\partial}{\partial p'}= \frac{\partial p}{\partial p'} \frac{\partial}{\partial p}=\frac{\partial}{\partial p}$$ The new Hamiltonian is $$H'=p'\dot x-L' = p \dot x-L+\frac{\partial F}{\partial x} \dot x - \frac{dF}{dt}=H- \frac{\partial F}{\partial t}$$ Hamilton's equations are then $$\frac{\partial H'}{\partial p'}=\frac{\partial H}{\partial p}- \frac{\partial}{\partial p} \frac{\partial F}{\partial t}=\dot x-0=\dot x$$ and $$\frac{\partial H'}{\partial x}=\frac{\partial H}{\partial x}- \frac{\partial}{\partial x} \frac{\partial F}{\partial t}= -\dot p-\frac{\partial }{\partial t} \frac{\partial F}{\partial x}$$ It is this last equation where I'm having trouble. To satisfy Hamilton's equations, the right side should be equal to $\dot p'= \frac{d}{dt}(p+\frac{\partial F}{\partial x})$ however I end up with a partial derivative on the last term rather than a total derivative as it should be. How can one justify this as satisfying Hamilton's equations?
Edit
It seems that the error is arising when taking the partial of $H'$. When applying $\partial/\partial x$ to $H'(x,p')$ we are implicitly holding $p'$ constant, where as $\partial H/\partial x=- \dot p$ is true only when we are holding $p$ constant, not $p'$. A workaround is to use the form $H'=p' \dot x-L'$ as the functional dependence is clear. Then $$\frac{\partial H'}{\partial x}= -\frac{\partial L'}{\partial x} = -\frac{\partial L}{\partial x}- \frac{\partial}{\partial x} \frac{d F}{dt}= -\frac{d}{dt} \left( \frac{\partial L}{\partial \dot x} + \frac{\partial F}{\partial x}\right) = -\dot p'$$ where Euler-Lagrange was used on the second last equality. I'm still unsure of how to apply the chain rule to my original expression to get the correct result. 
 A: This is a situation where it helps to be very careful about what everything means. First, (being very persnickety) the right hand side should be equal to $-\dot{p}'$ (since $F=-\nabla_x V$.) 
Secondly, (hint) the operator $\partial_x$ has a slightly different meaning when acting on functions of $p,x$ and functions of $p',x$.
Answer: 
Applying the chain rule explicitly, 
\begin{align*}
\partial_x|_{p'} H' &= \frac{\partial H}{\partial x}\Big|_p+\frac{\partial H}{\partial p}\Big|_x\frac{\partial p}{\partial x}\Big|_{p'}-\frac{\partial}{\partial x}\frac{\partial F}{\partial t}\quad \text{(since $F$ depends only on $x,t$)}\\
&=-\dot{p}+\dot{x}\Big(-\frac{\partial}{\partial x}\Big|_{p'}\frac{\partial}{\partial x}F(x,t)\Big)-\frac{\partial}{\partial x}\frac{\partial F}{\partial t}\\
&=-\dot p-\dot x\partial_x^2|_{p'}F(x,t)-\partial_x\partial_tF \\
&=-\dot p'
\end{align*}
A: First of all, the canonical Hamiltonian in classical mechanics and (or the canonical stress-energy tensor in classical field theory) is usually not necessarily gauge invariant.
For example, the Hamiltonian for an electron of mass m and charge e in an exterior electromagnetic field is
$$H=\frac{1}{2m}(p-(e/c)A)^2+e\varphi,$$
which is clearly not gauge invariant. The reason is that the exterior electromagnetic fields in the Lagrangian appear as non-dynamical variables.
Second, the transformation
$$L'=L+ \frac{dF}{dt}$$
you mentioned in your question is not a gauge transformation. A Lagrangian is always determined up to a total derivative, but it should be invariant under gauge transformations.
When talking about symmetries in classical mechanics and classical field theory, one must distinguish two types of "symmetries": Physical Symmetry (dynamical) and Gauge Redundancy (non-dynamical). Gauge redundancies arises from one's freedom of making choices of the way he may formulate the action. In the Langrangian formalism of classical field theory, one usually finds gauge regandancies when there are non-dynamical variables. For example, in classical electromagnetism, $A_{0}$ component is not dynamical because the Lagrangian density does not depend on its time derivative $\dot{A}_{0}$. Another example is the worldsheet metric tensor in string theory. In other words, by the implicit function theorem, one cannot find the corresponding canonical Hamiltonian via the Legendre transformation because the Hessian
$$\frac{\partial^{2}L}{\partial\dot{q}^{i}\partial\dot{q}^{j}}$$
is a singular matrix.
In your case, you should not call the transformation a gauge transformation. But if you are interested in gauge redundancies in your Lagrangian $L(x,\dot{x},t)$, then you must treat the variable $t$ as a separate non-dynamical variable. Then, the naive Hamiltonian
$$H=\dot{x}p-L$$
you gave does not make any sense at all. This is because the action
$$S[t,q(t)]=\int_{a}^{b} dtL(q,\dot{q},t)$$
now possesses a reparameterization invariance of $t$, which is clearly a gauge redundancy. To be specific, one can check that under a reparameterization of the variable $t$ which leaves the end points $t=a$ and $t=b$ fixed, the action becomes
$$\delta S[t,q(t)]=\int_{a}^{b}\left(\frac{\partial L}{\partial\dot{q}}\dot{q}-L\right)\delta tdt.$$
The above integral must vanish for arbitrary $\delta t$ that is fixed at $t=a$ and $t=b$, thus
$$H=p\dot{q}-L\equiv 0.$$
Thus, the naive canonical Hamiltonian vanishes identically. Note that the above naive Hamiltonian vanishes whether or not the action is extremized, which means that it is a mathematical identity that holds also off-shell.
An example of such a case is given by the geodesic of a Riemannian manifold, when parameterized by $q^{0}\equiv t$. The time variable $t$ becomes non-dynamical, and the Lagrangian explicitly depends on $t$ via the metric tensor $g_{\mu\nu}(t,q^{1}(t),q^{2}(t),q^{3}(t))$.
In your case, the canonical momentum $\pi$ of variable $t$ vanishes, but the Hessian has an invertible block
$$\Lambda_{ij}=\frac{\partial^{2}L}{\partial\dot{q}^{i}\partial\dot{q}^{j}}.$$
In principle, one can solve $\dot{q}^{i}$ in terms of variables $t$, $q^{i}$, $\pi$, and $p_{i}$. Plugging these solutions back into the definition of the canonical momenta, one can solve $\dot{q}^{i}$ in terms of $t$, $q^{i}$, $\pi$, $p^{i}$, and obtain a constraint equation on the phase space:
$$\phi(t,q,\pi,p)=0.$$
This means that the naive canonical variables $\left\{t,q,\pi,p\right\}$ on the phase space are not independent. This is known as the constraint system which was studied by Dirac. The physical phase space (reduced phased space) should be gauge fixed, and even dimensional.
