Q1: 35 points Q2: 35 points Q3: 40 points Q4: 20 points Total: 130 points
Question text is in black, solutions in blue.
Checking special cases, we find the f(0) = 0, f(1) = 1 - 0 = 1, f(2) =
2 - 1 = 1, f(3) = 3 - 1 = 2, and f(4) = 4 - 2 = 2. The key
observation is that for any natural n, f(n+2) = (n+2) - f(n+1) =
(n+2) - ((n+1) - f(n)) = 1 + f(n). Given this observation we can
complete the proof for odds and evens easily:
Odd n: Base case -- we observe that f(1) = 1 = (1+1)/2. As IH,
assume that f(n) = (n+1)/2. Then f(n+2) = f(n) + 1 = (n+1)/2 + 1
= (n+3)/2 = ((n+2)+1)/2. So P(n) → P(n+2) and we have a
proof for all odd n.
Even n: Base case -- we observe that f(0) = 0 = 0/2. As IH,
assume that f(n) = n/2. Then f(n+2) = n/2 + 1 = (n+2)/2. So P(n)
→ P(n+2) and we have a proof for all even n.
Single ordinary induction proof using proof by cases: Let P(n) be "if n is even,
then f(n) = n/2, and if n is odd, then f(n) = (n+1)/2". For the
base case, P(0) is clearly true because 0 = 0/2 and 0 is even.
Assuming P(n), we prove P(n+1) by cases. If n is even, f(n) = n/2
and by the definition of f, f(n+1) = (n+1) - n/2 = 1 + n/2 = (n+2)/2.
In this case P(n+1) is true because n+1 is odd and f(n+1) =
((n+1)+1)/2.
If n is odd, f(n) = (n+1)/2 and by the definition of f, f(n+1) =
(n+1) - (n+1)/2 = (n+1)/2. Thus P(n+1) is true because n+1 is even.
natural g (natural n) {
if (n == 0) return 0;
return n + g(n/2);}
where "/" is Java integer division, with no remainder, so that for
example "7/2" is 3. Prove that for all positive naturals n, the
method terminates on input n and outputs a number g(n) which is less
than 2n. (You should use strong induction.)
For strong induction on all positive numbers, the only base case we
need is that g(1) = 1 + g(0) = 1 + 0 = 1. To have a look at the
behavior of g, we can compute g(2) = 2 + 1 = 3, g(3) = 3 + 1 = 4, g(4)
= 4 + 3 = 7, and g(5) = 5 + 3 = 8, noting that in all cases (except
n = 0 which we have ruled out), g(n) < 2n.
For the strong induction we assume Q(n) ↔ ∀m: (1 ≤ m ≤
n) → g(m) < 2m. Given an arbitrary natural n+1, we need to prove
P(n+1),
that g(n+1) < 2(n+1). The definition tells us that g(n+1) = n + 1 +
g((n+1)/2). If (n+1)/2 = 0, we are in one of the special cases above
and we know that P(n+1) is true, Otherwise, we know that 1 ≤
(n+1)/2 ≤ n and we can assume P((n+1)/2), so we know that
g((n+1)/2) < 2((n+1)/2) ≤ n + 1. (Note that we cannot be sure that
2((n+1)/2) = n + 1 because of the Java integer division.) Thus we
have that g(n+1) = n + 1 + g((n+1)/2) < n + 1 + (n+1) = 2n + 2 and we
have
proved P(n+1) and completed the strong induction.
Many students observed (but did not prove) that in general g(n) = n
+ n/2 + n/4 + ... (where the "/"'s are Java integer division, which is
certainly no larger than n + n/2 + n/4 + ... (with real-number
division) = 2n. But you still need to prove this formula for g(n) by
induction, and also that the sum for g(n) is strictly less than
2n. For this last point you can observe that once 2i
becomes greater than n, the Java-division n/2i is zero
while the real-division n/2i is a real number between 0 and
1 -- thus the Java-division sum is strictly smaller.
Compute the string h("cardie").
h("cardie") = h("idrac")"e" = h("ardi")"ce" = h("dra")"ice" =
h("rd")"aice" = h("r")"daice" = h(λ)"rdaice" = "rdaice".
Most of the wrong answers on this one failed to continue the
recursion beyond the first application of h.
Prove that for any string w, h(w) is a string whose length is the same as the length of w. (You can use either induction on strings or ordinary induction on the length of w.)
By ordinary induction on the length of w: Let P(n) be "for all strings
w of length n, |h(w)| = |w|". (Here "|u|" denotes the length of
the string u.) For the base case of n = 0, λ is the only
string of length 0 and we are given that h(λ) = λ
and thus that |h(λ)| = |λ|. As IH, we assume
P(n).
Consider an arbitrary string w of length n+1 and write w as va
where v is a string of length n and a is a letter. By the
definition of h, h(va) = h(vR)a. By the IH, since
vR is a string of length n, we know that
|h(vR)| = n and thus that |h(w)| = n + 1 = |w|.
Since w was arbitrary, we have proved P(n+1) and completed the
induction.
String induction is complicated by the fact that if we set
P(w) to be "|h(w)| = |w|", the truth of P(va) depends not on
P(v) but on P(vR). We need "strong induction on
strings", where we assume that P(u) holds for all u shorter than
w, and then prove P(w). The inductive step for this proof is
exactly the same as in our first proof above.
Any customer who orders bean sprouts also orders tofu.
(R(w, b) ∨ R(k, b)) ∧ ¬R(k, t)
The parentheses around the first two terms are necessary.
Any two customers are similar if and only for any vegetable, the first customer orders that vegetable if and only the second customer did.
We must prove that S is reflexive, symmetric, and transitive. (Some
of you tried to prove that S is antisymmetric, which it isn't -- it
is certainly possible for two different customers to each be similar
to the other, if they order the same set of vegetables.)
Reflexive: We must prove ∀c: S(c,c) which translates to
∀c:∀v:R(c,v) ↔ R(c,v). We let c and v be
arbitrary and note that R(c,v) ↔ R(c,v) is a tautology.
Symmetric: We must prove ∀c:∀c': S(c,c') →
S(c',c). Let c and c' be arbitrary customers and assume S(c,c'),
which translates to ∀v:R(c,v) ↔ R(c',v). We need to
prove S(c',c) which translates to ∀u:R(c',u) ↔ R(c,u).
Let u be an arbitrary vegetable and specify the first statement to
u. This tells us R(c,u) ↔ R(c',u) which is equivalent to what
we want.
Transitive: We must prove ∀c:∀c':∀c'':
[S(c,c') ∧ S(c',c'')] → S(c,c''). Let c, c', and c'' be
three arbitrary customers and assume S(c,c') and S(c',c''). We must
prove S(c,c'') which translates to ∀v: R(c,v) ↔
R(c'',v). Letting v be an arbitrary vegetable and specifying the translations of S(c,c') and S(c',c'') to v,
we get that R(c,v) ↔ R(c',v) and that R(c',v) ↔ R(c'',v),
from which R(c,v) ↔ R(c'',v) follows by the transitivity of
↔. We have completed the proof that S is transitive and thus
completed the proof that S is an equivalence relation.
The easiest argument is to use the construction from lecture to get a
regular expression for L(M). We don't need to add a new start or
final state because M already meets the conditions to be an
r.e.-NFA. We kill state 3 and change the label on the loop at 2
from a to a + b(a+b). We then kill state 2 and get the final
regular expression (a+b)(a + b(a+b))*, which is
equivalent to R by the distributive law. By the correctness of this
construction, L(M) = L(R).
If we argue the two directions of the equivalence separately, we
must first show that any string in L(R) is also in L(M). To see
this, we note that any string in L(R) is an a or b followed by zero
or more strings in a + ba + bb. The first string can take M from
state 1 to 2, the following strings can each take M from 2 to 2, and
when the string is over we can take the λ-move to state 4 and
accept.
But we still have to argue that L(M) ⊆ L(R). Any accepting
path in M goes from 1 to 2, takes zero or more loops at 2, and then
goes on λ to 4. So the string read consists of an a or b,
followed by zero or more strings, each of which is a, ba, or bb.
Any such string is clearly in L(R).
The only λ-move is from 2 to 4, so we need only add a
letter-move to 4 coresponding to every letter-move to 2. Thus we
add five new transitions: (1,a,4), (1,b,4), (2,a,4), (3,a,4), and
(3,b,4), to go with the six letter-moves from M.
Many people formed an ordinary NFA by eliminating state 4 and
making state 2 final. This is a valid ordinary NFA (in fact a DFA)
with the correct
language, but since the question said "using the construction from
lecture" this answer received only partial credit.
Using the correct answer to (b), we get a nonfinal start state {1}
with moves on a or b to the final state {2,4}. Then {2,4} has an
a-move to itself and a b-move to the nonfinal state {3}. State {3}
has both an a-move and a b-move to {2,4}, completing the construction
with three states.
The second answer to (b) mentioned above is a DFA, so the Subset
Construction does not change it. You got full credit on (c) for
noting this, but only partial credit for just repeating the DFA with
no explanation.
The three-state DFA from (c) is not minimal. Forming class N from states {1} and {3}, we see that both states in this class have both a-moves and b-moves to class F (which has only the state {2,4}). We thus may form a two-state DFA with states N and F, start state N, final state set {F}, and transitions (N,a,F), (N,b,F), (F,a,F), and (F,b,N). By the correctness of the minimization construction, this DFA is minimal. (There couldn't be a one-state DFA for this language anyway as it is neither equal to ∅ or to Σ*.)
The DFA D'' is identical to D' above except that the final state set becomes {N} instead of {F}. Clearly for any string w, δ*(N,w) is the same state in both DFA's, so D'' accepts w if and only if D' does not.
We must add two new states, a start state S and a final state E -- we add transitions (S,λ,N) and (N,λ,E) and make the final state set {E}. We first kill state F, making a loop on N with label (a+b)a*b. Finally we kill state N, making the final regular expression ((a+b)a*b)*.
There is no such regular expression. By Kleene's Theorem, such a regular expression exists if and only if there is a DFA whose language is X. By the Myhill-Nerode Theorem, this is true if and only if the relation of X-equivalence on strings has a finite number of equivalence classes. But we can construct an infinite set S of pairwise X-distinguishable strings, proving that the set of equivalence classes is infinite. Let S = {λ, a, aa, ...} = {ai: i a natural}. Let i and j be two arbitrary naturals with i ≠ j. We must prove that the strings ai and aj are X-distinguishable, which we may do by taking z to be the string cai. Then aiz = aicai is in X, while ajz = ajcai is not because the strings ai and aj are not anagrams.
Let the tape alphabet of our Turing machine by {a, b, c, d, _, y, n} where _
is the blank character. Our TM first sweeps the tape to check
that the input has exactly one c -- if there is no c or more than
one c it rejects. Then, as long as it can, it enters a loop where
in each time through the loop it:
If this process ends after a complete phase with no a's or
b's on the tape, the TM accepts. If it fails to find an a or b
in step 1, or if it fails to find a matching letter in step 3,
it rejects. Here "accept" means "clear the tape and write a y"
and "reject" means "clear the tape and write an n". Since we
have defined a TM that halts on any input, and accepts if and
only if the input is in X, we have proved that X is Turing decidable.
Last modified 22 December 2010