Algebraic theory of probabilistic machines