0

I am trying to write a set of rules that copies a set of ticks, however long one space next to the original set, I have a loop which does so, however it does not stop and continues ahead and breaks the copied items.

http://i.imgur.com/8cpaYkN.png

under the cut off of the picture it should say 5 0 -> 1 Tick

This is based on the model found at: http://en.wikipedia.org/wiki/Turing_machine_examples#A_copy_subroutine

Any insight?

edit: it should halt when it reaches the middle zero between the two series of numbers, but mine keeps going.

edit:

So my program checks for a 1, if it finds it it turns it to a zero and skips the following ones until it reaches a zero, it skips the zero and the following ones (which there are none of at the start) and changes the first 0 to a 1, it then returns by skipping the ones and the zero, and then skipping the ones till it finds the first zero (the one that was changed) changes it to a one and then the program loops. It should stop when it reaches the centre zero that separates the two numbers.

It is like this.

State 1, 0 -> state 1, 0
State 1, 1 -> state 2, 1 [changes the first 1 to a 0]
state 2, 1 -> state 2, 1
state 2, 0 -> state 3, 0
state 3, 1 -> state 3, 1
state 3, 0 -> state 4, 1 (right) (goes back) [changes the first 0 to a 1]
state 4, 1 -> state 4, 1 (right)
state 4, 0 -> state 5, 0 (right)
state 5, 1 -> state 5, 1 (right)
state 5, 0 -> state 1, 1 (left) (loops) [changes the first changed 1 back]

If I do this for any sequence of ones, it will copy them, however, it will not stop the loop, and it will continue after it is finished and break the copy.

So if I input:

0 0 1 1 1 0 0 0 0 0 0.....

the rules will do the following:

0 0 1 1 1 0 0 0 0 0 0.....
0 0 0 1 1 0 1 0 0 0 0.....
0 0 1 0 1 0 1 1 0 0 0.....
0 0 1 1 0 0 1 1 1 0 0.....
0 0 1 1 1 0 1 1 1 0 0.....

(it is now supposed to stop but it keeps going, testing the new copied inputs.)

Blacklight Shining
  • 1,468
  • 2
  • 11
  • 28
James
  • 75
  • 1
  • 2
  • 6
  • .png on an external site is not a good format for sharing programs. Can you summarize or otherwise include the program in the question so it's self-contained? – Paul Hankin Mar 23 '15 at 01:13
  • I did it that way so that people would be able to understand it a little better, but give me a second I will edit the post – James Mar 23 '15 at 01:20
  • You need to include the direction the head moves in. – Paul Hankin Mar 23 '15 at 02:00
  • Your description of your machine ("It is like this") is unclear; it is missing some of its left/right indicators, and you neglect the HALT action in state 0. – Beta Mar 23 '15 at 02:01
  • if its not going right its going left, sorry, forgot to put that in – James Mar 23 '15 at 02:01
  • I am not sure where to place the halt 0, i tried placing it but i broke the program every time – James Mar 23 '15 at 02:02
  • You didn't put in a HALT, and you're puzzled that the machine isn't halting... – Beta Mar 23 '15 at 02:03

1 Answers1

1

This line is wrong:

State 1, 1 -> state 2, 1 [changes the first 1 to a 0]

It should be

State 1, 1 -> state 2, 0 [changes the first 1 to a 0]

But I'm a bit puzzled, because I think the effect of this mistake it to keep growing the number of 1s on the left of the tape.

The procedure should work like this:

Starting at the first 1 in the input:

  • If the current symbol is 0, stop.
  • Replace it with a zero.
  • Scan for the middle zero.
  • Scan over the existing 1's.
  • Write a 1
  • Scan backwards for the second 0.
  • Replace it with a 1.
  • Go right once.
  • Repeat

Here's a working implementation in Python. I think I've got left/right the opposite way to you (I think of left/right as describing the movement of the write head rather than the tape). Otherwise, the only change to your program is the mistake I mentioned at the start of this answer.

def machine(tape, program, start, pc):
    head = start
    while True:
        if head < 0:
            raise AssertionError('off tape')
        if head >= len(tape):
            tape.append(0)
        cmd = program[pc, tape[head]]
        if cmd == 'halt': return
        newpc, write, move = cmd
        tape[head], head, pc = write, head + move, newpc
        print pc, head, tape

L, R = -1, 1
tape = [1, 1, 1, 0]
program = {
    (1, 0): 'halt',
    (1, 1): (2, 0, R),
    (2, 1): (2, 1, R),
    (2, 0): (3, 0, R),
    (3, 1): (3, 1, R),
    (3, 0): (4, 1, L),
    (4, 1): (4, 1, L),
    (4, 0): (5, 0, L),
    (5, 1): (5, 1, L),
    (5, 0): (1, 1, R)
}

machine(tape, program, 0, 1)
Paul Hankin
  • 54,811
  • 11
  • 92
  • 118
  • Sorry, that was my mistake in typing the instructions, the line isn't wrong in the program. I will try your procedure – James Mar 23 '15 at 02:06