0% found this document useful (0 votes)
2 views

Week1 Sols

The document contains solutions to various problems from a Discrete Math course, focusing on propositional and predicate logic. It includes exercises on rewriting statements, proving logical equivalences, and expressing formulas in conjunctive and disjunctive normal forms. Additionally, it introduces the NOR operation and its universality in expressing Boolean formulas, along with practice problems involving quantifiers.

Uploaded by

zheng20040309
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Week1 Sols

The document contains solutions to various problems from a Discrete Math course, focusing on propositional and predicate logic. It includes exercises on rewriting statements, proving logical equivalences, and expressing formulas in conjunctive and disjunctive normal forms. Additionally, it introduces the NOR operation and its universality in expressing Boolean formulas, along with practice problems involving quantifiers.

Uploaded by

zheng20040309
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

CS30 (Discrete Math in CS), Fall 2024 Week 1 Problems

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

b : ability to write precise statements and proofs.

³ : an exercise is applying learnt concepts.

Y : a problem applying multiple concepts and requiring more thought.

r : teaches something possibly new which should be distilled as a concept.

Í : connection to CS

K : a more challenging problem than others.

Multiple ³ ’s indicate may be correlated with amount of time needed.


All problems contribute to the learning objective of writing precisely, clearly, and concisely, and thereby
growing mathematical maturity.

Color Coding:

• Problems in brown margin squares are to be handed in.

• Problems in blue shaded squares are extra-credit problems.

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.”

a. Winds from the south imply a strong thaw.


Solution: Winds from the south ⇒ a strong thaw.
b. Willy gets caught whenever he cheats.
Solution: Willy cheats ⇒ Willy gets caught.
c. You can access the website only if you pay the subscription fee.
Solution: You can access the website ⇒ you pay the subscription fee.

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.

a. I open my umbrella whenever it rains.


Rewrite the above sentence in the form p ⇒ q. Then write a natural sounding English sentence that
represents its inverse.
Solution: It rains ⇒ I open my umbrella.
Whenever it doesn’t rain, I keep my umbrella closed.
b. I miss class only if I am unwell.
Rewrite the above sentence in the form p ⇒ q. Then write a natural sounding English sentence that
represents its contrapositive.
Solution: I miss class ⇒ I am unwell.
If I am well, I wont miss class.
c. You can’t invent unless you are curious and knowledgeable.
Rewrite the above sentence in the form p ⇒ q, using the symbol ¬ wherever necessary. Then write a
natural sounding English sentence that represents its converse.
Solution:
You invent things ⇒ you are curious and knowledgeable.
If you are curious and knowledgeable, then you invent things.

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)

 if a + b is an odd number, then either a is an even number or b is an even number.


In plain English:
b. (p ⇒ q) ∧ p ⇒ q ≡ true (Modus Ponens)r
Using the above equivalence, what can you deduce from the following?
If it rains in Spain, then it snows in Klow. It is raining in Spain.
Solution:

(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

I am not eating cheese.

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

Problem 5 (Conjunctive and Disjunctive Normal Forms.). r


A literal is a Boolean variable or its negation. A formula ϕ on literals is in conjunctive normal form (CNF)
if it is expressed as a conjuction (AND) of a bunch of clauses where each clause itself is a disjunction (OR)
of literals. For example the following formula is in CNF:

ϕC := (p ∨ q ∨ ¬r) ∧ (¬p ∨ ¬q)

A formula ϕ on literals is in disjunctive normal form (DNF) if it is expressed as a disjunction (OR) of a


bunch of clauses where each clause itself is a conjunction (AND) of literals. For example, the following is
in disjunctive normal form:
ϕD := (p ∧ q) ∨ (p ∧ r) ∨ (q ∧ r)
a. Describe the formula ϕ whose truth table is shown below in both CNF and DNF form. ³

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.

ϕ = (p ∧ q ∧ r) ∨ (p ∧ q ∧ ¬r) ∨ (p ∧ ¬q ∧ ¬r) ∨ (¬p ∧ ¬q ∧ ¬r)

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

(p ∨ ¬q) ∧ (p ∨ ¬r) ∧ (q ∨ ¬r)

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.

Problem 6 (A new operation: NOR). r


Define the NOR operation as follows: for any two propositions p and q, the NOR of p and q is defined to be
¬(p ∨ q). We use the notation p ↓ q to denote the NOR of p and q. The following steps of the problem lead
to the conclusion that NOR is a “universal” operation.

a. Express ¬p using only NOR operations and p. ³


Solution: ¬p = p ↓ p. You can check this using a small truth table.

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))

c. Express p ∧ q using only NOR operations and p, q. ³³


