Turing Machine 2D

Turing Machine 2D preview image

2 collaborators

Uri_dolphin3 Uri Wilensky (Author)
Eytan Bakshy (Author)

Tags

computer science 

Tagged by Reuven M. Lerner almost 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 572 times • Downloaded 56 times • Run 1 time
Download the 'Turing Machine 2D' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This is a model of a multi-headed Turing machine on a 2 dimensional tape (2D MTM), which is an extension of the original machine proposed by Turing in 1936.

A Turing machine is a simple computing machine capable of doing anything a modern computer can do. A traditional Turing machine has a single processor, or "head," with a limited number of internal states that change depending on the data that is read by the head. As the Turing machine computes, the head moves back and forth across the tape, changing its internal state and the value of the current cell.

A multi-headed Turing machine on a 2 dimensional tape (2D MTM) can be emulated on a single headed one dimensional Turing machine (TM), but the rules of a 2D MTM may be significantly simpler than those of a traditional TM emulating a 2D MTM. In the model, there can be up to 256 "heads" which all follow the same set of basic rules. In this 2-state 2D MTM, the head may change its state, the value of its current cell, and move either north, east, west, or south, depending on whether or not the current cell is on or off and its current state.

This model demonstrates how multiple processors may interact with each other to complete complex processing tasks. It also shows that these machines can be heavily dependent on the number of processing agents. In addition to exploring the complexity of parallel computation, this model also demonstrates some of the caveats of parallel algorithms.

HOW IT WORKS

On each turn, each head moves forward. Depending on whether the patch ("cell") it's over is "on" (showing color) or "off" (invisible), the head will use the rule which transitions from its current state to the new state. In other words, if head A (which is in state 1, with position 2) is over cell B (which is on), then the on-1-state will show what the next state will be, the on-1-position slider will show what the next position will be for that head (0: North, 1: East, 2: South, 3: West), and if on-1-on? is true, then it will remain on. If on-1-on? is false, then it will turn off, becoming invisible.

HOW TO USE IT

HEADS: the number of heads used by the Turing machine

COLOR-PATHS?: Tells the heads to write color information onto the cell. This feature allows the user to analyze both the information written and the process in which it was written. It is only a device to keep track of which cell had been most recently turned on by a particular head; it does not affect on/off data written on the tape: colored cells are on, black cells are off.

HEAD-SIZE: How large the head, or turtle appears.

The rules of all heads are given by three parameters:
[cell state]-[head state]-state [cell state]-[head state]-position [cell state]-[head state]-on?

The prefix of each slider/toggle refers to the current state of the machine and the cell it is on.

First prefix - current cell state: on/off
Second prefix - current state of head, which may be either 0 or 1

These prefixes specify the initial state which the following rules are applied to:

Turn- specifies what direction the head will turn before moving forward 1 cell
New Head State- specifies the new head state
New Cell State- specifies the state to apply to the current cell

THINGS TO NOTICE

Here are some interesting phenomena that occur with the example setups:

Example 1: In the first example, the machine does nothing with only one head. With two or more heads, the heads cooperate with each other to fill the tape with data in a repetitive fashion forming a shape similar to a square rotated by 45 degrees. When the heads wrap around and converge with the written data, they get stuck in a loop and do not write any more data. If the tape was infinite, the growth of the square would be unbounded.

Example 2: Like the first example, the processors also aid each other in filling up the tape with data. The pattern they form is less symmetric, and two processors may get stuck in a small loop with each other as the tape gets filled with data, potentially stunting the growth of the data. This is an example where multiprocessing fails to work effectively. This is analogous common problems faced by parallel algorithms. The processing of shared resources between multiple processors may conflict with proper functioning.

Example 3: This example demonstrates the codependency of processors to perform complex computational tasks. If a head does not have a pair, it will get stuck in a tight loop and not be able to process data. The minimum number of heads required to produce chaotic behavior is 3 heads. Greater numbers of heads will produce chaotic behavior that will most likely produce complex patterns. Often times, the movement of heads is short lived and the entire machine will get stuck in a loop.

Example 4: This particular type of Turing machine is commonly known as Langton's vants (see references for more information). In this example, the head evaluates only the state of the current cell. If it is black, it changes the cell to white, turns white, and moves forward. If the cell is white, it turns off the cell, and turns left. With a single head, the van" moves chaotically on the tape, eventually creating "highways" of repetitive patterns that diverge from the main cluster. The behavior of this machine is highly dependent on its initial configuration. When small odd numbers of heads are created, they behave like the classic vants, moving randomly, building highways which other heads may follow and possibly deconstruct. When the machine is initially setup with an even number of heads arranged vertically, the heads will follow each other forming a shape similar to a rotated square which is constantly expanding. Once the square wraps around the horizontal edges, the system becomes chaotic. This is an example where pairs of "chaotic" computational machines may combine to produce a somewhat stable behavior.

Example 5: The rules of this machine is very similar to that of Langton's vants, and its behavior is similar but has more stable properties. With two processors, there is a tight loop that doesn't seem to go anywhere. Larger even numbers of heads create a 1-bit path which stably oscillates back and forth. The processing of data remains constrained. Odd numbers of heads start off similarly to even numbers of heads, but unwind as they oscillate. Their growth is unconstrained and chaotic, with behavior very similar to vants. When the number of heads is even and exceeds 128 processors (the tape has 256x256 cells), the end of the path being drawn hits the point of origin of the path and behaves similarly to configurations with larger odd numbers of heads. This model demonstrates that pairs of "chaotic" heads can produce very stable behavior given the proper initial conditions.

