Alex Rivera | Logout

Logic: is ( A && !(B || C)) || ( B || C ) the same as ( A || B || C )?

Asked 2011-01-21T20:56:09.913
10

I've encountered some obj-c code and I'm wondering if there's a way to simplify it:

#if ( A && !(B || C)) || ( B || C )

is this the same as?

#if ( A || B || C )

If not, is there another way to formulate it that would be easier to read?

[edit] I tried the truth table before asking the question, but thought I had to be missing something because I doubted that Foundation.framework/Foundation.h would employ this more complex form. Is there a good reason for it?

Here's the original code (from Foundation.h):

#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
Edit
Report

1 Answer

2

Yes it is the same. Using De Morgan rules:

(A && !(B || C)) || (B || C) = (A && !B && !C) || (B || C). So the second will be true when A = 1 and B, C = 0. If that is not the case the second part (B || C) will be true when B || C. So it is equal to the first.

answered 2011-01-21T21:01:20.270

Your Answer