Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does !a&&(a||b) simplify to?

I'm a little confused on !a&&(a||b). If I look at it directly and interpret it simply, it appears as if it is the same as

!a&&a or !a&&b

but this seems a little weird because since a can't be true and false, it would only be true if the latter was true. I also interpreted it like this

!a || a&&b

I don't really know how I came up with this one but it just looks more logical since there are no contradictions. Can anyone help me on this please?

like image 234
Andy Avatar asked Dec 20 '14 00:12

Andy


4 Answers

Tautology Table

 | a | b | !a | a || b |  !a && (a || b)  | !a && b | [ !a && (a || b) ] <=> [!a && b]    |
 |---|---|----|--------|------------------|---------|-------------------------------------|
 | 0 | 0 |  1 |   0    |      0           |    0    |                   1                 |
 | 0 | 1 |  1 |   1    |      1           |    1    |                   1                 |
 | 1 | 0 |  0 |   1    |      0           |    0    |                   1                 |
 | 1 | 1 |  0 |   1    |      0           |    0    |                   1                 |
 

"Proof"

  1. According to the Principle of Distributivity statement !a && (a || b) is equivalent to (!a && a) || (!a && b).

  2. Accordiong to the Law of Non-Contradiction (!a && a) is equivalent to false

  3. Putting it all together:

    !a && (a || b) <=> (!a && a) || (!a && b) <=> false || (!a && b) <=> !a && b

like image 161
Lukas Risko Avatar answered Oct 12 '22 22:10

Lukas Risko


You can simplify it like this (!a && b) because in expression (!a && a || !a && b) the condition !a && a is always false

like image 41
sol4me Avatar answered Oct 12 '22 22:10

sol4me


In Java like in most 1 languages the unary ! has higher precedence than &&.

So !a&&(a||b) is (!a)&&(a||b)

You can represent the truth table of that expression using a Karnaugh map:

      | a = 0 | a = 1 |
------+-------+-------+
b = 0 |   0   |   0   |
------+-------+-------+
b = 1 |   1   |   0   |
------+-------+-------+

Now, it can easily be seen that the only true case is when (!a) && b.

So !a&&(a||b) is !a && b


1See comments below.

like image 11
Sylvain Leroux Avatar answered Oct 12 '22 23:10

Sylvain Leroux


It simply means !a && b, a must be false and b must be true, for it to be true

like image 6
imtheman Avatar answered Oct 12 '22 21:10

imtheman