boolean-logic

Boolean negation


One of my exam questions reads:

! ( ! ( a != b)  &&  ( b > 7 ) )

The choices:

a) (a != b) || (b < 7)
b) (a != b) || (b <= 7)
c) (a == b) || (b <= 7)
d) (a != b) && (b <= 7)
e) (a == b) && (b > 7)

Initially, I thought it would be D. This is incorrect, and I realize why. I don't understand how the logical negation operator reverses && and greater than/less than. I believe I have narrowed it down to the first two. Is there any instance > would change to <= ?


Solution

  • Is there any instance > would change to <= ?

    Answer: every time you negate it.

    Consider x > 1. The negation of this is clearly x <= 1. If you simply negate it as x < 1 then neither case covers the x == 1 case.


    That being said, the given boolean ! ( ! ( a != b) && ( b > 7 ) ) can be decomposed as follows:

    1. Given:

      ! ( !(a != b) && (b > 7))

    2. Negate a != b:

      ! ((a == b) && (b > 7))

    3. Distribute the !:

      !(a == b) || !(b > 7)

    4. Negate a==b:

      (a != b) || !(b > 7)

    5. Negate b>7:

      (a != b) || (b <= 7)

    The answer is, therefore, B.