We denote the canonical probability distributions for the Hamiltonian and the trial Hamiltonian by formula_79 and formula_80, respectively. From Gibbs' inequality we know that:  holds. To see this, consider the difference between the left hand side and the right hand side. We can write this as:  Since  it follows that:  where in the last step we have used that both probability distributions are normalized to 1. We can write the inequality as:  where the averages are taken with respect to formula_80. If we now substitute in here the expressions for the probability distributions:  and  we get:  Since the averages of formula_57 and formula_58 are, by assumption, identical we have:  Here we have used that the partition functions are constants with respect to taking averages and that the free energy is proportional to minus the logarithm of the partition function. We can easily generalize this proof to the case of quantum mechanical models. We denote the eigenstates of formula_58 by formula_94. We denote the diagonal components of the density matrices for the canonical distributions for formula_57 and formula_58 in this basis as:  and  where the formula_99 are the eigenvalues of formula_58  We assume again that the averages of H and formula_58 in the canonical ensemble defined by formula_58 are the same:  where  The inequality  still holds as both the formula_79 and the formula_80 sum to 1. On the l.h.s. we can replace:  On the right-hand side we can use the inequality  where we have introduced the notation  for the expectation value of the operator Y in the state r. See here for a proof. Taking the logarithm of this inequality gives:  This allows us to write:  The fact that the averages of H and formula_58 are the same then leads to the same conclusion as in the classical case:  In the more general case, the mechanical term formula_115 must be replaced by the product of volume, stress, and an infinitesimal strain:  where formula_117 is the stress tensor, and formula_118 is the strain tensor. In the case of linear elastic materials that obey Hooke's law, the stress is related to the strain by  where we are now using Einstein notation for the tensors, in which repeated indices in a product are summed. We may integrate the expression for formula_120 to obtain the Helmholtz energy:  The Helmholtz free energy function for a pure substance (together with its partial derivatives) can be used to determine all other thermodynamic properties for the substance.