Partition function (statistical mechanics)
In statistical mechanics, the partition function  Z is used for the statistical description of a system in thermodynamic equilibrium. It depends on the physical system under consideration and is a function of temperature as well as other parameters (such as volume enclosing a gas etc.). The partition function forms the basis for most calculations in statistical mechanics. It is most easily formulated in quantum mechanics: 
=Classic partition function=
A system subdivided into N sub-systems, where each sub-system (e.g. a particle) can attain any of the energies  (i.e. , , ...) has the partition function given by
- 
where  ( is 
Boltzmann's constant and 
T is the 
temperature). The intepretation of  is that the probability that the particle (sub-system) will have energy  is . When the number of energies  is definite (e.g. particles  with spin in a crystal lattice under an external magnetic field), then the indefinite sum with  is replaced with a definite sum. However, the total partition function for the system containing 
N sub-systems is of the form
- 
where  is the partition function for the 
j:th sub-system. Another approach is to sum over all system's total energy states,
- 
where , but then the parameter 
r is from 1 to 
N·(
degrees of freedom). Note that for a system containing 
N non-interacting sub-system (e.g. a real gas), then the system's partition function is
- 
where 
N! is the 
factorial and ζ is the "common" partition function for a sub-system. This equation also has the more general form
- 
where  is the sub-system's Hamiltonian operator
The partition function has the following meanings:
-  It is needed as the normalization denominator for Boltzmann's probability distribution which gives the probability to find the system in state j when it is in thermal equilibrium at temperature T (the sum over probabilities has to be equal to one): 
 
 
-  Qualitatively, Z grows when the temperature rises, because then the exponential weights increase for states of larger energy. Roughly, Z is a measure of how many different energy states are populated appreciably in thermal equilibrium (at least when we suppose the ground state energy to be zero).
 
-  Given Z as a function of temperature, we may calculate the average energy  as 
 
 
-  The free energy of the system is basically the logarithm of Z: 
 
 
-  From these two relations, the entropy S may be obtained as
 
 
-  Alternatively, with , we have  and , as well as .
 
=Quantum mechanical partition function=
More formally, the partition function Z of a quantum-mechanical system may be written as a 
trace over all states (which may be carried out in any basis, as the trace is basis-independent):
- 
 
If the Hamiltonian contains a dependence on a parameter , as in  then the statistical average over  may be found from the dependence of the partition function on the parameter, by differentiation:
- 
 
If one is interested in the average of an operator that does not appear in the Hamiltonian, one often adds it artificially to the Hamiltonian, calculates Z as a function of the extra new parameter and sets the parameter equal to zero after differentiation.