# My Hamiltonian for a light ray vanishes

I have the following issue with understanding. A light ray traveling from $q(\tau_1)$ to $q(\tau_2)$ minimizes the integral $\int\limits_{\tau_1}^{\tau_2} n(q(\tau))|\dot{q}(\tau)| d\tau$, so the corresponding Lagrangian of the light ray is $$n(q(\tau))|\dot{q}(\tau)| .$$ Then the Legendre transform yields $$H = \dot{q}\frac{\partial L}{\partial \dot{q}} - L.$$ Now, the derivative of $L$ works out to $$\frac{\partial L}{\partial \dot{q}} = n(q) \frac{\dot{q}}{|\dot{q}|},$$ so the Hamiltonian is simply identical to zero. Surely this is now right. Can someone clarify my confusion? Thanks in advance!

The system is time-reparametrization invariant - changing $\tau$ to $\xi(\tau)$ transforms $$n(q(\tau))\mapsto n(q(\xi)),\quad \dot{q}\mapsto \frac{\mathrm{d}\xi}{\mathrm{d}\tau}q', \quad \mathrm{d}\tau\mapsto \frac{\mathrm{d}\tau}{\mathrm{d}\xi}\mathrm{d}\xi$$ and the action is invariant under this transformation (up to a sign we will ignore). It is a general fact that time-reparametrization-invariant actions where also $q$ and $p = \frac{\partial L}{\partial \dot{q}}$ are invariant lead to a zero Hamiltonian.