Now I'd like to examine physical theories that are more statistical in nature: statistical mechanics and quantum mechanics. Instead of assuming our system progresses exactly along the path of minimum action, we assign a probability distribution to weight the various paths it can take through phase space, with the most probable path being the one of stationary action. This formulation of statistical mechanics is much akin to Feynman's path integral approach to quantum mechanics, which I'll cover next time.
Let's start with a definition of the average action, \(\langle A\rangle=\int\rho A\,\mathcal{D}\phi\), where \(\rho[\phi(x)]\) is a probability distribution over all possible field configurations on the manifold of interest (spacetime), \(A[\phi(x)]\) is our usual action functional along the path, and \(\mathcal{D}\phi\) indicates that the integration is to be performed over all possible field configurations over all of the manifold. By definition, we must have \(\int\rho\,\mathcal{D}\phi=1\). We may also define the entropy from Shannon's theory as \(S=-\int\rho\ln\rho\,\mathcal{D}\phi\). Employing the method of Lagrange multipliers to impose the constraints, we find that \(\rho=\frac{1}{Q}e^{-\eta A}\), where \(Q=\int e^{-\eta A}\,\mathcal{D}\phi\) is the partition function for normalizing the probability, and \(\eta\) is the Lagrange multiplier, with units of inverse action (in quantum mechanics, \(\eta=\frac{1}{i\hbar}\)). We also obtain \(\langle A\rangle=-\frac{\partial}{\partial\eta}\ln Q\), and \(S=\ln Q+\eta\langle A\rangle\). The most important result, though, comes from using Hamilton's Principle, \(\delta A=0\). This means \[\begin{align*} 0&=\langle\delta A\rangle\\ &=\int\rho\delta A\,\mathcal{D}\phi\\ &=\delta\int\rho A\,\mathcal{D}\phi-\int A\delta\rho\,\mathcal{D}\phi\\ &=\delta\langle A\rangle-\int A\delta\rho\,\mathcal{D}\phi\end{align*}\]
But \(\delta\rho=-\eta\rho\delta A=0\), so \(\delta\langle A\rangle=0\). Hence Hamilton's Principle applies to the mean action as well (which we would expect). This immediately yields \(\delta S=0\) for the expected path: the entropy change is maximized for the field configuration path we expect. This is essentially the second law of thermodynamics. In this sense, the second law and Hamilton's Principle are equivalent: a statistical process that extremizes action extremizes entropy change. Though the action is in terms of a Lagrangian, we can see that under certain circumstances, we may make a Legendre transform to put it in the form of a Hamiltonian. Additionally (the derivation is a bit too long), we can find that in that case the Lagrange multiplier \(\eta\) is related to the temperature by defining \(T=\frac{\partial\langle H\rangle}{\partial S}\), and then from the partition function we may derive the many laws and formulae of thermodynamics.