-- Please post your practice midterm solutions to this thre
Originally Posted By: jnewth
Problem 7. Briefly explain how the amortized shifting works in our O(TLogT) universal TM simulation.
The amortized shifting is presented in the notes of September 12. It is presented as an improvement over the T^2 universal TM presented on pg 20-21 of the book. The T^2 UTM is summarized here:
Given a 3-tape (input, output, work) TM M, we can simulate each step of this machine using our 5-tape UTM. One of the extra UTM work tapes stores some representation of M's transition function and the other extra work tape acts as a register to store the current state of M. Thus, to simulate one step of M, we read the current state of M from the worktape, we scan the transition function on the other worktape, then update M's worktape and output tape as required. Each step of M takes C steps of UTM (the steps taken to scan the transition function are constant and the steps taken to update the register worktape are constant). But wait! It appears that if the runtime of M is T, then the runtime of UTM is C*T! The thing to remember is that the original TM may have been some other type of TM that was transformed in to the familiar 3-tape representation. This transformation may have introduced a quadratic slowdown, so we bound the UTM's operation with C'T^2.
The motivation for the amortizing shifting UTM is as follows. We can imagine a k-tape TM that we wish to simulate using our UTM. We can do this by expanding the alphabet of our UTM such that for each unique set of squares over the k-tapes we have a unique symbol in our UTM alphabet (pg 29). When you think about it, representing these 5 tapes as 5 tapes or as 1 tape are equivalent - it's just where you write the symbols. The problem is that in the k-tape machine we can assume k heads as well! But because it's easier to think of the tapes as separate, think of them as separate tapes that are all connected. Now, we can still move our k-tapes, but they have to move all together because they are connected. To simulate the independent motion of each tape, we will define a shift operation. This is pretty easy to describe. Let's pretend that we are going to move tape 1 to the right by 1 square with respect to the rest of the tapes. We would just have to index over all the squares of tape 1 from right to left, at each square writing each symbol to the next rightmost position. This would then make the symbols on the tape appear to have moved by 1 square with respect to the rest of the tapes, right?
The important thing is that we can still shift each tape's symbols with respect to the tape by this shift operation (shift as repeated copying and pasting). If you do the analysis, this still runs in O(T^2), because for each time we want to move a single square, we might have to move the whole string of symbols! The idea then is to write our sequence of symbols on each tape in such a way that when we have to move a single square, we can only bump a few symbols over, rather than the entire string of symbols.
The zones achieve this. By writing our symbols in zones, we leave spaces (which are not "blank" - the book uses squares with x's in them) so that we can shift symbols in to those spaces as needed.
Let's not worry about the analysis right now. Let's just make sure we understand how the shift operation would work. Please turn to page 31 of the book for the picture.
Following the steps of "Performing a shift":
1. We identify the smallest io such that Rio is NOT empty (meaning it's either full or half full). In our case, we are performing a left shift of tape 1, so that means R2 is the first first non-empty zone (because it contains "ly"). We shift "l" to position 0, and then we go to step 2. Because R2 is the highest non empty zone, this shift operation has INDEX=2.
2. Shift the rest of the lower half of zone R2 in to R0 and R1. This is possible because R2 = 8 squares. R1 = 4 squares, and R0 = 2 squares. If R2 was completely full, that means we need to relocate the top half of R2 in to the bottom half of R2, and then put the bottom half of R2 in to R1 and R0, without violating our "empty, half or completely full" rule for the zones. We take the four bottom squares of R2, put one square in to position 0, one in to the bottom half of zone 1, and two in to the bottom half of R1.
3. We then have to do the same shift operation on the left side of the tape, but again enforcing the notion that you only consume half the squares of a zone.
So now this looks like a lot of work to just move one square. Have we gained anything? Well, yes. Now that we moved something involving index 2, the next 2^i - 1 shifts will only use the zones 0 and 1, which obviously take a lot less work (I think half as much).
The analysis is a bit involved, but essentially:
Each zone represents 2^(i+1) squares.
To shift a zone of index i is proportional to the total size of the zones. The summation in the notes says sum from 0 to i for 2*2^i. In our case we calculate
number of shifts ~ 2*(2^0 + 2^1+ 2^2) = 14. This works out. For R2, we have to shift 4 elements. For R1 we have to shift 2. For R0 we just shift 1. And then we have to do the left side. I think we might be missing a constant in here, but that's going to drop out anyhow. So our shift operation is O(2^i) operations.
The final summation over k tapes for our worst case index and worst case number of shifts is on page 32 as O(T log T).
'''Originally Posted By: jnewth'''
Problem 7. Briefly explain how the amortized shifting works in our O(TLogT) universal TM simulation.<br><br>The amortized shifting is presented in the notes of September 12. It is presented as an improvement over the T^2 universal TM presented on pg 20-21 of the book. The T^2 UTM is summarized here:<br><br>Given a 3-tape (input, output, work) TM M, we can simulate each step of this machine using our 5-tape UTM. One of the extra UTM work tapes stores some representation of M's transition function and the other extra work tape acts as a register to store the current state of M. Thus, to simulate one step of M, we read the current state of M from the worktape, we scan the transition function on the other worktape, then update M's worktape and output tape as required. Each step of M takes C steps of UTM (the steps taken to scan the transition function are constant and the steps taken to update the register worktape are constant). But wait! It appears that if the runtime of M is T, then the runtime of UTM is C*T! The thing to remember is that the original TM may have been some other type of TM that was transformed in to the familiar 3-tape representation. This transformation may have introduced a quadratic slowdown, so we bound the UTM's operation with C'T^2.<br><br>The motivation for the amortizing shifting UTM is as follows. We can imagine a k-tape TM that we wish to simulate using our UTM. We can do this by expanding the alphabet of our UTM such that for each unique set of squares over the k-tapes we have a unique symbol in our UTM alphabet (pg 29). When you think about it, representing these 5 tapes as 5 tapes or as 1 tape are equivalent - it's just where you write the symbols. The problem is that in the k-tape machine we can assume k heads as well! But because it's easier to think of the tapes as separate, think of them as separate tapes that are all connected. Now, we can still move our k-tapes, but they have to move all together because they are connected. To simulate the independent motion of each tape, we will define a shift operation. This is pretty easy to describe. Let's pretend that we are going to move tape 1 to the right by 1 square with respect to the rest of the tapes. We would just have to index over all the squares of tape 1 from right to left, at each square writing each symbol to the next rightmost position. This would then make the symbols on the tape appear to have moved by 1 square with respect to the rest of the tapes, right?<br><br>The important thing is that we can still shift each tape's symbols with respect to the tape by this shift operation (shift as repeated copying and pasting). If you do the analysis, this still runs in O(T^2), because for each time we want to move a single square, we might have to move the whole string of symbols! The idea then is to write our sequence of symbols on each tape in such a way that when we have to move a single square, we can only bump a few symbols over, rather than the entire string of symbols.<br><br>The zones achieve this. By writing our symbols in zones, we leave spaces (which are not "blank" - the book uses squares with x's in them) so that we can shift symbols in to those spaces as needed.<br><br>Let's not worry about the analysis right now. Let's just make sure we understand how the shift operation would work. Please turn to page 31 of the book for the picture.<br><br>Following the steps of "Performing a shift":<br><br>1. We identify the smallest io such that Rio is NOT empty (meaning it's either full or half full). In our case, we are performing a left shift of tape 1, so that means R2 is the first first non-empty zone (because it contains "ly"). We shift "l" to position 0, and then we go to step 2. Because R2 is the highest non empty zone, this shift operation has INDEX=2.<br><br>2. Shift the rest of the lower half of zone R2 in to R0 and R1. This is possible because R2 = 8 squares. R1 = 4 squares, and R0 = 2 squares. If R2 was completely full, that means we need to relocate the top half of R2 in to the bottom half of R2, and then put the bottom half of R2 in to R1 and R0, without violating our "empty, half or completely full" rule for the zones. We take the four bottom squares of R2, put one square in to position 0, one in to the bottom half of zone 1, and two in to the bottom half of R1.<br><br>3. We then have to do the same shift operation on the left side of the tape, but again enforcing the notion that you only consume half the squares of a zone.<br><br>So now this looks like a lot of work to just move one square. Have we gained anything? Well, yes. Now that we moved something involving index 2, the next 2^i - 1 shifts will only use the zones 0 and 1, which obviously take a lot less work (I think half as much).<br><br>The analysis is a bit involved, but essentially:<br><br>Each zone represents 2^(i+1) squares. <br>To shift a zone of index i is proportional to the total size of the zones. The summation in the notes says sum from 0 to i for 2*2^i. In our case we calculate<br><br>number of shifts ~ 2*(2^0 + 2^1+ 2^2) = 14. This works out. For R2, we have to shift 4 elements. For R1 we have to shift 2. For R0 we just shift 1. And then we have to do the left side. I think we might be missing a constant in here, but that's going to drop out anyhow. So our shift operation is O(2^i) operations.<br><br>The final summation over k tapes for our worst case index and worst case number of shifts is on page 32 as O(T log T).