Simplify logical instruction

I have a brain fart

I have it

if(!A or (A and B))   //pseudocode

I want to deny that if-statement

this should work:

if(!(!A or (A and B)))  //pseudocode

but I believe that there is a way to simplify it, and it is slipping away from me at the moment

thanks

+4
source share
2 answers

Welcome to the world of de Morgan for Boolean algebra, followed by a simple spread:

if(!(!A or (A and B)) 
=> if(!(!A) and !(A and B))
=> if(A and (!A or !B))
=> if((A and !A) or (A and !B))
=> if(A and !B) 
+7
source

If you divide it into a truth table ...

A B  !A  (A and B)  A! or (A and B)
0 0  1   0          1
0 1  1   0          1
1 0  0   0          0
1 1  0   1          1

You can see that the result is true in all cases except A and !B, without the need to know / remember any rules of Boolean algebra. "Except" just "not," so ... !(A and !B)...

, !A or (A and B) , , , ...

+4

Source: https://habr.com/ru/post/1618066/


All Articles