Hi guys I am in need of some help understanding Boolean Expressions. I am a little lost on them and would like to see if any of you could enlighten me with some tips.
Thanks in advanced.
Printable View
Hi guys I am in need of some help understanding Boolean Expressions. I am a little lost on them and would like to see if any of you could enlighten me with some tips.
Thanks in advanced.
What's your question?
I need help understanding Boolean not. The whole true evaluates to false and vice versa is confusing me. So some help understanding how those are used would be helpful.
Why does it confuse you? Think of it as a light bulb. If it's on and you flip the switch, it's off. If it's off and you flip the switch, it's on.
Then how could it be used?
MikeD is dead.Quote:
Originally Posted by MikeD
Is the above statement true or false? If it is false, write a statement to express the truth. You are only allowed to insert the word "not" into the above statement to create this new statement.
You are going to feel so bad if he doesn't respond.
Soma
MikeD is not dead
So with the Boolean not operation you take a false statement and then make it true?
Yes. Beware this only changes the value of the statement, not the value of any variables involved.
All primitive (non-object) types, including pointers, in C++ can be true or false. Zero and NULL are considered false, everything else is true.Code:if (2+2 == 4) cout << true << endl;
if (!(2+2 == 5)) cout << true << endl; // same as (2+2 != 5)
Code:int a = 0, b = 666;
string *s = NULL, *s1 = new string("hey");
if (!a) cout << b << endl;
if (!s) cout << *s1 << endl;
I've tutored students before in symbolic logic, and I can suggest googling links on "propositional logic" or "classical logic" first. There are many more names in use for the fundamental logic that has been studied for centuries.
Boolean algebra is a mathematical systematization of these modes of reasoning. They make sense together, but in my experience, it is best to approach the logic from the ground up.
One of my students who was having problems with logic for his computer courses pulled out a mark in the 90s after going back to basics of logic. He has recommended this book:
Warren Goldfarb - "Deductive Logic"
Again, ignore "deductive" in the title. He has said that the introductory section on logical connectives (AND OR NOT IF->THEN ) was very helpful.
Do not think of it as "making" something true. Since we use Boolean expressions in programming to compare things so often, without changing the values themselves, you need to think of it more fundamentally. Think of it as checking, within some context or world (or program), whether some expression, A, describes the state of affairs correctly.
Moving away from the morbid:
Suppose we're in a world or scenario in which you are exactly 6 inches tall. If I were to utter the phrase, "MikeD is 6 inches tall.", my utterance would be TRUE. If I were to utter "Mike D is not 6 inches tall" my utterance would be FALSE. So if we let A stand for the first statement:
A = "MikeD is 6 inches tall."
!A = "MikeD is not 6 inches tall."
There are a number of ways that !A could be true, namely if you were any other height than 6 inches tall. The only way !A can be FALSE is precisely when A is true.
You are not "making" anything false, you are using the basic properties of logic to check conditions, etc. Look up "logical complement"... it is the more general idea behind NOT.
NOTE: As soon as we define the statement A, we have committed to what !A is, and vice versa.
Thanks for the help guys, it has cleared things up for me.
I suppose I understand where you are coming from, but I think it would be better to say that a null pointer is considered false. NULL is a null constant (which should not be used nowadays!) which should only be used with pointers, and as such, its meaning by itself should be "undefined."
Indeed, you cannot test whether nullptr is true or false in C++11.
That is overkill. Sure, it might be helpful for a software engineer, and someone achieving to be one, but otherwise...
Nevermind. It seems that a nullptr can be converted to false; but never to true, so it's a bit of an oddball.
I cannot get if (!nullptr) to compile, however.