Question

How to simplify these compound logical expressions?

!((x <= 5) && (y == 10) && (z < 5))  // 1
!(x == 10) || !((y == 5) || (z < 0)) // 2

I have read the rule for simplification, but I am not understanding what to do with ==.

This is from "Programing in ANSI C" written by E Balagurasy While designing decision statements, we often come across a situation where the logical NOT operator is applied to a compound logical expression, like !(x&&y || !z). However,a positive logic is always easy to read and comprehend than a negative logic. In such cases, we may apply what is known as De Morgan's rule to make the total expression positive.The rule is as follows: "Remove the parentheses by applying the NOT operator to every logical expression component, while complementing the relational operators." Example: !(x&&y || !z) becomes !x || !y && z.

Était-ce utile?

La solution

I'll give you some hints, so as to not do your homework for you:

!(a || b || c) = (!a && !b && !c)

!(a && b && c) = (!a || !b || !c)

!(a == b) = (a != b)

!(a <= b) = (a > b)

You should be able to take it from there.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top