Formal definition: the basic model


A Turing Machine (TM) is a 7-tuple where: 
 

  • is a finite non-empty set of states.
  • is a finite non-empty set of symbols called the tape alphabet.
  • is the input alphabet.
  • is the transition or next-move function that maps pairs of state symbol to subsets of triples state, symbol, head direction (left, right or stay). 
     
  • is the start state.
  • is the final accepting state.
  • is the blank symbol.


In each step of the computation, a TM can be described by an instantaneous description (ID). An ID is a triple where is the actual state, is the string contained in the cells at the left of the cell being scanned by the machine, and is the string contained in the current cell and the other cells to the right of the tape head until the cell that begins the infinite sequence of blanks.
The binary relation relates two IDs and is defined as follows, for all and and 
 

  • iff 
  • iff 
  • iff 
  • iff 
  • iff 
  • iff 


Let be the transitive and reflexive closure of , i.e. the application of zero or more transitions between IDs. Then, the language recognized by is defined as: .
If for all states and tape symbols has at most one element the TM is said to be deterministic. It there exist transitions with more than one choice, the TM is nondeterministic.
The sequence of IDs of deterministic TMs is linear. For nondeterministic TMs, it forms a computation tree. Nondeterminism can be thought as if the machine creates replicas of itself that proceed in parallel. This useful analogy will be used by our simulator.
At a first glance, we can think that nondeterministic TMs are more powerful than deterministic TMs because the ability to “guess” the correct path. But this is not true: a DTM is only a particular case of a NDTM, and any NDTM can be converted to a DTM. So, they have the same computational power.
In fact, several variants of TMs have been proposed: with two-way infinite tape, with several tracks, without stay option, etc. Interestingly, all of these variants are exhibit the same computational power than the basic model. They recognize the same class of languages.
In the next section we introduce a very useful variant: multitape nondeterministic TMs.
 

Multitape Nondeterministic Turing Machine simulator

This article tackles both theoretical and practical issues in Computer Science (CS). It reviews Turing Machines (TMs), a fundamental class of automata and presents a simulator for a broad variant of TMs: nondeterministic with multiple tapes. Nondeterminism is simulated by a breadth first search (BFS) of the computation tree.
The simulator is written in Python 3 and takes advantage of the power and expressiveness of this programming language, combining object oriented and functional programming techniques. 
The organization is as follows. First, TMs are introduced in an informal manner, highlighting its many applications in Theoretical CS. Then, formal definitions of the basic model and the multitape variant are given. Finally, the design and implementation the simulator is presented, providing examples of its use and execution. 
 

Similar Reads

Introduction

TMs are abstract automata devised by Alan Turing in 1936 to investigate the limits of computation. TMs are able to compute functions following simple rules.A TM is a primitive computational model with 3 components:...

Formal definition: the basic model

A Turing Machine (TM) is a 7-tuple where:...

Formal definition: the multitape TM

Multitape TMs have multiple input-output tapes with independent heads. This variant does not increases the computational power of the original, but as we will see it can simplify the construction of TMs using auxiliary tapes.A k-tape TM is a 7-tuple where all the elements are as in the basic TM, except the transition function that is a mapping . It maps pairs of state-read symbols to subsets of pairs new states-write symbols+directions.For example, the following 2-tape TM computes the sum of the numbers stored in unary notation in the first tape. The first tape contains factors: sequences of 1’s separated by 0’s that represent natural numbers. The machine writes all the 1’s in tape 2, computing the sum of all factors.Formally, let where is defined as follows:...

The Halting Problem

It is possible that a TM does not halt for some inputs. For example, consider the TM with .The halting problem states that it is undecidable to check if an arbitrary TM will halt on a given input string. This problem has profound implications, because it shows that there are problems that cannot be computed by TMs and, if the Church-Turing thesis is true, it means that no algorithm can solve this problems.For a TM simulator this is very bad news, because it implies that the simulator could enter in an infinite loop.We can not completely avoid this problem, but we can solve a restricted form of it. Consider the case of a nondeterministic TM were there are branches of the computation tree that enter an infinite loop and grow forever where others reach a final state. In this case the simulator should halt accepting the input string. But if we traverse the tree in a depth first search (DFS) fashion, the simulator will get stuck when it enters one of the infinite branches. To avoid this the simulator will traverse the computation tree via breadth first search (BFS). BFS is a graph traversal strategy that explores all the children of a branch prior to proceeding to their successors....

A simulator of multitape NDTMs in Python

In this section we will present a simulator for nondeterministic TMs with multiple tapes written in Python. The simulator consists of two classes: a Tape class and a NDTM class.Tape instances contain the list of current scanned cells and an index to the tape head, and provide the following operations:...

Source code of the simulator

...

A nontrivial example

Excluding input/output code and comments, the simulator is less than 100 lines of code. It is a testimony of Python power and economy. It’s object oriented but also uses functional constructs like list comprehensions....