![]() |
VOOZH | about |
Prerequisite - Turing Machine
Turing Machines can broadly be classified into two types, the Acceptors and the Transducers. Acceptor Turing Machine is an automaton used to define Turing-acceptable languages. Such a machine can be used to check whether a given string belongs to a language or not. It is defined as a 7-tuple machine.
Coming to Transducers: In general, transducers are the devices used to convert one form of signal into another. The same can be told about Turing Machine Transducers.
A transducer is a type of Turing Machine that is used to convert the given input into the output after the machine performs various read-writes. It doesn't accept or reject an input but performs series of operations to obtain the output right in the same tape and halts when finished.
A Turing machine is a theoretical machine that can perform any calculation that is algorithmically computable. It is often used as a theoretical model of computation and is considered as the theoretical foundation of modern computing.
A transducer Turing machine is a type of Turing machine that takes an input string and produces an output string, rather than just accepting or rejecting the input.
To construct a Turing machine in Java, you can create a class that implements the Turing machine's transition function and control logic. The transition function specifies how the machine will transition from one state to another based on the current state and the input symbol. The control logic implements the rules for reading and writing symbols and moving the tape head.
Few examples of Turing Machine transducers are:
Implementation:
Now we will be proposing a Java program that was written to simulate the construction and execution performed by turing machine transducers. There are two inputs that must be given while executing it: A .txt file to define the automaton (an example for unary multiplication machine is given after the code), and a string to be entered via the console window which will be the input on tape for the automaton to execute.
The .txt file's path must be given as input. This was done so that the same program can be used for various types of machines instead of hard-coding the automaton. We just need to write a different txt file for generating a different automaton.
Java was chosen specifically because of the OOP structure, using which a class was defined for State, Transition, Machine, etc, to be able to encapsulate various aspects of an entity within an object. For example, a transition is defined as a class whose members are three characters - read, write and shift which store read symbol, write a symbol, and shift direction respectively, along with the index of the next state to which the machine should transition to. The same applies to a State object, which stores a list of possible outgoing transitions.
Example
The input file that defines symbols, states, and transitions for Automaton for Unary multiplication:
//lines starting with '//' are ignored by the program while reading so that the input text can be commented
//title, will be printed on console
MACHINE FOR UNARY MULTIPLICATION
//input symbols - 1's for defining unary-number, 0 as delimiter
0 1
//tape symbols - other than inputs
Y
//blank symbol
B
//number of states
8
//start state
0
//transitions
//format - read,write,shift,next state
//for state q0, 2 transitions to be read for this state
2
1 B R 1
0 B R 6
//state q1
2
0 0 R 2
1 1 R 1
//state q2
2
0 0 L 5
1 Y R 3
//state q3
3
0 0 R 3
1 1 R 3
B 1 L 4
//state q4
3
0 0 L 4
1 1 L 4
Y Y R 2
//state q5
4
0 0 L 5
1 1 L 5
Y 1 L 5
B B R 0
//state q6
2
1 B R 6
0 B R 7
//state q7 - machine halts when it reaches this state as 0 transitions are defined
0
Text input for Turing Machine to copy data is given in LINK.
Note: The program must be executed on local machine or on an IDE that accepts path for I/O files.
Following is how the OUTPUT looks like for Unary Multiplication automaton with "1101110" as input (unary 2 * unary 3) :
(after several iterations)
With a bit of effort, the same program can be extended to also work for Acceptor-type Turing machines. Anyone interested is encouraged to improve the article.