In case states are defined in a continuous manner, the summation is replaced by an integral over all possible states, or equivalently we can consider the expected value of the logarithm of the probability that a microstate is occupied: S = − − k B ⟨ ln ⁡ ⁡ p ⟩ This definition assumes the basis states to be picked in a way that there is no information on their relative phases. In a general case the expression is: S = − − k B t r ( ρ ρ ^ ^ × × ln ⁡ ⁡ ρ ρ ^ ^ ) where ρ ρ ^ ^ is a density matrix, t r is a trace operator and ln is a matrix logarithm. Density matrix formalism is not required if the system occurs to be in a thermal equilibrium so long as the basis states are chosen to be eigenstates of Hamiltonian. For most practical purposes it can be taken as the fundamental definition of entropy since all other formulae for S can be derived from it, but not vice versa.