CMPSCI 601: Theory of Computation

David Mix Barrington

Spring, 2004

This page is for student questions and my answers related to HW#1. Questions are in black, answers in blue.

Question 1.20, 17 February 2004

Can you explain to me the difference between the "depth" and the "length" of an SLP? I am confused on this.

The length is the total number of instructions.

The depth is defined for each instruction. Inputs have depth 0, instructions that only access inputs have depth 0, instructions that only access inputs of depth 1 have depth 2, and so on. The formal definition is given in the hw assignment itself -- the depth of an instruction is one greater than the maximum depth of one of its inputs.

For example, let's look at two SLP's that each compute the AND of four variables:


y_1 = x_1 AND x_2
y_2 = y_1 AND x_3
y_3 = y_2 AND x_4
return y_3

y_1 = x_1 AND x_2
y_2 = x_3 AND x_4
y_3 = y_1 AND y_2
return y_3

Each of these SLP's has length 3. But the first one has depth 3, and the second has depth 2 -- can you see why?

Question 1.19, 17 February 2004

Just a couple of quick questions concerning Bloop: I am not allowed to do recursions, right? This means from within a function I am not allowed to call that same function again?

That is right. In principle you could replace all the function calls by in-line code using new variables, and everything would be statements and for loops.

What about exiting a function prematurely using return? Is something like this > possible:


 declare foo(x,y) {
   for(x) {
     if (y) return z;
   }
   return a;
 }

You should argue, as I did for "if", that adding this feature doesn't change the language because you can implement it with "if" and a new variable.

Oh, yes, and I am assuming I can use the enriched version of Bloop, meaning that I have an if-then statement and that I can use a function instead of a variable ( if(foo(y)) B; ), that I can assign 0, and that I can also use the functions we already defined in class?

Yes, though make sure you either use these features only as defined or justify any new features you add.

Question 1.18, 16 February 2004

In page 15 of lecture 1 in the decalration of mult(x,y) it is written "for (x) add(z,y);".

But I feel that instead it should be "for(x) z = add(z,y)" as all function calls are by value.

You are right, thank you. I should also mention another error in the lecture notes, though it probably doesn't come up on this homework. As I mentioned in lecture, I twice misstate the theorem about CFL's and regular languages. The correct statement is that if A is a CFL and B is regular, then the intersection of A and B is a CFL.

Question 1.17, 16 February 2004

With respect to question #7, is it true that saying "a<b" is saying that a is immediately to the left of b or can a be any place to the left of b?

Saying "a< b" means that a could be anywhere to the left of b. To say "immediately to the left of" is more complicated but you have the tools to say it.

Question 1.16, 15 February 2004

I have trouble with question #4 of the homework #1. Specifically, if the SLP should have length O(n), what is n supposed to be here? The length of the input string?

Yes.

In that case, I run into trouble, I think. My proof for question 1 (using truth tables and DNF) suggest an SLP of length O(2^n) in the number of inputs, and also another proof involving induction I have thought of comes down to an SLP of length O(2^n). Is there a better way to do it?

Note that the "n" in question 1 may not be the "n" in question 4, depending on how you apply question 1 to solve question 4.

On the other hand, if it was that simple we would not even need a DFA and Kleene, because any language with a fixed string length can be directly converted into a truth table and therefore we have an SLP with length O(2^n) for it.

Right, question 1 tells you that this SLP exists but I definitely want a shorter one!

But I was thinking about other ways to do it - after all, a regular language must have a finite number of equivalency classes (but this is not Kleene, but Myhill-Nerode...), therefore the size of the DFA is independent of the input length, and I am probably able to find an SLP that is equivalent to that DFA (well, I hope). But then the length of the program would not be dependent on the input length at all, and the n in O(n) would mean the number of equivalency classes?

Usually the single most useful fact about a regular language is that a DFA exists for it. This DFA has O(1) states, that is, a constant independent of n.

Did you solve the exactly-two-ones problem with an O(n) length SLP? If so, your solution might show you how to get an O(n) length SLP from an arbitrary DFA.

Question 1.15, 14 February 2004

A quick procedural question about question 8:

Is a state-transition diagram of the PDA sufficient "description", or do you insist on full 7-tuple definition and listing of \Delta?

A diagram is considered to be a complete description of a DFA, assuming it is completely specified. For example, you would get docked for having no arrows out of a death state, or not indicating a start state.

Question 1.14, 13 February 2004

What's this "+" sign in regular expressions in the homework?

As I think I mentioned in lecture, it's a common alternate notation for the "union" sign, so that the language R(S+T) is the union of the languages R(S) and R(T) (where S and T are regular expressions).

Question 1.13, 13 February 2004

I'm having a lot of trouble getting started on Question 7, making the first-order formula for (0+01)*. Can you give me some kind of hint?

