3.12. Minimizing (Reducing) Your Boolean Logic

Problem

Many times a Boolean equation quickly becomes large, complex, and even unmanageable. You need a way to manage this complexity while at the same time verifying that your logic works as designed.

Solution

To fix this situation, try applying the theorems shown in Table 3-1 to minimize these types of equations.

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) == !x & !x & !x & ... & !x

T21

x & x & x & ... & x == x

T22

!(x & x & x & ... & x) == !x | !x | !x | ... | !x

T23

(x | y) & (w | z) == (x & w) | (x * z) | (y & w) | (y * z)

T24

(x & y) | (w & z) == (x | w) & (x | z) & (y | w) & (y | z)

In Table 3-1, assume that w, x, y, and z are all variables of type bool. The Theorem ID column ...

Get C# Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.