February 21, 2013

De Morgan's Theorem

Wikipedia has more info on this
I am always forgetting this rule:
NOT (P  OR Q) = (NOT P) AND (NOT Q)
NOT (P AND Q) = (NOT P)  OR (NOT Q) 
or in more generealised form:
NOT (P  OR Q  OR R  OR ...) = (NOT P) AND (NOT Q) AND (NOT R) AND ...
NOT (P AND Q AND R AND ...) = (NOT P)  OR (NOT Q)  OR (NOT R)  OR ...
In C#
!(P || Q) = (!P) && (!Q)
!(P && Q) = (!P) OR (!Q) 
Can be useful sometimes to improve code readability but do not use it for optimisation (let the compiler do that)

No comments: