Pulmonary mechanics and gas exchange: a mathematical framework