- Answer the problems on the exam pages.
- There are four problems, each with multiple parts, for 120 total points. Actual scale was A = 110, C = 75.
- Some useful definitions precede the questions below.
- No books, notes, calculators, or collaboration.
- In case of a numerical answer, an arithmetic expression like
"2
^{17}- 4" need not be reduced to a single integer.

Q1: 30 points Q2: 20+10 points Q3: 40 points Q4: 30 points Total: 120 points

Exam text is in black, solutions in blue.

Here are definitions of some terms, sets, predicates, and statements used on this exam.

Question 1 deals with the following scenario:

Many of the dogs in my neighborhood are fans of rap music. One day a set D of four dogs: Cardie (c), Duncan (d), Rio (r), and Scout (s) met to discuss their preferences among a set R of four rap artists: Cardi B (CB), Drake (DR), Kendrick Lamar (KL), and Kanye West (KW).

Note that variables and constants with lower case letters denote dogs, and those with capital letters denote rappers. Note also that Cardie the dog is spelled differently from Cardi B the rapper.

The predicate P(x, Y, Z) means "dog x prefers rapper Y to rapper Z". Each dog's preferences establish a total order on the rappers, so that for each dog x the predicate "(Y = Z) ∨ P(x, Y, Z)" is reflexive, antisymmetric, transitive, and total.

Question 1 also refers to the following five statements, where the variables are of type "dog" or type "rapper".

The statements are:

