DEV Community

Cover image for Clear as the sun explanation of De Morgan's laws
Marat Latypov
Marat Latypov

Posted on • Edited on

1

Clear as the sun explanation of De Morgan's laws

Sometimes, novice developers struggle with basic logic expressions, especially De Morgan's laws. To help with this, I have prepared a simple explanation.

The following examples were made using a small React app that I created for this article. You can choose to download and play with it or not 😀️. The following text doesn't require the app installation.

Step 1. Where are we from

Ok. Let start with the basics. How looks a&&b result? I think everybody knows:

a && b

Step 2. Let's play with it

What if we negate b in this expression? Just imagine the column where b was true will changed to false, and vice versa. The matrix will be flipped horizontally, like reflection in a mirror!
a && b => a && !b

And if we negate a, it will be flipped vertically:
a && b => !a && b

Step 3. Try a little bit harder

What if we negate both a and b the same time? Right! The matrix will be flipped in both directions - horizontally and vertically:

a && b => !a && !b

Step 4. The Final

Nice, and what if we negate the entire expression after negating a and b? In that case the values in the matrix will change from true to false, and vice versa:

!a && !b => !(!a && !b)

But wait! It looks like matrix for a||b!

de Morgan's Law

Actually that's the de Morgan's Law

!(!a&&!b) === a||b or !a&&!b === !(a||b)

I hope this article was helpful.

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️