Foundations of Classical and Quantum Statistical Mechanics