Questions are in black, answers in blue.

There are five questions for 120 total points.

When your answer to a problem is a particular number, you may use
exponents, falling exponents, factorials, and/or the "choose" notation
to indicate the number. However, if the answer is *less than 100*,
you must give the number in ordinary decimal notation for full credit.

Many of the questions involve the following three regular languages
over the alphabet {a,b,c}.
The language X is denoted by the regular expression
a^{*}b^{*}c^{*}, the language Y is denoted by the
regular expression a^{*}b^{*}, and the language Z is denoted
by the regular expression a^{*}.

**Question 1 (30):**

In this problem we will construct, in a roundabout way, a DFA whose language is X.

- (a,5) Using our construction carefully and using the given regular expression,
give a λ-NFA whose language
is X. Your answer should have twelve states and satisfy the rules of the construction.
Whoops, I made a mistake -- there are only ten states. States are {1,...,10}, start state is 1, only final state is 10. There are three letter moves: (2,a,3), (5,b,6), and (8,c,9). Then there are λ-moves from 1 to 2, 2 to 3, 3 to 2, 3 to 4, 4 to 5, 5 to 6, 6 to 5, 6 to 7, 7 to 8, 8 to 9, 9 to 8, and 9 to 10.

- (b,5) Give a smaller λ-NFA whose language is X. (The fewer states
you have, the easier the remaining parts of this problem will be. It is possible to
have only three states.)
States {1,2,3}, start state 1, final state set {3}, λ-moves 1 to 2 and 2 to 3, a-loop on 1, b-loop on 2, and 3-loop on 3.

- (c,10) Give an ordinary NFA (with only letter moves) whose language is X, built
from your answer to (b).
Letter move (1,a,1) causes itself, (1,a,2), and (1,a,3).

Letter move (2,b,2) causes (1,b,2), (1,b,3), itself, and (2,b,3).

Letter move (3,c,3) causes (1,c,3), (2,c,3), and itself.

State 1 becomes final so the new state set is {1,3}.

- (d,10) Using the subset construction and your answer to (c) or otherwise, give
a DFA whose language is X.
Start state is {1}, a-move to {1,2,3}, b-move to {2,3}, c-move to {3}.

{1,2,3} has a-move to itself, b-move to {2,3}, c-move to {3}.

{2,3} has a-move to ∅, b-move to itself, and c-move to {3}.

{3} has a-move and b-move to emptyset, c-move to itself.

∅ has a-move, b-move, and c-move to itself.

All the states except ∅ are final.

Minimization would merge the states {1} and {1,2,3} to get a four-state DFA.

**Question 2 (15):**
These questions involve the language Q = {a^{i}b^{j}c^{i+j}:
i,j ≥ 0}.

- (a,10) Does there exist a DFA whose language is Q? Prove your answer.
There does not exist such a DFA, because Q has infinitely many Myhill-Nerode equivalence classes. We can demonstrate this by giving an infinite set of strings that are pairwise Q-distinguishable. Such a set is {a

^{i}: i≥0}. If u = a^{i}and v = a^{j}where i≠j, we can let w = c^{i}and then uw is in Q (because i+0=i) and vw is not in Q (because j+0≠i). So these two strings are Q-distinguishable and the given set is pairwise Q-distinguishable. - (b,5) Describe (informally) how a Turing machine could be designed to decide
whether its input string is in Q.
The Turing machine can first check that the string is in a

^{*}b^{*}c^{*}and reject if it is not. Then it returns to the left of the string and repeatedly carries out the following: Delete the first a or b, move to the right of the string, delete the final c, and move to the left again. If it has the empty string left when it has finished a pair of deletions, it accepts. If it has only a's and b's or only c's left, it rejects.

**Question 3 (20):**
Prove the following statements, carefully explaining your use of quantified proof
rules. The languages Y and Z are defined above. The type of variables u, v, and w
is "string over {a,b,c}" and the type of the variable n is "natural".

- (a,10) ∃u:∀v:(v∈Y→vu∈(Z-Y)). (The minus sign denotes
set subtraction.)
Whoops, another mistake, I meant "Y - Z" instead of "Z - Y" -- the statement as given is not true.

Let u be the string "b", let v be arbitrary, and assume that v is in Y. Then v must be a

