if(year@0==0 || (year0!=0 && year%4==0))
statement is in the form of a or (b' and c)
Does this reduce to a or (b or c')
?
if(year@0==0 || (year0==0 || year%4!=0))
Is there a mistake in this reduction? (I thought it was correct but these two does not give the same results.)
CodePudding user response:
Does this reduce to
a or ( b or c' )
?
No. You can see this by building a truth table.
We can change the and
to an or
.
b' and c
= ( b' and c )''
= ( b or c' )'
so
a or ( b' and c )
becomes
a or ( b or c' )'
Not useful, except to show it's not equivalent to a or ( b or c' )
.
We can change the and
to an or
using the same approach.
a or ( b' and c )
becomes
( a' and ( b or c' ) )'
Again, not useful.
It can be simplified to year % 4 == 0
, as long as you only deal with the years 1901 to 2099.
CodePudding user response:
Consider the example of year = 100
. Your first statement will return false, while the second will return true.
The second or
statement enclosed in parentheses does not need to be, and so can be considered as a simple check of the three conditions individually.