Partition function in statistical mechanics