Results 1 to 15 of 15

Thread: [Resolved] Logic Question

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Resolved [Resolved] Logic Question

    Let's say we have this: P -> Q...how do you write that as an if statement?

    Code:
    if ( /* P -> Q */) {
    
    }
    I'm so lost on this.
    Last edited by The Hobo; Oct 10th, 2004 at 11:32 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    If Statement in what syntax, maybe VB?
    Code:
    if P=Q then
    'code something
    end if
    If that'S what you want.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    That's not what I'm looking for.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    The truth table for P->Q is:

    Code:
    P | Q | P --> Q
    --+---+--------
    T | T |    T
    T | F |    F 
    F | F |    T
    F | T |    T
    So the best I could come up with is:

    Code:
    if (Q || (!P && ! Q)) {
        // ...
    }
    Because if Q is true, the statement is always true, and if both P and Q are false, the statement is true.

    Or possibly:

    Code:
    if (!(P && !Q)) {
        //...
    }
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Easy peasy.

    In Vb6 it would have been:

    VB Code:
    1. 'VB6
    2. If p Imp q then
    3. ...
    4. End If

    But Imp (implication) is no longer supported in VB.net so...
    VB Code:
    1. 'VB.Net
    2. If (not p) or q then
    3. ...
    4. End If
    I don't live here any more.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    What does -> mean? The only thing I know of for that is for referencing members through pointers in C++. However, that's not a logic question, so I assume that it means something else.
    My usual boring signature: Nothing

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    i was going to post the same thing last night, but thought that I was missing something. I still don't get it. How coud P imply Q?

  8. #8
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    I thoght he ment P goes to Q. Like if you are using the SUM sign. Or like with limits...

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    I looked up Imp(). It does a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to a table

    a b c a=bit in expression1 is
    0 0 1 b=bit in expression2 is
    0 1 1 c=the results is
    1 0 0
    1 1 1

    i thought this was a VB question, anyways

  10. #10

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Thanks for all the help. All I know about -> is the truth table that my math book gave me. I honestly don't understand it myself. They talk about it as if it's an if statement, but it's confusing. But it's my general opinion that this math book is not well written at all.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Originally posted by The Hobo
    Thanks for all the help. All I know about -> is the truth table that my math book gave me. I honestly don't understand it myself. They talk about it as if it's an if statement, but it's confusing. But it's my general opinion that this math book is not well written at all.
    Track down the author, crush his head with a rock and wear his skin to work.

  12. #12
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Hee's how it was explained to me:


    I propose that if it is raining then there are clouds in the sky.

    So P = "It's raining"
    and Q = "There are clouds in the sky"

    If P then Q

    It differs from a straight if statement because of the truth table.

    If you observe that it's raining and there are clouds in the sky then the statement is true.

    If you observe that it's raining but there aren't any clouds in the sky then the statement is false.

    If you observe that it's not raining then it doesn't matter whether there are clouds or not (since you can't test the implication because the first part (P) is false), so the statement could be true and you assume it is.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  13. #13
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    So our programs won't work when the weather is sunny?

    How does the computer know what it's like outside?
    I don't live here any more.

  14. #14
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Originally posted by wossname
    So our programs won't work when the weather is sunny?
    Not unless you shield them using SandpaperTM
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  15. #15
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width