^{i}b^{j}for some naturals i and j, possibly zero. The string vu is then a^{i}b^{j+1}. This string is in Y because it is a string of zero or more a's followed by a string of zero or more b's. It is not in Z because it contains the letter b and no string in Z contains the letter b. So it is in Y - Z, and we have completed a direct proof of the implication. Since v was arbitrary, we have proved ∀v:(v∈Y→vb∈(Y-Z). Since we found a u that worked, we have proved the entire statement. - (b,10) ∀u: (u∈Y)→[∀n:∃v:∃w:
(|w|≥n)∧(w∈Y)∧(uv=w)]. (Here |w| denotes the number of letters in
w. Hint: Let u be arbitrary and then use induction on n.)
Let u be arbitrary and assume that u is in Y. Let k be the length of u. If n≤k we can prove the desired statement by letting v be λ and letting w be u -- then |w| = k ≥ n and w is in Y by the assumption on u. We prove the statement for all n with n ≥ k by induction. The base case of n = k is already proved as part of the case with n ≤ k. Assume that we have strings v and w making the statement true for a particular value of n. Let v' = vb and let w' = wb. Then uv' = w', w' is in Y, and |w'| = |w| + 1 ≥ n + 1 by the IH. This completes the induction and thus proves the statement for all n. This proves the implication, and since u was arbitrary we are done.

**Question 4 (20)**:
This question involves certain boolean statements. For any positive natural n,
we define a compound statement P_{n} using the boolean variables
x_{1},...,x_{n}. P_{1} is the statement "1" or "true".
For n>1, P_{n} is defined recursively, as P_{n-1}∧
(x_{n-1}→x_{n}).

- (a,10) Prove, using propositional rules or a truth table, that P
_{3}implies the statement "x_{3}∨¬x_{1}".P

_{3}is the statement "(x_{1}→ x_{2}) ∧ (x_{2}→ x_{3}). Assume that P_{3}is true. We prove the desired statement by cases. If x_{1}is false, the desired statement follows by left joining. If x_{1}is true, x_{2}follows by modus ponens from the first implication of P_{3}(which is true by left separation). Then x_{3}follows by modus ponens from x_{2}and the second implication of P_{3}, which is true by right separation. Both cases make the conclusion true, so we have proved the conclusion from the assumption of P_{3}. - (b,10) Prove that for any positive natural n, if P
_{n}is true and x_{n}is false, then all the variables are false. (Hint: Use induction on n, with care for the base case.)The base case is n=1, and P

_{1}is the constant "true". Clearly in this case if x_{n}= x_{1}is false, all the variables are false because there is only one variable.Now assume as IH that if P

_{n}is true and x_{n}is false, then all the variables (x_{1}through x_{n}) are false. Assume that P_{n+1}is true and that x_{n+1}is false. By the definition of P_{n+1}, we know that P_{n}and (x_{n}→ x_{n+1}) are both true. Then x_{n}must be false, because otherwise the new implication would make x_{n+1}true and we know that it is false. So P_{n}is true and x_{n}is false, and the IH tells us that all the first n variables are false. Since the last variable is false, all n+1 variables are false and we have proven the n+1 case of the statement and completed our inductive step. - (c,15) Let r(n) be the number of settings of the variables x
_{1},..., x_{n}that make P_{n}true. (This is the number of rows in the truth table for P_{n}that have a one for the entire statement.) Prove that for all positive naturals n, r(n) = n+1.Since we are doing induction on positive naturals, the base case is n=1. Since P

_{1}is "true", all settings of one variable make it true and r(1) = 2. Since 2 = 1 + 1 is the desired answer, we have proven the base case.Now assume that r(n) = n+1 and examine the case of n+1 variables.For P

_{n+1}to be true, P_{n}and (x_{n}→ x_{n+1}must both be true. If x_{n+1}is true, then the last implication is definitely true and the whole statement is true if and only if P_{n}is. This, by the IH, happens in r(n) = n+1 settings of the first n variables. If x_{n+1}is false, by the result of part (b) we know that all the variables must be false to make P_{n+1}true. This gives us one more setting making it true, for n+2 in all. We have shown that r(n+1) = n+2, completing the inductive step.

**Question 5 (20)**:
Let f(n) be the number of strings of length n in the language X defined above.
Let g(n) be the number of strings of length n in Y, and let h(n) be the number of
strings of length n in Z.

- (a,5) Find the value of f(4) and find a general formula for f(n). (Hint:
This is a case of one of the four basic counting problems.)
The general solution is an instance of the fourth counting problem, since there is only one correct order for a given multiset of letters. We have n choices from three possible letters, so the solution to the fourth problem gives us (n+2 choose 2). In the case of n=4 the total is (6 choose 2) or 15.

- (b,5) If we choose a string of length n over the alphabet {a,b,c} at random,
with all strings being equally likely, what is the probability that the string is in
X? What is this value when n=4?
There are 3

^{n}strings of length n in all, so the probability is (n+2 choose 2)/3^{n}. In the case of n=4 this is 15/81 or 5/27. - (c,10) Give a combinatorial proof that for any positive natural n,
f(n) = f(n-1) + g(n-1) + h(n-1).
Let w be an arbitrary string in X of length n, where n is an arbitrary positive natural. Let u be the first n-1 letters of w. If the last letter of w is an a, then u must be in Z, and if u is any string in Z of length n-1, then ua is in X. If the last letter of w is b, then u is in Y, and if u is in Y, then ub is in X. If the last letter of w is c, then u is in X, and if u is in X, then uc is also in X. We have divided the length-n elements of X into three disjoint subsets. One bijects with the elements of Z of length n-1, one with the elements of Y of length n-1, and the third with the elements of Z of length n-1. By the Sum Rule and the definitions of the three functions, we have that f(n) = f(n-1) + g(n-1) + h(n-1).

Last modified 17 December 2004