Sure. The place to start is with the example in Lecture 1 of the formula for strings with exactly two ones. Read in English, it says "there exist positions x and y such that x is not equal to y and for any position z, z has a one if and only if z is either x or y".

You have a property of strings: "w is the concatenation of zero or more strings, each of which is either 0 or 01". You need to re-express this property in terms that you know how to translate into first-order logic. This is going to mean statements about positions existing or not existing, or things being true for all positions. Your atomic formulas can talk about positions being equal, or one being left or right of another (less than or greater), or about there being a one or a zero in a position. That should get you started.

Question 1.12, 13 February 2004

I wondering if there is a standard procedure for looking for all possible equivalence classes for a certain language. For the homework question, I just came up with a DFA, and look around to see if i can minimize it somehow (is there a some standard procedure to minimize a DFA? I seem to recall you said there is....I could be wrong). If it seems to be mininum then I just call the states in this DFA my equivalence classes. Lastly, I try to varify that by adding random strings to the end of the equivalence classes to see if there are any that are actually the same....

There is a formal procedure called "state minimization", described by Sipser in Exercise 7.35, that takes any DFA and produces the smallest DFA with the same language.

This doesn't seem very formal to me. Is there a better way, e.g. I can easily come up with a DFA for a language, and if there are some standard procedure to minimize that into a minimum DFA then I can just take the minumum DFA and call its states the equivalence classes without going through the proofs.

But your problem is simpler. You have a DFA that you think is minimal, and you want to prove that it is minimal so that the languages corresponding to its states (the language {w: δ*(q0,w) = qi} for each state qi) are the Myhill-Nerode classes.

The way to do this is to show, for each pair of your states, that they cannot be merged to get a correct DFA. We did this in lecture with the DFA for divisibility by seven, showing for each i and j that there was a string taking qi to final and qj to nonfinal.

Given two of your states, you can probably see a reason why they should not be merged. From this you can find a string w such that w takes one of the states to a final state and the other to a non-final state. (For example, if one of your two states is final and the other non-final already, choose w to be the empty string.)

for the hw, we can just do this on scrap paper, right? meaning, we don't need to explain why these are all the equivalence classes like that "div by 7" example you gave in class, right?

You should justify your claim that you have the right equivalence classes, by naming for each pair of classes a string that distinguishes them. In the example in lecture we did this by a single argument, but in this example the simplest thing is probably just to name a string for each pair, e.g., "my states s and t are different because of the string '01'". The correct number of states is small enough that this will not be burdensome.

Question 1.11, 13 February 2004

In Question 8, does "e" denote the empty string?

No, sorry, it's meant to be a terminal letter, so that the set of terminals for this grammar is {a,b,c,d,e}. This was perhaps a bad choice of notation on my part.

If it is, I don't see how the fourth rule adds anything to the language.

Again, it's a terminal. But if you replaced all the "e"'s by "ε"'s, then the fourth rule would add something to the language, because it would be the only rule that could get you to a string with no nonterminals. In that case, though, the third rule would become "S --> S", which doesn't add anything.

Question 1.10, 12 February 2004

I was wondering about bloop: > Is there a reason you would assign a number this way:

y = one();

as opposed to this way:

y = 1;

I don't have a symbol for "1" in the language, so "y = 1;" would be an abbreviation for "y = one();" or if you like "y++;" if y hasn't been mentioned before.

I ask because on slide 15 from lecture one, you have:


    y = one();
but on slide 16 you have:

    y = 0;

Under the strict rules for the language I should have said "y = zero();" or "y = z;" where z is a new variable.

Is it that zero is allowed, but not positive integers?

For any particular number you can write a function that just returns that number. In this exercise you're just trying to show that a particular function _exists_, so that anything you can show to exist you can use to show the existance of someone else.

Question 1.9, 12 February 2004

I'm looking for a name for a boolean expression like "p OR NOT p" that is always false. I've been using "false tautology" but I'm not sure that's right.

It isn't, though if you had defined it to mean that on your homework we would have been happy. More standard terms are "contradiction", "negation of a tautology", or "unsatisfiable formula".

Question 1.8, 10 February 2004

Must homework submissions be typeset, or is handwritten all right?

Handwritten is fine. If the grader has trouble reading your handwriting, or if the submission is too disorganized, etc., we'll let you know.

But I should point out that the default rule is no email submissions. It may be primitive, but I've found a stack of papers to be a much more robust way to keep a large set of submissions that has to be passed around among two graders and an instructor.

If you cannot attend a lecture but want to hand in your homework, I'd prefer that you email it to a friend, then have them print it and hand it in, so we don't have to deal with some paper and some electronic submissions.

Question 1.7, 8 February 2004

In HW 1 Question 4, can we take it as given that a regular language over an arbitrary alphabet can be represented by a regular language over {0,1}? This way, to show that any regular language can be decided by an SLP we can simply show it for binary regular languages.

