CSCI (Math) 361
|
Due Date | To Turn In: | To Do On Own: | Solutions: |
---|---|---|---|
9/11 | L&P: 1.4.1b | Annotate chapters of Jones w/ errata from course web page. | Solutions |
9/13 |
|
A. Let g: A -> B be surjective (onto) and suppose A is countable.
Show B is also countable. L&P: 1.5.8 |
Solutions |
9/16 |
|
L&P: 1.5.7, 1.5.9 | Solutions |
9/18 | L-P: 1.5.2, 1.5.6 | L&P: 1.5.1, 1.5.3, 1.5.5 | Solutions |
9/20 | Jones: 2.1 Hint: use a stack -- and write and test the program in a higher-level language first! In the high-level language define a list data structure that supports operations cons, hd, and tail -- and no fair using recursion - that makes it too easy! When you are done convert your program to our while language -- though you can use abbreviations we developed in class like if-then-else to make your life simpler. |
Write a program in the while language to compute the "and" of two boolean values. That is, your program should take as input (X.Y) where X and Y are elements of {true,false} (or rather their encodings) and it should output the encoding of true or false as appropriate. I don't care what the program returns if one or more of X and Y fails to be a boolean value. | Solutions |
9/23 | Jones: 2.5 Hint: Let C stand for the while loop in the reverse program. Prove by induction on n, that for all k, if Y = (e1,...,ek) and X = (d1,...,dn) before executing C, then Y = (dn,...,d1,e1,...,ek) and Y = nil after C has finished executing. For example, the base case is when n = 0, and hence X = () = nil = false according to our abbreviations. Once you have finished proving the above claim, then it should be easy to finish the proof that reverse does what it is supposed to. |
Jones: 2.3, 2.4, A. On page 34 of Jones is a program to calculate the sum of two numbers. Write WHILE programs to calculate the product of two numbers, and another to calculate the first number raised to the second number power, i.e, AB. Feel free to use procedures computing already known functions (like addition). |
Solutions |
9/25 | On page 41 of Jones, it is stated that no variable is allowed to occur twice in a pattern. Give an example of a case statement where one variable occurs twice in a pattern and show why the translation given in class (and in the text) is incorrect. That is give an example (for example one involving the pattern (X.X)). Give the translation of the case statement to the WHILE language (though you can use if-then-else, but not case). Finally, explain why that translation does not give the expected behavior. | Translate the program in Example 2.3.2 on page 40 into the WHILE language (where you are allowed to use IF statements). Your translation should be exactly the translation that would be obtained using the translation described on pages 41 and 42 of the text. A freehand translation is not acceptable. | Solutions |
9/27 | Define a compiling function from the WHILE language with if-then-else
to the pure WHILE language. The definition of the WHILE language with
if-then-else is obtained by adding an extra clause in Definition 2.1.3.
Add to the end of the definition of Commands the line: | if E then C else DThe compiling function should be defined on all Programs of this language. You will have to define it separately first for expressions (a trivial recursive function based on the clauses in the definition of expressions), then for commands (where the translation of commands different from if-then-else are trivial), and finally for programs. See the definition of concrete syntax for WHILE in Figure 3.1 for an example of a definition by recursion on expressions, commands, and programs. |
Extra Credit: Design a compiler in the WHILE language with if-then-else and case statements that compiles this extended language to the pure while language. This program should operate on the concrete syntax for WHILE (exended as necessary to include concrete syntax for if-then-else). | Solutions |
9/30 | Rewrite the program to add two numbers so that it only uses a single variable. | Write the tlrep and consrep functions defined on page 63 of Jones. | Solutions |
10/2 | Jones: 4.3. | The handout distributed in class stated invariants for the evaluation
of expressions and commands run in the interpreter. Show by induction
that the invariant holds for all expressions. That is, show the following
for all expressions E of the WHILE language:
Suppose p evaluates E in store [v1 -> d] to e and suppose initial values of Cd, St, V1 are (E.Cd'), S, and d before evaluation of E. Then eventually, new values will be Cd', e.S, and d. |
Solutions |
10/7 | Jones: 5.1, parts 2, 4, and 5 only | Show that there exists a fixed program, p0 such that determination of whether [[p0]](d) terminates for d in D is undecidable. I.e., find a program p0 such that {d in D | [[p0]](d) terminates} is undecidable. | Solutions |
10/9 | Jones: 5.3 (Do NOT use Rice's Theorem. Prove it directly as we did with the problem involving acceptance on nil.) | Prove that it is undecidable whether there exists an input to a given program for which it halts and writes nil. I.e., show the set {p in WHILE-programs | there is a d, such that [[p]](d) = nil} is undecidable. Do NOT use Rice's Theorem. | Solutions |
10/11 | Jones: 5.13, 5.14 Note: The order referred to in 5.14 is the order given in Lemma 5.7.1 | Jones: 5.8. | Solutions |
10/21 | L+P: 1.7.2c, 1.7.4ab | L+P: 1.7.3, 1.7.5, 1.7.6 | Solutions |
10/25 | L+P: 1.8.3ab, 2.1.3ad, 2.1.4a(i,ii) | L+P: 1.8.2abcd, 1.8.5abcd, 2.1.1, 2.1.2abc, 2.1.3bc | Solutions |
10/28 | 2.2.2b, 2.2.3ac | 2.2.1ab, 2.2.2a, 2.2.4, create ndfa accepting (a ∪ b)*ab+(aaa ∪ aba)b* | Solutions |
10/30 | 2.2.6, create dfa accepting (a ∪ b)*ab+(aaa ∪ aba)b* | 2.2.7, 2.2.9b, 2.2.10 | Solutions |
11/1 | 2.3.3, 2.3.6ag, 2.3.11a | 2.3.1, 2.3.2, 2.3.5, 2.3.6f | Solutions |
11/4 | 2.3.7b | 2.3.4b,2.3.7a | Solutions |
11/6 | 2.4.3ad, 2.4.4, 2.4.5a, 2.4.8ac | 2.4.2,2.4.3bce,2.4.8b | Solutions |
11/8 | 2.5.2, Find min state dfa equiv to dfa here | 2.5.1(i)(iii), both parts a and b | Solutions |
11/11 | Describe an algorithm to determine, given M1 and M2, if L(M1) and L(M2) are disjoint. | Solutions | |
11/13 | 3.1.3ab, 3.1.5b, 3.1.7 | 3.1.2, 3.1.3c, 3.1.4, 3.1.5a, 3.1.9ad | Solutions |
11/15 | No homework because Midterm due | ||
11/18 | 3.2.2, 3.3.2b, 3.3.3 | 3.2.3, 3.2.4b, 3.3.1, 3.3.2acd | Solutions |
11/20 | 3.4.1 | Solutions | |
11/22 | 3.5.1b, 3.5.2cd, show {aibjcidj | i,j >= 0} is not a cfl | 3.5.1acd | Solutions |
11/25 | 3.5.3a, 3.7.5a | 3.7.1a | Solutions |
12/2 |
1. Design a deterministic Turing machine to accept the language {wcw |
w in {a,b}*}.
You may use a tape language as large as you like. Hint: As you move back
and forth comparing characters, remember that you can change characters on
the tape. 2. Discuss how a non-deterministic Turing machine could accept the language {ww | w in {a,b}*}. Discuss how you could modify your deterministic Turing machine from problem 1 to accept {ww | w in {a,b}*} deterministically. |
Design a deterministic Turing machine to accept the language {anbncn | n >= 0}. Hint: Use a multitape Turing machine. You may describe the computation in English rather than write the detailed transitions. | Solutions |
12/4 |
1. Design a 2 tape deterministic TM that copies the contents of the first tape
onto the second tape. Originally the read head is to the left of the first
non-blank character of the first tape. I.e., the initial configuration is
(s,Bx,B) where we have shown the contents of both tapes. The
final configuration should be (h,Bx,Bx). That is, both read
heads should be at the blank before the input. 2. Design a deterministic Turing machine that will halt at the "." for input a term of D of the form (x.y) where x and y themselves are elements of D. Example: If the input is ((0.(0.0)).(0.0)), then the TM should halt at the 3rd ".". Hint: Use a scratch tape to keep track of any extra information needed. Recall that "0" is used to encode nil on the TM and the tape alphabet includes B, 0, "(", ")", and ".". |
Solutions |