A general framework for compositional reasoning with uncertainty