Mathematical Methods in Thermodynamics