Wednesday, September 14, 2011

Challenge 009’s Solution

When x = true and y = false, all three expressions are “true”. Statement I is “true” if both condition 1 and condition 2 can be “true”. Condition 1 can be “true” with “x”, and condition 2 can be “not false” with “!y”. Statement II is also true if  both condition 1 and condition 2 can be “true”. Condition 1 can be “true” with “x”, while condition 2 requires both statements to be “true”; however, “!(x && y)” is the same as “(!x || !y)”, making condition 2 “not false” with “!y”. Finally, Statement III is “true” as long as one of the two conditions is “true”. Condition 1 requires both statements to be “true”, and “(x && !y)” is “true” and “not false”. That is why all three Statements in Challenge 009 are “true”.
 
−Phoenix

3 comments:

  1. Methodical and detailed explanation here, most excellent.

    Two follow-up questions:

    What kind of evaluation is it when we determine that since the first part of a logical condition evaluates to true, then the rest has to be tue as well?

    Secondly, what's the name for the computer science laws that you reference when saying:

    !(x && y) == (!x || !y)

    Thank You

    ReplyDelete
  2. First, the idea that if “x” is true, then the entire expression is true, is called “Short−Circuit Evaluation”. It is possible because Condition 1 is always checked before Condition 2, allowing Condition 2 to be skipped entirely. Secondly, the idea that “!(x && y) == (!x || !y)” is called the “De Morgan’s Law”. It states that “not (x and y)” is the same expression as “not x or not y”.

    −Phoenix

    ReplyDelete
  3. Well done, 15 XPs awarded for the completion.

    ReplyDelete