Let's say we have this: P -> Q...how do you write that as an if statement?
I'm so lost on this.Code:if ( /* P -> Q */) {
}
Printable View
Let's say we have this: P -> Q...how do you write that as an if statement?
I'm so lost on this.Code:if ( /* P -> Q */) {
}
If Statement in what syntax, maybe VB?
If that'S what you want.Code:if P=Q then
'code something
end if
That's not what I'm looking for.
The truth table for P->Q is:
So the best I could come up with is:Code:P | Q | P --> Q
--+---+--------
T | T | T
T | F | F
F | F | T
F | T | T
Because if Q is true, the statement is always true, and if both P and Q are false, the statement is true.Code:if (Q || (!P && ! Q)) {
// ...
}
Or possibly:
Code:if (!(P && !Q)) {
//...
}
Easy peasy.
In Vb6 it would have been:
VB Code:
'VB6 If p Imp q then ... End If
But Imp (implication) is no longer supported in VB.net so...
VB Code:
'VB.Net If (not p) or q then ... End If
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.
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?
I thoght he ment P goes to Q. Like if you are using the SUM sign. Or like with limits...:D
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 :rolleyes:
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.Quote:
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.
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.
So our programs won't work when the weather is sunny?
How does the computer know what it's like outside?
Not unless you shield them using SandpaperTMQuote:
Originally posted by wossname
So our programs won't work when the weather is sunny?
:D