I should have said "any regular language over {0,1}", sorry. But if you pick an encoding of the letters as binary strings all of the same length, then as you say the regular language over the larger alphabet encodes as a regular language over {0,1}, by the result about closure under forward homomorphism.

Also, in saying that a regular language L can be decided by an SLP do you mean to say that one SLP decides L, and that all strings that belong to L can be fed into that SLP? Or could it be that there are different SLP^s for, say, different length strings, such that for all strings that belong to L there is always at least some SLP that can decide its membership.

There is a separate SLP for each input length, something I should have emphasized more in lecture. For the moment, we are not worrying about whether the different SLP's for different lengths have anything to do with each other.

Good questions!

Question 1.6, 6 February 2004

In the proof for question 1, can we assume that any (fixed finite) Boolean function can be represented by a truth table, and that those in turn can be translated into logical expressions in disjunctive normal form?

Truth table yes, CNF and DNF you need to justify.

It would remain only to show that DNF expressions can be implemented in SLP^s. While this simplifies the proof almost unfairly, it seems we should be allowed to bring in some conclusions about truth tables when working with Boolean functions.

You essentially prove that a truth table exists by describing it. We'll do this in lecture 5, but for now you need to argue (using truth tables if you want) that CNF and DNF exist if you want to use them in constructing the SLP.

Question 1.5, 5 February 2004

On question 3, you write "Can you get depth O(log n)? Depth O(1)?" Are you saying that those are the correct depths, or are you saying that we should search for SLPs in question 2 that have those depths as well as the lengths specifed in question 2? At the moment, both of my SLPs from question 2 appear to have depth O(n).

I am not saying what is possible, only asking you to try and get depth within those bounds. If you form an opinion that one or both of these goals can't be achieved, give me an argument for it.

If you have to pay for the improved depth with a worse length, then do it -- that's a potentially interesting question.

Open-ended questions like this at the end of an exercise often wind up as being in effect extra-credit questions. But you should think about the problem and give the best answer you can.

Question 1.4, 4 February 2004

Slide 21 on Lecture 3 asks us for an example of two strings that are PAL-equivalent without being equal. This is easy if the alphabet has only one letter, but I can't see how to do it otherwise.

This is because I made a mistake. If the alphabet has at least two letters, any two distinct strings u and v are PAL-inequivalent. If the longer string is u, its length is n, and its last letter is a, then you can check that taking w = bnuR guarantees that uw is a palindrome and that vw is not. Sorry!

Question 1.3, 4 February 2004

It would make my life easier if I had an equality operator in Bloop, so I could say "if (x==y) B" instead of just "if (x > 0) B". I don't see how to synthesize this with the given operations. May I have it for free?

No, you have to synthesize it. As a hint, you first want the "monus" operation, where monus(x,y) is x-y if x is at least as big as y, and zero otherwise. This is easy once you build a "decrement" function that subtracts one from any positive number. Decrement is similar to the example of if in the lecture -- you want to loop x times, incrementing y on every time through the loop except the first.

Question 1.2, 3 February 2004

I had a question about [your answer to Question 1.1 below]

The person asking the question was planning to do induction on k, with a base case of 2. You said to use a base case of 1. Why would the base case not be 2? It seems like since AND and OR are binary operators (that could operate on one variable), you would need a base case of 2 to generalize to the inductive step.

It might be that in doing the work to show that all binary functions (k=2) can be done with AND, OR, and NOT, you are also doing the work to get from an arbitrary k to k+1 even if k is as small as 1.

If you do an induction starting with k=2, look back at your induction step and see whether the assumption that k >= 2 was ever used. If not, a base of k=1 would do as well and be less tedious to prove -- that's all that I'm saying.

You're right that in proving the base case of k=1 you can't use AND or OR on two different variables, though functions like x_1 AND (NOT x_1) still come up.

Question 1.1, 1 February 2004

Hi Prof. Barrington--

In a rare moment of anti-procrastination, I'm trying to get an early start on the first 601 homework...and I have a question about the first problem.

Very virtuous of you, congratulations.

My question is, what can I take as axiomatic? e.g. can I take it as given that an SLP can compute all boolean functions f(x_1,x_2), or do I need to prove that? If I do need to prove that, is there a better way than exhaustively listing all 8x2 possible functions and constructing them from AND, OR, NOT, x_1, and x_2?

You _do_ need to prove that one way or the other, and starting at k=2 does mean that there are 16 cases. Listing the 16 boolean expressions would be fine, I think, rather than 16 explicit SLP's.

I think induction on k is the way to go here, and I think I can prove the inductive step given the k=2 step...

Induction is definitely the way to go*, but if you could work out how to make k=1 your base case you would save work. When you get your inductive proof you should see whether this is possible.

Hoping this isn't a dumb question,

It isn't. You get to start the Q&A file for HW#1.

Footnote: my "definitely" here is too strong, as there are ways to do it starting with "let k be arbitrary" that are perfectly valid.

Last modified 17 February 2004