Boolean Logic
Boolean Logic
[email protected] (Personal)
[email protected] (Official)
+91-8220417476
Boolean Logic
1
▶ Boolean Logic is a symbolic logic system that was created by Mathematician named
George Boole around 1850.
▶ Boolean logic is a form of logic that deals with statements having one of only two
values: true of false (usually).
▶ Different corresponding values could be used in other contexts: 1 or 0; on or off;
black or white.
▶ Modern computing system rely heavily on the rules of Boolean logic for generating
correct and reliable results.
▶ George Boole is considered to be the “Father of symbolic logic”.
▶ A single proposition can’t be both true and false simultaneously. There is no way to
express levels of certainty.
Example. “It is travelling fast”.
The above statement can be evaluated as either true or false.
Since if “it” is a car travelling at 150 kmph along the highway then that’s probably fast.
But if “it” is a rocket travelling towards Moon at 150 kmph, that’s undoubtedly slow.
▶ So, we need to qualify statements where necessary to avoid ambiguity.
Example. “It is travelling fast, where fast is 70 kmph or greater”.
P Q P AND Q (P ∧ Q)
True True True
True False False
False True False
False False False
One can use simply ‘T’ for True and ’F‘ for False. Further. some textbooks uses 1 and 0 for
True and False.
P Q P OR Q (P ∨ Q)
True True True
True False True
False True True
False False False
▶ NOT operator also known as negation – this operator doesn’t chain propositions
together itself, rather it modifies a single proposition.
▶ If flips the truth value of the proposition.
▶ Sometimes, negating a proposition can make it easier to express the chain of
reasoning.
▶ Example.
If a square is not occupied, then a player may add their symbol to that square.
P NOT P (¬P)
True False
False True
▶ IMPLIES also known as implication – this operator is used to state that there is a
correlation between the two statements.
▶ If the first statement is true, then the second must be true also.
▶ Implication is a correlation not a causation.
▶ Therefore, we can’t necessarily work backwards from the conclusion of an
implication.
▶ Example.
If a player achieves a row, then the game is over.
P Q P IMPLIES Q
(P → Q)
True True True
True False False
False True True
False False True
▶ In the above table the first two rows are seem sensible.
▶ If P begin true implies Q is true, then the implication is valid
▶ Likewise, if P is true, but its consequent Q is not true, then the implication is invalid.
▶ However, the last two lines, seem odd. Why it is valid for P to imply Q when P is false?
▶ The explanation is that no conclusion can be drawn about an implication when the
antecedent (i.e., P) is false.
▶ For example consider the statement “if it raining (P), then the grass is wet (Q)”.
▶ Now saying “it is not raining (NOT P)” doesn’t contradict the grass is wet.
▶ The grass may be wet because of other reasons such as because of snow or because
of the sprinkler is on.
▶ So, mathematicians have judged that an implication with a false antecedent is true
until proven otherwise.
▶ IF AND ONLY IF also known as biconditional – this operator behaves very similarly to
implication, but a biconditional means that the second proposition is influenced
solely by the first.
▶ If the first proposition is true, the second proposition is true. If the first proposition is
false, the second proposition is false.
▶ Example.
If and only if all squares are occupied, then no more moves are possible.
P Q P IF AND ONLY IF Q
(P ↔ Q)
True True True
True False False
False True False
False False True
Tom was telling you what he ate yesterday afternoon. He tells you,
“I had either popcorn or raisins. Also, if I had cucumber sandwiches, then I had soda. But I
didn’t drink soda or tea.”
Of course you know that Tom is the worlds worst liar, and everything he says is false.
What did Tommy eat?
Hint: Justify your answer by writing all of Tom’s statements using sentence variables (P
for Popcorn; C for Cucumber; R for Raisins; S for Soda; and T for Tea;), taking their
negations, and using these to deduce what Tommy actually ate.
Holmes owns two suits: one black and one tweed. He always wears either a tweed suit or
sandals. Whenever he wears his tweed suit and a purple shirt, he chooses to not wear a
tie. He never wears the tweed suit unless he is also wearing either a purple shirt or
sandals. Whenever he wears sandals, he also wears a purple shirt. Yesterday, Holmes
wore a bow tie. What else did he wear?
An interview session between the software engineer (SE), and me, might go something like the following
dialogue:
SE: What should happen when the “open door” button is pressed?
ME: The door should open.
SE: The front door or the rear door or both?
ME: The front door should open if the elevator is on either floor 1 or 2, otherwise the rear door should
open.
SE: What if the “open door” and “close door” buttons are pressed at the same time?
ME: Hmmm. I hadn’t thought about that. I guess nothing should happen.
SE: What if the elevator is moving between two floors and the “open door” button is pressed?
ME: Nothing should happen.
SE: What if emergency personnel have inserted a key to manually override the software control system. In
that case, what should happen when the “open door” button is pressed?
ME: Hmmmm. That’s a good question. I guess that both the front and rear doors should open regardless of
which floor the elevator is on or even if the elevator is moving between floors.
Formulate a logical sequence of steps to carry out the elevator control system software following the above
conservation.
Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)
Boolean Logic
Elevator Doors 36
The “open door” function for the elevator that has to be specified by Software Engineer
has four steps.
▶ (Floor=1 OR Floor=2) AND (Not Moving) AND Button_Pushed IMPLIES
Front_Door_Opens
▶ (Floor=3 OR Floor=4) AND (Not Moving) AND Button_Pushed IMPLIES
Rear_Door_Opens
▶ (Emergency_Key_Inserted AND Button_Pushed) IMPLIES (Front_Door_Opens AND
Rear_Door_Opens)
▶ In all OTHER CASES, the System Must Do NOTHING