Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 <= ?

like image 512
Tanner Avatar asked May 08 '26 11:05

Tanner


2 Answers

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.

like image 192
Roddy of the Frozen Peas Avatar answered May 10 '26 16:05

Roddy of the Frozen Peas


The answer should be B. This is because the negation next to the (a != b) is evaluated first, then you distribute the outside negation to the entire proposition.

Using DeMorgan's Laws, the && will switch to ||. Similarly, != becomes ==, and > becomes <=.

!(!(a != b) && (b > 7))
!((a == b) && (b > 7))
 (a != b) || (b <= 7)
like image 37
Evan Bechtol Avatar answered May 10 '26 17:05

Evan Bechtol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!