Logic
Logic
1/50
Outline
1 Introduction
2 Logic
2/50
Introduction
Logic
3/50
Prepared by Dr Vishal Pradhan KIIT Bhubaneswar
Contd...
4/50
Course contents
I Logic (Chapter 1)
I Sets, Relations and Functions (Chapter 2)
I Recurrence relations and their solutions (Chapter 5)
I Algebraic structures (Other book)
1
1
Text book: Kenneth H. Rosen, Discrete Mathematics and its
Applications, 7th Edition, McGraw Hill Education, 2011
Introduction
Logic
Introduction to Logic
6/50
Prepared by Dr Vishal Pradhan KIIT Bhubaneswar
Contd...
7/50
Proposition
Definition
A proposition is a declarative sentence that is either true or false, but
not both.
Example (Example 1)
All the following declarative sentences are propositions.
1 Washington, D.C., is the capital of the United States of America.
2 Toronto is the capital of Canada.
3 1 + 1 = 2.
4 2 + 2 = 3.
Propositions 1 and 3 are true, whereas 2 and 4 are false.
Proposition contd...
Example (Example 2)
Consider the following sentences.
1 What time is it?
2 Read this carefully.
3 x + 1 = 2.
4 x + y = z.
Sentences 1 and 2 are not propositions because they are not
declarative sentences. Sentences 3 and 4 are not propositions because
they are neither true nor false.
Note that each of sentences 3 and 4 can be turned into a proposition
if we assign some values to the variables x, y and z.
9/50
Proposition contd...
10/50
Proposition contd...
11/50
Negation
Definition (Negation)
Let p be a proposition. The negation of p, denoted by ∼ p, is the
statement It is not the case that p.
p ∼p
T F
F T
12/50
Negation contd...
Example (Negation)
Find the negation of the proposition p : Michaels PC runs Linux.
Example (Negation)
Find the negation of the proposition q : Jennifer and Teja are friends..
I The negation is “∼ q : It is not the case that Jennifer and Teja are
friends.
I This negation can be more simply expressed as “∼ q : Jennifer and
Teja are not friends.
Negation contd...
Example (Negation)
Find the negation of the proposition Vandanas smartphone has at
least 32GB of memory and express this in simple English.
I The negation is “It is not the case that Vandanas smartphone has
at least 32GB of memory.
I This negation can also be expressed as “Vandanas smartphone does
not have at least 32GB of memory.
I or even more simply as “Vandanas smartphone has less than 32GB
of memory.
14/50
Connectives
Connectives:
We will now introduce the logical operators that are used to form new
propositions from two or more existing propositions. These logical
operators are also called connectives.
Conjunction:
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.
p q p∧q
T T T
T F F
F T F
F F F
15/50
Connectives contd...
Example
Find the conjunction of the propositions p and q where p is the
proposition Rebeccas PC has more than 16 GB free hard disk space
and q is the proposition The processor in Rebeccas PC runs faster
than 1 GHz.
Disjunction:
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.
p q p∨q
T T T
T F T
F T T
F F F
17/50
Connectives contd...
Example
Translate the statement Students who have taken calculus or
introductory computer science can take this class in a statement in
propositional logic using the propositions p: A student who has taken
calculus can take this class and q: A student who has taken
introductory computer science can take this class.
18/50
Connectives contd...
Exclusive or:
Let p and q be propositions. The exclusive or of p and q, denoted by
p ⊕ q, is the proposition that is true when exactly one of p and q is
true and is false otherwise.
p q p⊕q
T T F
T F T
F T T
F F F
20/50
Connectives contd...
Example
Express the statement I will use all my savings to travel to Europe or
to buy an electric car in propositional logic using the statement p: I
will use all my savings to travel to Europe and the statement q: I will
use all my savings to buy an electric car.
21/50
Conditional Statement
Definition
Let p and q be propositions. The conditional statement p → q is the
proposition if p then q.
Truth table:
p q p→q
T T T
T F F
F T T
F F T
22/50
Conditional statement contd...
I Given that “p: Maria learns discrete mathematics” and “q: Maria
will find a good job”.
From the definition of conditional statements, we see that p → q
represents the statement “If Maria learns discrete mathematics then
she will find a good job.”
I There are many other ways to express this conditional statement
in English. Among the most natural of these are:
•“Maria will find a good job when she learns discrete mathematics.
•“For Maria to get a good job, it is sufficient for her to learn discrete
mathematics.
•“Maria will find a good job unless she does not learn discrete
mathematics.
Conditional statement contd...
25/50
Converse, Inverse and Contrapositive
Example
What are the contrapositive, the converse, and the inverse of the
conditional statement “The home team wins whenever it is raining”.
I Contrapositive statement is “If the home team does not win, then
it is not raining.”
I Converse statement is “If the home team wins, then it is raining.”
I Inverse statement is “If it is not raining, then the home team does
not win.”
Note: We will see that of these three conditional statements formed
from p → q, only the contrapositive always has the same truth value
as p → q.
27/50
Converse, Inverse and Contrapositive contd...
Truth Table:
p q p→q q→p ∼p ∼q ∼ p →∼ q ∼ q →∼ p
T T T T F F T T
T F F T F T T F
F T T F T F F T
F F T T T T T T
28/50
Biconditional statement
Truth table:
p q p↔q
T T T
T F F
F T F
F F T
Biconditional statement contd...
Example
Let p be the statement “You can take the flight,” and let q be the
statement “You buy a ticket.” Then biconditional statement p ↔ q is
the statement “You can take the flight if and only if you buy a ticket.”
Operators Precedence
∼ 1
∧ 2
∨, ⊕ 3
→ 4
↔ 5
Example
∼p∧q ⇒ (∼ p) ∧ q
p∧q∨r ⇒ (p ∧ q) ∨ r
p→q∨r ⇒ p → (q ∨ r)
∼p⊕q →r∧s ⇒ ((∼ p) ⊕ q) → (r ∧ s)
Applications of Propositional Logic
32/50
Applications contd...
33/50
Applications contd...
System Specifications:
Translating sentences in natural language into logical expressions is
an essential part of specifying both hardware and software systems.
Example
Determine whether these system specifications are consistent:
“The diagnostic message is stored in the buffer or it is retransmitted.”
“The diagnostic message is not stored in the buffer.”
“If the diagnostic message is stored in the buffer, then it is
retransmitted.”
Example
Alternative: To determine whether the above mentioned
specifications are consistent or not, we first express them using logical
expressions. Let p : The diagnostic message is stored in the buffer and
let q : The diagnostic message is retransmitted. The specifications can
then be written as p ∨ q, ∼ p, and p → q. We have to find an
assignment of truth values that makes all three specifications true. It
can be viewed by constructing the truth table.
p q ∼p p∨q p→q
T T F T T
T F F T F
F T T T T
F F T F T
It is seen that all the specifications are true when p is false and q is
true. So, the system specifications are consistent.
Applications contd...
Example
In continuation with the previous example, if another specification
“The diagnostic message is not retransmitted” is added, then check
the consistency.
37/50
Applications contd...
Boolean Searches:
Logical connectives are used extensively in searches of large
collections of information, such as indexes of Web pages. Because
these searches employ techniques from propositional logic, they are
called Boolean searches. In Boolean searches, the connective AND is
used to match records that contain both of two search terms, the
connective OR is used to match one or both of two search terms, and
the connective NOT (sometimes written as AND NOT) is used to
exclude a particular search term. Careful planning of how logical
connectives are used is often required when Boolean searches are used
to locate information of potential interest.
38/50
Applications contd...
Logic Circuits:
Propositional logic can be applied to the design of computer
hardware. 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. In this section we will restrict our
attention to logic circuits with a single output signal; in general,
digital circuits may have multiple outputs. Complicated digital
circuits can be constructed from three basic circuits, called gates, as
shown in the below figure.
39/50
Applications contd...
40/50
Applications contd...
Logic Puzzles:
Puzzles that can be solved using logical reasoning are known as logic
puzzles. Solving logic puzzles is an excellent way to practice working
with the rules of logic. Also, computer programs designed to carry
out logical reasoning often use well-known logic puzzles to illustrate
their capabilities. Many people enjoy solving logic puzzles, published
in periodicals, books, and on the Web, as a recreational activity.
Example
A father tells his two children, a boy and a girl, to play in their
backyard without getting dirty. However, while playing, both children
get mud on their foreheads. When the children stop playing, the
father says “At least one of you has a muddy forehead,” and then
asks the children to answer “Yes” or “No” to the question: “Do you
know whether you have a muddy forehead?” The father asks this
question twice. What will the children answer each time this question
is asked, assuming that a child can see whether his or her sibling has
a muddy forehead, but cannot see his or her own forehead? Assume
that both children are honest and that the children answer each
question simultaneously.
41/50
Applications contd...
Example (Answer)
Let p be the statement that the son has a muddy forehead and let q
be the statement that the daughter has a muddy forehead. When the
father says that at least one of the two children has a muddy
forehead, he is stating that the disjunction p ∨ q is true. Both children
will answer “No” the first time the question is asked because each sees
mud on the other child’s forehead. That is, the son knows that q is
true, but does not know whether p is true, and the daughter knows
that p is true, but does not know whether q is true.
After the son has answered “No” to the first question, the daughter
can determine that q must be true. This follows because when the
first question is asked, the son knows that p ∨ q is true, but cannot
determine whether p is true. Using this information, the daughter can
conclude that q must be true, for if q were false, the son could have
reasoned that because p ∨ q is true, then p must be true, and he would
have answered “Yes” to the first question. The son can reason in a
similar way to determine that p must be true. It follows that both
children answer “Yes” the second time the question is asked.
Tautology, contradiction and contingency
Definition
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
We can construct examples of tautologies and contradictions using
just one propositional variable. Consider the truth tables of p∨ ∼ p
and p∧ ∼ p.
p ∼p p∨ ∼ p p∧ ∼ p
T F T F
F T T F
When two compound propositions always have the same truth values,
regardless of the truth values of its propositional variables, we call
them equivalent.
Definition
The compound propositions p and q are called logically equivalent if
p ↔ q is a tautology.
44/50
Logical equivalences contd...
Example
Show that p → q ≡∼ p ∨ q.
p q ∼p p→q ∼p∨q
T T F T T
T F F F F
F T T T T
F F T T T
Here we see that the columns for p → q and ∼ p ∨ q are identical, i.e.,
they agree for all possible combinations of the truth values of p and q.
Hence two given compound propositions are logically equivalent.
Logical equivalences contd...
De Morgan’s Law
For any two propositions p and q,
∼ (p ∧ q) ≡ (∼ p∨ ∼ q) and ∼ (p ∨ q) ≡ (∼ p∧ ∼ q)
47/50
Logical equivalences contd...
48/50
Well-Formed Formulae (WFF)
Example
The proposition (p ∧ q) ∨ r is a wff whereas p ∧ q ∨ r is not wff.
p ∼ ∧q and pq∨ are not wff.
49/50
Functionally complete set of connectives
Definition
A set of connectives is called functionally complete if every compound
proposition can be expressed as a logically equivalent proposition
involving only these connectives.
Example
The set {∼, ∧}, {∼, ∨}, {∼, ∧, ∨} are functionally complete.
Propositional Satisfiability
Definition
A compound proposition is satisfiable if there is an assignment of
truth values to its variables that makes it true (i.e., when it is a
tautology or a contingency).
When no such assignments exists, i.e., when the compound
proposition is false for all assignments of truth values to its variables,
the compound proposition is unsatisfiable.
Example
Determine whether each of the following compound proposition is
satisfiable.
1 (p∨ ∼ q) ∧ (q∨ ∼ r) ∧ (r∨ ∼ p)
2 (p ∨ q ∨ r) ∧ (∼ p∨ ∼ q∨ ∼ r)
r: Tushar is studious.
Definition
A predicate is a statement that contains variables and they may be
true or false depending on the values of these variables.
Definition
The domain of a predicate is the collection of all possible values that
the variable may take.
Predicates contd...
Example
Consider the predicate P (x) : “x2 > 10”, where the domain is Z. Find
the truth value of P (2) and P (−5).
Here the proposition P (2) : “4 > 10” is false and the proposition
P (−5) : “25 > 10” is true.
56/50
Quantifiers
The area of logic that deals with predicates and quantifiers is called
the predicate calculus.
Universal Quantifiers
Example
Let P (x) be the statement “x + 1 > x.” What is the truth value of the
quantification ∀x P (x), where the domain consists of all real numbers?
Example
Let Q(x) be the statement “x < 2.” What is the truth value of the
quantification ∀x Q(x), where the domain consists of all real numbers?
Q(x) is not true for every real number x, because, for instance, Q(3)
is false. That is, x = 3 is a counter-example for the statement
∀x Q(x). Thus ∀x Q(x) is false.
59/50
Universal Quantifiers contd...
Besides “for all” universal quantification can be expressed in many
other ways, including “for every,” “all of,” “for each,” “given any,”
“for arbitrary,” “for each” etc.
Example
What is the truth value of ∀x P (x), where P (x) is the statement
“x2 < 10” and the domain consists of the positive integers not
exceeding 4?
Example
What is the truth value of ∃x P (x), where P (x) is the statement
“x2 > 10” and the universe of discourse consists of the positive
integers not exceeding 4?
Because the domain is {1, 2, 3, 4}, the proposition ∃x P (x) is the same
as the disjunction P (1) ∨ P (2) ∨ P (3) ∨ P (4). Because P (4), which is
the statement “42 > 10,” is true, it follows that ∃x P (x) is true.
62/50
Quantifiers with Restricted Domains
The statement ∀x < 0 (x2 > 0) states that for every real number x
with x < 0, x2 > 0. That is, it states “The square of a negative real
number is positive.” This statement is the same as
∀x (x < 0 → x2 > 0).
Secondly, the statement ∃z > 0 (z 2 = 2) states that there exists a real
number z with z > 0 such that z 2 = 2. That is, it states “There is a
positive square root of 2.” This statement is equivalent to
∃z (z > 0 ∧ z 2 = 2).
63/50
Binding Variables
64/50
Logical Equivalences Involving Quantifiers
Definition
Statements involving predicates and quantifiers are logically equivalent
if and only if they have the same truth value no matter which
predicates are substituted into these statements and which domain of
discourse is used.
Example
Show that ∀x (P (x) ∧ Q(x)) ≡ ∀x P (x) ∧ ∀x Q(x) (where the same
domain is used throughout).
66/50
Negation of Quantifiers
∼ ∃x P (x) ≡ ∀x ∼ P (x).
The above two rules for negations for quantifiers are called De
Morgans laws for quantifiers.
Negation of Quantifiers contd...
Example
What are the negations of the statements “There is an honest
politician” and “All Americans eat cheeseburgers”?
Example
Express the statement “Every student in this class has studied
calculus” using predicates and quantifiers.
69/50
Some more examples contd...
Example
Express the statements “Some student in this class has visited
Mexico” using predicates and quantifiers.
70/50
Some more examples contd...
Example
Show that ∼ ∀x (P (x) → Q(x)) and ∃x (P (x)∧ ∼ Q(x)) are logically
equivalent.
72/50
Rules of inference contd...
Example
Consider the following argument involving propositions: “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.”
Here, the first two statements “If you have a current password, then
you can log onto the network” and “You have a current password” are
the premises of the argument and final statement “You have a current
password” is the conclusion of the argument.
74/50
Rules of Inference for Propositional Logic
75/50
Rules of Inference contd...
77/50
Rules of Inference contd...
Example (continued)
We construct an argument to show that our premises lead to the
desired conclusion as follows.
∼p∧q
∴∼ p (by Simplification rule)
r→p
∴∼ r (by Modus tollens rule)
∼r→s
∴ s (by Modus ponens rule)
s→t
∴ t (by Modus ponens rule)
Fallacies
79/50
Fallacies contd...
Example
Given an argument “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.” Check whether the
argument is valid?
Let p be the proposition “You did every problem in this book.” Let q
be the proposition “You learned discrete mathematics.” Then this
argument is of the form:
p→q
q
∴p
This is an example of an incorrect argument using the fallacy of
affirming the conclusion. Indeed, it is possible for you to learn
discrete mathematics in some way other than by doing every problem
in this book. (You may learn discrete mathematics by reading,
listening to lectures, doing some, but not all, the problems in this
book, and so on.)
80/50
Rules of Inference for Quantified Statements
We have discussed rules of inference for propositions. We will now
describe some important rules of inference for statements involving
quantifiers. These rules of inference are used extensively in
mathematical arguments, often without being explicitly mentioned.
81/50
Rules of Inference contd...
Example
Show that the premises “Everyone in this discrete mathematics class
has taken a course in computer science” and “Marla is a student in
this class” imply the conclusion “Marla has taken a course in
computer science.”
82/50
Rules of Inference contd...
Example
Show that the premises “A student in this class has not read the
book,” and “Everyone in this class passed the first exam” imply the
conclusion “Someone who passed the first exam has not read the
book.”
Let C(x) be “x is in this class,” B(x) be “x has read the book,” and
P (x) be “x passed the first exam.” The premises are
∃x (C(x)∧ ∼ B(x)) and ∀x (C(x) → P (x)). The conclusion is
∃x (P (x)∧ ∼ B(x)).
Rules of Inference contd...
Example (continued)
These steps can be used to establish the conclusion from the premises.
∃x (C(x)∧ ∼ B(x))
∴ C(a)∧ ∼ B(a) (by Existential instantiation)
∴ C(a) (by Simplification)
∀x (C(x) → P (x))
C(a) → P (a) (by Universal instantiation)
∴ P (a) (by Modus ponens)
∼ B(a)
∴ P (a)∧ ∼ B(a) (by Conjunction)
∴ ∃x (P (x)∧ ∼ B(x)) (by Existential generalization)
84/50
Rules of Inference contd...
85/50
Rules of Inference contd...
Example
Assume that “For all positive integers n, if n is greater than 4, then
n2 is less than 2n ” is true. Use universal modus ponens to show that
1002 < 2100 .
Let P (n) denote “n > 4” and Q(n) denote “n2 < 2n .” The statement
“For all positive integers n, if n is greater than 4, then n2 is less than
2n ” can be represented by ∀n (P (n) → Q(n)), where the domain
consists of all positive integers. We are assuming that
∀n (P (n) → Q(n)) is true. Note that P (100) is true because 100 > 4.
Then by universal modus ponens
∀n (P (n) → Q(n))
P (100)
∴ Q(100)
i.e. 1002 < 2100