PHP
Negate the following Boolean expressions using both approaches.
i. $b != 4

iv. $a == true

Solution
First Approach
i. !($b != 4)
ii. !($a * 3 + 2 > 0)
iii. !(!($a == 5 && $b >= 7)),
or the equivalent $a == 5 and $b >= 7
Notice: Two negations result in an affirmative. That is, two NOT operators in a row negate each other.
iv. !($a == true)
v. !($b > 7 && !($x > 4))
vi. !($a == 4  $b != 2)
Second Approach
i. $b == 4
ii. $a * 3 + 2 <= 0
Notice: Please note that arithmetic operators are not negated. Don’t you ever dare replace the plus (+) with a minus () operator!
iii. !($a != 5  $b < 7)
Notice: Please note that NOT operator remains intact.
iv. $a != true
v. $b <= 7  !($x <= 4)
vi. $a != 4 && $b == 2
Java, C++, C#
Negate the following Boolean expressions using both approaches.
i. b != 4

iv. a == true

Solution
First Approach
i. !(b != 4)
ii. !(a * 3 + 2 > 0)
iii. !(!(a == 5 && b >= 7)),
or the equivalent a == 5 and b >= 7
Notice: Two negations result in an affirmative. That is, two NOT operators in a row negate each other.
iv. !(a == true)
v. !(b > 7 && !(x > 4))
vi. !(a == 4  b != 2)
Second Approach
i. b == 4
ii. a * 3 + 2 <= 0
Notice: Please note that arithmetic operators are not negated. Don’t you ever dare replace the plus (+) with a minus () operator!
iii. !(a != 5  b < 7)
Notice: Please note that NOT operator remains intact.
iv. a != true
v. b <= 7  !(x <= 4)
vi. a != 4 && b == 2
Visual Basic
Negate the following Boolean expressions using both approaches.
i. b <> 4

iv. a = True

Solution
First Approach
i. Not(b <> 4)
ii. Not(a * 3 + 2 > 0)
iii. Not(Not(a = 5 And b >= 7)),
or the equivalent a = 5 And b >= 7
Notice: Two negations result in an affirmative. That is, two NOT operators in a row negate each other.
iv. Not(a = True)
v. Not(b > 7 And Not(x > 4))
vi. Not(a = 4 Or b <> 2)
Second Approach
i. b = 4
ii. a * 3 + 2 <= 0
Notice: Please note that arithmetic operators are not negated. Don’t you ever dare replace the plus (+) with a minus () operator!
iii. Not(a <> 5 Or b < 7)
Notice: Please note that NOT operator remains intact.
iv. a != True
v. b <= 7 Or Not(x <= 4)
vi. a <> 4 And b = 2
Python
Negate the following Boolean expressions using both approaches.
i. b != 4

iv. a == True

Solution
First Approach
i. not(b != 4)
ii. not(a * 3 + 2 > 0)
iii. not(not(a == 5 and b >= 7)),
or the equivalent a == 5 and b >= 7
Notice: Two negations result in an affirmative. That is, two NOT operators in a row negate each other.
iv. not(a == True)
v. not(b > 7 and not(x > 4))
vi. not(a == 4 or b != 2)
Second Approach
i. b == 4
ii. a * 3 + 2 <= 0
Notice: Please note that arithmetic operators are not negated. Don’t you ever dare replace the plus (+) with a minus () operator!
iii. not(a != 5 or b < 7)
Notice: Please note that NOT operator remains intact.
iv. a != True
v. b <= 7 or not(x <= 4)
vi. a != 4 and b == 2
Leave a Reply