Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

Conditional Statements

Started by Mybowlcut Aug 8, 2007 at 9:44 AM 1 replies 1k views
Original Post
Mybowlcut
Mybowlcut
I started university today, and I'm already having trouble with some math stuff. I'm used to an if statement working like it does in most programming languages:
if(1)
   // do something
but using "Symbolic Logic" I think it's called, the meaning changes:
Quote:
If I win lotto, I'll give you $500. Define: L: I win lotto, G: I give you $500 So my promise becomes: L -> G Now suppose I do win and I give you $500. I have kept my promise. Suppose I don't win and don't give you $500. I haven't broken my promise. Suppose I don't win, and I give you $500. Lucky you! But it still does not contradict my promise, because I did not say what I would do if I didn't win. My promise is broken only if I win and I don't give you $500. L G promise ----------- 0 0 kept 0 1 kept 1 0 broken 1 1 kept
That is a quote out of one of my lectures. This doesn't make sense to me... to me, if the first condition is false, the whole statement should be considered false. Can anyone explain this in a way that's easier to understand? Thanks.

SiCrane
SiCrane
In programming languages, conditional statements are imperative: they are instructions for what to do. In symbolic logic, conditional statements are declarative: they are statements about what is. In the former case the statements are evaluated for their side effects, in the latter case the statements are evaluated for their value.

So let's say you have a statement A->B; and let's assume A->B is true. If you know A is false, then you don't know anything about B. For example, "if an animal is a cow, then it has horns". Now, let's give you a random animal Fred that we know isn't a cow. Fred could have horns he was a rhino or he could not have horns if he was a dog. All we know is that he isn't a cow. Now let's take another animal, George that has horns. He could be a cow or he could be a rhino. But if we have an animal Bessy that is a cow, then we know she has horns. Either that or the statement "if an animal is a cow it has horns" is false.
ToohrVyk
ToohrVyk
You could consider the following pseudo-code program representing the decision tree for the promise described in your course:

PROGRAM:  L = random_bool()   // You may win or not win the lottery  if (L)     G = true          // If you win, you must give $500  else     G = random_bool() // If you don't win, you may do anything  return (L,G)


Programming does not define what it means for a program (or a statement) to be "true" or "false". The program above does return a pair of booleans (representing winning the lotto and giving $500), but you have no way of knowing the value of these by just looking at the program (after all, you may or may not win the lottery, and it's perfectly random).

Symbolic logic does define a statement's truth—and since programming doesn't define a notion of truth for statements, there is no possible collision or confusion here. In programming terms, given the results (L,G) of a program, the program is defined to be true if and only if the results (L,G) could have been returned by this program. So, if there is no way for the program to return the results (L,G), then it is defined to be false.

Can the program above return (false,true) ? It certainly can. Thus, "0 ⇒ 1" is true. Can it return (true,false) ? No: if L was true, then G would be as well. Thus, "1 ⇒ 0" is false.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.