Week1 Sols
Week1 Sols
SOLUTIONS
Legend. Most of the (sub-parts) of problems will have an emoticon associated. Very loosely, they correspond
to the learning objectives of the course. Here is my rough mapping
Í : connection to CS
Color Coding:
1
Propositional Logic
Problem 1. ³
Rewrite each of the following statements in English in the form p ⇒ q. For example, the statement “I catch
cold if I eat ice cream” should be rewritten “I eat ice cream ⇒ I catch cold.”
Problem 2. ³
Let S be the statement p ⇒ q for two propositions p and q. Define the converse, inverse, and contrapositive
of the statement S to be the statements represented by q ⇒ p, ¬p ⇒ ¬q, and ¬q ⇒ ¬p, respectively. Now
consider the following sentences and do what is asked.
Problem 3. ³b
Without using truth tables, and using the important equivalences done in class and given in the lecture notes,
prove the following logical equivalences.
a. p ⇒ q ≡ ¬q ⇒ ¬p r(Contrapositive)
In plain English, write down the contrapositive of the following statement:
If a is an odd number and b is an odd number, then a + b is an even number.
2
Solution:
p⇒q≡ ¬p ∨ q Implication as OR
≡ q ∨ ¬p Commutativity
≡ ¬(¬q) ∨ ¬p Negation of Negation
≡ ¬q ⇒ ¬p Implication as OR
For the English statement, let r be the proposition “a is an odd number” and s be the proposition “b
is an odd number” and t be the proposition “(a + b) is an even number”. Then the statement and it’s
contrapositive is
(r ∧ s) ⇒ t ≡ ¬t ⇒ ¬(r ∧ s) ≡ ¬t ⇒ (¬r ∨ ¬s)
(p ⇒ q) ∧ p ≡ (¬p ∨ q) ∧ p Implication as OR
≡ (¬p ∧ p) ∨ (q ∧ p) Distributitive
≡ false ∨ (q ∧ p) AND with negation
≡ (q ∧ p) OR with False
Therefore,
(p ⇒ q) ∧ p ⇒ q ≡ (q ∧ p) ⇒ q Previous deduction
≡ ¬(q ∧ p) ∨ q Implication as OR
≡ (¬q ∨ ¬p) ∨ q De Morgan
≡ (¬q ∨ q) ∨ ¬p Associavity
≡ true ∨ ¬p OR with Negation
≡ true OR with TRUE
It
is snowing in Klow.
c. (p ⇒ q) ∧ ¬q ⇒ ¬p ≡ true (Modus Tolens)r
Using the above equivalence, what can you deduce from the following?
If I eat cheese, Alice eats cheese. Alice isn’t eating cheese.
Solution:
(p ⇒ q) ∧ ¬q ≡ (¬p ∨ q) ∧ ¬q Implication as OR
≡ (¬p ∧ ¬q) ∨ (q ∧ ¬q) Distributitive
≡ (¬p ∧ ¬q) ∨ false AND with negation
≡ (¬p ∧ ¬q) OR with False
3
Therefore,
(p ⇒ q) ∧ ¬q ⇒ ¬p ≡ (¬p ∧ ¬q) ⇒ ¬p Previous deduction
≡ ¬(¬p ∧ ¬q) ∨ ¬p Implication as OR
≡ (p ∨ q) ∨ ¬p De Morgan
≡ (p ∨ ¬p) ∨ q Associavity
≡ true ∨ q OR with Negation
≡ true OR with TRUE
Problem 4.
Without writing truth-table, and using the important equivalences in the lecture notes, prove the fol-
lowing logical equivalences ³b
• (p ⇒ p) ⇒ ( (¬p ⇒ ¬p) ∧ q) ≡ q
• (p ⇒ ¬p) ⇒ ((q ⇒ (p ⇒ p)) ⇒ p) ≡ p
p q ϕ
true true true
true false false
false true false
false false true
Solution: We can write ϕ in the DNF formula by noting the rows in which ϕ evaluates to true. We
see this occurs when p = true, q = true and when p = false, q = false. Thus, in the DNF the formula
looks as
ϕ = (p ∧ q) ∨ (¬p ∧ ¬q)
4
where the first clause corresponds to the first row and the second clause corresponds to the fourth row.
To get the CNF form, we just use the distributive law (and simply using idempotence, operation with
negation, and operation with true, false) to get
ϕ = (¬p ∨ q) ∧ (p ∨ ¬q)
b. Describe the formula ϕ whose truth table is given below in both CNF and DNF form. ³
p q r ϕ
true true true true
true true false true
true false true false
true false false true
false true true false
false true false false
false false true false
false false false true
Solution: We apply the same logic as in the previous exercise. The first, second, fourth, and last row
evaluate to true. And this leads to the following DNF form.
We simplify this by using the following equivalence (a ∧ b) ∨ (a ∧ ¬b) ≡ a; to see this, one could write
a truth table. The DNF simplifies to
ϕ = (p ∧ q) ∨ (¬q ∧ ¬r)
To get the CNF form, we use the distributive property and simplify to get
In fact, the middle (p ∨ ¬r) is not needed! The above is equivalent to (p ∨ ¬q) ∧ (q ∨ ¬r); one can
see this via truth tables. I (deepc) couldn’t figure this out via the logical equivalences done in class.
5
b. Express p ∨ q using only NOR operations and p, q. ³
Solution: To express p ∨ q, note that by definition p ∨ q = ¬(p ↓ q). But the previous exercise tells
us how to replace the ¬ by ↓. We do just that to get
p ∨ q = ((p ↓ q) ↓ (p ↓ q))
Predicate Logic
Problem 8 (Practice with Quantifiers).
For each of the following statements in predicate logic, mark if they are TRUE or FALSE, and give reasons
for your answer. Below, N is the set of natural numbers, {1, 2, 3 . . .}, (a | b) is the short-form for “a divides b”,
and a prime number is one whose only factors are 1 and the number itself. For this exercise, for simplicity,
we will say 1 is a prime number (this is not standard practice).
a. ∀n ∈ N, ∃m ∈ N : (m > n) ³b
Solution: Fix any number n ∈ N, Then m := n + 1 is ∈ N and m > n. So, for every n ∈ N there exists
at least one m ∈ N with m > n. This statement is theorefore TRUE.
b. ∃n ∈ N, ∀m ∈ N : (m > n). ³b
Solution: The statement says that there is some natural number n which is strictly smaller than all
natural number m. This is FALSE because the number n itself is equal to n, and can’t be strictly
smaller.
Note, however, if (m > n) were replaced by (m ≥ n), then this statement would be TRUE; the number
n = 1 would make the above true.
6
h i
c. ∀n ∈ N : (n is prime) ⇒ [ ∀m ∈ N : (m | n) ⇒ (m = n) ∨ (m = 1) ] ³b
Solution: hThis is indeed the definition of the prime numbers. So, it is TRUE. i
d. ∀n ∈ N : ∃m ∈ N : (m | n) ∧ (m , 1) ∧ (m , n) ⇒ (n is not a prime) ³b
Solution: This is TRUE. Indeed, the predicate
h i
P(n) := ∃m ∈ N : (m | n) ∧ (m , 1) ∧ (m , n) ⇒ (n is not a prime)
which is a function of n is the contrapositive ( ??) of the predicate Q(n) from the previous part
h i
Q(n) := (n is prime) ⇒ [ ∀m ∈ N : (m | n) ⇒ (m = n) ∧ (m = 1) ]
is TRUE. Since n was picked arbitrarily, this would prove ∀n ∈ N : P(n) is true.
Indeed, set m := n+1 (or any m > n). Clearly, (m | n) is FALSE. And so, (m | n) ∧ (m , 1) ∧ (m , n)
is FALSE. And so, (m | n) ∧ (m , 1) ∧ (m , n) ⇒ n is prime is TRUE (“false implies anything”).
And thus, P(n) is true.
The difference is this. The previous part says
For any number n, if there exists some m such that m isn’t 1, isn’t n and m divides n, then
n is not prime.
while this statement says
For any number n, there exists some m such that if m isn’t 1, isn’t n and m divides n, then
n is prime.
When written in English, perhaps one sees why this is not what it may have been (even if one doesn’t
see it’s true). One can still get a tripped because “false implies anything” takes something getting used
to.
7
(a) ϕ = ∀n ∈ N : P(n) ⇒ P(n2 )
(b) The negation of the statement is
(b) The negation of the statement is
¬ϕ = ¬ ∀n ∈ N : P(n) ⇒ P(n2 )
≡ ∃n ∈ N : ¬ P(n) ⇒ P(n2 )
≡ ∃n ∈ N : ¬ ¬P(n) ∨ P(n2 )
≡ ∃n ∈ N : P(n) ∧ P(n2 )
(c) In English, ¬ϕ says there exists some odd natural number n such that n2 is even.
• All prime numbers at least 3 are odd. ³³
Use the predicate P(n) which is true if n is prime, and Q(n) is true if n is odd.
Solution:
(a) ϕ = ∀n ∈ N : ((P(n) ∧ (n ≥ 3)) ⇒ Q(n)).
(b) The negation of the statement is
(c) In English, ¬ϕ says there exists some natural number which is larger than 3, prime, and even.
Problem 10.
In this part, you need to express statements in predicate logic. You can use any math operation in
the set {+, −, ×, >, =, <, ≤, ≥}. The domain of discourse must be N := {1, 2, 3, . . .}, the set of natural
numbers.
(a) Given two numbers a and b, we denote a | b if a divides b and a ∤ b if a does not divide b. Let
isPrime(n) be the predicate which evaluates to true if n is prime and false otherwise; recall, a
number n is prime if the only number dividing it are 1 and n. For simplicity, let 1 be a prime
number. Using quantifiers and propositional logic, describe the predicate isPrime(n). ³
(b) Using the predicate isPrime(n) describe the following statement in predicate logic. ³
One way to interpret “infinitely many primes” is that there is no “largest prime number”.
(c) Next, write down the negation of the statement in predicate logic, and interpret it back in English.
Whenever you write the negation, the ¬ sign should be as deep in the parentheses as possible. ³
8
Problem 11 (Converting statements into predicate logic and negating). ³³
Let P[1 . . . m, 1 . . . n] be a 2-dimensional array of the pixels of a black-and-white image: for every x and y,
the value of P[x, y] = 0 if and only if the (x, y)th pixel is black, and P[x, y] = 1 if it is white. Translate
the following statements into predicate logic. Then, take their negations. Then, convert their negations into
plain English.
Solution: The predicate P(x, y) takes integer variables where x ranges from 1 to m and y ranges from 1 to n.
P(x, y) evaluates to true if P[x, y] = 0, that is, if the (x, y)th pixel is black, and it evaluates to false otherwise.
Using this, we can express the statements in predicate logic as follows.
a. ∀1 ≤ x ≤ m, 1 ≤ y ≤ n : P(x, y)
It’s negation is
∃1 ≤ x ≤ m, 1 ≤ y ≤ n : ¬P(x, y)
which in plain English is: there is some white pixel.
b. ∀1 ≤ x ≤ m ∃1 ≤ y ≤ n : ¬P(x, y)
It’s negation is
∃1 ≤ x ≤ m ∀1 ≤ y ≤ n : P(x, y)
which in plain English is: there is some row all of whose pixels are black.
c. ∃1 ≤ y ≤ n ∃1 ≤ x ≤ m − 1 : ¬P(x, y) ∧ ¬P(x + 1, y)
It’s negation is
∀1 ≤ y ≤ n ∀1 ≤ x ≤ m − 1 : P(x, y) ∨ P(x + 1, y)
which in plain English is: for every column and for any pixel in that column except the bottom most
one, either it is black or the one right below it is black.
9
a. Every non-empty subset of natural numbers has a smallest element.
Solution: My English converse: there is some subset of natural numbers with no smallest element.
The given statement in predicate logic is
It’s negation is
∃S ⊆ N : (S , ∅) ∧ (∀a ∈ S , ∃b ∈ S \ {a} : b ≤ a)
which in English translates to: there is some subset of natural numbers such that for any element in it,
there is some other element which is smaller than it. I think this interpretation is better.
By the way, this “theorem” is actually an axiom called the “well ordering principle”, and forms the
basis of mathematical induction. But we get ahead of ourselves.
b. For any two subsets of natural numbers, either they are disjoint or one is a subset of the other.
Solution:
My English converse: there exists two subsets of natural number which are neither disjoint nor is one
the subset of the other.
The given statement in predicate logic is
∀A ⊆ N, B ⊆ N : (A ∩ B = ∅) ∨ (A ⊆ B) ∨ (B ⊆ A)
It’s negation is
∃A ⊆ N, B ⊆ N : A ∩ B , ∅ ∧ A ⊈ B ∧ B ⊈ A
In English, it translates to my guess. However, when we do proofs by contradiction, it is the presence
of these sets A and B, who have been named and exist, which would be very useful. The English
probably not.
The statement of course is trivially false, and one can show this by giving examples of A and B which
make the converse true: A = {1, 2} and B = {2, 3} suffice. However, in many applications in discrete
optimization, the set N is replaced by something else, in which case a theorem like this is true. But
again, that’s a story for a different course.
c. In any subset of natural numbers with at least two elements, if it contains one odd number, then it
contains at least another odd number.
Solution: My English converse: there is a subset of naturals containing more than two elements with
exactly one odd number.
The given statement in predicate logic is
∀S ⊆ N : (|S | ≥ 2 ∧ ∃a ∈ S : 2 ∤ a) ⇒ ∃b ∈ S \ {a} : (2 ∤ b)
10
The statement is of course false shown, once again, by describing a subset S which makes the converse
true. S = {1, 2} would work.
d. In any array A[1 : n] with n integers where n ≥ 2, if A[1] > 0 and A[n] < 0, then there must exist two
consecutive elements where the first is positive and the second is not positive.
Solution: My English converse is: there is some array A[1 : n] for some n ≥ 2 such that A[1] > 0 and
A[n] < 0 but for any two consecutive numbers either the first is not positive or the second is positive.
The given statement in predicate logic is
∃n ≥ 2, ∃A[1 : n] : ¬ ((A[1] > 0 ∧ A[n] < 0) ⇒ (∃1 ≤ i ≤ n − 1 : A[i] > 0 ∧ A[i + 1] ≤ 0))
≡ ∃n ≥ 2, ∃A[1 : n] : (A[1] > 0 ∧ A[n] < 0) ∧ ¬ (∃1 ≤ i ≤ n − 1 : A[i] > 0 ∧ A[i + 1] ≤ 0)
≡ ∃n ≥ 2, ∃A[1 : n] : (A[1] > 0 ∧ A[n] < 0) ∧ ∀1 ≤ i ≤ n − 1 : (A[i] ≤ 0 ∨ A[i + 1] > 0)
11