You are on page 1of 34

Module 1

LOGIC
+ Crucial for mathematical reasoning
+ Important for program design
+ Used for designing electronic circuitry

+ (Propositional )Logic is a system based on propositions.

+ A proposition is a (declarative) statement that is either true or false (not


both).
+ We say that the truth value of a proposition is either true (T) or false (F).
+ Corresponds to 1 and 0 in digital circuits

2
Propositional Logic
Propositional Logic is the logic of compound
statements built from simpler statements
using so-called Boolean connectives. George Boole
(1815-1864)

Some applications in computer science:


+ Design of digital electronic circuits.
+ Expressing conditions in programs.
+ Queries to databases & search engines.
Chrysippus of Soli
(ca. 281 B.C. – 205 B.C.)
Definition of a Proposition
Definition: A proposition (denoted p, q, r, …) is simply:

• a statement (i.e., a declarative sentence) with some definite meaning,


(not vague or ambiguous)
• having a truth value that’s either true (T) or false (F)
1. it is never both, neither, or somewhere “in between!
2. However, you might not know the actual truth value,
3. and, the truth value might depend on the situation or context.
• Later, we will study probability theory, in which we assign degrees of
certainty (“between” T and F) to propositions.
The Statement/Proposition Game
“Elephants are bigger than mice.”

Is this a statement? yes

yes
Is this a proposition?

What is the truth value true


of the proposition?

5
The Statement/Proposition Game
“520 < 111”

Is this a statement? yes

Is this a proposition? yes

What is the truth value false


of the proposition?
The Statement/Proposition Game
“y > 5”
Is this a statement? yes
Is this a proposition? no

Its truth value depends on the value of y, but this value is


not specified. We call this type of statement a propositional
function or open sentence.
The Statement/Proposition Game
“Please do not fall asleep.”

Is this a statement? no
It’s a request.

Is this a proposition? no

Only statements can be propositions.


The Statement/Proposition Game
“x < y if and only if y > x.”

Is this a statement? yes

Is this a proposition? yes


… because its truth value does not
depend on specific values of x and y.

What is the truth value true


of the proposition?
Combining Propositions
As we have seen in the previous examples, one
or more propositions can be combined to form a single
compound proposition.
We formalize this by denoting propositions with
letters such as p, q, r, s, and introducing several logical
operators.
Logical Operators (Connectives)
We will examine the following logical operators:
• Negation ¬ (NOT)
• Conjunction ∧ (AND)
• Disjunction ∨ (OR)
• Exclusive or ⊕ (XOR)
• Implication → (if – then)
• Biconditional ↔ (if and only if)
Truth tables can be used to show how these operators can
combine propositions to compound propositions.
•Negation (NOT)
The unary negation operator “¬” (NOT) transforms a
propositional into its logical negation and has this truth table:

p ¬p

T F

F T
Examples

1) If p denotes “The earth is round.”, then ¬p denotes “It is


not the case that the earth is round,” or more simply “The
earth is not round.”

2) If p = “I have brown hair.”, then


¬p = “I do not have brown hair.”
•Conjunction (AND)
The binary conjunction operator “” (AND) combines two
propositions to form their logical conjunction and has this truth table:

p q p∧q
T T T
T F F
F T F
F F F
Examples

1) If p denotes “I am at home.” and q denotes “It is raining.”,


then p ∧q denotes “I am at home and it is raining.”

2) If p = “ I will have salad for lunch.”


q = “I will have steak for dinner.”
Then p ∧q = I will have salad for lunch and I will have steak for
dinner.”
•Disjunction (OR)
The binary disjunction operator “” (OR) combines two
propositions to form their logical disjunction and has this truth table:

p q p ∨q
T T T
T F T
F T T
F F F
Examples

1) If p denotes “I am at home.” and q denotes “It is raining.”,


then p ∧q denotes “I am at home and it is raining.”

2) If p = “My car has a bad engine.”


q = “My car has a bad carburetor.”
Then p ∧ q = =“Either my car has a bad engine, or my car
has a bad carburetor.”
•Exclusive Or (XOR)
The binary exclusive-or operator “” (XOR) combines two propositions
to form their logical “exclusive or” (exjunction). In English “or” has two distinct
meanings.

“Inclusive Or” - In the sentence “Students who have taken CS202 or


