Hey ptt.

The first thing to do is to take your probabilities and form a joint distribution.

After you do this, then create a routine to evaluate a condition. For the sum of states, you will need to use a couple of for loops (or do loops) and fix the first value and inside a new loop pick a value for the second variable and so on right until the last variable, and get that specific probability.

Then when it finishes, if you have added up all the probabilities then you will get the final probability.

You will need to implement these functions yourself or use some statistics package that has a querying language and create instructions for that querying language to get the answer.