This is actually a regular language. (The RE would be $1*00*11*(00*11*00*11*)*$.) You might have noticed that the TM never changes a symbol on its tape and that it processes the input on the tape in a strict left-to-right progression. In effect, all of the work is done in the TM’s controller, and that controller is a DFA.
1.2 TMs as Functions
Often we think of TMs not so much as acceptors of languages as computers of functions. The input to the function is the initial content of the tape and the output is the final content of the tape when the TM reaches an accepting state.
It shifts all of the characters on the right of its starting position one step to the left, overwriting whatever character the head was originally positioned over.
It shifts all of the characters on the right of its starting position one step to the left, overwriting whatever character the head was originally positioned over. This time, however, we made use of a couple of JFlap shortcuts:
~ denotes “any character” in input, or “whatever character was just read” in output.
characters}v denotes the “storage” of a single symbol in a “variable”. In section 8.3.1 of your textbook, this is called “storage in the state” and, while a convenient programming style for TMs, has no effect on the power of a TM to recognize variaous langauges.
Notice how it reduces the number of explicitly drawn states, by relieving us of the necessity of separately rendering “symmetric” treatment of different possible input characters.
There are a couple of bugs in JFlap 7.0 regarding the handling of stored variables. I have patched these bugs and made a repaired version of JFlap available via the CS390 library page.
1.5 TMs as Functions 4
What is the function (over the input language $\{a,b\}^*$) computed by this TM?
Answer
This is sort of a failed attempt at a palindrome generator. Given an input string over {a,b}, it places an ‘x’ at the end of the string, then writes the reverse of the input string after the ‘x’.
I consider this a “failed” attempt at a palindrome generator because we had to rewrite the input string in order to remember what parts of the input had and had not yet been processed and, of course, we introduced the artificial ‘x’ character in the middle.
It constructs a palindrome of a string over {a,b} by appending the reverse of the input string onto the end of itself.
1.6 TMs as Functions 5
What is the function (over the input language $\{a,b\}^*$) computed by this TM?
Answer
It constructs a palindrome of a string over {a,b} by appending the reverse of the input string onto the end of itself. Here we have strung together three of our previous TMs:
The “failed” palindrome generator that replaced the a’s and b’s in the original input by their upper-case equivalents and left an ‘x’ in the middle.
Our TM to convert strings over {a,b,A,B} to all-lowercase.
Our TM to shift everything to the right of our starting point one step to the left, to overwrite the ‘x’ left in the middle of the string.
Try running this one yourself on various strings over {a,b} to see that it works.
This is a good illustration of how, just as in programming, we can combine separately composed TM “functions” to achive a more complicated overall calculation.
In fact, we can be more explicit about our re-use by using another JFlap shortcut, “building blocks”. We can insert any previously defined TM as a single “state” in a new one. Here I have inserted our “shiftLeft” TM from earlier.
A building block state connects incoming transitions to the start state of the inserted TM.
A building block state connects outgoing transitions to (all) final states of the inserted TM.
2 Constructing TMs
2.1 $a^ib^i$
Construct a TM to recognize the language $\{a^ib^i | i \geq 0\}$.
Answer
There’s at least a couple of ways to handle this. One is to match characters at the opposite ends of the strings until we either run out of characters or discover characters that don’t match.
Another is to process the a and b parts left to right, using a marker character (‘x’) to indicate portions of the input that we have already processed.
Construct a TM to recognize the language $\left\{wcw | w \in \{a,b\}^*\right\}$.
Answer
In q0 we are looking at the leftmost unprocessed input. Remember it (in v), mark it as processed (overwriting with ‘x’) and start moving to the right (q`).
In q1, keep moving to the right until we hit the ‘c’, then go go q2 on ‘c’.
In q2, we move past any ‘x’ marker characters to the right of the ‘c’.
We make the transition successfully into q3 only if the first non-marker character matches the symbol we stored in v.
q3 and q4 move us left, past the c and stops at the leftmost unprocessed input.
If, from q0, we have processed all input, we will be looking at a ‘c’. If so we leave the main processing (q0 -> q5).
In q5 and q6 we make a final pass over the input to be sure that all characters were matched - there are no a’s or b’s left that were not processed.
Suppose that a tape contains an integer $k$ in unary form (i.e., a string of 1’s, where the value of the integer is the length of the string. Construct a TM to replace its input by the value of the function $f(k) = k+1$.
Answer
OK,this one is so easy that some of you may have figured it had to be more difficult than it really is.
To add 1 to a number written in unary format, we just add another ‘1’ to either end.
2.4 Unary Form Integer Addition
Suppose that a tape contains pair of integers $m, k$ in unary form separated by a single ‘x’. Construct a TM to replace its input by the value of the function $f(m,k) = m+k$.
Answer
All we need to do is to remove the ‘x’ separating the two numbers.
Again, we can use Building Blocks to simplify this slightly.
2.5 Binary Interleave
Suppose that a tape contains two strings over {0,1} of equal length, separated by an x. Construct a TM to compute the interleave of those two strings, i.e., the string formed by taking alternate symbols from each of the input strings. e.g., given the input 0101x1110, we want to get 01110110
Answer
This naturally divides into two steps. q0…q5 copy the second number to the left of the input with a ‘y’ marker between each symbol. For example, given the input 0101x1110 we get and output of y1y1y1y0 0101x at q1 just before dropping down to q6.
Then q6…q11 copy the first number, overwriting the ’y’s previously left behind.
Suppose that a tape contains pair of integers $m, k$ in conventional binary form separated by an ‘x’. Assume that m and k have the same number of binary digits. Construct a TM to compute the function $f(m,k) = m+k$.
(Hint; start with the interleave from the previous problem.)
Answer
There are lots of binary addition TMs on the internet, but most of them are quite unsatisfying. Most of them work by decrementing one number followed by incrementing the other, repeating until the first number has been reduced to zero.
I dislike that approach because it means that the TM runs in time proportional to $2^n$, where $n$ is the number of bits in the input numbers. But we know from grade-school addition that we can add numbers in time proportional to the $n$, the number of digits in the number.
This TM uses our interleave from the prior problem as a building block. q10,q11, & q12 then implement the addition of two successive bits of the number, replacing one by an ‘x’ and the other by their sum. If both numbers are a ‘1’, we shift over to q14, q15, & q16, which implement similar addition logic for the case where we have a “carry” from the addition of the lower digits.
We exit the “main logic” at q17, where we just need to find and remove all of the x’s, which we can do with our shiftLeft building block.
2.7 Binary Addition - Multitape
Suppose that a TM has three tapes with a pair of integers $m, k$ in conventional binary form on tapes 1 and 2. Assume that m and k have the same number of binary digits. Construct a TM to compute the function $f(m,k) = m+k$, writing the output to the third tape.
Answer
Much easier than trying to do this with just the one tape.
q0 shifts both input tape heads to the far right of the numbers.
q1 implements the logic of addition of binary digits where there is no “carry” from a previous step.
q2 implements the logic of addition of binary digits where there is a “carry” from a previous step.
You can see, for example, that we go to q2 from q1 when both numbers have a ‘1’.