« back

Boolean Algebra- Let's Talk About X Ba-by

13 Sep 2012

Welcome to a land where 1 + 1 = 1.

In my lastpost, I talked about the +(OR) operator. This time, let's talk about x. Let me refresh your memory and remind you that values used in this algebra are 0(or false) and 1(or true) instead of actual numbers. In Boolean Algebra, the x operator stands for an INTERSECTION. An intersection is everything that is in the first class AND everything that is in the second class. This operator also holds true to the commutative property. It can be written like this H x M, M x H, HM, or MH.

Let's pretend we know a very fancy lady. She will not leave the house without her hair AND her makeup done. Let's say it's Sunday and she needs milk but she refuses to do her hair and her makeup. This means Hair = false(0), AND Makeup = false(0). If we put this into a Ruby expression, it would look like this...

1       if Hair (is true(1)) &&  Makeup(is true(1))
2          puts "I am on my way out to get milk."
3       else
4          puts "I wouldn't be caught dead looking like this!"
5       end
6     

The result is "I wouldn't be caught dead looking like this!"

Now let's pretend she started getting ready and got her Hair done,(Hair = true(1)) but did not do her Makeup(Makeup = false(0))

1       if Hair (is true(1)) &&  Makeup(is true(1))
2          puts "I am on my way out to get milk."
3       else
4          puts "I wouldn't be caught dead looking like this!"
5       end
6     

The result is "I wouldn't be caught dead looking like this!" since she does not have both of those things happening.

Now let's say that on Saturday she got a new lipstick and a new hair bow. She is ready to be seen looking fabulous. On Sunday, she just can not wait until Monday to get ready (This is how you can tell this story is complete fiction. :) ) and decides that even though it is Sunday, she is going to do her Hair(Hair = true(1))) AND Makeup(Makeup = true(1)).

1       if Hair (is true(1)) &&  Makeup(is true(1))
2          puts "I am on my way out to get milk."
3       else
4          puts "I wouldn't be caught dead looking like this!"
5       end
6     

Now the result is "I am on my way out to get milk."

Once again, as if that were not enough, here is a truth table to look at it a different way.

and_table

1       if "learned about OR" &&  "Learned about AND"
2          puts "George Boole would be proud!"
3       else
4          puts "I need to re read these posts!"
5       end
6     

"George Boole would be proud!"

comments powered by Disqus