CS128 FS2012 Exam 1 Key

CS128 FS2012 Exam 1 Key
This is a closed-book, closed-notes exam. The only items you are allowed to use are writing implements.
Mark each sheet of paper you use with your name and the string “cs128fs2012 exam1”. If you are caught
cheating, you will receive a zero grade for this exam. The max number of points per question is indicated in
square brackets after each question. The sum of the max points for all the questions is 63, but note that the
max exam score will be capped at 60 (i.e., there are 3 bonus points but you can’t score more than 100%).
You have exactly 75 minutes to complete this exam. Keep your answers clear and concise while complete.
Good luck!
1. Is the sentence “1 − x = x + 1” a statement? Explain your answer! [2]
No, because whether it is false or true depends on the value of x.
2. Compute gcd(45,150). [2]
gcd(45, 150) = gcd(32 · 51 , 21 · 31 · 52 ) = 31 · 51 = 15
3. Compute lcm(36,10). [2]
lcm(36, 10) = lcm(22 · 32 , 21 · 51 ) = 22 · 32 · 51 = 4 · 9 · 5 = 180
4. Given the informal statement “If each student has a professor who he admires, then some professors
sleep well at night.”
(a) Rewrite the statement formally using quantifiers and variables. [3]
Let P ROF be the set of all professors and ST U the set of all students
Let ADM IRES(x, y) be the predicate “x admires y”
Let SLEEP (z) be the predicate “z sleeps well at night”
(∀s ∈ ST U, ∃p ∈ P ROF, ADM IRES(s, p)) → (∃q ∈ P ROF, SLEEP (q))
(b) Give the formal negation of the statement. [3]
∼ ((∀s ∈ ST U, ∃p ∈ P ROF, ADM IRES(s, p)) → (∃q ∈ P ROF, SLEEP (q)))
≡ (∀s ∈ ST U, ∃p ∈ P ROF, ADM IRES(s, p)) ∧ (∼ (∃q ∈ P ROF, SLEEP (q)))
≡ (∀s ∈ ST U, ∃p ∈ P ROF, ADM IRES(s, p)) ∧ (∀q ∈ P ROF, ∼ SLEEP (q))
(c) Give the informal negation of the statement. [2]
Each student has a professor who he admires, but no professor sleeps well at night.
(d) Give the formal contrapositive of the statement. [4]
∼ (∃q ∈ P ROF, SLEEP (q)) →∼ (∀s ∈ ST U, ∃p ∈ P ROF, ADM IRES(s, p))
≡ (∀q ∈ P ROF, ∼ SLEEP (q)) → (∃s ∈ ST U, ∀p ∈ P ROF, ∼ ADM IRES(s, p))
(e) Give the informal contrapositive of the statement. [2]
If no professor sleeps well at night, then there is a student who does not admire any professor.
5. Let the predicate C(x) be “−1 ≤ x3 ≤ 16”. What is the truth set of C(x) for the domain Z? [3]
{−1, 0, 1, 2}
6. Determine whether the statement “For all integers a and b, if a|10b, then a|10 or a|b” is true or false.
If it’s true, then prove it directly from the definition; if it’s false, then give a counterexample. [4]
The statement is false. Counterexample: Let a = 25 and b = 5. Then a|10b because 25|50, but a 6 |10
because 25 6 |10 and a 6 |b because 25 6 |5.
7. Determine whether the statement “The difference of the squares of any two consecutive integers is
odd.” is true or false. If it’s true, then prove it directly from the definition; if it’s false, then give a
counterexample. [8]
The statement is true. Proof: Suppose n is the smaller of two consecutive integers and m is the difference
of the squares of n and n + 1. Then:
m = (n + 1)2 − n2 = (n2 + 2n + 1) − n2 = 2n + 1
So m = 2 · (an integer) + 1, and therefore m is an odd integer by the definitions of integer and odd.
8. Use a truth table to determine whether x > 7 implies x ≥ 7; include a few words of explanation. [8]
(x > 7) → (x ≥ 7) ≡ (x > 7) → ((x > 7) ∨ (x = 7))
This corresponds to the statement form p → p ∨ q.
p q p∨q p→p∨q
T T
T
T
T F
T
T
F T
T
T
F F
F
T
The truth table shows that p → p ∨ q is always true, hence (x > 7) ⇒ (x ≥ 7) is a tautology, so the
answer is yes, x > 7 implies x ≥ 7.
9. Use a truth table to determine whether the following argument form is valid. Indicate which columns
represent the premises and which represent the conclusion, and include a few words of explanation to
support your answer. [10]
∼ p → q∨ ∼ r
∼ q ∨ (p ∧ r)
∴ p∨ ∼ q
p q r
∼ p ∼ q ∼ r q∨ ∼ r p ∧ r ∼ p → q∨ ∼ r ∼ q ∨ (p ∧ r) p∨ ∼ q
T T T
F
F
F
T
T
T
T
T
T T F
F
F
T
T
F
T
F
T
T F T
F
T
F
F
T
T
T
T
T F F
F
T
T
T
F
T
T
T
F T T
T
F
F
T
F
T
F
F
F T F
T
F
T
T
F
T
F
F
F F T
T
T
F
F
F
F
T
T
F F F
T
T
T
T
F
T
T
T
The 9th and 10th columns are the premises, the 11th column is the conclusion. All the critical rows
have a true conclusion, hence the argument form is valid.
10. Use the quotient-remainder theorem with d = 3 to prove that the square of any integer has the form 3k
or 3k + 1 for some integer k. [10]
Proof: Suppose n ∈ Z. By the quotient-remainder theorem with d = 3, we know:
∃q ∈ Z, n = 3q ∨ n = 3q + 1 ∨ n = 3q + 2.
Case 1 (n = 3q): n2 = (3q)2 [by substitution]
= 3 · (3q 2 ) [by algebra]
Let k = 3q 2 . Then k ∈ Z because it is a product of integers. Hence ∃k ∈ Z, n2 = 3k.
Case 2 (n = 3q + 1): n2 = (3q + 1)2 [by substitution]
= 9q 2 + 6q + 1 [by algebra]
= 3(3q 2 + 2q) + 1 [by algebra]
Let k = 3q 2 + 2q. Then k ∈ Z because it is a sum of products of integers. Hence ∃k ∈ Z, n2 = 3k + 1.
Case 3 (n = 3q + 2): n2 = (3q + 2)2 [by substitution]
= 9q 2 + 12q + 4 [by algebra]
= 9q 2 + 12q + 3 + 1 [by algebra]
= 3(3q 2 + 4q + 1) + 1 [by algebra]
Let k = 3q 2 + 4q + 1. Then k ∈ Z because it is a sum of products of integers. Hence ∃k ∈ Z, n2 = 3k + 1.
Conclusion: In all three cases, ∃k ∈ Z, n2 = 3k ∨ n2 = 3k + 1, as was to be shown.