


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions to logic and sets problems involving truth tables, logical equivalences, rational numbers, and functions. The solutions include explanations and justifications.
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Problem 1: (a) Build a truth table with columns for p → q, p ∧ (p → q), and so forth to determine whether (p ∧ (p → q)) → q is a tautology. Explain why your answer is intuitively reasonable. (b) Verify the result of (a) by applying logical equivalences. State which equivalence you are using at each step. (c) Prove that for any sets A, B and C we always have
A ∩ ( A¯ ∪ B) ⊂ B.
Solution: (a) A compound proposition, which depends on propositions p, q, r and so forth, is a tautology when it evaluates to true for any values of the propositions p, q and so forth. Intuitively, if we know p is true and p implies q when true, then we know that q is true. The truth table reads
p q p → q p ∧ (p → q) (p ∧ (p → q)) → q F F T F T F T T F T T F F F T T T T T T
(b) By definition of implication, the given statement is equivalent to
¬(p ∧ (¬p ∨ q)) ∨ q
which by de Morgan is equivalent to
¬p ∨ (p ∧ ¬q) ∨ q.
Distributing each single-variable or over each and gives
(((¬p ∨ p) ∧ (p ∨ ¬q))) ∨ q.
Excluded middle and domination simplify the expression to
p ∨ ¬q ∨ q
by associativity of ∨, which reduces to T by associativity, excluded middle and domination. (c) Translate the previous logical statement into sets and quantify.
Problem 2: Define Z+^ = { 1 , 2 , 3 ,... } and
Q+^ = {p/q | p ∈ Z+^ ∧ q ∈ Z+^ ∧ gcd(p, q) = 1}.
Define f : Q+^ → Z+^ by f (p/q) = p + q − 1. Justify your answers to the following questions.
(a) Is f onto?
(b) Do Z+^ and Q+^ have the same cardinality?
Solution: (a) Every element n of Z+^ is given by n = f (p/q) for p/q =
n/ 1 ∈ Q+. Hence f is onto. (Since f (5/3) = f (3/5) = 8, f is not one-to-
one.) (b) Since Z+^ is N with 0 removed, it is infinite and countable. We know that the rationals are countable, and a (bijective image of a) subset of a countable set is countable, so Q+^ is countable. Since it contains Z+, it is infinite, so
Z+^ and Q+^ have the same cardinality.
Problem 4: Consider the following pseudocode:
G(n ∈ N, m ∈ N, function f : { 0 , 1 , 2 ,... , n − 1 } → { 0 , 1 , 2 ,... , m − 1 }) for i := 0 to m − 1 hi := 0 end for j := 0 to n − 1 i := f (j) hi := hi + 1 end for i := 0 to m − 1 if (hi 6 = 1) then return F end return T end
(a) What function of f , n and m does G return? (b) What is its worst-case complexity in terms of m and n in big-O notation? Justify your answer. (c) Let n = m > 2. For what values of a ∈ Z does G return T for the function f defined by f (j) = aj mod n?
Solution: (a) It returns T iff the input function f is a bijection (a one-to- one correspondence). (b) The worst-case complexity is W (m, n) = O(m + n). (c) This function is a bijection when a is invertible (mod n), which happens when gcd(a, n) = 1. Note: on the actual exam, the sets were { 1 ,... , n} and { 1 ,... , m} so this function was (a) not a function into the desired range and (b) never a bijection, since n was not in the range of aj mod n. Hence the answer “never” was also accepted as correct.