
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Minimizing (Reducing) Your Boolean Logic
|
131
You were able to remove only a single operator from this equation. This optimiza-
tion might or might not improve the performance and readability of your code, since
it is such a minor change.
You may think that this expression is in its most reduced form. However, if you
examine this expression more closely, you may notice that it is the equation for the
XOR operator. Knowing this, you can simplify the equation to the following:
X ^ Y
This technique really shines when you are faced with a large and complex Boolean
expression, such as the one shown here:
(!X & !Y & !Z) | (!X & Y & Z) | (X & !Y & !Z) | (X & !Y & Z) |
(X & Y & Z)
Using theorem T9, you get the following equation:
(!X & ((!Y & !Z) | (Y & Z))) | (X & ((!Y & !Z) | (!Y & Z) |
(Y & Z)))
Notice that the equation (!Y&!Z)|(Y&Z)is the equivalent of the NOT XOR
operation on
Y and Z. So you can simplify this equation much further:
(!X & !(Y ^ Z)) | (X & ((!Y & !Z) | (!Y & Z) | (Y & Z)))
Using theorem T9, once again, you get the following equation:
(!X & !(Y ^ Z)) | (X & (!Y & (!Z | Z) | (Y & Z)))
Using theorem T2, you get the final equation:
(!X & !(Y ^ Z)) | (X & (!Y | (Y & Z)))
This equation is much simpler than the original and requires much less processing to
evaluate, as well.
While it is