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?
 A: Assuming $x,\dot x$ and $p'$ are independent we have $$\frac{\partial H'}{\partial x}= \frac{\partial}{\partial x } \left( p' \dot x-L'\right)= -\frac{\partial L'}{\partial x}=-\frac{\partial L}{\partial x}-\frac{\partial}{\partial x}\frac{dF}{dt}$$ By Euler-Lagrange: $$\frac{\partial L}{\partial x}= \frac{d}{dt} \left( \frac{\partial L}{\partial \dot x}\right) = \frac{d p}{dt}$$ Commuting the partial in $x$ and the total time derivative we get  $$\frac{\partial H'}{\partial x}= -\frac{d}{dt} \left( p+ \frac{\partial F}{\partial x}\right)=-\dot p$$
A: I ran into this same problem, and it's a problem of lack of clarity in the notation.
Indeed, as you proved above, new momentum $p'$ is related to the old one $p$ as
$$ p' = p + \frac{\partial F}{\partial t}.$$
However, this implies that with respect to the $(x,p)$ variables, the new momentum $p'$ depends on $x$, since the spatial dependence of $F$ is dragged into $p'$. 
When you take the Legendre transformation of $L'$ to write $H'$, you are implicitly stating that you can write $\dot{x}$ as as a function of $p'$. If we write variable dependence of $H'$, we get
$$ H' = H'(x,p',t)  = \dot{x}(p')p' - L'(x,\dot{x}(p'),t).$$
Now we want to relate this $H'$ to the $H$ that we obtain by applying the Legendre transform of $L$. Indeed, we can just substitute $L'$ in terms of $L$
and $F$, but this time we will explicitly write the dependence on $p$:
$$ H'(x,p',t)= \dot{x}(p)\left(p +\frac{\partial F}{\partial x}\right) - L(x,\dot{x}(p),t) - \frac{\mathrm{d}F}{\mathrm{d}t} = H(x,p,t) - \frac{\partial F}{\partial t}$$
Therefore we have
$$ H(x,p,t) = H'(x,p',t) + \frac{\partial F}{\partial t}.$$
Now we want the equation for $\dot{p}'$, which is 
$$
\dot{p}' = \dot{p} + \frac{\mathrm{d}}{\mathrm{d}t}\frac{\partial F}{\partial x}=  -\frac{\partial H(p)}{\partial x} + \frac{\mathrm{d}}{\mathrm{d}t}\frac{\partial F}{\partial x}$$
Here we've written the explicit dependence of $H$ on $p$. Now we use
the chain rule and the first Hamilton equation $\dot{x} = \partial_{p'}H'$
that you already proved which is still valid since $\partial_{p}F = 0$:
$$\begin{align}
\frac{\partial}{\partial x}H(x,p,t) &= \frac{\partial}{\partial x}H'(x,p',t) + \frac{\partial}{\partial x}\frac{\partial F}{\partial t}\\
&= \frac{\partial H'}{\partial x} + \frac{\partial H'}{\partial p'}\frac{\partial p'}{\partial x} + \frac{\partial}{\partial x}\frac{\partial F}{\partial t}\\
&= \frac{\partial H'}{\partial x} + \dot{x}\frac{\partial^2 F}{\partial x^2} + \frac{\partial}{\partial x}\frac{\partial F}{\partial t}\\
&= \frac{\partial H'}{\partial x} + \frac{\partial }{\partial x}\left(\dot{x}\frac{\partial F}{\partial x} + \frac{\partial F}{\partial t}\right)\\
&= \frac{\partial H'}{\partial x} + \frac{\partial }{\partial x}\frac{\mathrm{d}F }{\mathrm{d}t}
\end{align}$$
Finally,
$$\dot{p}' = -\frac{\partial H'}{\partial x} - \frac{\partial }{\partial x}\frac{\mathrm{d}F }{\mathrm{d}t} + \frac{\mathrm{d}}{\mathrm{d}t}\frac{\partial F}{\partial x} = -\frac{\partial H'}{\partial x}.$$
A: The problem is that the transformation $L'=L+ \frac{dF}{dt}$ you investigated is not a gauge transformation. Lagrangian is always determined up to a total derivative, but this is not necessarily related with gauge regundancies. In fact, a gauge transformation should leave the Lagrangian invariant!
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). Examples of physical symmetris are internal (global) symmetries in QCD and QED, and isometries (diffeomorphisms that preserve the metric components, such as Poincare group). Examples of gauge redundancies are (local) $U(1)$-gauge in QED, and diffeomorphism in GR and string theory.
In QFT, matter fields must fulfill projective representations of the physical symmetry group in the Hilbert space. The physical symmetry group acts on a physical state in the Hilbert space by transforming it into other physical states. However, physical states should form a trivial representation of the gauge group. The action of a gauge group on any physical state in the Hilbert space leaves it unchanged, since physics should be invariant under gauge transformations.
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}$. In other words, one cannot find the corresponding canonical Hamiltonian via the Legendre transformation because the Hessian
$$\frac{\partial^{2}\mathfrak{L}}{\partial\dot{\phi}^{I}\partial\dot{\phi}^{J}}$$
is singular in such cases.
Another example is the worldsheet metric in string theory. In Polyakov's action of Bosonic string theory
$$S[X,\gamma]=-\frac{1}{4\pi\alpha^{\prime}}\int_{M}d\tau d\sigma\sqrt{|\gamma|}\gamma^{ab}\partial_{a}X^{\mu}\partial_{b}X^{\nu}G(X)_{\mu\nu}$$
contains a non-dynamical metric field $\gamma^{ab}$. The action has exhibits two types of gauge redundancies: worldsheet diffeomorphism and $2D$ Weyl invariance.
Since gauge redundancies are unphysical, one must apply Faddeev-Popov method of gauge fixing when performing the quantization.
In your case, if you want the Lagrangian $L(x,\dot{x},t)$ to have a gauge redundancy, then the variable $t$ should be non-dynamical. Then you should consider $t$ as a Lagrangian multiplier, and the Hamiltonian
$$H=\dot{x}p-L$$
you used is not correct anymore. You must use Dirac's method for constrained system to find the physical Hanmiltonian. An example of such a case is the reparameterization invariance of the geodesic on a Riemannian manifold. A generic action of such a case is
$$S[q(t)]=\int_{a}^{b} dtL(q,\dot{q},t).$$
Under a reparameterization of the variable $t$ which leaves the end points $a$ and $b$ fixed, the action becomes
$$\delta S[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 the naive canonical Hamiltonian
$$H=p\dot{q}-L=0.$$
Note that the above naive Hamiltonian vanishes whether or not the action is extremized. Similar things happens in GR and string theory, where the Hilbert stress-energy tensor is conserved (on-shell and off-shell) due to diffeomorphism invariance.
