CMPSCI 601: Theory of Computation

David Mix Barrington

Spring, 2003

These are questions and answers concerning homework assignment #2. Questions are in black, answers in blue. Most recently answered questions are listed first.

Question 2.9, 28 Feb 2003

You said below in your answer to Question 2.6 that Bloop has recursive function calls. But can't I use recursion to create an infinite loop, for example defining f(n) to be f(n+1)?

Aak! You're quite right, and I spoke stupidly. Bloop programs are supposed to always halt. Functional definition and thus functions calls cannot be recursive -- you must define the functions in some order and only make calls to a function already defined. I apologize for the confusion.

Question 2.8, 24 Feb 2003

On Question 2 part (c), are the "both alleged bijections" referred to meant to be the functions rho and P?

Yes, sorry if that wasn't clear.

Question 2.7, 24 Feb 2003

For question 4, part a, could you give a more rigorous definition of "enumerated in increasing order" ? For example, if a TM M, on input epsilon, continually wrote b1b (where b = blank) to the tape, erased it, then wrote it again, would it be enumerating the sequence 1, 1, 1, ... or just a single 1? I understand that E(M) = {1}, but the definition of the "order of enumeration" is a bit fuzzy. I guess all that I want to know is whether "increasing order" means strictly increasing or monotonically increasing order (it seems like it'd have to be defined as strictly increasing to make the proof work...) Thanks.

Sorry, I meant to say "in strictly increasing order", so that each number is strictly larger than the previous number. Of course, if I enumerate a finite set in strictly increasing order I have to stop somewhere, and normally enumerators run forever. So I'm restricting the problem to deal only with infinite sets, as I should have at the beginning. It now says "prove that if S is infinite, then S is recursive iff S is enumerable in strictly increasing order".

Question 2.6, 24 Feb 2003

The syntax for Bloop and Floop isn't terribly clear. What is the scoping of variables? Can blocks of code be parameters to functions? Hofstadter defines a bunch of other constructs in his book, may I use them? How do I handle recursive function calls?

I admit I haven't defined things in anything like a rigorous manner, and I apologize. (In general I will tend to be sloppy with definitions in cases where small changes in the definition don't change the results, but I go too far with this, I admit.) As to the specific questions:

Question 2.5, 17 Feb 2003

I've succeeded in solving Question 3b, implementing "if" with bounded loops. But I'm having trouble with the first item of 3a. Can we have an equality test or a greater-than test for free?

No, I want you to use bounded loops, addition, and multiplication to implement "equals". (Then you can use an equals test as the boolean argument of if statements, for example.) This is not trivial, so here's a hint. It's useful to first implement the "minus" function, where minus(x,y) is x-y if x > y and 0 otherwise. And a good step on the way to this is the "decrement" or "--" function: decr(x) is x-1 if x > 0, and 0 otherwise. This can be done with bounded loops, addition (actually just "++"), and "if".

By the way, make sure that your implementation of "if" doesn't inherit the scope restrictions from the bounded loop. For example, when you say "if x then P else Q", you'd really like to be able to modify the value of x in either P or Q. So you don't want P or Q to be inside a "loop x times", because then you wouldn't be allowed to touch x.

Question 2.4, 15 Feb 2003

Another quick question -- with FlooP, are you allowed bounded loops as well (ie: the same kind of loops allowed in BlooP)? If you are to ever "break" out of one (part c), it would seem you'd have to... Thanks, again!

I should be able to define the free loop syntax so that you can simulate bounded loops with it, but since I seem to need bounded loops to simulate an "if" and I seem to need an "if" to do this simulation, it's much easier to just give you bounded loops in Floop although it makes (c) pretty easy...

I'll fix the assignment so that Floop has _both_ kinds of loops, thanks.

Question 2.3, 15 Feb 2003

Since we show in Question 3b how to simulate an "if" statement using Bloop, is it OK to use the "if" construct in answers to other parts of Question 3 as a convenience and to improve understandability or is it necessary to simulate the "if" statement each time we wish to use an "if" in question 3?

This is a good question. Yes, use the construct! We want your Bloop and Gloop programs to be readable and understandable. Any constructs you develop (which are actually "macros" that some sort of a compiler could unwind) are helpful to improve the readability and understandability and should be used whenever possible.

It's the same as the way we now describe Turing machine algorithms -- we say "copy this part of the tape over to here" rather than talk about the states needed to do that, for example. > > Thanks, > Brian >

Question 2.2, 15 Feb 2003

For the Bloop language, what are valid values for the loop counter to take on? For example, is "loop cell(0) times P" valid for negative or zero values for cell(0)?

A variable can't be negative because I said that they range only over the "numbers", which means "non-negative integers". (I added a reminder of this to the HW#2 assignment.) If cell(0) is 0, "loop cell(0) times P" is still valid as long as P does not modify cell(0), and it does nothing.

Question 2.1, 15 Feb 2003

On HW #2, question 2, in the description of the pairing function P, I believe there is a typo. Rather than reading "... N takes numbers i and j to rho^(-1)(p(rho(i),rho(j)))," I believe that should read "... N takes numbers i and j to rho(p(rho^(-1)(i),rho^(-1)(j))).

Yes, you're right of course, I've fixed this on the HW#2 assignment, thanks.

Answers to Questions during HW#1 (through 12 Feb 2003)

Last modified 5 March 2003