I’m working with some tools, and the only way it can determine if a particular transaction is successful is if it passes various checks. However, it is limited in the way that it can only do one check at a time, and it must be sequential. Everything must be computed from left to right.
For example,
A || C && D
It will be computed with A || C first, and then the result will be AND‘ed with D.
It gets tougher with parenthesis. I am unable to compute an expression like this, since B || C would need to be compututed first. I cannot work with any order of operations;
A && ( B || C)
I think I’ve worked this down to this sequential boolean expression,
C || B && A
Where C || B is computed first, then that result is AND‘d with A
Can all boolean expressions be successfully worked into a sequential boolean expression? (Like the example I have)
The answer is no:
Consider
A || B && C || Dwhich has the truth table:If it were possible to evaluate sequentially there would have to be a last expression which would be one of two cases:
Case 1:
X || Ysuch thatYis one ofA,B,C,Dand X is any sequential boolean expression.Now, since there is no variable in
A,B,C,Dwhere the entire expression is true whenever that variable is true, none of:can possibly be the last operation in the expression (for any X).
Case 2:
X && Y: such thatYis one ofA,B,C,Dand X is any sequential boolean expression.Now, since there is no variable in
A,B,C,Dwhere the entire expression is false whenever that variable is false, none of:can possibly be the last operation in the expression (for any X).
Therefore you cannot write
(A || B) && (C || D)in this way.The reason you are able to do this for some expressions, like:
A && ( B || C)becomingC || B && Ais because that expression can be built recursively out of expressions which have one of the two properties above:IE.
The truth table for
A && ( B || C)is:Which we can quickly see has the property that it is false whenever A is 0. So Our expression Could be
X && A.Then we take A out of the truth table and look at only the rows where A is 1 is the original:
Which has the property that it is True whenever B is 1 (or C, we can pick here). So we can write the expression as
X || Band the entire expression becomesX || B && AThen we reduce the table again to the portion where B was 0 and we get:
X is just C. So the final expression is
C || B && A