You are on page 1of 45

Module #1 - Logic

University of the Cordilleras


College of Teacher Education
Mathematics Department
Asst. Prof. Ronald Judan

Slides for a Course Based on the Text


Discrete Mathematics & Its Applications (5th Edition)
by Kenneth H. Rosen

2021-01-17 Asst Prof Ronald F. Judan


Module #1 - Logic

Course Work:
Students grades are calculated according to their
performance in the following course work:

Assignments Quizzes Attendance Midterm Exam Final Exam

Class Standing 50 % 50 %
50%
Academic Integrity:
--- Plagiarism, cheating, and other forms of academic
dishonesty are prohibited and may result in grade F for the
course.
--- An incomplete grade is given only for an exceptional reason
and such reason must be documented.
2021-01-17
Module #1 - Logic

Module #1:
Foundations of Logic

2021-01-17 Asst Prof. Ronald F. Judan 3


Module #1 - Logic

Module #1: Foundations of Logic


(lectures)
Mathematical Logic is a tool for working with
complicated compound statements. It includes:
• A language for expressing them.
• A concise notation for writing them.
• A methodology for objectively reasoning about
their truth or falsity.
• It is the foundation for expressing formal proofs in
all branches of mathematics.

2021-01-17 Asst Prof. Ronald F. Judan 4


Module #1 - Logic

Foundations of Logic: Overview

• Propositional logic:
– Basic definitions.
– Equivalence rules & derivations.

2021-01-17 Asst Prof. Ronald F. Judan 5


Module #1 - Logic Topic #1 – Propositional Logic

Propositional Logic
Propositional Logic is the logic of compound
statements built from simpler statements
using so-called Boolean connectives.
Some applications in computer science: George Boole
(1815-1864)
• Design of digital electronic circuits.
• Expressing conditions in programs.
• Queries to databases & search engines.

Chrysippus of Soli
2021-01-17 Asst Prof. Ronald F. Judan (ca. 281 B.C. – 205 B.C.)6
Module #1 - Logic Topic #1 – Propositional Logic

Definition of a Proposition
A proposition (p, q, r, …) is simply a statement (i.e.,
a declarative sentence) with a definite meaning,
having a truth value that’s either true (T) or false
(F) (never both, neither, or somewhere in
between).
(However, you might not know the actual truth
value, and it might be situation-dependent.)
(for now: think True/False only!)

2021-01-17 Asst Prof. Ronald F. Judan 7


Module #1 - Logic Topic #1 – Propositional Logic

Examples of Propositions
• “It is raining.” (In a given situation.)
• “Beijing is the capital of China.” • “1 + 2 = 3”
But, the following are NOT propositions:
• “Who’s there?” (interrogative, question)
• “La la la la la.” (meaningless interjection)
• “Just do it!” (imperative, command)
• “Yeah, Way nas di, whatever...” (vague)
• “1 + 2” (expression with a non-true/false value)

2021-01-17 Asst Prof. Ronald F. Judan 8


Module #1 - Logic

Logic and Mathematical Statements


