Code for computing probabilities