Questions are in black, solutions are in blue.
For example, A(0) = 0, A(1) = -1, A(2) = -1 + 3 = 2, and A(3) = -1 + 3 - 5 = -3. (Note that (-1)i is 1 if i is even and -1 if i is odd.)
Find a closed-form formula for A(n) (a simple expression with no summation)
and prove it correct for all n by induction. (It is possible to do this either
by ordinary or by odd-even induction.)
The closed form is A(n) = (-1)nn. We let P(n) be the statement
that A(n) = (-1)nn. For the base of
of the inductions, we prove P(0) by noting that A(0) is the empty sum 0, and
that (-1)00 evaluates to 0.
For the inductive step of the ordinary induction, we assume P(n), that
A(n) is (-1)nn, and try to prove P(n+1), that A(n+1) is
(-1)n+1(n+1). By definition, A(n+1) is A(n) plus (-1)n+1
(2(n+1)-1), or A(n+1) plus (-1)n+1(2n+1). By the IH, A(n) is
(-1)nn = -(-1)n+1n = (-1)n+1(-n).
Plugging into our expression for A(n+1), we get (-1)n+1[-n+(2n+1)]
which is (-1)n+1(n+1), as desired.
Several people got the expression and the base case right, but then offered
an inductive case that never used the definition of A, and thus never expressed
A(n+1) in terms of A(n).
The odd-even induction works as follows. We prove for all even n that A(n)
= n. This is proved above for n = 0. To prove P(n+2) from P(n), we express
A(n+2) as A(n) - (2n+1) + (2n+3), using the fact that n is even. This reduces
to A(n) + 1, and since the IH says that A(n) = n, we have that A(n+2) = n+2.
For odd n, we prove that A(n) = -n. We prove the base case P(1) by observing
that A(1) = -1. For the inductive case, we prove P(n+2) from P(n) by
expressing A(n+2) as A(n) + (2n+1) - (2n+3), using the fact that n is odd.
This reduces to A(n) - 2, and since P(n) says that A(n) = -n, we have that
A(n+2) = -(n+2) as desired.
If n is positive, we get b(n+1) from b(n) by concatenating "01" on the right of b(n). This is the same as shifting the number f(n) left by two places and then adding 1. Since shifting left doubles a binary number, we obtain f(n+1) by doubling f(n) twice and then adding 1, to get 4f(n) + 1.
You may choose to prove ∀n:P(n) ∧ Q(n) by ordinary induction, to prove ∀n:P(n) and ∀n:Q(n) separately by odd-even induction, or to prove both by strong induction.
I think the easiest is odd-even induction. It suffices to prove P(0), Q(1),
∀n:P(n)→P(n+2), and ∀n:Q(n)→Q(n+2). P(0) and Q(1)
follow from the facts that f(0) = 0 and f(1) = 1. For any n, part (a) tells
us that f(n+1) = 4n+1, and thus that f(n+2) = 4f(n+1) + 1 = 16f(n) + 5.
P(n) says that f(n) ≡ 0, so if P(n) is true then f(n+2) ≡ 16(0) + 5
≡ 0 and P(n+2) is true. Q(n) says that f(n) ≡ 1, so if Q(n) is
true then f(n+2) = 16f(n) + 5 ≡ 16(1) + 5 ≡ 1 (mod 5), because
16 ≡ 1 (mod 5).
The ordinary induction proves P(n+1) from Q(n) if n is odd, and proves
Q(n+1) from P(n) if n is odd, using arithmetic mod 5 and the fact that f(n+1)
= 4f(n) + 1.
The strong induction proves P(0), P(1), Q(0), and Q(1), then proves P(n+1)
from P(n-1) and Q(n+1) from Q(n-1), as above.
We need only run the Euclidean Algorithm on f(5) = 341 and f(3) = 21. Using the hint, we observe that 341 = 16(21) + 5. Then 21 = 4(5) + 1, and because we have reached 1 we have proved that 341 and 21 are relatively prime.
We carry out the inverse algorithm by writing each of the numbers in the Euclidean Algorithm as a linear combination of 341 and 21. We write 341 = 1(341) + 0(21), 21 = 0(341) + 1(21), 5 = 1(341) - 16(21), and 1 = 21 - 4(5) = -4(341) + 65(21). So we take x to be 65 and y to be -4.
When we apply the Euclidean Algorithm to f(n+1) and f(n), we first divide f(n+1) by f(n). By the result of part (a), it goes into f(n+1) four times with a remainder of 1. So the next pair of numbers in the Euclidean Algorithm are f(n) and 1, and since we have reached 1 we have proved that f(n+1) and f(n) are relatively prime. (The only way this would not work is if f(n) were 0, which is why we require n to be positive.)
Since we proved 341 and 21 to be relatively prime in part (c), the Chinese
Remainder Theorem tells us that there exists an integer c such that
x satisfies these two congruences if and only if x ≡ c (mod 7161). (Here
7161 = 341(21), though you were not required to multiply this out.)
Furthermore, we can obtain the number c. The quick way to do this is to
notice that c = 42 works, since all we need is any number that is congruent
to 42 both mod 21 and mod 341. If we don't notice this, we can follow the
proof of the CRT (and use the inverses from part (d), and let c be
(42 times 341 times -4) + (42 times 21 times 65). Of course this is
42 times (341(-4) + 21(65) = 42, using the equation found in part (d).
If w is a string of letters, we define the score of w by two rules:
Here are your questions:
As suggested, we let u be arbitrary and use string induction on v. The base
case is v = λ, and in this case the score of cat(u,λ) is the
score of u by the definition of the cat function, and this equals the score
of u plus the score of λ because the latter is 0 by the definition of
score.
For the inductive case, we let a be an arbitrary letter, let v be an
arbitrary string, assume P(v) (that score(cat(u,v))
= score(u) + score(v)) and
set out to prove P(va) (that score(cat(u,va)) = score(u) + score(va).
By the definition of cat, score(cat(u,va)) = score(cat(u,v)a). By the
definition of score, this is score(cat(u,v)) + lab(a). By the IH, this is
score(u) + score(v) + lab(a) = score(u) + [score(v) + lab(a)] which is
score(u) + score(va) by the definition of score. We have proved P(va) from
P(v) for arbitrary v and a, completing the string induction.
scoreOf
that
takes a string w and returns the score of w. You may assume that a method
lab
has already been defined as above. Do not worry about error
handling, such as for invalid characters in w.
public natural scoreOf (string w)
{// Returns Scrabble score of w as defined by lab
if (w == emptystring) return 0;
return scoreOf(allButLast(w)) + lab(last(w));}
For the base case, we must show that the method returns the score of λ,
which is defined to be 0, on input λ. This is true because the third
line of the code checks for w = λ and returns 0 if it is.
For the inductive case, we let v be an arbitrary string, let a be an
arbitrary letter, and assume that scoreOf(v)
terminates and
returns the correct score of v. Given these assumptions, we consider what
happens when scoreOf
is called with input va. We reach the last
line, compute allButLast(va)
to be v and last(va)
to
be a, and then return scoreOf(v) + lab(a)
. By the IH, this is
the correct score of v plus lab(a), and by the definition of score this is
the correct score of va. So scoreOf(va)
returns the correct
answer and we have completed the string induction.
Last modified 3 April 2006