Negation
• The opposite of a given mathematical statement. One thing to keep in mind is that if a
statement is true, then its negation is false (and if a statement is false, then its negation
is true
• Negation of "A or B".

Consider the statement "You are either rich or happy." For this statement to be false,
you can't be rich and you can't been happy. In other words, the opposite is to be not
rich and not happy. Or if we rewrite it in terms of the original statement we get "You
are not rich and not happy."

If we let A be the statement "You are rich" and B be the statement "You are happy",
then the negation of "A or B" becomes "Not A and Not B."

In general, we have the same statement: The negation of "A or B" is the statement "Not
A and Not B."

2021-01-17 Asst Prof. Ronald F. Judan 9


Module #1 - Logic

Logic and Mathematical Statements

• Negation of "A and B".


• Again, let's analyze an example first.
Consider the statement "I am both rich and happy." For
this statement to be false I could be either not rich or not
happy. If we let A be the statement "I am rich" and B be
the statement "I am happy", then the negation of "A
and B" becomes "I am not rich or I am not happy" or
"Not A or Not B".

2021-01-17 Asst Prof. Ronald F. Judan 10


Module #1 - Logic

Logic and Mathematical Statements

Negation of "If A, then B". ⌐ ( A→B )


• To negate a statement of the form "If A, then B" we should replace it
with the statement "A and Not B". This might seem confusing at first,
so let's take a look at a simple example to help understand why this is
the right thing to do.

Consider the statement "If I am rich, then I am happy." For this


statement to be false, I would need to be rich and not happy. If A is the
statement "I am rich" and B is the statement "I am happy,", then the
negation of "A ⇒ B" is "I am rich" = A, and "I am not happy" = not B.

So the negation of "if A, then B" becomes "A and not B".

2021-01-17 Asst Prof. Ronald F. Judan 11


Module #1 - Logic

Logic and Mathematical Statements

Example.
• Now let's consider a statement involving some
mathematics. Take the statement "If n is even,
then n2 is an integer." For this statement to be
false, we would need to find an even integer n for
which n2 was not an integer. So the opposite of
this statement is the statement that "n is even and
n2 is not an integer."

2021-01-17 Asst Prof. Ronald F. Judan 12


Module #1 - Logic

Logic and Mathematical Statements

Negation of "For every ...", "For all ...", "There


exists ...“

• Sometimes we encounter phrases such as "for


every," "for any," "for all" and "there exists" in
mathematical statements.

2021-01-17 Asst Prof. Ronald F. Judan 13


Module #1 - Logic

Logic and Mathematical Statements

Example.
• Consider the statement "For all integers n, either n is even or n is odd".
Although the phrasing is a bit different, this is a statement of the form "If A,
then B." We can reword this sentence as follows: "If n is any integer, then
either n is even or n is odd."

How would we negate this statement? For this statement to be false, all we
would need is to find a single integer which is not even and not odd. In other
words, the negation is the statement "There exists an integer n, so that n is not
even and n is not odd."

In general, when negating a statement involving "for all," "for every", the
phrase "for all" gets replaced with "there exists." Similarly, when negating a
statement involving "there exists", the phrase "there exists" gets replaced with
"for every" or "for all."

2021-01-17 Asst Prof. Ronald F. Judan 14


Module #1 - Logic

Logic and Mathematical Statements

Example.
Negate the statement "If all rich people are happy, then all poor
people are sad."
• First, this statement has the form "If A, then B", where A is the
statement "All rich people are happy" and B is the statement "All poor
people are sad." So the negation has the form "A and not B." So we
will need to negate B. The negation of the statement B is "There exists
a poor person who is not sad."

Putting this together gives: "All rich people are happy, but there exists
a poor person who is not sad" as the negation of "If all rich people are
happy, then all poor people are sad."

2021-01-17 Asst Prof. Ronald F. Judan 15


Module #1 - Logic

Summary

Statement Negation

"A or B" "not A and not B"

"A and B" "not A or not B"

"if A, then B" "A and not B"

"For all x, A(x)" "There exist x such that not A(x)"

"There exists x such that A(x)" "For every x, not A(x)"

2021-01-17 Asst Prof. Ronald F. Judan 16


Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

Operators / Connectives
An operator or connective combines one or
more operand expressions into a larger
expression. (E.g., “+” in numeric exprs.)
Unary operators take 1 operand (e.g., −3);
binary operators take 2 operands (eg 3  4).
Propositional or Boolean operators operate on
propositions or truth values instead of on
numbers.
2021-01-17 Asst Prof. Ronald F. Judan 17
Module #1 - Logic

Some Popular Boolean Operators

Formal Name Nickname Arity Symbol


Negation operator NOT Unary ¬
Conjunction operator AND Binary 
Disjunction operator OR Binary 
Exclusive-OR operator XOR Binary 
Implication operator IMPLIES Binary 
Biconditional operator IFF Binary ↔

2021-01-17 Asst Prof. Ronald F. Judan 18


Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

The Negation Operator


The unary negation operator “¬” (NOT)
transforms a prop. into its logical negation.
E.g. If p = “I have brown hair.”
then ¬p = “I do not have brown hair.”
Truth table for NOT: p p
T :≡ True; F :≡ False T F
“:≡” means “is defined as” F T
Operand Result
column column
2021-01-17 19
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

The Conjunction Operator


The binary conjunction operator “” (AND)
combines two propositions to form their
logical conjunction. ND
E.g. If p=“I will have salad for lunch.” and
q=“I will have steak for dinner.”, then
pq=“I will have salad for lunch and
I will have steak for dinner.”
Remember: “” points up like an “A”, and it means “ND”
2021-01-17 Asst Prof. Ronald F. Judan 20
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

Conjunction Truth Table


Operand columns
• Note that a
p q pq
conjunction
p1  p2  …  pn F F F
of n propositions F T F
will have 2n rows T F F
in its truth table. T T T
• Also: ¬ and  operations together are suffi-
cient to express any Boolean truth table!
2021-01-17 Asst Prof. Ronald F. Judan 21
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

The Disjunction Operator


The binary disjunction operator “” (OR)
combines two propositions to form their
logical disjunction.
p=“My car has a bad engine.” 
q=“My car has a bad carburetor.”
pq=“Either my car has a bad engine, or
my car has a bad carburetor.” After the downward-
pointing “axe” of “”
splits the wood, you
Meaning is like “and/or” in English. can take 1 piece OR the
other, or both.
2021-01-17 Asst Prof. Ronald F. Judan 22
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

Disjunction Truth Table


• Note that pq means
p q pq
that p is true, or q is
true, or both are true! F F F
Note
F T T difference
• So, this operation is
also called inclusive or,
T F T from AND

because it includes the T T T


possibility that both p and q are true.
• “¬” and “” together are also universal.
2021-01-17 Asst Prof. Ronald F. Judan 23
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

Nested Propositional Expressions


• Use parentheses to group sub-expressions:
“I just saw my old friend, and either he’s
grown or I’ve shrunk.” = f  (g  s)
– (f  g)  s would mean something different
– f  g  s would be ambiguous
• By convention, “¬” takes precedence over
both “” and “”.
– ¬s  f means (¬s)  f , not ¬ (s  f)
2021-01-17 Asst Prof. Ronald F. Judan 24
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

A Simple Exercise
Let p=“It rained last night”,
q=“The sprinklers came on last night,”
r=“The lawn was wet this morning.”
Translate each of the following into English:
¬p = “It didn’t rain last night.”
r  ¬p = “The lawn was wet this morning, and
it didn’t rain last night.”
¬ r  p  q = “Either the lawn wasn’t wet this
morning, or it rained last night, or
the sprinklers came on last night.”
2021-01-17 Asst Prof. Ronald F. Judan 25
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

The Exclusive Or Operator


The binary exclusive-or operator “” (XOR)
combines two propositions to form their
logical “exclusive or” (exjunction?).
p = “I will earn an A in this course,”
q = “I will drop this course,”
p  q = “I will either earn an A for this
course, or I will drop it (but not both!)”

2021-01-17 Asst Prof. Ronald F. Judan 26


Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

Exclusive-Or Truth Table


• Note that pq means
p q pq
that p is true, or q is
true, but not both! F F F
F T T
• This operation is
called exclusive or,
T F T
because it excludes the T T F Note
difference
from OR.
possibility that both p and q are true.
• “¬” and “” together are not universal.
2021-01-17 Asst Prof. Ronald F. Judan 27
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

Natural Language is Ambiguous


Note that English “or” can be ambiguous
regarding the “both” case! p q p "or" q
“Pat is a singer or F F F
Pat is a writer.” -  F T T
“Pat is a man or T F T
Pat is a woman.” -  T T ?
Need context to disambiguate the meaning!
For this class, assume “or” means inclusive.
2021-01-17 Asst Prof. Ronald F. Judan 28
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

The Implication Operator


antecedent consequent
The implication p  q states that p implies q.
I.e., If p is true, then q is true; but if p is not
true, then q could be either true or false.
E.g., 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.” (else, it could go either way)

2021-01-17 Asst Prof. Ronald F. Judan 29


Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

Implication Truth Table


• p  q is false only when p q pq
p is true but q is not true.
F F T
• p  q does not say F T T The
that p causes q! T F F only
• p  q does not require T T T
False
case!
that p or q are ever true!
• E.g. “(1=0)  pigs can fly” is TRUE!

2021-01-17 Asst Prof. Ronald F. Judan 30


Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

Examples of Implications
• “If this lecture ends, then the sun will rise
tomorrow.” True or False?
• “If Tuesday is a day of the week, then I am
a penguin.” True or False?
• “If 1+1=6, then Bush is president.”
True or False?
• “If the moon is made of green cheese, then I
am richer than Bill Gates.” True or False?
2021-01-17 Asst Prof. Ronald F. Judan 31
Module #1 - Logic

Why does this seem wrong?


• Consider a sentence like,
– “If I wear a red shirt tomorrow, then the U.S. will
attack Iraq the same day.”
• In logic, we consider the sentence True so long as
either I don’t wear a red shirt, or the US attacks.
• But in normal English conversation, if I were to
make this claim, you would think I was lying.
– Why this discrepancy between logic & language?

2021-01-17 Asst Prof. Ronald F. Judan 32


Module #1 - Logic

Resolving the Discrepancy


• In English, a sentence “if p then q” usually really
implicitly means something like,
– “In all possible situations, if p then q.”
• That is, “For p to be true and q false is impossible.”
• Or, “I guarantee that no matter what, if p, then q.”
• This can be expressed in predicate logic as:
– “For all situations s, if p is true in situation s, then q is also
true in situation s”
– Formally, we could write: s, P(s) → Q(s)
• This sentence is logically False in our example,
because for me to wear a red shirt and the U.S. not to
attack Iraq is a possible (even if not actual) situation.
– Natural language and logic then agree with each other.
2021-01-17 Dr.Eng. Mohammed Alhanjouri 33
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

English Phrases Meaning p  q


• “p implies q” • “p only if q”
• “if p, then q” • “p is sufficient for q”
• “if p, q” • “q is necessary for p”
• “when p, q” • “q follows from p”
• “whenever p, q” • “q is implied by p”
• “q if p” We will see some equivalent
logic expressions later.
• “q when p”
• “q whenever p”

2021-01-17 Asst Prof. Ronald F. Judan 34


Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

Converse, Inverse, Contrapositive

Some terminology, for an implication p  q:


• Its converse is: q  p.
• Its inverse is: ¬p  ¬q.
• Its contrapositive: ¬q  ¬ p.
• One of these three has the same meaning
(same truth table) as p  q. Can you figure
out which?

2021-01-17 Asst Prof. Ronald F. Judan 35


Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

How do we know for sure?


Proving the equivalence of p  q and its
contrapositive using truth tables:
p q q p pq q p
F F T T T T
F T F T T T
T F T F F F
T T F F T T

2021-01-17 Asst Prof. Ronald F. Judan 36


Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

The biconditional operator


The biconditional p  q states that p is true if and
only if (IFF) q is true.
p = “Duterte wins the 2016 election.”
q = “Duterte will be president for all of 2017.”
p  q = “If, and only if, Duterte wins the 2016
election, Duterte will be president for all of 2017.”
Are there
similarities?

Asst Prof. Ronald F. Judan


2021-01-17 2016 2017 37
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

Biconditional Truth Table


• p  q means that p and q p q pq
have the same truth value.
F F T
• Note this truth table is the
exact opposite of ’s! F T F
– p  q means ¬(p  q) T F F
• p  q does not imply T T T
p and q are true, or cause each other.

2021-01-17 Asst Prof. Ronald F. Judan 38


Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

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
2021-01-17 Asst Prof. Ronald F. Judan 39
Module #1 - Logic Topic #1.0 – Propositional Logic: Operators

Some Alternative Notations

Name: not and or xor implies iff


Propositional logic:      
Boolean algebra: p pq + 
C/C++/Java (wordwise): ! && || != ==
C/C++/Java (bitwise): ~ & | ^
Logic gates:

2021-01-17 Asst Prof. Ronald F. Judan 40


Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences

Logical Equivalence
Compound proposition p is logically
equivalent to compound proposition q,
written pq, IFF the compound
proposition pq is a tautology.
Compound propositions p and q are logically
equivalent to each other IFF p and q
contain the same truth values as each other
in all rows of their truth tables.
2021-01-17 Asst Prof. Ronald F. Judan 41
Module #1 - Logic Topic #1.1 – Propositional Logic: Equivalences

Proving Equivalence
via Truth Tables
Ex. Prove that pq  (p  q).

p q pq p q p  q (p  q)


F F F T T T F
F T T T F F T
T F T F T F T
T T T F F F T

2021-01-17 Asst Prof. Ronald F. Judan 42


Module #1 - Logic

Translate the following into Logical Expressions

1. You can access the internet from the campus only if you are an info tech
student or you are not a freshman.
2. You cannot access the internet if you are a sophomore unless you are an info
tech student.
3. Suppose we have the following statements for P and Q.
P: It rains ;Q: They can cancel school Write the ff forms:
a) implication
b) converse
c) Inverse
d) Contapositive

