De Morgan Law

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

Does x! = 0 mean simplification to x> 0? Or am I mistaken in the following:

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

Thanks.

+4
source share
6 answers

Does x! = 0 mean simplify to x> 0?

No, it is not. Because integers are signed.


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

Consider the following rules:

According to 1. this means that

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

By virtue of 2. this means that

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

<h / "> To check, 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+")");
    }
}
+5
source

java , , x!= 0 x > 0

+1

DeMorgans :

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

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

PS: , . ?

"X x = 0 x > 0?"

+1

x!= 0 x > 0? :

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

, ?

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

.

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

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

, Java do-while, , , .

For example, if I want to ask the user to enter a value that should 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 means that (! (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.

0
source

All Articles