# How to replace one symbol with two on Turing machine's tape

I want to implement following algorithm on Turing machine:

rewrite binary numbers to their unary counterparts. For example: 101 will be rewritten to a string of 5 consecutive bars

But I don't know how to make the replacement "|0" -> "0||" because it requires 3 cells. Basically I want to insert additional cell or shift all cell symbols from current position to the left(right). Is there a simple way of doing it?

## 3 Answers

The way I'd do it is as follows: The syntax is from the Turing simulator I link to below. It is

[transition name],[symbol]
[next transition],[new symbol],[direction]


The actual code:

name: Binary to Unary
init: moveright2
accept: end

moveright2,_
moveright1,_,>

moveright2,0
moveright2,0,>

moveright2,1
moveright2,1,>

moveright1,_
moveleft,1,<

moveright1,0
moveright1,0,>

moveright1,1
moveright1,1,>

moveleft,_
sub1,_,<

moveleft,0
moveleft,0,<

moveleft,1
moveleft,1,<

sub1,0
sub1,1,<

sub1,1
moveright2,0,>

sub1,_
blankout2,_,>

blankout2,_
blankout1,_,>

blankout2,1
blankout2,_,>

blankout1,1
end,_,>


Basically move till you've passed two blanks(Step 1), then write a 1(Step 2), move left till you find a blank(Step 3), treat the number to the left as a binary number and subtract one from it(see below for details on how this works)(Step 4), Then repeat steps 1-4 until you can't subtract any more(in my case the subtract routine turns all 0's in the number we've been subtracting from to 1 and then hits a blank), go back turning all ones to blanks till you hit a blank, then go one farther turning that one into a blank.

It turns 101 into 11111

Subtraction routine, start at the far right of the number, if it's 0 change it to one and move left doing the same thing to each digit you come across, if it's one see step 1

• It's pretty cool how tape is used to store state. Thanks. – pusheax Apr 30 '15 at 21:06
• @pusheax Being able to store state in the tape is exactly what makes a Turing machine more powerful than a DFA. It's also what lets you write a universal Turing machine that simulates Turing machines arbitrarily large state sets. – David Richerby Apr 30 '15 at 21:07

Hint: $1101_2 = 11111111_1 * 1 + 1111_1 * 1 + 11_1 * 0 + 1_1 *1$

At each step you will erase the rightmost digit of your input. In case it's a $1$, just add (concatenate) its multiplier (already in unary) to the result. Update the multiplier, repeat.

It can be shown that allowing Turing machines the ability to insert characters in the tape doesn't increase their power. But, in this case, it's easier just to not do the replacement in-place. That is, writing - for the blank symbol, if your initial tape contents is

101------------ ...


then the result would be

---|||||------- ...

• André Souza Lemos gave me a link to this question. I just posted a question asking whether such a model has been used somewhere, by whom and under what name. Splicing squares on a Turing Machine finite tape – babou May 3 '15 at 22:15