Damons Laboratory
    The most exciting place on the internet!


A Science & Engineering OnLine Laboratory Notebook   
This is the laboratory notebook of Damon Bruccoleri.  Here you will find engrossing, thoughtful and fun commentary/opinion.  Leave a comment and let others know what you think about any post here, or view my photo gallery.

New is my list of developed products accessible from the top tab.

"...one of the strongest motives that lead men to art and science is escape from everyday life with its painful crudity and hopeless dreariness, from the fetters of one's own ever-shifting desires. A finely tempered nature longs to escape from the personal life into the world of objective perception and thought." - Albert Einstein


Latest Notebook Entries

 Sunday, April 12, 2009


Using DeMorgans Theorm   

I do not usually write lab notes on specific programming issues. I try to keep my web site general so many people can understand it. This note is an exception, its a real simple software related issue. Over the years of writing software I keep coming back to DeMorgan’s Theorem. It was one of those things that in college I never thought I would use, but it seems to pop up on a regular basis at work. I think this is fascinating stuff, particularly when academia meets the pavement.

First, the background. DeMorgan’s Theorem states:
image001.jpg .
DeMorgan’s theorem cannot be proved or reduced using math. The only proof is a brute force proof. At this point your probably thinking, "how can this academic theorem prove to be useful at work?" Let me show by example.

switch Circuit.jpgThis is going to be a real simple contrived example to demonstrate DeMorgan. Suppose the programming job is to read two switch inputs and to turn a motor on if both switches are closed. Perhaps to drive the motor ON we also have to output a LOW. It is common in computer to have negative I/O logic. Here is a schematic for this. We can see that if either switch is closed the input to the computer will go low.

I can now write software to implement the required function.

If ( SW1 = 0) AND ( SW1=0)
THEN MOTOR = 0
ELSE MOTOR =1

Do you see the correlation between this software statement and DeMorgan’s Theorem? Now we can simplify the programming statement using DeMorgan’s. Two simplifications make the statement easier to read. We take advantage of BOOLEAN type's and we can switch around the THEN and ELSE part to get rid of a NOT operator.

If (SW1 OR SW2)
THEN MOTOR =1
ELSE MOTOR =0

An astute programmer might note a further simplification by writing a single algebraic Boolean expression for this statement such as

MOTOR = SW1 OR SW2.

Understanding and using DeMorgan’s Theorem has simplified the programming, if only a little here. In larger applications we would get a larger return on our simplification investment.

Even though many compilers will reduce expressions internally, simplifying your programming pays rewards in understandable code. ALWAYS simplify code and remember to use DeMorgan.



damon at 7:30 AM |
(6) Comments | Add a comment | Permalink





Commments
Daniel said...

If this were a test would this be on it ... People who then would read this will get credit, right?... Daniel

Monday, April 13, 2009 8:46 PM

rapid4me said...

Very informative! I just needed this info! Thanks.

Friday, September 04, 2009 12:59 AM

FrancisHG said...

There is a proof available using identities and postulates. Contact me at fgelderl@mail.usf.edu for the proof

Monday, September 14, 2009 8:23 PM

Legendarydevils said...

DeMorgan's Theorems describe the equivalence between gates with inverted inputs and gates with inverted outputs. Simply put, a NAND gate is equivalent to a Negative-OR gate, and a NOR gate is equivalent to a Negative-AND gate.

Sunday, March 20, 2011 1:23 AM

cube tablet pc said...

The Newfreeshipping an online store, operates various brands,a variety of large-screen smart phones and tablet PCs,and the necessities of life.

Friday, May 10, 2013 1:22 AM

android Tablet pc said...

L first came here, I see it every day you update the blog also know a lot of interesting things.I have a better understanding of electronic products.

Monday, May 13, 2013 10:47 PM

  Leave a comment

Enter Your Name:
 
Enter your website
Security code from image below:  
Need Custom Controls Work or Training?