Course : MATH6025 – Discrete Mathematics
Effective Period : September 2020
Logic
Session 1-3
Acknowledgement
These slides have been adapted from :
Kenneth H. Rosen, “ Discrete
Mathematics and its
Applications”, 8th edition,2019,
McGraw-Hill Education, New York,
ISBN 978-1-259-67651-2
Chapter 1&12
2
Learning Objectives
On successful completion of this Course, students will be
able to:
LO1:
LO1:
Evaluate the logic of compound,
Evaluate the logic of compound,
quantified statements and method
quantified statements and method
of proof related to discrete
of proof related to discrete
problems
problems
Sub Topics
• Propositional Logic
1
• Propositional Equivalences
2
• Rules of Inference
3
• Applications of Propositional Logic
4
• Boolean Expressions and Boolean Functions
5
• Logic Gates and Karnaugh Map
6
4
Propositional Logic
Propositions
A proposition is a declarative sentence (that is, a sentence that
declares a fact) that is either true or false, but not both.
Example :
1. Washington, D.C., is the capital of the
United States of America. (T)
2. Toronto is the capital of Canada. (F)
3. 1 + 1 = 2. (T)
4. 2 + 2 = 3. (F)
Propositions
Consider the following sentences :
1. What time is it?
(not propositions , not declarative sentences)
2. Read this carefully.
(not propositions, not declarative sentences)
3. x + 1 = 2.
(not propositions - neither true nor false)
4. x + y = z.
(not propositions - neither true nor false)
Logical Operators
Negation
Example : Find the negation of the proposition
“Michael’s PC runs Linux”
Solution : The negation is :
“Michael’s PC does not run Linux.”
Logical Operators
Conjunction
Definition 2:
Let p and q be propositions. The conjunction of p
and q, denoted by p ∧ q, is the proposition “p and
q.” The conjunction p ∧ q is true when both p and
q are true and is false otherwise.
Example : Find the conjunction of the propositions p and q where
p : “Rebecca’s PC has more than 16 GB free hard disk space”
q : “The processor in Rebecca’s PC runs faster than 1 GHz.”
Solution : The conjunction is :
“Rebecca’s PC has more than 16 GB free hard disk space,
and its processor runs faster than 1 GHz.”
Logical Operators
Disjunction
Definition 3:
Let p and q be propositions. The disjunction of p
and q, denoted by p ∨ q, is the proposition “p or
q.” The disjunction p ∨ q is false when both p and
q are false and is true otherwise.
Example : What is the disjunction of the propositions p and q,
p : “Rebecca’s PC has more than 16 GB free hard disk space”
q : “The processor in Rebecca’s PC runs faster than 1 GHz.”
Solution : The disjunction is :
“Rebecca’s PC has at least 16 GB free hard disk space, or
the processor in Rebecca’s PC runs faster than 1 GHz.”
Logical Operators
Exclusive Or
Definition 4:
Let p and q be propositions. The exclusive or of p
and q, denoted by p ⊕ q (or pXOR q), is
the proposition that is true when exactly one of p
and q is true and is false otherwise.
Example : Let
p : “A student can have a salad with dinner” and
q : “A student can have soup with dinner,”
What is p ⊕ q, the exclusive or of p and q?
Solution :
“A student can have soup or a salad with dinner,” (but not both)
Conditional Statements
Conditional Statements
Definition 5:
Let p and q be propositions. The conditional statement p → q is the
proposition “if p, then q.” The conditional statement p → q is false when p
is true and q is false, and true otherwise. In the conditional statement p →
q, p is called the hypothesis (or antecedent or premise) and q is called the
conclusion (or consequence).
Conditional Statement Ways
to express this conditional
statement:
“if p, then q”
“if p, q”
“p is sufficient for q”
“q if p”
“q when p”
“a necessary condition for p is q”
“q unless p”
Conditional Statements
Example : Let
p : “Maria learns discrete mathematics” and
q : “Maria will find a good job.”
Then
p → q : “If Maria learns discrete mathematics, then she will find a good
job.”
Other ways to express this conditional statement :
“Maria will find a good job when she learns discrete mathematics.” (q
when p)
“For Maria to get a good job, it is sufficient for her to learn discrete
mathematics.” ( p is sufficient for q )
“Maria will find a good job unless she does not learn discrete
mathematics.”
Conditional Statements
There are three related conditional statements of p → q :
1. Converse : q → p
2. Contrapositive : q → p
3. Inverse : p → q
Example :
Find the contrapositive, the converse, and the inverse of the conditional
statement
“The home team wins whenever it is raining.”
Solution :
p → q : “If it is raining, then the home team wins.”
1. Contrapositive : “If the home team does not win, then it is not raining.”
2. Converse : “If the home team wins, then it is raining.”
3. Inverse : “If it is not raining, then the home team does not win.”
Biconditional Statements
Definition 6 :
Let p and q be propositions. The biconditional statement p ↔ q is the
proposition “p if and only if q.” The biconditional statement p ↔ q is
true when p and q have the same truth values, and is false otherwise.
Biconditional statements are also called bi-implications.
Biconditional Statement Ways to express this Biconditional
statement:
“p is necessary and sufficient for q”
“if p then q, and conversely”
“p if q.”
“p exactly when q.”
Biconditional Statements
Definition 6 :
Let p and q be propositions. The biconditional statement p ↔ q is the
proposition “p if and only if q.” The biconditional statement p ↔ q is
true when p and q have the same truth values, and is false otherwise.
Biconditional statements are also called bi-implications.
Biconditional Statement Ways to express this Biconditional
statement:
“p is necessary and sufficient for q”
“if p then q, and conversely”
“p if q.”
“p exactly when q.”
Biconditional Statements
Example : Let
p : “You can take the flight,” and
q : “You buy a ticket.”
Then
p ↔ q: “You can take the flight if and only if you buy a ticket.”
This statement is true if :
p and q are either both true or both false, that is, if you buy a ticket and
can take the flight or if you do not buy a ticket and you cannot take the
flight.
It is false when :
you do not buy a ticket, but you can take the flight (such as when you get a
free trip) and when you buy a ticket but you cannot take the flight (such as
when the airline bumps you).
Precedence of Logical Operators
The precedence levels of the logical operators :
Example :
p ∨ q ∧ r means p ∨ (q ∧ r)
p ∧ q ∨ r means (p ∧ q) ∨ r
p → q ∨ r means p → (q ∨ r)
p ∨ q → r means (p ∨ q) → r
Logic and Bit Operations
Computers represent information using bits.
A bit is a symbol with two possible values, namely,0 (zero) and 1 (one).
The word bit comes from binary digit, because zeros and ones are the
digits used in binary representations of numbers.
A bit can be used to represent a truth value, because there are two
truth values, namely, true and false. As is customarily done, we will use
a 1 bit
to represent true and a 0 bit to represent false.
A variable is called a Boolean variable if its value is either true or false.
Logic and Bit Operations
Definition 7 :
A bit string is a sequence of zero or more bits. The length of this string is the
number of bits in the string.
Example : 101010011 is a bit string of length nine.
The bitwise OR, bitwise AND, and bitwise XOR of two strings of the
same length to be the strings that have as their bits the OR, AND, and
XOR of the corresponding bits in the two strings, respectively.
The symbols ∨, ∧, and ⊕ to represent the bitwise OR, bitwise AND, and
bitwise XOR operations
Logic and Bit Operations
Example :
Find the bitwise OR, bitwise AND, and bitwise XOR of the bit strings
01 1011 0110 and 11 0001 1101.
Solution:
01 1011 0110
11 0001 1101
11 1011 1111 bitwise OR
01 0001 0100 bitwise AND
10 1010 1011 bitwise XOR
Propositional Equivalences
Compound proposition
Compound proposition : an expression formed from propositional
variables using logical operators
Definisi 1.
A compound proposition that is always true, no matter what the truth
values of the propositional variables that occur in it, is called a tautology.
A compound proposition that is always false is called a contradiction. A
compound proposition that is neither a tautology nor a contradiction is
called a contingency.
Example Tautology Contradiction
:
Logical Equivalences
Logically equivalent. : Compound propositions that have the same truth
values in all possible cases.
Definisi 2.
The compound propositions p and q are called logically equivalent if p ↔ q
is a tautology. The notation p ≡ q (p ⇔ q) denotes that p and q are logically
equivalent.
Example : (p ∨ q) and p ∧ q are logically equivalent.
Logical Equivalences
Logical Equivalences Identities
Constructing New Logical
Equivalences
Example : Show that (p ∨ (p ∧ q)) and p ∧ q are logically equivalent by
developing a series of logical equivalences.
Solution :
(p ∨ (p ∧ q) )≡ p ∧ (p ∧ q) by the second De Morgan law
≡ p ∧ [(p) ∨ q] by the first De Morgan law
≡ p ∧ (p ∨ q) by the double negation law
≡ (p ∧ p) ∨ (p ∧ q) by the second distributive law
≡ F ∨ (p ∧ q) because p ∧ p ≡ F
≡ (p ∧ q) ∨ F by the commutative law for disjunction
≡p∧q by the identity law for F
Consequently (p ∨ (p ∧ q)) and p ∧ q are logically equivalent.
Rules of Inference
Rules of Inference
Proofs in mathematics are valid arguments that establish the truth of
mathematical statements.
By an argument, we mean a sequence of statements that end with a
conclusion. By valid, we mean that the conclusion, or final statement
of the argument, must follow from the truth of the preceding
statements, or premises, of the argument.
An argument is valid if and only if it is impossible for all the premises
to be true and the conclusion to be false.
Fallacies : some common forms of incorrect reasoning which lead to
invalid arguments.
Valid Arguments in
Propositional Logic
Determine whether this is a valid argument !
“If you have a current password, then you can log onto the network.”
“You have a current password.”
Therefore,
“You can log onto the network.”
Solution :
Let p : “You have a current password” and
q : “You can log onto the network.”
Then, the argument has the form
p → q Because the statement
((p→q) ∧ p) → q is a
p
tautology so this argument
∴ q is valid.
where ∴ is the symbol that denotes “therefore.”
Valid Arguments in
Propositional Logic
Definition :
An argument in propositional logic is a sequence of propositions. All but
the final proposition in the argument are called premises and the final
proposition is called the conclusion. An argument is valid if the truth of all
its premises implies that the conclusion is true. An argument form in
propositional logic is a sequence of compound propositions involving
propositional variables. An argument form is valid if no matter which
particular propositions are substituted for the propositional variables in
its premises, the conclusion is true if the premises are all true.
Remark: From the definition of a valid argument form we see that the
argument form with premises p1, p2,…, pn and conclusion q is valid
exactly when (p1 ∧ p2 ∧⋯∧ pn) → q is a tautology.
Rules of Inference
Rules of Inference
Using Rules of Inference to
Build Arguments
Example :
Show that the premises :
“It is not sunny this afternoon and it is colder than yesterday,”
“We will go swimming only if it is sunny,”
“If we do not go swimming, then we will take a canoe trip,” and
“If we take a canoe trip, then we will be home by sunset”
lead to the conclusion :
“We will be home by sunset.”
Solution:
Let p : “It is sunny this afternoon,”
q : “It is colder than yesterday,”
r : “We will go swimming,”
s : “We will take a canoe trip,” and
t : “We will be home by sunset.”
∴ The conclusion is simply t.
Using Rules of Inference
to Build Arguments
Construct an argument :
Step Reason
1. p ∧ q Premise
2. p Simplification using (1)
3. r → p Premise
4. r Modus tollens using (2) and (3)
5. r → s Premise
6. s Modus ponens using (4) and (5)
7. s → t Premise
8. t Modus ponens using (6) and (7)
So, each of the four hypotheses is true, the conclusion is also
true
Resolution
• Many of computer programs make use of a rule of inference known as
resolution. This rule of inference is based on the tautology,
((p ∨ q) ∧ (p ∨ r)) → (q ∨ r).
The final disjunction in the resolution rule, q ∨ r, is called the resolvent.
When we let q = r in this tautology, we obtain (p ∨ q) ∧ (p ∨ q) → q.
Furthermore, when we let r = F, we obtain (p ∨ q) ∧ (p) → q (because q ∨
F ≡ q), which is the tautology on which the rule of disjunctive syllogism is
based.
Example :
Use resolution to show that the hypotheses :
“Jasmine is skiing or it is not snowing” and
“It is snowing or Bart is playing hockey”
imply that
“Jasmine is skiing or Bart is playing hockey.”
Resolution
•
Solution :
Let p : “It is snowing,”
q : “Jasmine is skiing,” and
r : “Bart is playing hockey.”
We can represent the hypotheses
“Jasmine is skiing or it is not snowing” (p ∨ q )
“It is snowing or Bart is playing hockey” (p ∨ r )
Using resolution, the proposition :
q ∨ r, (“Jasmine is skiing or Bart is playing hockey,”)
follows.
Fallacies
1. Fallacy of affirming the conclusion.
The proposition ((p → q) ∧ q) → p is not a tautology, because it is false
when p is false and q is true. However, there are many incorrect arguments
that treat this as a tautology.
Example :
Is the following argument valid?
If you do every problem in this book, then you will learn discrete
mathematics. You learned discrete mathematics.
Therefore, you did every problem in this book.
Solution : p→q
q
Let p : “You did every problem in this book.”
p ?
q : “You learned discrete mathematics.”
This is incorrect reasoning called the fallacy of affirming the
conclusion.
Fallacies
•2. Fallacy of denying the hypothesis
The proposition ((p → q) ∧ p) → q is not a tautology, because it is false
when p is false and q is true. Many incorrect arguments use this incorrectly
as a rule of inference.
Example :
Is it correct to assume that you did not learn discrete mathematics if you
did not do every problem in the book, assuming that if you do every
problem in this book, then you will learn discrete mathematics?
Solution : p→q
Let p : “You did every problem in this book.” p
q?
q : “You learned discrete mathematics.”
It is possible that you learned discrete mathematics even if you did not do
every problem in this book.
This is incorrect reasoning called the Fallacy of denying the hypothesis
Applications of Propositional Logic
Applications of Propositional
Logic
1. Translating English Sentences
Example :
How can this English sentence be translated into a logical
expression?
“You can access the Internet from campus only if you are a
computer science major or you are not a freshman.”
Solution :
let
a : “You can access the Internet from campus”
c : “You are a computer science major”
f : “You are a freshman”
this sentence can be represented as
a → (c ∨ f )
Applications of Propositional Logic
•2. System Specifications
Example:
Express the specification
“The automated reply cannot be sent when the file system is full”
using logical connectives.
Solution :
let p : “The automated reply can be sent” and
q : “The file system is full.”
p : “It is not the case that the automated reply canbe sent,”
Consequently, specification can be represented by the conditional
statement
q→p
Applications of Propositional Logic
3. Boolean Searches
Example:
Web Page Searching : using Boolean searching to find Web pages about
universities in New Mexico.
we can look for pages matching at search engines :
- NEW AND MEXICO AND UNIVERSITIES
- “NEW MEXICO” AND UNIVERSITIES.
Applications of Propositional
Logic
4. Logic Puzzles
Example :
As a reward for saving his daughter from pirates, the
King has given you the opportunity to win a treasure
hidden inside one of three trunks. The two trunks that
do not hold the treasure are empty. To win, you must
select the correct trunk :
- Trunks 1 and 2 are each inscribed with the message
“This trunk is empty,” and
- Trunk 3 is inscribed with the message “The treasure
is in Trunk 2.”
The Queen, who never lies, tells you that only one of
these inscriptions is true, while the other two are
wrong. Which trunk should you select to win?
Logic Puzzles
Solution :
Let pi be the proposition that the treasure is in Trunk i, for i = 1, 2, 3. To
translate into propositional logic the Queen’s statement that exactly one
of the inscriptions is true, we observe that the inscriptions on Trunk 1,
Trunk 2, and Trunk 3, are ¬ p1, ¬ p2, and p2, respectively. So, her
statement can be translated to
( ¬ p1 ∧ ¬ ( ¬ p2) ∧ ¬ p2) ∨ ( ¬ ( ¬ p1) ∧ ¬ p2 ∧ ¬ p2) ∨ ( ¬ ( ¬ p1) ∧ ¬
( ¬ p2) ∧ p2)).
≡ (p1 ∧ ¬ p2) ∨ (p1 ∧ p2).
≡ p1 ∧ ( ¬ p2 ∨ p2).
≡ p1 ∧ T
≡ p1
So the treasure is in Trunk 1 (that is, p1 is true), and p2 and p3 are false;
and the inscription on Trunk 2 is the only true one.
Applications of Propositional Logic
5. Logic Circuits
A logic circuit (or digital circuit) receives input signals p1, p2,…, pn,
each a bit [either 0 (off) or 1 (on)], and produces output signals s1, s2,
…, sn, each a bit.
Complicated digital circuits can be constructed from three basic
circuits, called gates, that is NOT gate, OR gate, and AND gate.
Logic Circuits
Combinations of these three basic gates called A combinatorial circuit.
Example 1 : (p ∧ ¬ q) ∨ ¬ r
A combinatorial circuit.
Example 2 :
(p∨ ¬ r) ∧ ( ¬ p ∨ (q∨ ¬ r))
Boolean Algebra
Boolean expressions
•Example
The values of the Boolean function represented by F(x, y, z) = xy +
Identities of Boolean Algebra
Identities of Boolean Algebra
Example 1 :
Show that the distributive law x(y + z) = xy + xz is valid.
Solution :
The identity holds because the last two columns of the table agree.
Identities of Boolean Algebra
Example 2 :
Prove the absorption law x(x + y) = x using the other identities of Boolean
algebra
Solution:
x(x + y) = (x + 0)(x + y) Identity law for the Boolean sum
=x+0⋅y Distributive law of the Boolean sum over the
Boolean product
=x+y⋅0 Commutative law for the Boolean product
=x+0 Domination law for the Boolean product
=x Identity law for the Boolean sum.
Representing Boolean Functions
1. Sum-of-Products Expansions / disjunctive normal form
Example 1 :
Find Boolean expressions that represent the functions F(x, y, z) and G(x, y,
z), which are given in Table below
Solution :
F(x, y,z) = xz
G(x,
y, z) = xy + y
Representing Boolean Functions
1. Sum-of-Products Expansions / disjunctive normal form
Example 2 :
Find
the sum-of-products expansion for the function F(x, y, z) = (x + y)
Solution :
a. Using Boolean identities
F(x, y, z) = (x + y)
=x +y Distributive law
= x1 + 1y Identity law
= x(y + ) + (x + )y Unit property
= xy + x + xy + y Distributive law
= xy + x + y Idempotent law
Representing Boolean Functions
Solution :
b. By determining the values of F for all possible values of the variables x,
y, and z
This gives :
F(x, y, z) = xy + x + y
Representing Boolean Functions
Representing Boolean Functions
The basic elements of circuits are called gates
The circuits that give output that depends only on the input, and not
on the currentstate of the circuit. In other words, these circuits have
no memory capabilities. Such circuits are called combinational
circuits or gating networks.
Basic types of gates.
Combinations of Gates
Example
Construct circuits that produce the following outputs:
(a) (x + y)
(b) and
(c) (x +y + z)( ).
Solution :
Combinations of Gates
Examples of Circuits
Example 1 . Majority Voting
A committee of three individuals decides issues for an organization. Each
individual votes either yes or no for each proposal that arises. A proposal
is passed if it receives at least two yes votes. Design a circuit that
determines whether a proposal passes.
Solution :
Let
x = 1 if the first individual
votes yes,
y = 1 if the second individual
votes yes,
z = 1 if the third individual
votes yes,
Examples of Circuits
Example 2 . A light controlled by two switches
Sometimes light fixtures are controlled by more than one switch. Circuits
need to be designed so that flipping any one of the switches for the fixture
turns the light on when it is off and turns the light off when it is on. Design
circuits that accomplish this when there are two switches.
Solution :
Let F(x, y) = xy +
x = 1 when the first switch is closed
y = 1 when the second switch is closed
F(x, y) = 1 when the light is on
F(x, y) = 0 when the light is off
F(1, 1) = 1 (Decide that the light will be on when both
switches are closed)
F(1, 0) = F(0, 1) = 0 (When one of the two switches is
opened, the light goes off,
F(0, 0) = 1 (When the other switch is also opened, the light
goes on)
A Circuit light controlled
by two switches
Solution :
Adders
The circuit that has two output is called the half adder, namely, s and c,
where s is the sum bit and c is the carry bit .
Example
Output for the half adder :
Karnaugh Map
Karnaugh Map
A Karnaugh map or K-map, for finding terms to combine for
Boolean functions involving a relatively small number of variables
The method we will describe was introduced by Maurice Karnaugh
in 1953. His method is based on earlier work by E.W. Veitch.
K-maps give us a visual method for simplifying sum-of-products
expansions; they are not suited for mechanizing this process
A Karnaugh map has zero and one entries at different positions. Each
position in a grid corresponds to a truth table entry.
Given a Boolean function described by a truth table or logic function,
then:
• Draw the Karnaugh Map for the function.
• Use the information from a Karnaugh Map to determine the smallest
sum-of-products function.
67
Karnaugh Map in
Two Variables
There are four possible minterms in the sum-of-products expansion of
a Boolean function in the two variables x and y.
A K-map for a Boolean function in these two variables consists of four
cells, where a 1 is placed in the cell representing a minterm if this
minterm is present in the expansion. Cells are said to be adjacent if
the minterms that they represent differ in exactly one literal.
For instance, the cell representing is adjacent to the cells
representing
and
68
Karnaugh Map in
Two Variables
Example :
Find the K-maps for Boolean expression E that equal to :
Solution :
E=y E= E=
69
Karnaugh Map in three variables
Let (x,y,z) be a sum of product Boolean expression such that minterm
consists of three variables x,y,z. To define the K-map for (x,y,z) , we
consider the following table
70
Blocks in K-maps in three variables.
Karnaugh Map in three variables
Example :
Use K-maps to minimize these sum-of-products expansions
Karnaugh Map in three variables
Solution :
A K-map in four variables
Let (x,y,z,w) be a sum
of product Boolean
expression such that
minterm consists of
three variables x,y,z,w.
To define the K-map
for (x,y,z,w), we
consider the following
table
74
Blocks in K-maps in four variables
A K-map in four variables
Example :
Use K-maps to simplify these sum-of-products expansions.
A K-map in four variables
Solution :
Reference
Kenneth H. Rosen, “ Discrete Mathematics and
its Applications”, 8th edition,2019, McGraw-Hill
Education, New York, ISBN 978-1-259-67651-2
Thank You