Equivalence of Unrestricted Grammars and Turing Machines
Learn why unrestricted grammars and Turing machines are equivalent.
Constructing a Turing machine for an unrestricted grammar
As we know, the behavior of unrestricted grammars is procedural, and any procedure can be simulated by a Turing machine. Therefore, for every unrestricted grammar there is a that recognizes (but not necessarily decides) its language or performs its function. To create a for an unrestricted grammar, we can use a nondeterministic with four tapes/memory areas that contain the following:
- Tape 1 holds the string to accept or reject.
- Tape 2 contains the ongoing, working derivation.
- Tape 3 holds all the left-hand sides of the grammar rules.
- Tape 4 holds all the right-hand sides of the grammar rules, in the same order that the left-hand sides appear on Tape 3.
To begin a derivation, we place the start variable, or starting configuration if we are simulating a function, on Tape 2, and execute the following logic:
repeatnon-deterministically choose a cell on Tape 2non-deterministically choose the parts of a rule from Tapes 3 and 4apply the appropriate changes to the derivation on Tape 2until the contents on Tape 2 matches Tape 1
If we place an invalid string on Tape 1, the procedure does not halt, but it halts on every valid input. This shows that the language of an unrestricted grammar is recursively enumerable. Likewise, any computational grammar can be simulated by a by placing the input on Tape 1 before running the machine.
Remember: For every unrestricted grammar, there is a Turing machine that recognizes the same language or performs the same function.
Converting a TM to an unrestricted grammar
Going the other direction, it is straightforward to construct a computational grammar for a by rewriting the 's transitions in grammatical form, using the states as variables. Let’s look at a few examples to understand the construction of unrestricted grammar for a .
Example 1
Consider the following for adding two unary numbers.
Let’s convert this to computational grammar. We repeat the transitions below in functional form. Note that the ...