user3003605
user3003605

Reputation: 385

De Morgan's Law

I am trying to simplify the following using DeMorgan's Law: ! (x!=0 || y !=0)

Does x!=0 simplify to x>0? Or am I wrong in the following:

 !(x>0 || y>0)
 !(x>0) && !(y>0)
 ((x<=0) && (y<=0))

Thanks.

Upvotes: 7

Views: 14690

Answers (6)

brimborium
brimborium

Reputation: 9512

DeMorgans Law states the following:

!(A & B) = !A | !B    (I)
!(A | B) = !A & !B    (II)

In your case (II) applies: !(x!=0 || y!=0) => !(x!=0) && !(y!=0) => (x==0) && (y==0)

PS: Your question: "Does x!=0 simplify to x>0?" can be answered with "no" unless x can not take negative values (for example if the type of x is unsigned).

Upvotes: 3

John Cupak
John Cupak

Reputation: 1

When I teach how to write Java do-while loops, I explain how to write the condition which terminates the loop.

For example, if I want to ask the user to enter a value which must be 0, 1, 2, or 3, I want the while condition to continue if the input value is not (value >= 0 and value <= 3).

This translates into while (!(value >= 0) or !(value <= 3)).

But !(value >= 0) means (value < 0), and !(value <= 3) means (value > 3), so the while loop is written as while (value < 0 || value > 3).

Hope this helps.

Upvotes: 0

Alexis C.
Alexis C.

Reputation: 93842

Does x!=0 simplify to x>0?

No that's not true. Because integers are signed.


How to simplify : !(x!=0 || y !=0) ?

Consider this rules :

  1. enter image description here (second De Morgan's laws )

  2. enter image description here

By 1., it implies

!(x!=0 || y !=0) <=> (!(x!=0)) && (!(y != 0))

By 2., it implies

(!(x!=0)) && (!(y != 0)) <=> (x == 0) && (y == 0)


To test you can write the following loop :

for(int x = -5; x < 5; x++){
     for(int y = -5; y < 5; y++){
         if(!(x!=0 || y !=0))
            System.out.println("True : ("+x+","+y+")");
    }
}

Upvotes: 7

Muhammad Kashif Nazar
Muhammad Kashif Nazar

Reputation: 23835

The conversion of the first two comparisons according to De' Morgan's law is the following.

 !(x>0 || y>0)        --->      x <= 0 && y <= 0

 !(x>0) && !(y>0)     --->      !(x <=0 || y <=0)   

Upvotes: 0

Vorsprung
Vorsprung

Reputation: 34297

In java integers are always signed so it is not necessarily true that x!=0 is the same as x>0

Upvotes: 1

Paul Samsotha
Paul Samsotha

Reputation: 208944

Does x!=0 simplify to x>0? Or am I wrong in the following:

x != 0  // reads x does not equal 0; any number BUT 0

x > 0 // reads x is greater than 0; only numbers greater than 0

Do these two look the same, when you write it out like this?

Combined

(x != 0 && x > 0) // any number above 0
(x != 0 || x > 0) // any number BUT 0

Upvotes: 1

Related Questions