Math120 may take this class,” we assume that students need to have taken one of
the prerequisites, but may have taken both. This is the meaning of disjunction.
For p ∨ q to be true, either one or both of p and q must be true.
“Exclusive Or” - When reading the sentence “Soup or salad comes
with this entrée,” we do not expect to be able to get both soup and salad. This
is the meaning of Exclusive Or (Xor). In p ⊕ q , one of p and q must be true,
but not both. The truth table for ⊕ is:

p q p ⊕q
T T F
T F T
F T T
F F F
Note that p  q means that p is true, or q is true, but not both!

This operation is called exclusive or, because it excludes the possibility that
both p and q are true.
•Implication (if - then)
antecedent consequent

The implication p  q states that p implies q. If p is true, then q is true;


but if p is not true, then q could be either true or false.
If p and q are propositions, then p →q is a conditional statement or
implication which is read as “if p, then q ” and has this truth table:
p q p →q
T T T
T F F
F T T
F F T
Examples

1. If p denotes “I am at home.” and q denotes “It is raining.” then p →q


denotes “If I am at home then it is raining.” In p →q , p is the
hypothesis (antecedent or premise) and q is the conclusion (or
consequence).

2. Let p = “you study hard.”


q = “you will get a good grade.”
p  q = “if you study hard, then you will get a good grade.”
Different Ways of Expressing p →q
if p, then q p implies q
if p, q p only if q
q unless ¬p q when p
q if p q whenever p
p is sufficient for q q follows from p
q is necessary for p a necessary condition for p is q
a sufficient condition for q is p
•Converse, Contrapositive, and Inverse
 From p →q we can form new conditional statements .
• q →p is the converse of p →q
• ¬q → ¬ p is the contrapositive of p →q
• ¬ p → ¬ q is the inverse of p →q

Example 1: Find the converse, inverse, and contrapositive of


“If it is raining, then I will not go to town.”

Solution:
Converse : If I do not go to town, then it is raining.
Inverse : If it is not raining, then I will go to town.
Contrapositive : If I go to town, then it is not raining.
•Converse
The converse of a conditional statement is formed by
switching the hypothesis and the conclusion.
Example:

(Conditional) If I am sleeping, then I am breathing.


(Converse) If I am breathing, then I am sleeping.
•Inverse
The inverse of a conditional statement is formed by negating
(inserting “not”) the hypothesis and the conclusion.
Example:

(Conditional) If I am sleeping, then I am breathing.


(Converse) If I am not sleeping, then I am not breathing.
•Contrapositive
The contrapositive of a conditional statement is formed by
negating the hypothesis and the conclusion of the converse.
Example:

(Converse) If I am breathing, then I am sleeping.


(Contrapositive) If I am not breathing, then I am not sleeping.
•Biconditional
If p and q are propositions, then we can form the
biconditional proposition p ↔q , read as “p if and only if q .” The
biconditional p ↔q denotes the proposition with this truth table:

p q p ↔q
T T T
T F F
F T F
F F T

+
Examples

1. If p denotes “I am at home.” and q denotes “It is raining.” then p ↔ q denotes


“I am at home if and only if it is raining.”

2. p = “Trump will be president for all of 2021.”


q = “Trump wins the 2020 election.”

p  q = “Trump will be president for all of 2021 if and only if Trump wins the
2020 election,.”
 p  q means that p and q have the same truth value.

 Note this truth table is the exact opposite of ’s! Thus, p  q


means ¬(p  q)

 p  q does not imply that p and q are true, or that either of


them causes the other, or that they have a common cause.
Tautologies, Contradictions, and Contingencies
+ A tautology is a proposition which is always true.
• Example: p ∨¬p
+ A contradiction is a proposition which is always false.
• Example: p ∧¬p
+ A contingency is a proposition which is neither a tautology nor a
contradiction, such as p
P ¬p p ∨¬p p ∧¬p

T F T F

F T T F
Boolean Operations Summary
We have seen 1 unary operator (out of the 4 possible) and 5 binary
operators (out of the 16 possible). Their truth tables are below.

p q p pq pq pq pq pq


F F T F F F T T
F T T F T T T F
T F F F T T F F
T T F T T F T T
Construct a truth table for
p q r r pq p  q → r

T T T F T F
T T F T T T
T F T F T F
T F F T T T
F T T F T F
F T F T T T
F F T F F T
F F F T F T
ACTIVITY 1:

Direction: Construct a truth table for each exercise.


1. (p ∧ q) ∨ ¬p
2. ¬q → (¬p ∨ q )
3. (¬p → q ) ∨ (¬p ∧ ¬q )

You might also like