2021-01-17 Asst Prof. Ronald F. Judan 43


Module #1 - Logic

Exercises
1. Write the truth table for (PVQ)→R.
2. Show that ⌐(P V Q) is equivalent to ⌐PɅ⌐Q.
3. Construct a truth table: (⌐ P Ʌ Q) V (PɅ⌐Q)
4. Show that ⌐(P Ʌ Q) is equivalent to ⌐PV⌐Q.
5. Show that PɅ(QɅR) is equivalent to (PɅQ) ɅR.
6. Show that P→(Q→R) is equivalent to (PɅQ)→R.
7. Show that P→Q is not equivalent to the converse Q→P.
Assignment 1 whole: Nos. 4,5,6 only

2021-01-17 Asst Prof. Ronald F. Judan 44


Module #1 - Logic

Course Textbook(s)
1- Kenneth H. Rosen, "Discrete Mathematics and its
Applications", McGraw-Hill, Fifth Edition,2003.

Other Recommended Resources:


1- William Barnier, Jean B. Chan, "Discrete
Mathematics: With Applications", West Publishing Co.,
1989.
2- Mike Piff, "Discrete Mathematics, An Introduction
for Software Engineers", Cambridge University
Press,1992.
3- Todd Feil, Joan Krone, "Essential Discrete
Mathematics", Prentice Hall, 2003.
2021-01-17 Asst Prof. Ronald F. Judan 45

You might also like