Solution: This is slightly more interesting. We recall De Morgan’s law to get that p∧q = ¬ (¬(p ∧ q)) =
¬ (¬p ∨ ¬q). And thus, by definition of ↓, we get p ∧ q = ¬p ↓ ¬q. Since we know how to convert
¬s to ↓s, we get
p ∧ q = (p ↓ p) ↓ (q ↓ q)

Problem 7 (NOR is a universal operator). rY


After solving Problem 5 and Problem 6, argue that any formula in any number of variables can be
expressed only using NOR operations. More precisely, suppose you are given a “box”, called a gate in
the parlance, which takes two inputs and one output, and the inputs are Boolean variables p and q, and
the output is p ↓ q, the NOR of p and q. With this NOR gate in hand, and given the truth table of any
Boolean formula on n variables, clearly describe how to construct a “circuit” which takes the n inputs
on n “wires” and the final output will have the formula answer, and you can use any number of NOR
gates as you want. b
Using your method draw the circuit which takes two Boolean variables as input and outputs TRUE if
exactly ONE is TRUE and otherwise it returns FALSE. How many NOR gates did you use?

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) ]

h  that ¬(p ⇒ q) ≡ ¬(¬p ∨ q) ≡ p ∧ ¬q.


To see this, note (recall?)
 i
e. ∀n ∈ N, ∃m ∈ N : (m | n) ∧ (m , 1) ∧ (m , n) ⇒ n is prime Y³b
Solution: This is TRUE(!)
If you have done the previous part, then at first glance you would think that the above statement is
clearly FALSE (how can we conclude n is both prime and not prime)? However, do you note that the
“exists” quantifier has come out of the square-brackets? And this would make the statement TRUE.
Let’s prove this first, and then “explain”. Fix any n ∈ N. We now show an m such that the predicate
h    i
P(n) := ∃m ∈ N : (m | n) ∧ (m , 1) ∧ (m , n) ⇒ n is prime

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.

Problem 9 (Practice with Negation in Predicate Logic).


For the following italicized statements,
(a) express them in predicate logic using the predicate given,
(b) write down the negation of the statement taking the negations as deep as possible, and
(c) interpret the negation back in English.
You can use any mathematical operation you want.

• The square of an odd natural number is always odd. ³³


Use the predicate P(n) which is true if n is odd.
Solution:

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

¬ϕ = ¬∀n ∈ N : ((P(n) ∧ (n ≥ 3)) ⇒ Q(n))


≡ ∃n ∈ N : ¬ ((P(n) ∧ (n ≥ 3)) ⇒ Q(n))
≡ ∃n ∈ N : ¬ (¬ (P(n) ∧ (n ≥ 3)) ∨ Q(n))
≡ ∃n ∈ N : (P(n) ∧ (n ≥ 3)) ∧ Q(n)

(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. ³

There are infinitely many prime numbers.

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.

a. Every pixel in the image is black.


b. Every row has at least one white pixel.
c. There is a column with two consecutive white squares.

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.

Problem 12 (Practice taking converses). ³³


In the next module, we will see the method of proof by contradiction which goes as follows: for any
“theorem”, we assume it is false, and so its negation is true. We then use the fact that the negation is true to
logically deduce something false thereby reaching our contradiction. The mechanical part in this method is
to write the converses.
For each of these “theorems”, first write down what you think are their negations in plain English. After
doing so, write the theorems in predicate logic and negate them to get the negation in predicate logic. Does
the English interpretation of the negation match yours? You can use any mathematical operation and even
self-defined predicates.

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

∀S ⊆ N : (S , ∅) ⇒ (∃a ∈ S , ∀b ∈ S \ {a} : a < b)

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)

It’s converse (need’s some work) is

∃S ⊆ N : ¬ ((|S | ≥ 2 ∧ ∃a ∈ S : 2 ∤ a) ⇒ ∃b ∈ S \ {a} : (2 ∤ b))


≡ ∃S ⊆ N : |S | ≥ 2 ∧ (∃a ∈ S : 2 ∤ a) ∧ ¬ (∃b ∈ S \ {a} : (2 ∤ b))
≡ ∃S ⊆ N : |S | ≥ 2 ∧ (∃a ∈ S : 2 ∤ a) ∧ ∀b ∈ S \ {a} : (2 | b)

where we have used ¬(p ⇒ q) ≡ ¬(¬p ∨ q) ≡ p ∧ ¬q.


In plain English, it states there exists a subset with at least two elements and at least one odd number
such that every other number other than it in the set is even. This is logically same as the “exactly one
odd number” which, I think, is conciser.

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)

It’s converse (need’s some work) 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)

which is pretty much the same thing in English.


The statement is actually true (do you see why), but this is an example where a proof by contradiction
is the wrong way to move forward.

11

You might also like