Professional Documents
Culture Documents
Rosen, 7 th Edition
1.1 Logic
Logics consist of the following
A formal system for describing states of affairs, consisting of
1. the syntax of the language ,and
2. the semantics of the language
The Proof –Theory: a set of rules for deducing the entailments of a set
of sentences.
Logic is a formal language, with precisely defined syntax and semantics,
which supports reasoning.
Different logics exist, which allow you to represent different kinds of things,
and which allow more or less efficient inference.
Syntax: of a language describes the possible configurations that can
constitute a sentence.
Semantics: determines the facts in the world to which the sentence refer.
1.2 Proposition
A proposition is a declarative sentence (that is, a sentence that declares a fact)
that is either true or false, but not both.
Example of declarative sentences which are propositions.
1. Kathmandu is the capital of the Nepal. True proposition
2. Sun rises in west. False proposition
3. 5+ 1 = 6. True proposition
4. 7+ 2 = 8 False proposition
Example 2: Consider the following sentences.
1. What time is it?
2. Read this carefully.
3. z + 1 = 5.
4. a + b = c.
Sentences 1 and 2 are not propositions because they are not declarative
sentences. Sentences 3and 4 are not propositions because they are
neither true nor false. Note that each of sentences 3and 4 can be turned
into a proposition if we assign values to the variables.
Propositional Logic: letters are used to represent propositional variables (or
statement variables), that is, variables that represent propositions,
The letters used for propositional variables: p, q, r, s . . .
Negation
Let p be a proposition. The negation of p, denoted by “¬p”, is the statement
“It is not the case that p.”
The proposition ¬p is read “not p.”
The truth values of p, and ¬p, are opposite to each other.
Example1
Find the negation of the proposition “Ram’s laptop runs Windows”
Solution: The negation is “It is not the case that Ram’s laptop runs
Windows.”
In other way: “Ram’s laptop does not run Windows.”
The notable fact is that Ram’s laptop does not run Windows mean that
Ram’s laptop runs Linux or UNIX.
Example 2
Find the negation of the proposition “Sony’s Smartphone has at least
4GB of RAM”
Solution: The negation is: “It is not the case that Sony’s Smartphone
has at least 4GB of RAM.”
In other way “Sony’s Smartphone does not have at least 4GB of RAM”
More simply as “Sony’s Smartphone has less than 4GB of RAM.”
P ¬p
T F
F T
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.
Example: Find the conjunction of
Kathmandu is the capital city of Nepal and Ancient name of
Kathmandu is Patan.
Suppose p means “Kathmandu is the capital city of Nepal” and q mans
“Ancient name of Kathmandu is Patan”.
Then p ∧ q: Kathmandu is the capital city of Nepal and Ancient name
of Kathmandu is Patan.
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.
Example: Find the disjunction of the propositions p and q where p is the
proposition “Ram’s PC has more than 16 GB free hard disk space” and q is
the proposition “The processor in Ram’s PC runs faster than 1 GHz.”
Then p ∨ q: “Ram’s PC has more than 16 GB free hard disk space, or the
processor in Ram’s PC runs faster than 1 GHz.”
p q p∧q
F F F
F T F
T F F
T T T
p q p∨q
F F F
F T T
T F T
T T T
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.
Truth Table of Exclusive OR
p q p⊕q
F F F
F T T
T F T
T T F
Conditional Statement
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).
The statement p → q is called a conditional statement because p → q asserts
that q is true on the condition that p holds.
A conditional statement is also called an implication. Thus p → q can be read
as “p implies q”.
We can express all of the following ways to express this conditional
statement:
“if p, then q” “p implies q”
“if p, q” “p only if q”
“p is sufficient for q” “a sufficient condition for q is p”
“q if p” “q whenever p”
“q when p” “q is necessary for p”
p q p→q
F F T
F T T
T F F
T T T
Consider an Example: "If you get an A grade, then I'll give you a Bike. “The
statement will be true if I keep my promise and false if I don’t. Suppose it's
true that you get an A grade and it's true that I give you a Bike. Since I kept
my promise, the implication is true. This corresponds to the first line in the
table. Suppose it's true that you get an A but it's false that I give you a Bike.
Since I didn't keep my promise, the implication is false. This corresponds to
the second line in the table. What if it's false that you get an A? Whether or
not I give you a Bike, I haven't broken my promise. Thus, the implication
can't be false, so (since this is a two-valued logic) it must be true. This
explains the last two lines of the table.
Biconditional Statement
Example: Let p be the statement “You can take the flight,” and let q be the
statement “You buy a ticket.”
Then p ↔ q is the statement: “You can take the flight if and only if you buy a
ticket.”
The truth table for biconditional statement
p q p↔q
F F T
F T F
T F F
T T T
Operator Precedence
¬ 1
∧ 2
∨ 3
→ 4
↔. 5
A bit, abbreviated for binary digit, is a symbol with two possible values 0
(zero) and 1 (one). Zeros and ones are the digits used in binary
representations of numbers.
Information is often represented using bit strings. A bit string is a sequence of
zero or more bits. The length of this string is the number of bits in the string.
We define 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.
We use the symbols∨,∧, and ⊕ to represent the bitwise OR, bitwise AND,
and bitwise XOR operations, respectively.
The truth table of bitwise operator
Find the bitwise OR, bitwise AND, and bitwise XOR of the bit strings 01
1011 0110 and 11 0001 1101.
Solution:
First String 01 1011 0110
Second String 11 0001 1101
Bitwise OR 11 1011 1111
Bitwise AND 01 0001 0100
Bitwise XOR 10 1010 1011
1.6 Propositional logic
P
------- addition rule
P V Q
Example 2:Hari is a computer science major and a mathematics major.
Therefore, Hari is a mathematics major.
Solution: P: Hari is a mathematics major & Q: Ram is a computer
science major
PQ
------- simplification rule
P
Rule of Inference
P Q
Q
------- Modus Tollens
P
Example 4: Show that the hypotheses “Ram works hard,” “If Ram works
hard, and then he is a dull boy,” and “If Ram is a dull boy, and then he will
not get the job” imply the conclusion “Ram will not get the job.”
Solution:
P: Ram works hard,
Q: Ram is a dull boy
R: Ram will not get the job.
Premises: P Q, Q R and P
Conclusion: R
1. P
2. P Q
3. Q R
---------
4. Q from 1 and 2 by MP
5. R from 3 and 4 by MP
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)
Example 8: Show that the premises “If you send me an e-mail message, then
I will finish writing the program,” “If you do not send me an e-mail message,
then I will go to sleep early,” and “If I go to sleep early, then I will wake up
feeling refreshed” lead to the conclusion “If I do not finish writing the
program, then I will wake up feeling refreshed.”
Solution:
p: “You send me an e-mail message,”
q: “I will finish writing the program,”
r: “I will go to sleep early,” and
s: “I will wake up feeling refreshed.”
Premises: p → q, ¬p → r, and r → s.
Conclusion: ¬q → s.
Step Reason
1. p → q Premise
2. ¬q →¬p Contrapositive of (1)
3. ¬p → r Premise
4. ¬q → r Hypothetical syllogism using (2) and (3)
5. r → s Premise
6. ¬q → s Hypothetical syllogism using (4) and (5)
Example 9: Use rules of inference to show that the hypotheses “If it does not
rain or if it is not foggy, then the sailing race will be held and the lifesaving
demonstration will go on,” If the sailing race is held, then the trophy will be
awarded,” and “The trophy was not awarded” imply the conclusion “It
rained.”
Solution:
R: It is rain.
F: It is foggy.
S: The sailing race will be held.
L: Lifesaving demonstration will go on.
T: The trophy will be awarded.
Premises: (¬R V ¬ F)→ (S L) , S→T, ¬ T
Conclusion: R
Step Reason
1. ¬ T Premise
2. S→T Premise
3. ¬ S MT
4. (¬R V ¬ F) → (S L) Premise
5. ¬ (S L) → ¬ (¬R V ¬ F) Contrapositive
6. (¬S V ¬ L) → (R F) De Morgan’s law
7. (¬S V ¬ L) Addition law of 1 &3
8. (R F) MP using 6 & 7
9. R Simplification of 8.
1.8.1 Predicates
1.8.2 Quantifiers
Quantification expresses the extent to which a predicate is true over a range
of elements. In English, the words all, some, many, none, and few are used in
quantifications.
There are two types of quantification universal quantification, and
existential quantification.
The area of logic that deals with predicates and quantifiers is called the
predicate calculus.
Example1: What is the truth value of ∀x(x2 ≥ x) if the domain consists of all
real numbers? What is the truth value of this statement if the domain consists
of all integers?
Solution: The universal quantification ∀x(x2 ≥ x), where the domain
consists of all real numbers, is false. For example, (1/2)2 ≥ 1/2. Note
that x2 ≥ x if and only if x2 − x = x(x − 1) ≥ 0.
Consequently, x2 ≥ x if and only if x ≤ 0 or x ≥ 1. It follows that ∀x(x2
≥ x) is false if the domain consists of all real numbers (because the
inequality is false for all real numbers x with 0 < x < 1).
However, if the domain consists of the integers, ∀x(x2 ≥ x) is true,
because there are no integers x with 0 < x < 1.
“for at least one,” or “there is.” The existential quantification xP(x) is read
as
“There is an x such that P(x),”
“There is at least one x such that P(x),” or
“For some xP(x).”
The meanings of the quantifiers are summarized in below table.
Example 1: What are the negations of the statements ∀x(x2 > x) and ∃x(x2
= 2)?
Solution: The negation of ∀x(x2 > x) is the statement ¬∀x(x2 > x),
which is equivalent to ∃x¬(x2 > x). This can be rewritten as ∃x(x2 ≤
x).
The negation of ∃x(x2 = 2) is the statement ¬∃x(x2 = 2), which is
equivalent to ∀x¬(x2 = 2). This can be rewritten as ∀x(x2 ≠2). The
truth values of these statements depend on the domain.
Example 2: Show that ¬∀x (P(x) → Q(x)) and ∃x(P(x)∧¬Q(x)) are
logically equivalent.
Solution: By De Morgan’s law for universal quantifiers, we know that
¬∀x (P(x) → Q(x)) and ∃x (¬ (P (x) → Q(x))) are logically
equivalent. We know that ¬ (P (x) → Q(x)) and P(x) ∧¬Q(x) are
logically equivalent for every x. Because we can substitute one
logically equivalent expression for another in a logical equivalence, it
follows that ¬∀x (P(x) → Q(x)) and ∃x (P(x) ∧¬Q(x)) are logically
equivalent.
It is important to note that the order of the quantifiers is important, unless all
the quantifiers are universal quantifiers or all are existential quantifiers.
Quantifications of Two Variables
14. Example 14: “If a person is female and is a parent, then this person is
someone’s mother”.
∀x ((Female(x) ∧ Parent(x)) → ∃ yMother(x, y)) or
∀x ∃ y ((Female(x) ∧ Parent(x)) → Mother(x, y)).
[Because y does not appear in Female(x) ∧ Parent(x)]
15. Example 15: Everyone has exactly one best friend.
∀x ∃y (Bestfren(x, y) ∧ ∀z ((z≠y) →¬Bestfren(x, z))).
[To say that x has exactly one best friend means that there is a person y who
is the best friend of x, and furthermore, that for every person z, if person z is
not person y, then z is not the best friend of x.]
16. Example 16: Everyone plays some sports. ∀x ∃y play(x, y)
17. Example 17: There is a student in this class who can speak French.
∃y Speak(y, French)
18. Example 18: All students in this class have learned at least one programming
languages. (∀x) (∃y Learned_Prog_Language(x, y))
19. Example 19: 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.”
Solution:
Let D(x) denote “x is in this discrete mathematics class,” and
let C(x) denote “x has taken a course in computer science.”
Premises: ∀x (D(x) → C(x)) and D(Marla).
Conclusion: C (Marla).
Step Reason
1. ∀x(D(x) → C(x)) Premise
2. D(Marla)→C(Marla) Universal instantiation from (1)
3. D(Marla) Premise
4. C(Marla) Modus ponens from (2) and (3)
20. Example 20: 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.”
Solution:
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.”
Premises: ∃x(C(x) ∧¬B(x)) and ∀x(C(x) → P(x)).
Conclusion: ∃x(P(x)∧¬B(x)).
Step Reason
1. ∃x(C(x) ∧¬B(x)) Premise
2. C(a)∧¬B(a) Existential instantiation from (1)
3. C(a) Simplification from (2)
4. ∀x(C(x) → P(x)) Premise
5. C(a) → P(a) Universal instantiation from (4)
6. P(a) Modus ponens from (3) and (5)
7. ¬B(a) Simplification from (2)
8. P(a)∧¬B(a) Conjunction from (6) and (7)
9. ∃x(P(x)∧¬B(x)) Existential generalization from (8)
Direct Proofs
A direct proof of a conditional statement p → q is constructed when the first
step is the assumption that p is true; subsequent steps are constructed using
rules of inference, with the final step showing that q must also be true.
A direct proof shows that a conditional statement p → q is true by showing
that if p is true, then q must also be true, so that the combination p true and q
false never occurs.
In a direct proof, we assume that p is true and use axioms, definitions, and
previously proven theorems, together with rules of inference, to show that q
must also be true.
Exaple1: Give a direct proof of the theorem “If n is an odd integer, then n2 is
odd.”
Solution: we assume that the hypothesis of this conditional statement is
true, and assume that n is odd. By the definition of an odd integer n = 2k +
1, where k is some integer. We want to show that n2 is also odd. We can
square both sides of the equation n = 2k + 1 to obtain a new equation that
expresses n2.
n2 = (2k + 1)2
= 4k2 + 4k + 1
= 2(2k2 + 2k) + 1
Indirect Proofs
Indirect Proofs: It does not start with the premises and end with the
conclusion. An extremely useful type of indirect proof is known as proof by
contraposition.
Proofs by contraposition make use of the fact that the conditional statement
p → q is equivalent to its contrapositive, ¬q →¬p. This means that the
conditional statement p → q can be proved by showing that its
contrapositive, ¬q →¬p, is true.
In a proof by contraposition of p → q, we take ¬q as a premise, and using
axioms, definitions, and previously proven theorems, together with rules of
inference, we show that ¬p must follow.
Example 3: Prove that if n is an integer and 3n + 2 is odd, then n is odd.
Solution: Assume that the conclusion of the conditional statement “If
3n + 2 is odd, then n is odd” is false; and assume that n is even. Then,
by the definition of an even integer, n = 2k for some integer k.
Substituting 2k for n,
3n + 2 = 3(2k) + 2
= 6k + 2
= 2(3k + 1)
This tells us that 3n + 2 is even and therefore not odd. This is the
negation of the premise of the theorem. Because the negation of the
conclusion of the conditional statement implies that the hypothesis is
false, the original conditional statement is true. Our proof by
contraposition succeeded; we have proved the theorem “If 3n + 2 is
odd, then n is odd.”
= k (k + 1) + 2(k + 1)
2
= (k + 1) (k + 2)
2
This last equation shows that P (k + 1) is true under the assumption
that P (k) is true.
Example 2: Use mathematical induction to show that 1 + 2 + 22 +· · ·+2n = 2
n +1
–1 for all nonnegative integers n.
Solution: Let P(n): 1 + 2 + 22 +· · ·+2n = 2 n +1 – 1 for the integer n.
Basis Step: P(0) is true because 20 = 1 = 21 − 1.
Inductive Step: For the inductive hypothesis, assume that P(k) is
true for an arbitrary nonnegative integer k. That is, we assume that
1 + 2 + 22 +· · ·+2k = 2 k +1 – 1
Under this assumption, it must be shown that P (k + 1) is true
1 + 2 + 22 +· · ·+2k + 2k+1 = 2(k+1)+1 − 1 = 2k+2 − 1
Now we obtain
1 + 2 + 22 +· · ·+2k + 2k+1= (1 + 2 + 22 +· · ·+2k) + 2k+1
= (2 k +1 – 1) + 2k+1
= 2 · 2k+1− 1
=2k+2 − 1
The induction step is complete. Because we have completed the
basis step and the inductive step, by mathematical induction we
Compiled By: Bal Krishna Nyaupane balkrishnanyaupane@gmail.com Page 30
Reference @Kenneth H. Rosen, 7 th Edition
know that P(n) is true for all nonnegative integers n. That is, 1 + 2 +
22 +· · ·+2n = 2 n +1 – 1 for all nonnegative integers n.
Example 3: Use mathematical induction to prove the inequality n < 2n for all
positive integers n.
Solution: Let P(n) : n < 2n
Basis Step: P(1) is true, because 1 < 21 = 2
Inductive Step: For the inductive hypothesis, assume that P(k) is
true for an arbitrary all positive integers k. That is, we assume that
k < 2k
Under this assumption, it must be shown that P (k + 1) is true
k + 1 < 2 k+1
To show this, first add 1 to both sides of k < 2k, and then note that 1
≤ 2k. Then
k + 1 <2k + 1
≤ 2k + 2k k
= 2 · 2k
= 2k+1
The induction step is complete. Therefore, because we have
completed both the basis step and the inductive step, by the
principle of mathematical induction we have shown that n < 2n is
true for all positive integers n.
Example 4: Use mathematical induction to prove that 7n+2 + 82n+1 is divisible
by 57 for every nonnegative integer n.
Solution: let P(n): 7n+2 + 82n+1 is divisible by 57.
Basis Step: P(0) is true because 7 0+2 + 8 2·0+1 = 72 + 81 = 57 is
divisible by 57. Inductive Step: For the inductive hypothesis,
assume that P(k) is true for an arbitrary all positive integers k. That
is, we assume that
7k+2 + 82k+1 = 57(t), where t is an integer (also divisible
by 57)
Under this assumption, it must be shown that P (k + 1) is true
7(k+1)+2 + 82(k+1)+1 is divisible by 57 is also true.
Now can obtain
7(k+1)+2 + 82(k+1)+1 = 7 k+3 + 8 2k+3
= 7 · 7 k+2 + 82 · 8 2k+1
= 7 · 7 k+2 + 64 · 8 2k+1
= 7 · 7 k+2 + 7 · 8 2k+1+ 57 · 8 2k+1
= 7(7 k+2 + 8 2k+1) + 57 · 8 2k+1
=7(57(t)) + 57 · 8 2k+1 ; from induction step
= 57 (7.t + 8 2k+1)
Compiled By: Bal Krishna Nyaupane balkrishnanyaupane@gmail.com Page 31
Reference @Kenneth H. Rosen, 7 th Edition