Fermat's principle
Fermat's principle states that the path taken by light between two points is stationary with respect to time. It is the oldest surviving variational principle in physics, it precedes the calculus of variations by nearly a century, and it is the historical bridge to mechanics: the analogy Hamilton exploited runs from this principle to his own.
Statement

In a medium of refractive index , light travels at speed . The transit time along a path is
The quantity is the optical path length. Fermat's principle is that light follows a path for which (1) is stationary.
Fermat himself said least, and for the cases he treated the two coincide. The correction to stationary is required, and the failures are exhibited at the end of this page.
Snell's law
Take two media, indices above and below a flat interface. Light goes from to with , crossing at . Straight segments within each medium — the index is constant there, so each leg is a straight line — give the time as a function of the single unknown :
This is ordinary calculus, not the calculus of variations: the variational problem has collapsed to one variable because the path shape within each medium is already known. Differentiate:
The two fractions are the sines of the angles from the normal, so setting (3) to zero gives
Snell's law, from a stationarity condition in three lines.
The second derivative of (2) is positive for all , so this stationary point is a genuine minimum — refraction at a flat interface really is least time. That will not survive curved interfaces.
The law of reflection follows the same way with and both points on the same side, giving equal angles.
The continuous case
For a medium with varying index the problem is a genuine variational one. With the path written in the plane,
Two special cases are worth having.
Stratified medium, . The integrand carries no explicit , so the Beltrami identity of the Beltrami identity applies. The same collapse as in the brachistochrone gives
Since with measured from the vertical, (6) reads — Snell's law again, now holding continuously along the ray rather than at an interface. The discrete law is the first integral of the continuous problem.
This is the mirage. Hot air near a road surface has lower index; a ray descending into it bends until and turns back up, and the observer sees sky below the horizon.
Constant index. Then (5) is arc length and the rays are straight lines, the case worked on the Euler-Lagrange equation.
Rays are geodesics
Equation (5) is the arc-length functional of Geodesics with the metric conformally rescaled by :
So light rays are geodesics of the optical metric, and every result about geodesics transfers. In particular the geodesic equation (6) of that page supplies the ray equation, and conjugate points supply the foci.
Compare this with Jacobi's form of Maupertuis' principle on Abbreviated action: Maupertuis versus Hamilton, where a particle of energy in potential follows a geodesic of the metric rescaled by . The two statements are the same statement under
That correspondence is the optical-mechanical analogy, and it is developed on the optical-mechanical analogy.
Stationary, not least
Three standard cases show that least fails, and none of them is contrived.
A concave mirror at its focus. Place source and observer at the two foci of an ellipsoidal mirror. Every path via the surface has the same optical length. The time is stationary and constant — neither minimum nor maximum, and not isolated.
A mirror curved more sharply than the ellipse. Replace the ellipsoidal surface by one curving away more sharply through the same reflection point. The reflected path now has greater optical length than neighbouring paths: the actual light path is a local maximum of time. The reflection law (4) still holds, and the light still goes that way.
Beyond a focus. A ray passing through a focus and continuing is stationary but no longer minimal, for exactly the reason a great-circle arc past the antipode is not shortest. The focus is a conjugate point of the Jacobi condition and conjugate points, and the optical and mechanical statements are the same statement under (7).
This is the cleanest place in the volume to see why the correction to "stationary" is forced. A maximum-time path is not an edge case of least time; it is the opposite, and the principle as Fermat stated it is simply false there.
Historical note
Fermat proposed the principle in the 1650s and defended it against Descartes' derivation of the refraction law from an assumption about light travelling faster in denser media. Fermat's principle requires the opposite, and the question was settled experimentally by Foucault in 1850, two centuries later, in Fermat's favour.
The metaphysical framing — that nature acts by the shortest paths — was contested at the time and is the same framing Maupertuis would use for mechanics ninety years later. Both principles survived; both framings did not. The corrected statement is stationarity, and it carries no claim about nature's economy.
Provenance: the historical paragraph is editorial summary. The Fermat row of the survey on Sources is UNCOMPUTED — no full text of the Synthesis ad refractiones has been located for this volume — so no words are attributed to Fermat here, and every equation on this page is derived on it.
Next
the optical-mechanical analogy makes the correspondence (8) the subject rather than a remark.