Unrestricted grammar

From testwiki
Revision as of 01:41, 24 June 2024 by imported>Explicit (Removing link(s) Wikipedia:Articles for deletion/Thue (programming language) (2nd nomination) closed as delete (XFDcloser))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:Short description In automata theory, the class of unrestricted grammars (also called semi-Thue, type-0 or phrase structure grammars) is the most general class of grammars in the Chomsky hierarchy. No restrictions are made on the productions of an unrestricted grammar, other than each of their left-hand sides being non-empty.[1]Template:Rp This grammar class can generate arbitrary recursively enumerable languages.

Formal definition

An unrestricted grammar is a formal grammar G=(N,T,P,S), where

As the name implies, there are no real restrictions on the types of production rules that unrestricted grammars can have.[note 2]

Equivalence to Turing machines

The unrestricted grammars characterize the recursively enumerable languages. This is the same as saying that for every unrestricted grammar G there exists some Turing machine capable of recognizing L(G) and vice versa. Given an unrestricted grammar, such a Turing machine is simple enough to construct, as a two-tape nondeterministic Turing machine.[1]Template:Rp The first tape contains the input word w to be tested, and the second tape is used by the machine to generate sentential forms from G. The Turing machine then does the following:

  1. Start at the left of the second tape and repeatedly choose to move right or select the current position on the tape.
  2. Nondeterministically choose a production βγ from the productions in G.
  3. If β appears at some position on the second tape, replace β by γ at that point, possibly shifting the symbols on the tape left or right depending on the relative lengths of β and γ (e.g. if β is longer than γ, shift the tape symbols left).
  4. Compare the resulting sentential form on tape 2 to the word on tape 1. If they match, then the Turing machine accepts the word. If they don't, the Turing machine will go back to step 1.

It is easy to see that this Turing machine will generate all and only the sentential forms of G on its second tape after the last step is executed an arbitrary number of times, thus the language L(G) must be recursively enumerable.

The reverse construction is also possible. Given some Turing machine, it is possible to create an equivalent unrestricted grammar[1]Template:Rp which even uses only productions with one or more non-terminal symbols on their left-hand sides. Therefore, an arbitrary unrestricted grammar can always be equivalently converted to obey the latter form, by converting it to a Turing machine and back again. Some authorsTemplate:Cn use the latter form as definition of unrestricted grammar.

Computational properties

The decision problem of whether a given string s can be generated by a given unrestricted grammar is equivalent to the problem of whether it can be accepted by the Turing machine equivalent to the grammar. The latter problem is called the halting problem and is undecidable.

Recursively enumerable languages are closed under Kleene star, concatenation, union, and intersection, but not under set difference; see Recursively enumerable language#Closure properties.

The equivalence of unrestricted grammars to Turing machines implies the existence of a universal unrestricted grammar, a grammar capable of accepting any other unrestricted grammar's language given a description of the language. For this reason, it is theoretically possible to build a programming language based on unrestricted grammars (e.g. Thue).

See also

Notes

Template:Reflist

References

Template:Reflist

Template:Formal languages and grammars


Cite error: <ref> tags exist for a group named "note", but no corresponding <references group="note"/> tag was found