The Hamiltonian formalism of mechanics is based on the definitions posed by [Lagrangian mechanics](/en/physics/mechanics/lagrangian-mechanics/lagrangian-formalism) and the axioms, postulates and principles posed in the [Newtonian formalism](/en/physics/mechanics/newtonian-mechanics/newtonian-formalism/).
Where the Lagrangian formalism used the [principle of virtual work](/en/physics/mechanics/lagrangian-mechanics/lagrange-equations/#principle-of-virtual-work) to derive the Lagrangian equations of motion, the Hamiltonian formalism will derive the Lagrangian equations with the stationary action principle. A derivative of Fermat's principle of least time.
> *Principle 1*: of all the kinematically possible motions that take a mechanical system from one given configuration to another within a time interval $T \subset \mathbb{R}$, the actual motion is the stationary point of the time integral of the Lagrangian $\mathcal{L}$ of the system. Let $S$ be the functional of the trajectories of the system, then
>
> $$
> S = \int_T \mathcal{L} dt,
> $$
>
> has stationary points.
The functional $S$ is often referred to as the action of the system. With this principle the equations of Lagrange can be derived.
> *Theorem 1*: let $\mathcal{L}: (\mathbf{q}, \mathbf{q'}) \mapsto \mathcal{L}(\mathbf{q}, \mathbf{q'})$ be the Lagrangian, the equations of Lagrange are given by
Let the redefined generalized coordinates $\mathbf{q}: (t,a) \mapsto \mathbf{q}(t,a)$ be given by
$$
\mathbf{q}(t,a) = \mathbf{\hat q}(t) + a \varepsilon(t),
$$
with $\mathbf{\hat q}: t \mapsto \mathbf{\hat q}(t)$ the generalized coordinates of the system and $\varepsilon: t \mapsto \varepsilon(t)$ a smooth differentiable function.
Let $S: a \mapsto S(a)$ be the action of the system and let $\mathcal{L}: (\mathbf{q}, \mathbf{q'}) \mapsto \mathcal{L}(\mathbf{q}, \mathbf{q'})$ be the Lagrangian of the system, according to Hamilton's principle