MATLAB: Compute probability of a logical/boolean expression

booleanexpressioninclusion/exclusion principlelogical and operatorlogical expressionslogical or operator |logical?MATLABprobability

Hi,
I have boolean expressions as inputs, then I want to simplify the expression as it is shown below.
syms a b c;
mcs(a,b,c) = simplify((a|b)&c);
the output will be a symfun:
>> mcs(a, b, c) =
c & (a | b)
The struggle for me is how to assign probailities (scalars) to a , b , c; and apply the inclusion/exclusion principle to above expression.
Manually it will looks like somthing like this:
p(c) = 0.5;
p(a) = 0.5;
p(b) = 0.5;
p(a OR b) = p(a)+ p(b) – p(a)*p(b);
p = p(c)* p(a OR b);
But evantually my expressions are much more complicated than this example, so I need to figure out a smart way to this.

Best Answer

Hey Sara,
You can make 2 separate symfuns, each for OR and AND operations, and evaluate the expressions. You can then directly call the function with the values and get the result.
Let's say you can define OR and AND functions as:
syms OR(x,y)
OR(x,y) = x + y
syms AND(x,y)
AND(x,y) = x + y
And you expression is (assuming you already have the values for x,y,z defined):
OR(z , OR(x,y) )
Calling the function above would give you the result.