art-ificial ramblings...

Monday, March 14, 2005

Boolean Logic

I've been reading "Write Great Code, Understanding the Machine" by Randall Hyde. Tonight's chapter is on boolean logic. I found this chapter pretty interesting since many high level languages process boolean expressions and by optimizing these expressions, it can greatly improve performance. I ran across a flaw in a boolean logic (in one of my SQL SP's) at work the other day. Interesting how something so simple can get quite complex.

What's interesting is the boolean postulates (assumptions) used in boolean algebra:

Assume A, B, and C are logical states that can have the values 0 (false) and 1 (true). "+" means OR, "·" means AND, and NOT[A] means NOT A.


(1) A + 0 = A A · 1 = A identity
(2) A + NOT[A] = 1 A · NOT[A] = 0 complement
(3) A + B = B + A A · B = B · A commutative law
(4) A + (B + C) = (A + B) + C A · (B · C) = (A · B) · C associative law
(5) A + (B · C) = (A + B) · (A + C) A · (B + C) = (A · B) + (A · C) distributive law


When used in boolean operators:


(1)Closed - AND (+), OR (·), NOT (')
(2)AND and OR are commutative
(3)AND and OR are associative
(4)AND and OR are distributive with respect to each other
(5)Identity of AND is 1, OR is zero and no identity to NOT
(6)For every A, there exists a A' such that A · A' = 0 and A + A' =1


Cool logic puzzles that can be solved using Boolean algebra.

0 Comments:

Post a Comment

<< Home