**Statement I:**∀Y: (Y ≠ CB) → P(c, CB, Y)**Statement II:**Every dog prefers both Drake and Kendrick Lamar to Kanye West.**Statement III:**(P(d, DR, CB) → P(d, CB, KL)) ∧ ¬(P(s, KL, CB) → P(d, CB, DR)**Statement IV:**Scout and Rio each prefer Cardi B to at least one other rapper.*(Note added in test: There are two possible interpretations of this English statement. Either one may be used in Question 1, but if you see both of them you should explain in English which you intend.)***Statement V:**∃Y: ∀x: ∀Z: (Y = Z) ∨ P(x, Z, Y)

**N** is the set of **naturals** (non-negative integers, {0,
1, 2, 3,...}.

Question 2 uses a recursive function f from **N** to **N** defined by
the rules f(0) = 1, and for n ≥ 0, f(n+1) = f(n) + n^{2}
+ n - 1.

Question 2 also refers to the language L, over the alphabet {a, b,
c}, which is denoted by the regular expression (∅^{*}
+ b + bb)(a + ab + abb + acc)^{*}. Note that a similar but different
regular language is the subject of Question 3.

Question 2 also uses a recursive function g from **N** to
**N**, defined by the rules g(0) = 1, g(1) = 2, g(2) = 4, and,
for n ≥ 2, g(n+1) = g(n) + g(n-1) + 2g(n-2).

Question 3 uses the following λ-NFA N, which has state set {1, 2, 3, 4}, start state 1, final state set {1}, alphabet {a, b, c}, and transition relation Δ = {(1, a, 2), (2, λ, 1), (2, b, 3), (2, c, 4), (3, b, 1), (3, λ, 1), and (4, c, 1)}.

Here is a diagram of N, with "L" representing λ:

```
c
----------(4)
| ^
| | c
| |
V a |
>((1)) -----> (2)
^ <------ |
| L |
| | b
| |
| |
| b, L V
--------- (3)
```

**Question 1 (30):**This question deals with the scenario described above, and with the five statements about a set of dogs D, consisting of exactly the four dogs Cardie (c), Duncan (d), Rio (r), and Scout (s), and a set of rappers R, consisting of exactly the four rappers Cardi B (CB), Drake (DR), Kendrick Lamar (KL), and Kanye West (KW). Note that variables and constants with lower case letters denote dogs, and that those with capital letters denote rappers. Note also that Cardie the dog is spelled differently from Cardi B the rapper.The predicate P(x, Y, Z) means "dog x prefers rapper Y to rapper Z". Each dog's preferences establish a total order on the rappers, so that for each dog x the predicate "(Y = Z) ∨ P(x, Y, Z)" is reflexive, antisymmetric, transitive, and total.

- (a, 10) Translate each of these five statements as indicated.
**Statement I:**(to English) ∀Y: (Y ≠ CB) → P(c, CB, Y)"If any rapper is not Cardi B, then Cardie prefers Cardi B to them." That is, "Cardi B is Cardie's favorite rapper" or "Cardie prefers Cardi B to all other rappers".

**Statement II:**(to symbols) Every dog prefers both Drake and Kendrick Lamar to Kanye West.∀x: P(x, DR, KW) ∧ P(x, KL, KW)

**Statement III:**(to English) (P(d, DR, CB) → P(d, CB, KL)) ∧ ¬(P(s, KL, CB) → P(d, CB, DR)"If Duncan prefers Drake to Cardi B, then he also prefers Cardi B to Kendrick Lamar. And it is not the case that if Scout prefers Kendrick Lamar to Cardi B, then Duncan prefers Cardi B to Drake." Many people did some of the work of part (b) here, by translating the second part to "Scout prefers Kendrick Lamar to Cardi B, and Duncan does not prefer Cardi B to Drake", using the Definition of Implication and DeMorgan. This was fine, of course.

**Statement IV:**(to symbols) Scout and Rio each prefer Cardi B to at least one other rapper.*(Note added in test: There are two possible interpretations of this English statement. Either one may be used in Question 1, but if you see both of them you should explain in English which you intend.)*I thought it was pretty clear that since "each" dog preferred Cardi B to some rapper, there was no reason that those two rappers had to be the same. So I was looking for "∃Y:∃Z P(s, CB, Y) ∧ P(r, CB, Z)" which allows Y and Z to be the same rapper but does not require it. If you instead said "∃Y: P(s, CB, Y) ∧ P(r, CS, Y)", I took off a point unless you made it clear that you were interpreting the English that way.

**Statement V:**(to English) ∃Y: ∀x: ∀Z: (Y = Z) ∨ P(x, Z, Y)"There is a rapper such that for every dog and every other rapper, either the two rappers are the same or the dog prefers the second rapper over the first." Equivalently, "There is a rapper who is the common least favorite of all the dogs".

- (b, 10) Using Statement III only, along with the given
properties of the relation P, determine the truth value of
the three propositions P(d, CB, DR), P(d, CB, KL), and
P(s, KL, CB).
If we let a, b, and c denote those three propositions, we can first observe that P(d, DR, CB) is equivalent to ¬a because the relation is antisymmetric and total, and DR and CB are different rappers. So Statement III becomes "(¬a → b) ∧ ¬(c → a)". By Definition of Implication and DeMorgan, this becomes "(¬a → b) ∧ (c ∧ ¬a)". So c must be true, a must be false, and (by Modus Ponens on the first part) b must be true.

- (c, 10) Using Statements I, II, III, and IV, along
with the given properties of the relation P, prove
Statement V. You may use English, symbols, or a
combination, but make your use of quantifier proof rules clear.
A short but convincing proof in English goes like this: Because each dog's preference establishes a total order and there are only finitely many rappers, each dog must have a least favorite rapper. By Statement II, this rapper cannot be DR or KL, as all dogs prefer them over KW. We can rule out CB as the least favorite of any dog, using cases to consider each dog. Cardie prefers CB over all others, Duncan prefers her over KL, and Scout and Rio each prefer her over some unspecified rapper. So KW must be the common least favorite of all the dogs.

Here is a more traditional proof using the methodology of quantifier proofs in the text. Since the conclusion is an existential statement, our last rule will be Existence. So we must first decide for which

**rapper**Y we can prove "∀x:∀Z:(Y = Z) ∨ P(x, Z, y)". We choose to let Y be KW. (By the way, some of you showed that none of the other three**rappers**could be Y and then concluded that Y was KW, neglecting to prove that the dogs shared a common least favorite rapper at all.)**(Corrections in bold made 19 December 2019.) Now we have a Generalization proof. We let x be an arbitrary dog and let Z be an arbitrary rapper, and set out to prove "(KW = Z) ∨ P(x, Z, KW)" by cases:**- Case 1: Z = KW, proof by joining.
- Case 2: Z = KL or Z = DR, proof by Specification on Statement II.
- Case 3: Z = CB and x = c, proof by Specification on Statement I.
- Case 4: Z = CB and x = d, proof by Separation on
Statement III to get P(d, CB, KL), Specification on
Statement II to get P(d, KL, KW), and the transitivity of
P.
(Some people didn't get part (b) fully but still correctly
observed that the first part of Statement III means that
Duncan must prefer CB to
*either*DR or KL, and that either case means he prefers CB to KW by transitivity.) - Case 5: Z = CB and x = s or x = r, Specification and Instantiation on IV to get P(x, CB, Y) for some Y, then use cases on Y: Y = CB is ruled out by IV, Y = KW means we win, and Y = KL or Y = DR means we win again by transitivity using Specification on II.

**Question 2 (20+10):**This question uses the functions f and g, and the language L, defined above. The rules defining f are f(0) = 1, and for any n with n ≥ 0, f(n+1) = f(n) + n^{2}+ n - 1. The rules defining g are g(0) = 1, g(1) = 2, g(2) = 4, and for any n with n ≥ 2, g(n+1) = g(n) + g(n-1) + 2g(n-2). The language L, over the alphabet {a, b, c}, is denoted by the regular expression (∅^{*}+ b + bb)(a + ab + abb + acc)^{*}.- (a, 10) Prove by ordinary induction on all naturals n that f(n) =
(n
^{3}- 4n + 3)/3.Base Case: f(0) = 1 by the definition, and the formula says f(0) = (0

^{3}- 4(0) + 3)/3 = 1, so the statement P(0) is true. It was*not*sufficient to just say "f(0) = 1" -- you need to check against the formula.Inductive Hypothesis: f(n) = (n

^{3}- 4n + 3)/3.Inductive Goal: f(n+1) = ((n+1)

^{3}- 4(n+1) + 3)/3.Inductive Step: By the definition, f(n+1) is f(n) + n

^{2}+ n -1, which by the IH is (n^{3}- 4n + 3)/3 + n^{2}+ n - 1 = (n^{3}- 4n + 3 + 3n^{2}+ 3n - 3)/3 = (n^{3}+ 3n^{2}- n)/3 = ((n^{3}+ 3n^{2}+ 3n + 1) - 4(n+1) + 3)/3, matching the desired formula for f(n+1). We have proved P(n+1) from the assumption of P(n), completing the inductive step of an ordinary induction. - (b, 10) Prove by strong induction on all naturals n
that g(n) = 2
^{n}. Make sure that you have the correct base cases.Base cases: We need three base cases because the general rule does not tell us about g(n+1) unless n ≥ 2. We are told that g(0) = 1, g(1) = 2 and g(2) = 4. To prove the base cases, we must note that each of these three values matches the formula g(n) = 2

^{n}, since 1 = 2^{0}, 2 = 2^{1}, and 4 = 2^{2}.Strong Inductive hypothesis: g(i) = 2

^{i}for all i such that i ≤ n. In particular we will need to use the cases i = n, i = n-1, and i = n-2.Inductive Step: We must prove that g(n+1) = 2

^{n+1}. We are told that g(n+1) = g(n) + g(n-1) + 2g(n-2), and by the SIH this equals 2^{n}+ 2^{n-1}+ 2(2^{n-2}), which by arithmetic equals 2^{n+1}. - (c, 10XC) Let h(n) be the number of strings in L of length
n. Prove by strong induction for all naturals n that h(n) =
g(n). Make sure that you have the correct base cases.
Base cases: We need three base cases because we will not be able to prove anything about h(n+1) from earlier cases unless n ≥ 2. We need to show that h(0) = 1, h(1) = 2, and h(2) = 4. To do this we check the strings of these lengths in the language L. For length 0 there is only λ, for length 1 there are a and b, and for length 2 there are aa, ab, ba, and bb.

Strong Inductive Hypothesis: h(i) = g(i) for all i with i ≤ n. In particular we will need that h(n) = g(n), h(n-1) = g(n-1), and h(n-2) = g(n-2).

Inductive Step: We need to prove that h(n+1) = h(n) + h(n-1) + 2h(n-2), from which we can get (by the SIH) that h(n+1) equals the given formula for g(n+1). To prove this we need to analyze all strings in L of length n+1. Since n ≥ 2, these strings must each have a nonempty component from the language (a+ab+abb+acc)

^{*}, meaning that they end with a string from (a+ab+acc+abb). It's important that the entire string can end with such a string in only one way, so that the total number of strings is just the sum of the numbers of strings that can be made in each way, without any correction for double counting.If the string w is of the form va, then v is a string in L of length n. If w = vab, v is a string in L of length n-1. If w = vabb or w = vacc, v is a string in L of length n-2. We know that the number of strings in L of each of these lengths is h(n), h(n-1), and h(n-2) respectively, giving us the result that h(n+1) = h(n) + h(n-1) + 2h(n-2). So the strong induction is complete.

- (a, 10) Prove by ordinary induction on all naturals n that f(n) =
(n
**Question 3 (40):**This question is the usual one about Kleene's Theorem constructions, using the λ-NFA N given above.- (a, 5) Use the construction from lecture and the text to find
a λ-NFA whose language is denoted by the regular
expression (a + ab + abb + acc)
^{*}. For full credit, use the construction*exactly*, without any simplifications.We have nine states with start state 1 and only final state 9. The transitions are (1, λ, 2), (2, λ, 8), (2, a, 3), (2, a, 4), (2, a, 6),

**(2, a, 8)**, (3, b, 8), (4, b, 5), (5, b, 8), (6, c, 7), (7, c, 8), (8, λ, 2), and (8, λ, 9). I gave four points out of five for*any*λ-NFA with the correct langauge that was not isomporphic to this one (meaning, this one with possibly different node names). This includes simpler automata made by merging some or all of the a-edges into one, because these are made from different, though equivalent, regular expresssions.**(Correction in bold made 13 December 2018.)** - (b, 10) Using the construction from the text on the
λ-NFA N given above (not on your answer to part (a)),
build an ordinary NFA N' such that L(N') = L(N).
We have the same state set {1, 2, 3, 4}, the same start state 1, and the same final state {1}. (States 2 and 3 do

*not*become final according to the construction, although making them final does not change the language of the machine and does not affect the result of part (c).) The λ-moves of N are already transitive, so we don't need to add any new ones. To find the transitions of N', we look at each letter-move of N. Move (1, a, 2) gives rise to six letter moves in N', because we can get to state 1 from state 2 or 3, and go from state 1 to state 2. These six moves are (1, a, 1), (1, a, 2), (2, a, 1), (2, a, 2), (3, a, 1), and (3, a, 2). Move (2, 3, b) gives rise to itself and (2, b, 1). The other three letter moves give rise only to themselves, so we have in all six a-moves, three b-moves, and two c-moves. - (c, 10) Using the Subset Construction on N', find a
DFA D such that L(D) = L(N) = L(N').
The start state is {1}, which is final. This has an a-move to {1, 2}, which is final, and a b-move and c-move to ∅, which is non-final. State {1, 2} has an a-move to itself, a b-move to {1, 3} which is final, and a c-move to {4} which is non-final. State ∅ has all three moves to itself. State {1, 3} has an a-move to {1, 2}, a b-move to {1}, and a c-move to ∅. State {4} has an a-move and a b-move to ∅ and a c-move to {1}. We are done because each of these five states has moves only to states among these five.

- (d, 5) Find a minimal
DFA D' with L(D') = L(D). You may use the
minimization construction, or prove directly that your
D is already minimal.
Minimization construction: We divide the five states into the final states F = {{1}, {1, 2}, {1, 3}} and the non-final states N = {∅, {4}}. The behaviors of the three states in F on a, b, and c are (F, N, N), (F, F, N), and (F, F, N). So state {1} must be in its own class. The behaviors of the two states in N are (N, N, N) and (N, N, F), so these states are each in their own class. We must perform a second round of the construction on the class X containing states {1, 2} and {1, 3}. Their behaviors are now (X, X, {4}) and (X, {1}, ∅), which are different, so each of the five states is in its own class. Hence D was already minimal.

Direct proof: We can separate {1} from {1, 2} by the string a, {1} from {1, 3} by the string cc, and {1, 2} from {1, 3} by the string cc. We can separate ∅ from {4} by the string c. Since each pair of final states, and each pair of non-final states, can be separated, the DFA is minimal. (Here "separating states x and y by string w" means that w takes one of the two states to a final state and the other to a non-final state.)

- (e, 10) By using the State Elimination
construction on either D or D', find a regular
expression for
L(N). (In fact, L(N) is the language of the regular
expression from part (a) of this question, so you
have a correct regular expression already, but I want
the one from the construction, which will probably be
more complicated.)
We begin by adding a new start state i, with a transition {i, λ, {1}), adding a new final state f with λ-moves from the three final states, and eliminating the death state ∅. (The latter requires adding no new moves.

We eliminate state {4}, creating the single new move ({1, 2}, cc, {1}).

We could now eliminate any of the three remaining intermediate states. I think it is easiest to eliminate {1, 3}, creating three new transitions ({1, 2}, bb, {1}) (which merges to create ({1, 2}, bb + cc, {1})), ({1, 2}, ba, {1, 2}) (which merges to create ({1, 2}, a + ba, {1, 2})), and ({1, 2}, b, f) (which merges to create ({1, 2}, λ + b, f).

Now we can eliminate {1} and create four new moves: (i, a, {1, 2}), (1, λ, f), ({1, 2}, (bb+cc)a, {1, 2}) (which merges to create ({1, 2}, a+ba+bba+cca, {1, 2}), and ({1, 2}, bb+cc, f) (which merges to create ({1, 2}, λ + b + bb + cc, f).

Finally, eliminating {1, 2} gives us the regular expression

λ + a(a + ba + bba + cca)

^{*}(λ + b + bb + cc).

- (a, 5) Use the construction from lecture and the text to find
a λ-NFA whose language is denoted by the regular
expression (a + ab + abb + acc)
**Question 4 (30):**Identify each of the following fifteen statements as true or false. There are two points for each correct answer, with no explanation needed or wanted. Note that there is no penalty for guessing. Some of these statements refer to terms defined at the beginning of the exam. sheet.- (a) In the scenario of Question 1, define the function h from
D to R so that h(x) is dog x's favorite rapper. Then, given
Statements I-V, the function h is neither onto nor one-to-one.
TRUE. Statement V says that there exists a rapper who is the least preferred by every dog, which means this rapper cannot be the favorite of any dog. Statement II by itself implies that KW cannot be the favorite of any dog. Thus the function h is not onto. Since its domain (D) and its codomain (R) are the same size, h is onto if and only if it is one-to-one. So it is not one-to-one either. The statements do not suffice to tell us

*which*two dogs have the same favorite, but this has to happen because four dogs are choosing favorites from a set of three rappers. - (b) Let x be a natural number that is congruent to 3
modulo 4 and is congruent to 5 modulo 6. Then x must be congruent
to 23 modulo 24.
FALSE. 11 is a counterexample. This appears to be an attempt to use the Chinese Remainder Theorem, ignoring the requirement that the moduli be relatively prime (4 and 6 are not).

- (c) Let p be any prime number and let x be any positive
natural. Then there exists a natural e such that p
^{e}divides x and p^{e+1}does not divide x.TRUE. Let e be the number of times p occurs in the prime factorization of x (which must exist by the Fundamental Theorem of Arithmetic). Then p

^{e}is a factor of x but p^{e+1}is not. It is important that e is allowed to be 0, to cover the case where p is not a factor of x at all. - (d) Let G be the directed graph made from the λ-NFA
N above by ignoring the edge labels and merging parallel edges.
Then G is not strongly connected.
FALSE. There is a path from 1 to 2 to 4 to 1 to 2 to 3 to 1. We can get from any node to any other node by following this path. So the graph

*is*strongly connected. - (e) Let H be an undirected graph with node set {1, 2, 3,
4, 5, 6} and an edge between nodes i and j if and only if i + j is
odd. Then H is a bipartite graph.
TRUE. If there is an edge between i and j, one of the numbers is odd and the other even. So we can partition the nodes into odd and even, and be sure that no edge goes from odd to odd or from even to even.

- (f) There exists a labeled undirected graph G, with
positive integer edge weights, a start node s, a goal node g, and
an admissibile and consistent heuristic function h for g, such
that the path found by an A
^{*}search from s with goal node g is shorter (has smaller total cost) than the path found by a uniform-cost search from s with goal node g.FALSE. Both A

^{*}searches (with proper heuristics) and uniform-cost searches find an optimal path, and all optimal paths have the same total cost or they wouldn't be optimal. The advantage of A^{*}search is that it may find an optimal path more quickly than uniform-cost search does. - (g) Let G be any undirected graph with n nodes, where n
> 0. Then G is a tree if and only if for every node x of G,
the DFS tree of any depth-first search of G from x contains
exactly n-1 tree edges and no back edges.
TRUE. Since a tree is connected, the DFS will find all the nodes and will need to put all n-1 edges in the tree in order to do so (as each node other than the start node is found through a separate edge). If there are n-1 edges in the DFS tree and no other edges, then this tree is equal to the original graph, has n nodes and contains all the nodes.

- (h) Consider a game with a finite game tree, where each
leaf is labeled as a win for White or Black and each internal node
is labeled as to whether White or Black moves next from that
node. Then one of the two players has a winning strategy, and
there is an algorithm to determine which, given the entire tree as input.
TRUE. This is the Game Determinacy Theorem from the text. The algorithm marks every node of the game tree, starting from the leaves, as a winning position for either Black or White. When it marks the start node, it has the answer as to which player has the winning strategy.

- (i) Let X and Y be two languages over the alphabet {0, 1}.
Then is it possible that Y is regular, X ⊆ Y, and X is not
regular.
TRUE. If Y is Σ

^{*}, which is regular, X could be*any language at all*, including a non-regular langauge like Paren. - (j) The language of the regular expression ab + ba, where
the alphabet is {a, b}, has exactly five Myhill-Nerode equivalence
classes.
TRUE. Representatives of the classes are λ, a, b, ab, and aa. The string ba is equivalent to ab, and every string w except for λ, a, b, ab, and ba four of these is equivalent to aa, because wx is not in the language for any string x.

- (k) For every two-way DFA M, there exists a regular
expression R such that L(M) = L(R).
TRUE. It is proved in the text that the langauge of any 2WDFA has finitely many Myhill-Nerode classes, and thus must be regular.

- (l) Let X and Y be any languages with X ⊆ Y. If Y is
Turing recognizable, then X must be Turing recognizable but may
not be Turing decidable.
FALSE. For example, X could be &Sigma

^{*}, which is TD and therefore TR, and Y could be*any language at all*, including a non-TR language such as L_{BS}. - (m) A language X is Turing recognizable if and only if
both X and its complement are Turing decidable.
FALSE. This is a garbled version of the TR-TD Theorem, which says that the language is TD if and only if both it and its complement are TR. It is true that if X is TD, both X and X-bar are TR. But the other half of the garbled version is false. For example, the langauge L

_{BS}-bar is TR, but neither it nor its complement is TD. - (n) An ordinary one-tape Turing machine, as originally
defined in the text, may move more than one space on its tape in a
single step.
FALSE. It moves exactly one step left or right, unless it halts and does not move at all.

- (o) The set of descriptions of DFA's that have non-empty
languages is Turing decidable.
TRUE. The question is whether a Turing machine could take the description of a DFA as input and determine whether the DFA has a non-empty language. It has a non-empty language if and only if there is a path in the DFA's diagram from the start state to any final state. This can be determined by a DFS or BFS of the diagram's directed graph starting from the start state. Since an algorithm can solve this general problem, getting the correct solution for any DFA, by the Church-Turing thesis a TM could be designed to solve this problem.

- (a) In the scenario of Question 1, define the function h from
D to R so that h(x) is dog x's favorite rapper. Then, given
Statements I-V, the function h is neither onto nor one-to-one.

Last modified 19 December 2018

- (a, 10) Translate each of these five statements as indicated.