DeMorgan’s Laws

Sean Coates
Jul 24, 2017 · 1 min read

These can come in handy when refactoring boolean logic.


Or more plainly in code:

!A && !B == !(A || B)
!A || !B == !(A && B)

These equivalences can be used to refactor your code to make things easier to understand. It’s not huge change and it won’t rock your world, but every once in a while using one of these substitutions will improve the code.

Sean Coates

Written by

Occasional posts from @fooyay about software engineering, crypto, finance, and more. https://about.me/fooyay (Content reflects my opinion and not my employer.)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade