Scalar field Hamiltonian $H = 0$ from parameterization independence This question is related (but not similar) to this old one of mine:
How to derive the two Friedmann-Lemaître equations from a Lagrangian?
Consider the Lagrangian of an isotropic-homogeneous spacetime (Robertson-Walker metric), containing a simple scalar field and a cosmological constant (this expression comes from the standard Hilbert-Einstein and scalar field action, in an isotropic-homogeneous spacetime.  The space coordinates were integrated out and an hypersurface term was discarded) :
\begin{equation}\tag{1}
\mathcal{L} = -\: \frac{1}{8 \pi G} (3 \, a \, \dot{a}^2 - 3 k \, a + \Lambda \, a^3) + \frac{1}{2} \; \dot{\phi}^2 a^3 - \mathcal{V}(\phi) \, a^3.
\end{equation}
The function $\mathcal{V}(\phi)$ is the potential energy density of the scalar field.  The action is simply
$$\tag{2}
S = \int_{t_1}^{t_2} \mathcal{L} \, dt.
$$
Just for reference, the hypersurface term that was neglected is the following:
$$\tag{1b}
\mathcal{L}_{\text{surf}} =\frac{1}{8 \pi G} \, \frac{d}{dt} ( 3 \, a^2 \, \dot{a}).
$$
It's easy to find the Hamiltonian:
\begin{equation}\tag{3}
\mathcal{H} \equiv \dot{a} \, \frac{\partial \mathcal{L}}{\partial \, \dot{a}} + \dot{\phi} \, \frac{\partial \mathcal{L}}{\partial \, \dot{\phi}} - \mathcal{L} = -\: \frac{3}{8 \pi G} \Big( \frac{\dot{a}^2}{a^2} + \frac{k}{a^2} - \frac{\Lambda}{3} \Big) \, a^3 + \Big( \frac{1}{2} \, \dot{\phi}^2 + \mathcal{V}(\phi) \Big) \, a^3.
\end{equation}
That Hamiltonian can be proved to be 0, by a transformation of the time variable $dt \Rightarrow N \, dt$, where $N$ is an arbitrary function of $t$ (the "lapse" function).  This changes the lagrangian (1):
\begin{equation}\tag{4}
\tilde{\mathcal{L}} = -\: \frac{1}{8 \pi G} (3 \, a \, \dot{a}^2/N - 3 k \, a N + \Lambda \, a^3 N) + \frac{1}{2} \; \dot{\phi}^2 a^3 / N - \mathcal{V}(\phi) \, a^3 N.
\end{equation}
Since $N$ is arbitrary, we then could consider it as a new variable that can be varied.  The Euler-Lagrange equation applied to the lapse function implies that $\mathcal{H} = 0$.
What confuses me is that this reasoning could also be applied to any other Lagrangian, starting from its action and applying an arbitrary time transformation that doesn't change the end points:
$$\tag{5}
S = \int_{t_1}^{t_2} L \Big(q, \frac{dq}{dt} \Big) \, dt = \int_{t_1}^{t_2} L \Big(q, \frac{1}{N} \, \frac{dq}{d\tilde{t}} \Big) \, N \, d\tilde{t},
$$
so that
$$\tag{6}
\tilde{L} = N \, L \Big(q, \frac{1}{N} \, \frac{dq}{d\tilde{t}} \Big).
$$
Applying the Euler-Lagrange equation to $N$ (which is still arbitrary) then gives an absurdity: $H = 0$ for any Lagrangian!  Of course, this cannot be true!
So two questions:

*

*Where did I made a stupid mistake in this reasoning?  It certainly should be obvious, but I don't see it!

*I often read that $H = 0$ comes from the parameterization invariance of the action.  But then, like most classical Lagrangians, (1) and (2) don't seem to be independent of the time parameterization (even if I bring back the surface term that was discarded at the beginning).  So how can we show that (1)-(2) are actually independent of the time parameterization and show the relation to the Hamiltonian being zero?

 A: There's no mistake, everything is correct. The thing is that by considering $N$ to be a dynamical variable, you've changed the Lagrangian, by introducing gauge invariance - your action is now time reparametrization invariant. And the Hamiltonian of a reparametization invariant action is zero, by the simple argument you've given.
This makes sense since the Hamiltonian is linked to the time variable, so to speak: it generates time translations. And since you've effectively gotten rid of the physical time by introducing the lapse function, the Hamiltonian is now zero. It's not absurd, and the equations of motion still work.
A: *

*First of all, reparametrizing the Lagrangian 1-form$^1$
$$\mathbb{L}_1~=~L_1\left(q,\frac{dq}{d\tilde{t}}\right)\mathrm{d}\tilde{t}
~=~L_1\left(q,\frac{1}{N}\frac{dq}{dt}\right)N\mathrm{d}t \tag{A}$$
using a fixed function $N$
$$ \frac{d\tilde{t}}{dt}~=~N(t)\tag{B} $$
does not change the model.


*However, if we promote the lapse function $N$ as a new variable to be varied in the stationary action principle with new Lagrangian
$$L(q,\dot{q},N)~=~NL_1\left(q,\frac{\dot{q}}{N}\right),\tag{C} $$
then we do change the model, cf. Javier's answer. For starters we get an algebraic EOM for $N$. Also the new Lagrangian (C) has a local worldline (WL) reparametrization gauge symmetry.


*Example: $$L_1(q,\dot{q})~=~\frac{m}{2}\dot{q}^2-V(q).\tag{D}$$
The energy function
$$ h_1(q,\dot{q})
~:=~\left( \dot{q}\frac{\partial}{\partial\dot{q}}-1\right) L_1 
~\stackrel{(D)}{=}~ \frac{m}{2}\dot{q}^2+V(q)  \tag{E}$$
does in general not vanish. Then the new Lagrangian becomes
$$L(q,\dot{q},N)~\stackrel{(C)+(D)}{=}~\frac{m}{2N}\dot{q}^2 - N V(q).\tag{F} $$
The algebraic EOM for $N$ is$^2$
$$ N^2~\approx~ \frac{m\dot{q}^2}{-2V}.\tag{G} $$
The first lesson is that we must demand that the potential $V<0$ is negative in order to have solutions to eq. (G). Secondly, we declare that the lapse function $N>0$ is positive in order to avoid an unphysical negative square root branch. If we integrate out $N$, the Lagrangian (F) takes a square root form:
$$ L_0(q,\dot{q})~\stackrel{(F)+(G)}{=}~\sqrt{-2Vm\dot{q}^2},\tag{H}$$
which still has WL reparametrization gauge symmetry.
The corresponding energy function
$$ h_0(q,\dot{q})
~:=~\left( \dot{q}\frac{\partial}{\partial\dot{q}}-1\right) L_0 
~\stackrel{(H)}{=}~0, \tag{I}$$
vanishes identically, cf. e.g. this Phys.SE post. This should be contrasted with the energy function for the new Lagrangian (F),
$$ \begin{align} h(q,\dot{q},N)
~:=~&\left( \dot{q}\frac{\partial}{\partial\dot{q}}+\dot{N}\frac{\partial}{\partial\dot{N}}-1\right) L\cr
~\stackrel{(F)}{=}~& \frac{m}{2N}\dot{q}^2 + N V(q) 
~\stackrel{(G)}{\approx}~ 0, \end{align}  \tag{J}$$
which only vanishes on-shell.
--
$^1$ For later convenience we have exchanged the notation of $t\leftrightarrow \tilde{t}$ as compared to OP, but that's immaterial.
$^2$ The $\approx$ symbol means equality modulo EOM.