THINGS TO TRY

Start by tinkering around with the number of heads in the example models, and consider the following:

How do the heads interact with each other?

What can you conclude about the number of heads in relation to the complexity of their execution?

Can you find any other configurations that will yield interesting results?

EXTENDING THE MODEL

Change the starting position of the heads. How does this affect the execution of the 2D MTM?

What happens to the execution of configurations when they start with random bits of data on the tape?

Try adding more states to the cells and/or heads to the model. Do different types of complexities emerge? Are there more states that yield complex behavior?

CREDITS AND REFERENCES

Langton, C. 1984. Self-reproduction in cellular automata. Physica D 10, 134-144
Langton, C. 1986. Studying artificial life with cellular automata. Physica D 22, 120-149 Sipser, M. 1997. Introduction to the Theory of Computation. PWS Publishing 125-147.
Wolfram, S. 2002. A New Kind of Science. Wolfram Media Inc. Champaign, IL.
Pegg, E. 2002. Turmite. http://mathworld.wolfram.com/Turmite.html.

Thanks to Ethan Bakshy for his work on this model.

HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

  • Wilensky, U. (2002). NetLogo Turing Machine 2D model. http://ccl.northwestern.edu/netlogo/models/TuringMachine2D. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
  • Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

COPYRIGHT AND LICENSE

Copyright 2002 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

This model was created as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

turtles-own [rule-set bg fg state]
patches-own [on?]

to setup
  clear-all
  create-turtles heads [
    set size 5
    set state 0    ;; initialize all head states to 0
    set heading 0
    fd who    ;; have all the turtles line up vertically
    set bg black
    ifelse color-paths?  ;; if show-path? is enabled, color the turtles
      [ set fg color ]
      [ set fg white ]
  ]
  ask patches [ set on? false ] ;; clear cell values
  reset-ticks
end 

to setup-example
  if example = 1
    [ apply-rules [[1 180 true] [1 90 true] [0 180 true] [1 270 true]] ]
  if example = 2
    [ apply-rules [[0 270 true] [1 180 false] [1 90 true] [0 0 true]] ]
  if example = 3
    [ apply-rules [[1 90 false] [0 90 true] [0 0 false] [0 180 false]] ]
  if example = 4
    [ apply-rules [[0 90 true] [0 0 false] [0 270 false] [0 0 false]] ]
  if example = 5
    [ apply-rules [[1 180 true] [1 270 true] [0 270 true] [1 90 false]] ]
  setup
end 

to go
  ask turtles [ set rule-set find-rule ]
  ask turtles [
    set on? last rule-set
    ifelse on?
      [ set pcolor fg ]
      [ set pcolor bg ]
  ]
  ask turtles [
    rt item 1 rule-set
    fd 1
    set state first rule-set
  ]
  tick
end 

;; find the rule to use for current head state and cell state

to-report find-rule  ;; turtle procedure
  ifelse on?  ;; check state of this patch
  [
    if state = 0 [ report fput on-0-state list (direction-to-number on-0-turn) on-0-on? ]
    if state = 1 [ report fput on-1-state list (direction-to-number on-1-turn) on-1-on? ]
  ]
  [
    if state = 0 [ report fput off-0-state list (direction-to-number off-0-turn) off-0-on? ]
    if state = 1 [ report fput off-1-state list (direction-to-number off-1-turn) off-1-on? ]
  ]
end 

;; change the current configuration to the given list of rules

to apply-rules [l]
  set off-0-state  item 0 item 0 l
  set off-0-turn   number-to-direction (item 1 item 0 l)
  set off-0-on?    item 2 item 0 l
  set off-1-state  item 0 item 1 l
  set off-1-turn   number-to-direction (item 1 item 1 l)
  set off-1-on?    item 2 item 1 l
  set on-0-state   item 0 item 2 l
  set on-0-turn    number-to-direction (item 1 item 2 l)
  set on-0-on?     item 2 item 2 l
  set on-1-state   item 0 item 3 l
  set on-1-turn    number-to-direction (item 1 item 3 l)
  set on-1-on?     item 2 item 3 l
end 

to-report direction-to-number [direction]
  if direction = "--"
    [ report 0 ]
  if direction = "Right"
    [ report 90 ]
  if direction = "Backwards"
    [ report 180 ]
  if direction = "Left"
    [ report 270 ]
end 

to-report number-to-direction [number]
  if number = 0
    [ report "--" ]
  if number = 90
    [ report "Right" ]
  if number = 180
    [ report "Backwards" ]
  if number = 270
    [ report "Left" ]
end 


; Copyright 2002 Uri Wilensky.
; See Info tab for full copyright and license.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky almost 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 11 years ago Updated version tag Download this version
Uri Wilensky over 11 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky over 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky almost 14 years ago Turing Machine 2D Download this version

Attached files

File Type Description Last updated
Turing Machine 2D.png preview Preview for 'Turing Machine 2D' about 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.