Sei sulla pagina 1di 3

What's boolean algebra?

From Wikipedia, the free encyclopedia Boolean algebra, as developed in 1854 by George Boole in his book An Investigation of the Laws of Thought, is a variant of ordinary elementary algebra differing in its values, operations, and laws. Instead of the usual algebra of numbers, Boolean algebra is the algebra of truth values 0 and 1: 0 is cosidered FALSE and 1 is considered TRUE. Using TRUE and FALSE as values of propositions is possible to rewrite sentences with Boolean variables ad use Boolean algebra and truth table to simplify them. Boolean Algebra basic operations Basic Boolean operations are AND, OR and NOT, also called conjunction, disjunction and complement. These operations are the counterparts of multiplication, addiction and negation. Conjunction or AND operation AND operation, indicated as <*> behaves on TRUE and FALSE as ordinary algebra does on 1 and 0. Something * FALSE is equal to FALSE and only TRUE * TRUE result TRUE. If A and B are 2 boolean variables A*B is TRUE only if both operands are TRUE, if at least one of them is FALSE the result is FALSE. Disjunction or OR operation OR operation, indicated as <+>, is called also logic sum. Is enought that an operand is TRUE to set the whole expression as TRUE. The result is FALSE only if both operands are FALSE. Complement or NOT operation Complement works almost like negation in normal algebra, but in Boolean algebra there are only 2 symbols and complement operation switches between TRUE and FALSE. If A is a boolean variable and is FALSE, NOT(A) is TRUE, instead if A is TRUE NOT(A) is FALSE. Is indicated as overline or with apex. NOT( NOT(A) ) is equal to A. Special expressions Using basic definitions is possible to define other useful expressions to simplify complex Boolean equationes (A and B are Boolean variables): most import ant are the DeMorgan laws and the adsorbiment theorem. DeMorgan laws: NOT( AB ) = NOT(A) + NOT(B) = (AB)' = A' + B' NOT(A + B) = NOT(A) * NOT(B) = (A + B)' = A'B' Adsorbiment theorem A + A'B = A + B Special properties A + 1 = 1 A + A' = A A * A' = 0 A * 0 = 0 Some examples A,B,C are boolean variables and U the result 1) U = A'B + A'B' + AB' + AB = A(B + B') + A'(B + B') = A + A' = 1

U = 1 2) U = A'(B + C) + ABC' + AB + C U = A'(B + C) + AB(C' + 1) + C = A'(B + C) + AB + C = A'B + A'C + AB + C = = B(A' + A) + C(A' + 1) = B + C U = B + C 3) U = AB(C + D')' + AB'C + CD(A'B')' + AB' U = AB(C'(D'')) + AB'C + CD(A + B) + AB' = ABC'D + AB'C + CDA + CDB + AB' = = BD(AC' + C) + AB'(C + 1) + CDA = BD(A + C) + AB' + CDA = = ABD + CBD + AB' + ACD = A(BD + B') + BCD + ACD = A(D + B') + BCD + ACD = = AD + AB' + BCD + ACD = AD(1 + C) + BCD + AB' = AD + BCD + AB' U = AD + BCD + AB' These examples demonstrate how is possible to semplify complex boolean expressions, but how can I use them? Practical cases Boolean algebra can be used to simplify code, if structures and complex decisional situations. if(CondA) { if(CondB) { call_function_A(); } } else { if(!CondC) { If(CondB) { call_function_A(); } } } This is a code sample that can be semplified with boolean algebra: CondA, CondB and CondC are the boolean variables and the if structure gives us the boolean expression. --------------------------------A B C U --------------------------------F F F F F F T F F T F T F T T F T F F F T F T F T T F T T T T T --------------------------------This table shows all possible cases (2^n cases with n variables) and U indicates when the function is called. Important cases are the third, the seventh and the eighth, when U is TRUE. Interpreting the table using boolean algebra we have: U = A'BC + ABC' + ABC This expression can be reduced:

U = A'BC + ABC' + ABC = A'BC + AB(C' + C) = = A'BC + AB = B(A + A'C) = = B(A + C) call_function_A() will be invoked when U is TRUE and U is TRUE when B(A + C) it's TRUE. It let us rewrite the if statement like this: if( CondB && (CondA CondC) ) { call_function_A(); } Now there's only one big condition and 1 statement in the if.

Potrebbero piacerti anche