Problem Set 01 Solutions
Problem Set 01 Solutions
(a) Prove the lemma, used by Aristotle in his proof, which says that if n2 is even,
so is n. (Hint: Remember that a → b is equivalent to ¬b → ¬a.
ANSWER: It is easiest to prove the contrapositive of the lemma, that if n is
odd, then n2 is odd. An odd number is one that can be written in the form of
2k + 1 for some other whole number k. So suppose that n = 2k + 1. Then
n2 = (2k + 1)2 = 4k 2 + 4k + 1 = 2(2k 2 + 2k) + 1
And so n2 is odd. This proves the contrapositive and hence the lemma.
(b) Prove that the square root of 3 is irrational using Aristotle’s techniques. Make
sure to prove the appropriate lemma.
ANSWER: We need the following lemma:
1
2
Lemma:
For any whole number n, n2 is divisible by 3 implies that n is divisible by 3
(a) Write a Scheme program that prints out the number of goals and the number of
near misses to achieve a given total greater than 60.
(b) Prove that you can achieve any score greater than 60. Think inductively and
experiment.
ANSWER:
(a) ADU-BALL returns a list of all goal, near-miss pairs that add up to the given
number The loop subtracts off multiples of 7 from the given number, and adds
a solution to the list if the result is divisible by 11. Note the use of let*,
which unlike let, does perform each assignment before going to the next one.
(define (adu-ball n)
(define (iter i result)
(let* ((a (- n (* 7 i))) (b (remainder a 11)))
(cond ((< a 0) result)
((= b 0) (iter (inc i) (cons (cons (/ a 11) i) result)))
(else (iter (inc i) result)))))
(iter 0 nil))
(adu-ball 187)
;Value: ((3 . 22) (10 . 11) (17 . 0))
(b) Actually you can achieve any score greater than or equal to 60. We will prove this
by induction. There will actually be seven base cases here, since the induction
will go down by steps of seven. Here is a formal statement of what will prove:
For any n ≥ 60 there are natural numbers x, y such that n = 11x + 7y
Base Cases:
• n = 60. We can let x = 1, y = 7
11x + 7y = n − 7
4
(8) Euclid proved that there are an infinite number of primes, by assuming that n is the
highest prime, and exhibiting a number that he proved must either be prime itself, or
else have a prime factor greater than n. Write a scheme program to find the smallest
n for which Euclid’s proof does not provide an actual prime number.
ANSWER: There was some confusion as to whether the question wants you i) to
use all primes less than a given prime n, i.e. to generate the primes in some other
fashion an then apply Euclid’s proof to an initial sequence of primes or ii) to use all
primes generated by Euclid’s proof. These are not the same since Euclid’s proof skips
over many primes. For example, starting with 2, Euclid’s proof generates 3, 7 for the
next two primes, skipping over 5. The program we include here uses interpretation
i).
(define (prime? x) ; tests whether x is prime
(define (iter count)
(cond ((> (* count count) x) true)
((= 0 (remainder x count)) false)
(else (iter (inc count)))))
(iter 2))
(define ones (cons-stream 1 ones)) ; 1,1,1,1,1,1,...
(9) You have proved before that a truth table with n variables has 2n rows.
(a) How many different Boolean functions with n variables are there?
n
ANSWER: 22
7
(b) For n = 2, list all the functions and identify as many as you can by name.
ANSWER:
a b 0 a∧b a→b a b→a b a⊕b a∨b a↓b a↔b b b→a a a → b a|b 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
1 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
(Aside: Note that ⊕ is just the negation of ↔. )
(10) Prove by induction that for n > 5 , 2n > n2 .
ANSWER: Actually, we can take n ≥ 5.
Base Case: n = 5. Then 25 = 32, which is greater than 52 , which is 25
Inductive step: Suppose for a fixed n that 2n > n2 We want to show that 2n+1 >
(n + 1)2 . Multiplying the n-th case by 2, we get
2 · 2n > 2n2 ,
or
2n+1 > 2n2 .
So all we have to show is that
2n2 > (n + 1)2
for all n ≥ 5. Expanding out, this is true if and only if
n2 − 2n − 1 > 0
for all n ≥ 5. This in turn could be proven by induction or we could use the following
trick. If we add 2 to the left hand side it becomes a perfect square:
n2 − 2n + 1 > 2
In other words,
(n + 1)2 > 2
But this is true if and only if
√
(n + 1) > 2
or equivalently √
n> 2 − 1 ≈ 0.4
So it is certainly true that
2n2 > (n + 1)2
for all n ≥ 5 and so
2n+1 > 2n2 > (n + 1)2
and we have proved the inductive step. Q.E.D.
(11) Guess the number of different ways for n people to arrange themselves in a straight
line, and prove your guess is correct by induction.
ANSWER: The number of ways for n people to arrange themselves is n!. We will
see why a bit later, but all we have to do here is prove the formula by induction.
8
Base Case: The number of ways one person can arrange themselves in line is 1,
which agrees with 1!
Inductive Step: Assume that for a given n the number of ways n people can arrange
themselves in line is n. We would like to show that the number of ways n + 1 people
can arrange themselves in line is then necessarily (n+1)!. We can do this by breaking
the process in to two steps. First we line up the first n people and then we pick a
spot for the last person to go to. By the rule of independent outcomes (which we
assume you just sort of know about from common sense - we’ll see it again when we
do probability) the number of ways to do both things in sequence is the product of
the number of ways to do each separate thing. Lining up n people can be done in n!
ways by the induction hypothesis. The (n + 1)st has n + 1 places to go - either before
all the people, or after the first person, or after the second person . . . . (Technically,
we should also prove that there are n + 1 places to go by another induction, but we’ll
skip this for our sanity and since the claim is sufficiently believable). Therefore the
number of ways to arrange n + 1 people is the product of the two numbers,
(n + 1) · n! = (n + 1)!
∀xS(x) → C(x)
∃xS(x) ∧ ¬M (x)
∃xC(x) ∧ ¬M (x)
(b) Let’s prove that the third follows from the first two. We’ll go about it like the
hint says, by assuming the first two and the negation of the third (we don’t
really have to take the conjunction of the first two statements, we’ll just list
9
1. ∀xS(x) → C(x)
2. ∃xS(x) ∧ ¬M (x)
3. ¬∃xC(x) ∧ ¬M (x) 1.-3. are the assumptions we are making
4. ∀x¬C(x) ∨ M (x) by 3. and the properties of quantifiers
5. S(p) ∧ ¬M (p) for some p, by existential instantiation of 2.
6. S(p) → C(p) by universal instatiation of 1.
7. ¬S(p) ∨ C(p) by the definition of →
8. ¬C(p) ∨ M (p) by universal instatiation of 4.
9. ¬S(p) ∨ M (p) by resolution of 7. and 8.
10. ¬ (¬S(p) ∨ M (p)) by 5. and Demorgan’s Laws
This is a contradiction, since 9. and 10. are negations of each other. Therefore
if 1. and 2. hold, 3. cannot hold. Q.E.D.
(13) The following algebraic idea is central for Karnaugh maps. Karnaugh maps are a
method of minimizing the size of circuits for digital logic design.
(a) Using algebraic manipulation, prove that the two Boolean formulae below are
equivalent. (Hint: x(a + a) is equivalent to x.)
xy + yz + xz and xy + yz + xz
ANSWER: We’ll show that the two formulas have the same canonical disjunc-
tive normal form (CDNF). The formulas are already in disjunctive normal form.
The CDNF is the DNF you would get using a truth table. What distinguishes it
from DNF is that each variable in the formula must appear in each of the terms
being or’ed togther. The formulas above do not include all of the variables x, y,
z in each term. We can fix by using the trick suggested by the hint. The first
formula expands to
Now the two expanded formulas are the same up to permutation, so the original
formulas are equivalent.
10