Art of Programming

Using DeMorgan's Laws in Programming

Published on

Theories can be pretty boring if you don't immediately see the implications that they might have i.e., you don't know how to apply them practical situations. The theories behind logic are no exception. I used to doze off during my logic and philosophy classes because of this. A few years later when I became a software engineer, it hit me that I can use some of those laws and theories in programming! They suprisingly made my life easier. One of those laws is DeMorgan's laws.

Here's how it is defined:

The rules can be expressed in English as:
- the negation of a disjunction is the conjunction of the negations;
- and the negation of a conjunction is the disjunction of the negations;

The DeMorgan’s laws are a set of rules that allow us to transform a logic expression. I use these to make my boolean expressions simpler. 

If you liked this post please Buy Me a Coffee at ko-fi.com