In physics and thermodynamics, the ergodic hypothesis says that, over long periods of time, the time spent by a system in some region of the phase space of microstates with the same energy is proportional to the volume of this region, i.e., that all accessible microstates are equiprobable over a long period of time.
Liouville's Theorem states that, for Hamiltonian systems, the local density of microstates following a particle path through phase space is constant as viewed by an observer moving with the ensemble (i.e., the convective time derivative is zero). Thus, if the microstates are uniformly distributed in phase space initially, they will remain so at all times. But Liouville's theorem does not imply that the ergodic hypothesis holds for all Hamiltonian systems.
The ergodic hypothesis is often assumed in the statistical analysis of computational physics. The analyst would assume that the average of a process parameter over time and the average over the statistical ensemble are the same. This assumption that it is as good to simulate a system over a long time as it is to make many independent realizations of the same system is not always correct. (See, for example, the Fermi–Pasta–Ulam experiment of 1953.)
Assumption of the ergodic hypothesis allows proof that certain types of perpetual motion machines of the second kind are impossible. The figure above displays situations where the ergodic hypothesis does and does not hold for a simplistic model of an ideal gas. If the walls are perfectly smooth and circular, the ergodic hypothesis does not hold. If it was possible to construct a sort of tunnel whereby specular reflections cause atoms to move from a less populated container to an identical one with greater density, this would allow the direct conversion of random thermal energy into useful work in a way that does not require a heat bath. But, by Liouville's theorem, if all regions of phase space are equally populated at time, t=0, then they are equally probable for all time. No reflective 'trap' or Maxwell's demon (such as depicted in the figure) will 'unmix' a gas that has randomly filled both containers with equal density and pressure.