CMPSCI 250: Introduction to Computation

David Mix Barrington

Spring, 2005

Homework #4 Questions and Answers

Question 4.5, 24 March 2005

In 4.6.4, what if x=2 and y=1? The definition says that RP(2,1) = RP(1,1) = true, but if I run the EA on 2 and 1 the first line is "2%1 = 0" and my output is not 1. Doesn't this contradict what I'm supposed to prove in part (a)?

You are right about RP(2,1) = 1 but wrong about the EA. The output of the EA is the last nonzero number to appear in the sequence. Since the sequence starts with the two inputs, and in this case (or any case when the second argument is 1) we create no new nonzero numbers, the output of the EA is 1 as (a) says it should be.

Question 4.4, 23 March 2005

On 4.7.5 again, may I use "predecessor" on naturals? I don't see how to reach a base case otherwise.

Yes, you may use predecessor. I meant to say that you may use all the basic operations on naturals and strings.

Question 4.3, 22 March 2005

I'm working on Exercise 4.4.1 for practice and I'm confused by the solution. Where do you suddenly get the term "n2/10 + 47"?

You're right, I should have spelled out this solution more completely. The statement P(n) is "n2/10 > 47n". After proving P(471), we want to prove the ordinary inductive step "P(n) → P(n+1)". So we assume that n2/10 is greater than 47n, and try to prove that (n+1)2/10 is greater than 47(n+1). Since 47(n+1) is equal to 47n + 47, and the IH tells us that n2/10 is greater than 47n, we know that n2/10 + 47 is greater than 47(n+1). So all we need to do is to prove that (n+1)2/10 is greater than n2/10 + 47, because then we can use the transitivity of ">" to say that (n+1)2/10 is greater than 47(n+1). The Exercise solution goes on to do this by showing that (n+1)2/10 is greater than n2/10 + 2n/10, and then that 2n/10 is greater than 47.

So we have (n+1)2/10 > n2/10 + 2n/10 > n2/10 + 47 > 47n + 47 = 47 (n+1). The IH is used for the last ">" in this sequence. Remember that when you have a sequence of terms connected by ">"'s, "≥"'s and "="'s, you may conclude that the first term is greater than or equal to the last term. And if there is at least one ">" in the sequence, you may conclude that the first term is greater than the last term.

Question 4.2, 21 March 2005

In Problem 4.7.5, the pseudo-Java definition of charAt, the problem does not clearly state if functions other than successor and append may be used. May I use "last" and "allButLast"?

Yes, you may, sorry. This function should look like the ones in section 4.7.2 for length, cat, and rev.

Question 4.1, 20 March 2005

I'm confused about Problem 4.4.1 -- are you sure it works with $4 and $11 bills? I wrote a computer program to look for a solution and didn't find one.

I'm not sure what your program was looking for but the problem is formulated correctly. Actually given any two denominations that are relatively prime, you can make any amount greater than some starting point. In the example in lecture, we had $2 and $5 bills and we could not make $3 with them, but we could make $4 and all larger amounts. Once the amount gets large enough, there are lots of possibilities, for example:

With these four examples, it's not hard to construct a proof by strong induction that every number of dollars that is 100 or more can be made with $4 and $11 bills. (If P(n) is "$n can be made", the inductive step "P(n) implies P(n+4)" is easy.) What you need to do is to find the largest number that cannot be made (it's less than 100) and prove by induction that every number after than point can be made.

Last modified 24 March 2005