Search code examples
if-statementboolean-operations

Simplify logic statement


I have this:

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

I want to negate that if-statement:

This should work:

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

but I believe there is a way to simplify it and it's escaping me at the moment.


Solution

  • Welcome to the world of de-Morgan for boolean algebra followed by simple distribution :

    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)