Reputation:
Working in JS and just started learning about boolean algebra. Wondering if there is a way to simplify this expression:
(!variableOne || !variableTwo)
I recall hearing something about how two 'nots' means you can change the sign, but I'm not seeing much about this when I google 'boolean algebra'.
Thanks!
Upvotes: 0
Views: 835
Reputation:
Late answer but to put further explanation:
- The negation of an and statement is logically equivalent to the or statement in which each component is negated.
Symbolically:
!(A && B) = !A || !B
- The negation of an or statement is logically equivalent to the and statement in which each component is negated.
Symbolically:
!(A || B) = !A && !B
In your case you had used !variableOne || !variableTwo
so it's equivalent to the first Law !(variableOne && variableTwo) == !variableOne || !variableTwo
.
Upvotes: 0
Reputation: 526
As the De'Morgans Law says, you can transform !a || !b
in !(a && b)
so you can have !(variableOne && variableTwo)
Upvotes: 1
Reputation: 386634
You could take De Morgan's laws:
!(a && b) = !a || !b
!(a || b) = !a && !b
In your case it is
!(variableOne && variableTwo)
Upvotes: 2