0% found this document useful (0 votes)
6 views

Boolean Logic

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Boolean Logic

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

MAT6012 - Programming for Data Analysis

Module 1: Algorithmic Problem Solving

Dr. B.S.R.V. Prasad


Department of Mathematics
School of Advanced Sciences
Vellore Institute of Technology
Vellore

[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”.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
2

▶ Propositions form the basic units of Boolean logic.


▶ A Proposition is a statement that can be either true of false.
Example. “Mount Everest is the tallest mountain in the world”.
Example. “The Mississippi is the longest river in the world”.
▶ The statements such as
“Brush your teeth”
“How tall is Mount Everest?”
do not have a truth value and are therefore not propositions at all.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
3

▶ 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”.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
4

▶ Propositions can either simple of compound.


▶ A simple proposition is one that cannot be broken into parts.
▶ A compound proposition is formed by combining simple propositions using logical
connectives, also known as logical operators.
▶ There are four fundamental logic operators that are best described by the words
AND, OR, IMPLIES, and NOT.
▶ Example:
Simple: “I am hungry.”
Simple: “I am cold.”
Compound: “I am hungry and I am cold.”

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Logical Operators and their symbols 5

Operator Name Symbol Example


AND ∧ P∧Q
OR ∨ P∨Q
NOT ¬ ¬P
IMPLIES → P→Q
IF AND ONLY IF ↔ P↔Q

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Symbolic Form 6

▶ To help us manage our reasoning, mathematics gives us symbolic logic.


▶ Symbolic logic recommends using symbols instead of natural language sentences.
▶ Consider the example, “If at least one square on the board is still empty and neither
player has achieved a row then the game is still in progress” contains two
propositions that are replaceable by symbols.

P = at least one square on the board is still empty


Q = neither player has achieved a row
R = the game is still in progress
Symbolic form: If P and Q, then R. (or) P ∧ Q → R.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Boolean Operators 7

▶ AND operator also known as conjunction – It chains propositions together in a way


that all of them must be true for the conclusion to be true.
▶ If any of them is false, the conclusion is rendered false also.
▶ Example. Consider the following statements:
1. At least one square on the board is still empty.
2. Neither player has achieved a row.
3. Therefore, the game is still in progress.
▶ The above can be expressed as:
If at least one square on the board is still empty and neither player has achieved a
row, then the game is still in progress.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Truth Tables 8

▶ In symbolic logic the meaning of each logical operator is specified in precise


mathematical detail.
▶ The standard way to do this to use a truth table.
▶ In truth table we list all the possible combinations of values of the propositions and
states whether each combination is logically valid or not.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Truth Table of Conjunction (logical AND) 9

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.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Boolean Operators 10

▶ OR operator also known as disjunction – this operator chains propositions together


in a way that at least one of them must be true for the conclusion to be true also.
▶ The only way that the conclusion is falsified is if all propositions are false.
▶ Example.
If player 1 achieves a row or player 2 achieves a row, then the game is over.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Truth Table of Disjunction (logical OR) 11

P Q P OR Q (P ∨ Q)
True True True
True False True
False True True
False False False

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Boolean Operators 12

▶ 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.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Truth Table of Negation (logical NOT) 13

P NOT P (¬P)
True False
False True

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Boolean Operators 14

▶ 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.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Truth Table of Implication (logical IMPLIES) 15

P Q P IMPLIES Q
(P → Q)
True True True
True False False
False True True
False False True

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Truth Table of Implication (logical IMPLIES) 16

▶ 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.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Truth Table of Implication (logical IMPLIES) 17

▶ 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.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Boolean Operators 18

▶ 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.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Truth Table of Biconditional (logical IF AND ONLY IF) 19

P Q P IF AND ONLY IF Q
(P ↔ Q)
True True True
True False False
False True False
False False True

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
20

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.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
21

Let P = Tom had popcorn,


C = Tom had cucumber sandwich,
R = Tom had Raisins,
S = Tom drink Soda,
T = Tom drink Tea.
We now have the following symbolic form of the statements made by Tommy:
S1 : P ∨ R,
S2 : C → S,
S3 : ¬(S ∨ T).
Since we know that Tom is a liar, we will take negations of above statements and we obtain
¬S1 : ¬(P ∨ R), is true if P ∨ R is false. So, both P and R are false.
¬S2 : ¬(C → S), is true if C → S is false. So, C is true and S is false.
¬S3 : ¬(¬(S ∨ T)), is true if S ∨ T is true. Since S is false, we must have T is true.
From the above statements we conclude that “Tom had Cucumber Sandwich and drink Tea”.
Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)
Boolean Logic
Deduction Problem 22

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?

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Deduction Problem 23

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Deduction Problem 24

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Deduction Problem 25

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Deduction Problem 26

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Deduction Problem 27

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Deduction Problem 28

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Deduction Problem 29

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Deduction Problem 30

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Deduction Problem 31

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Deduction Problem 32

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Deduction Problem 33

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Elevator Doors 34

As a corporate client, I wish to hire a software engineer to write software to control an


elevator system for a small four-floor office building. The elevator has two doors that are
known as the front and the rear door. The front doors are usable only on the first two
floors, and the rear doors are usable only on the top two floors.

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)


Boolean Logic
Elevator Doors 35

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

Dr. B.S.R.V. Prasad | MAT6012 - Programming for Data Analysis (Python)

You might also like