Can the following expression be simplified?
(M == null && C == null) ||
(M != null && C != null && D == C)
Mathematically I know this can’t be simplified and I checked on WolframAlpha to confirm this, but I was wondering if it might be possible with use of one of the boolean logical operators (&, |, ^), to make that condition shorter. I’ve tried to think of ways but I’m having a mental block… is this actually possible to shorten?
No, it can’t be shortened.
As Ferdinand Liu observes, your expression is true in two cases:
MandCare null, orMandCare not null, andCandDare equal.You need to check both
MandCin both conditions, so you can’t simplify the expression.Interesting but only slightly-related note:
If you didn’t need to check
CandDfor equality, then the expression would beand this can be simplified to
which is true when
MandChave the same “null-ness.”