
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Minimizing (Reducing) Your Boolean Logic
|
129
Solution
To fix this situation, try applying the theorems shown in Table 3-1 to minimize these
types of equations.
In Table 3-1, assume that
w, x, y, and z are all variables of type bool. The theorem IDs
allow easy identification of which theorems are being used in the Boolean equations
that are being minimized in the Discussion section.
Discussion
Simplifying your Boolean logic will benefit your code by making it less cluttered and
making its logic clearer and more readily understood. This simplification will lessen
Table 3-1. Boolean theorems
Theorem ID Theorem definition
T0
!(!x) == x
T1 x | x == x
T2 x | !x == true
T3 (DeMorgan’s Theorem) !x | !y == !(x & y)
T4 x & x == x
T5 x & !x == false
T6 (DeMorgan’s Theorem) !x & !y == !(x | y)
T7 (Commutative Law) x | y == y | x
T8 (Associative Law) (x | y) | z == x | (y | z)
T9 (Distributive Law) x & y | x & z == x & (y | z)
T10 x | x & y = x
T11 x & y | x & !y = x
T12 (x & y) | (!x & z) | (y & z) == (x & y) | (!x & z)
T13 (Commutative Law) x & y == y & x
T14 (Associative Law) (x & y) & z == x & (y & z)
T15 (Distributive Law) (x | y) & (x | z) == x | (y & z)
T16 x & (x | y) = x
T17 (x | y) & (x | !y) = x
T18 (x | y) & (!x | z) & (y | z) == (x | y) & (!x | z)
T19 x | x | x | ... | x == x
T20 !(x | x | x | ... | x) ...