Results 1 to 11 of 11

Math Help - if and else statements rogether with propositionlogic

  1. #1
    Junior Member
    Joined
    Jun 2011
    Posts
    66

    if and else statements rogether with propositionlogic

    Hi,

    I am looking at this question:

    Consider the following program:
    if X then RED else if Y then BLUE else if Z then YELLOW else GREEN.
    Under which of the following conditions is GREEN executed?

    With what proposition will GREEN only be executed here?

    XY Z
    (XY Z)
    XY Z
    (XY Z)

    If I write this out in code I get:
    Code:
                       if X then
           RED
      elseif Y then
           BLUE
    elseif Z then
           YELLOW
    else
           GREEN
      end if
    So with the first one XY Z
    Means "NOT X AND NOT Y AND NOT Z"
    So the only conclusion can be NOT RED NOT BLUE NOT YELLOW BUT GREEN.
    This is correct right?

    But the second one confuses me with the brackets ...
    What are the rules regarding that?
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,501
    Thanks
    765

    Re: if and else statements rogether with propositionlogic

    But the second one confuses me with the brackets ...
    What are the rules regarding that?
    With respect to brackets, (X ∨ Y ∨ Z) is similar to -(a + b + c) on integers: you first add a, b and c and the find the opposite of that sum. Similarly, in (X ∨ Y ∨ Z), you take the disjunction of X, Y and Z (strictly speaking, you first find X ∨ Y and then take a disjunction with Z), and then apply the negation.

    Due to De Morgan's laws, the first two formulas are equivalent, as are the last two. You are right that the first (and hence the second) formula is correct. To show that the last two formulas are incorrect, find some truth values of X, Y and Z such that X ∨ Y ∨ Z is true, but GREEN is not executed.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Junior Member
    Joined
    Jun 2011
    Posts
    66

    Re: if and else statements rogether with propositionlogic

    So this is what you are saying:

    X∧Y ∧Z = GREEN EXECUTED
    (X∨Y ∨Z) = GREEN EXECUTED
    X∨Y ∨Z = GREEN NOT EXECUTED
    (X∧Y ∧Z) = GREEN NOT EXECUTED

    And that the first 2 are actually the same due to "Demorgans Law"
    So X∧Y ∧Z becomes X∧Y ∧Z when you remove the brackets of (X∨Y ∨Z) ...
    Is that correct?
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,501
    Thanks
    765

    Re: if and else statements rogether with propositionlogic

    Quote Originally Posted by iwan1981 View Post
    So this is what you are saying:

    X∧Y ∧Z = GREEN EXECUTED
    (X∨Y ∨Z) = GREEN EXECUTED
    X∨Y ∨Z = GREEN NOT EXECUTED
    (X∧Y ∧Z) = GREEN NOT EXECUTED
    Strictly speaking, I did not say that if X ∨ Y ∨ Z is true, then GREEN is not executed. Both X ∧ Y ∧ Z and X ∨ Y ∨ Z can be true. In fact, if the first of these formulas is true, i.e., X = Y = Z = F, then so it the second. However, it can be that the second formula is true, but GREEN is not executed.

    And that the first 2 are actually the same due to "Demorgans Law"
    Yes.

    So X∧Y ∧Z becomes X∧Y ∧Z when you remove the brackets of (X∨Y ∨Z) ...
    (X∨Y ∨Z) becomes X∧Y ∧Z, yes.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member
    Joined
    Jun 2011
    Posts
    66

    Re: if and else statements rogether with propositionlogic

    it can be that the second formula is true, but GREEN is not executed.
    This part confuses me a little bit ...
    Because with that said ... this means that (X∨Y ∨Z) can be either GREEN EXECUTED or GREEN NOT EXECUTED ...

    And that this is wrong then:

    X∧Y ∧Z = GREEN EXECUTED
    (X∨Y ∨Z) = GREEN EXECUTED
    X∨Y ∨Z = GREEN NOT EXECUTED
    (X∧Y ∧Z) = GREEN NOT EXECUTED
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,501
    Thanks
    765

    Re: if and else statements rogether with propositionlogic

    Quote Originally Posted by emakarov
    it can be that the second formula is true, but GREEN is not executed.
    Quote Originally Posted by iwan1981 View Post
    This part confuses me a little bit ...
    Because with that said ... this means that (X∨Y ∨Z) can be either GREEN EXECUTED or GREEN NOT EXECUTED ...
    In saying "the second formula," I referred to the immediate context in my post, not to your original post. I meant that X ∨ Y ∨ Z can be true, but GREEN is not executed.

    And that this is wrong then:

    X∧Y ∧Z = GREEN EXECUTED
    (X∨Y ∨Z) = GREEN EXECUTED
    X∨Y ∨Z = GREEN NOT EXECUTED
    (X∧Y ∧Z) = GREEN NOT EXECUTED
    Yes, the last two lines are wrong in that neither the left- nor the right-hand side imply the other.

    There are only 8 sets of truth values for X, Y and Z. You can go through all of them and see which formulas are true and which code is executed.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Junior Member
    Joined
    Jun 2011
    Posts
    66

    Re: if and else statements rogether with propositionlogic

    So your actually saying that in all options GREEN can be executed ...
    Follow Math Help Forum on Facebook and Google+

  8. #8
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,501
    Thanks
    765

    Re: if and else statements rogether with propositionlogic

    Quote Originally Posted by iwan1981 View Post
    So your actually saying that in all options GREEN can be executed ...
    Yes. When the first two formulas from the OP are true, GREEN has to be executed; when the last two formulas are true, GREEN may or may not be executed.
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Junior Member
    Joined
    Jun 2011
    Posts
    66

    Re: if and else statements rogether with propositionlogic

    Quote Originally Posted by emakarov View Post
    Yes. When the first two formulas from the OP are true, GREEN has to be executed; when the last two formulas are true, GREEN may or may not be executed.
    What do you mean with forst 2 formula's from OP ...
    I think I have lost you :-)

    Sorry :-(
    Follow Math Help Forum on Facebook and Google+

  10. #10
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,501
    Thanks
    765

    Re: if and else statements rogether with propositionlogic

    "OP" stands for the "original post." It is the first post in the thread. The first two formulas in that post are X ∧ Y ∧ Z and (X ∨ Y ∨ Z) (they are equivalent).
    Follow Math Help Forum on Facebook and Google+

  11. #11
    Junior Member
    Joined
    Jun 2011
    Posts
    66

    Re: if and else statements rogether with propositionlogic

    I think I have the concept now ...

    X∧Y ∧Z = GREEN EXECUTED
    (X∨Y ∨Z) = GREEN EXECUTED
    X∨Y ∨Z = GREEN NOT EXECUTED / OR MAY BE EXECUTED
    (X∧Y ∧Z) = GREEN NOT EXECUTED / OR MAY BE EXECUTED

    So the last 2 formula's is correct either way ... if we only have 2 answer options there (Executed of Not Executed)

    Thanks!
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. if then statements
    Posted in the Discrete Math Forum
    Replies: 3
    Last Post: October 24th 2010, 10:13 AM
  2. Logical statements
    Posted in the Discrete Math Forum
    Replies: 20
    Last Post: August 17th 2010, 01:55 AM
  3. Statements
    Posted in the Discrete Math Forum
    Replies: 2
    Last Post: October 23rd 2009, 09:48 AM
  4. T or F statements
    Posted in the Discrete Math Forum
    Replies: 9
    Last Post: March 29th 2009, 03:36 PM
  5. Conditional statements
    Posted in the Geometry Forum
    Replies: 2
    Last Post: November 6th 2008, 01:57 PM

/mathhelpforum @mathhelpforum