# Tag system

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Tag_system
> Markdown URL: https://mediated.wiki/source/Tag_system.md
> Source: https://en.wikipedia.org/wiki/Tag_system
> Source revision: 1340381376
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Deterministic model of computation}}
In the [theory of computation](/source/theory_of_computation), a '''tag system''' is a deterministic [model of computation](/source/model_of_computation) published by [Emil Leon Post](/source/Emil_Leon_Post) in 1943 as a simple form of a [Post canonical system](/source/Post_canonical_system).{{sfn|Post|1943}} A tag system may also be viewed as an [abstract machine](/source/abstract_machine), called a '''Post tag machine''' (not to be confused with [Post–Turing machines](/source/Post%E2%80%93Turing_machine))—briefly, a [finite-state machine](/source/finite-state_machine) whose only tape is a [FIFO](/source/FIFO_(computing_and_electronics)) [queue](/source/Queue_(data_structure)) of unbounded length, such that in each transition the machine reads the symbol at the head of the queue, deletes a constant number of symbols from the head, and appends to the tail a symbol-string that depends solely on the first symbol read in this transition.

Because all of the indicated operations are performed in a single transition, a tag machine strictly has only one state.

== Definitions ==

A ''tag system'' is a triplet (''m'', ''A'', ''P''), where

* ''m'' is a positive [integer](/source/integer), called the ''deletion number''.
* ''A'' is a finite alphabet of symbols, one of which can be a special ''halting symbol''. All finite (possibly empty) strings on ''A'' are called ''words''.
* ''P'' is a set of ''production rules'', assigning a word ''P(x)'' (called a ''production'') to each symbol ''x'' in ''A''.  The production (say ''P({{mono|H}})'') assigned to the halting symbol is seen below to play no role in computations, but for convenience is taken to be ''P({{mono|H}})'' = ''{{mono|'H'}}''.

A ''halting word'' is a word that either begins with the halting symbol or whose length is less than ''m''.

A transformation ''t'' (called the ''tag operation'') is defined on the set of non-halting words, such that if ''x'' denotes the leftmost symbol of a word ''S'', then ''t''(''S'') is the result of deleting the leftmost ''m'' symbols of ''S'' and appending the word ''P(x)'' on the right. Thus, the system processes the m-symbol head into a tail of variable length, but the generated tail depends solely on the first symbol of the head.

A ''computation'' by a tag system is a finite sequence of words produced by iterating the transformation ''t'', starting with an initially given word and halting when a halting word is produced.  (By this definition, a computation is not considered to exist unless a halting word is produced in finitely-many iterations.  Alternative definitions allow nonhalting computations, for example by using a special subset of the alphabet to identify words that encode output.)

The term ''m-tag system'' is often used to emphasise the deletion number.  Definitions vary somewhat in the literature (cf. References), the one presented here being that of Rogozhin.{{sfn|Rogozhin|1996}}

The use of a halting symbol in the above definition allows the output of a computation to be encoded in the final word alone, whereas otherwise the output would be encoded in the entire sequence of words produced by iterating the tag operation.

A common alternative definition uses no halting symbol and treats all words of length less than ''m'' as halting words. Another definition is the original one used by {{harvtxt|Post|1943}} (described in the historical note below), in which the only halting word is the [empty string](/source/empty_string).

=== Example: A simple 2-tag illustration ===

This is merely to illustrate a simple 2-tag system that uses a halting symbol.

<pre>
2-tag system 
    Alphabet: {a,b,c,H} 
    Production rules:
         a  -->  ccbaH
         b  -->  cca
         c  -->  cc

Computation
    Initial word: baa
                    acca
                      caccbaH
                        ccbaHcc
                          baHcccc
                            Hcccccca (halt).
</pre>

=== Example: Computation of Collatz sequences ===

This simple 2-tag system is adapted from {{harvtxt|De Mol|2008}}. It uses no halting symbol, but halts on any word of length less than 2, and computes a slightly modified version of the [Collatz sequence](/source/Collatz_conjecture).

In the original Collatz sequence, the successor of ''n'' is either {{sfrac|''n''|2}} (for even&nbsp;''n'') or 3''n''&nbsp;+&nbsp;1 (for odd n).  The value 3''n''&nbsp;+&nbsp;1 is even for odd&nbsp;''n'', hence the next term after 3''n''&nbsp;+&nbsp;1 is always {{sfrac|3''n''&nbsp;+&nbsp;1|2}}. In the sequence computed by the tag system below we skip this intermediate step, hence the successor of ''n'' is {{sfrac|3''n''&nbsp;+&nbsp;1|2}} for odd&nbsp;''n''.

In this tag system, a positive integer ''n'' is represented by the word aa...a with ''n'' a's.

<pre>
2-tag system 
    Alphabet: {a,b,c} 
    Production rules:
         a  -->  bc
         b  -->  a
         c  -->  aaa

Computation
    Initial word: aaa <--> n=3
                    abc  
                      cbc
                        caaa
                          aaaaa  <--> 5
                            aaabc
                              abcbc
                                cbcbc
                                  cbcaaa
                                    caaaaaa
                                      aaaaaaaa  <--> 8
                                        aaaaaabc
                                          aaaabcbc
                                            aabcbcbc
                                              bcbcbcbc
                                                bcbcbca
                                                  bcbcaa
                                                    bcaaa
                                                      aaaa  <--> 4
                                                        aabc
                                                          bcbc
                                                            bca
                                                              aa  <--> 2
                                                                bc
                                                                  a  <--> 1
                                                                   (halt)
</pre>

== Turing-completeness of ''m''-tag systems ==

For each ''m'' > 1, the set of ''m''-tag systems is [Turing-complete](/source/Turing_completeness); i.e., for each ''m'' > 1, it is the case that for any given [Turing machine](/source/Turing_machine) '''T''', there is an ''m''-tag system that [emulates](/source/Surrogate_model) '''T'''. In particular, a 2-tag system can be constructed to emulate a [Universal Turing machine](/source/Universal_Turing_machine), as was done by {{harvtxt|Wang|1963}} and by {{harvtxt|Cocke|Minsky|1964}}.

Conversely, a Turing machine can be shown to be a Universal Turing Machine by proving that it can emulate a Turing-complete class of ''m''-tag systems. For example, {{harvtxt|Rogozhin|1996}} proved the universality of the class of 2-tag systems with alphabet {''a<sub>1</sub>'', ..., ''a<sub>n</sub>'', {{mono|H}}} and corresponding productions {''a<sub>n</sub>a<sub>n</sub>W<sub>1</sub>'', ..., ''a<sub>n</sub>a<sub>n</sub>W<sub>n-1</sub>'', ''a<sub>n</sub>a<sub>n</sub>'', {{mono|H}}}, where the ''W<sub>k</sub>'' are nonempty words; he then proved the universality of a very small (4-state, 6-symbol) Turing machine by showing that it can simulate this class of tag systems.

The 2-tag system is an efficient simulator of universal Turing machines, in <math>O(t^4 \ln^2 t)</math> time. That is, if <math>M</math> is a deterministic single-tape Turing machine that runs in time <math>t</math>, then there is a 2-tag system that simulates it in <math>O(t^4 \ln^2 t)</math> time.<ref>{{Cite journal |last1=Woods |first1=Damien |last2=Neary |first2=Turlough |date=2009-02-17 |title=The complexity of small universal Turing machines: A survey |journal=Theoretical Computer Science |series=Computational Paradigms from Nature |volume=410 |issue=4 |pages=443–450 |doi=10.1016/j.tcs.2008.09.051 |s2cid=10257004 |issn=0304-3975|url=https://authors.library.caltech.edu/103354/1/1110.2230.pdf }}</ref>

== The 2-tag halting problem ==
This version of the [halting problem](/source/halting_problem) is among the simplest, most-easily described [undecidable](/source/Undecidable_problem) [decision problem](/source/decision_problem)s:

Given an arbitrary positive integer ''n'' and a list of ''n''+1 arbitrary words ''P''<sub>1</sub>,''P''<sub>2</sub>,...,''P''<sub>''n''</sub>,''Q'' on the alphabet {1,2,...,''n''}, does repeated application of the tag operation ''t'': ''ijX'' → ''XP''<sub>''i''</sub> eventually convert ''Q'' into a word of length less than 2?  That is, does the sequence ''Q'', ''t''<sup>1</sup>(''Q''), ''t''<sup>2</sup>(''Q''), ''t''<sup>3</sup>(''Q''), ... terminate?

== Historical note on the definition of tag system ==

The above definition differs from that of {{harvtxt|Post|1943}}, whose tag systems use no halting symbol, but rather halt only on the empty word, with the tag operation ''t'' being defined as follows:

* If ''x'' denotes the leftmost symbol of a nonempty word ''S'', then ''t''(''S'') is the operation consisting of <u>first appending</u> the word ''P(x)'' to the right end of ''S'', and <u>then deleting</u> the leftmost ''m'' symbols of the result &mdash; <u>deleting all</u> if there be less than ''m'' symbols.

The above remark concerning the Turing-completeness of the set of ''m''-tag systems, for any ''m'' &gt; 1, applies also to these tag systems as originally defined by Post.

=== Origin of the name "tag" ===

According to a footnote in {{harvtxt|Post|1943}}, B. P. Gill suggested the name for an earlier variant of the problem in which the first ''m'' symbols are left untouched, but rather a check mark indicating the current position moves to the right by ''m'' symbols every step. The name for the problem of determining whether or not the check mark ever touches the end of the sequence was then dubbed the "problem of tag", referring to the children's [game of tag](/source/Tag_(game)).

==Cyclic tag systems==

A cyclic tag system is a modification of the original tag system.  The alphabet consists of only two symbols, '''0''' and '''1''', and the production rules comprise a list of productions considered sequentially, cycling back to the beginning of the list after considering the "last" production on the list.  For each production, the leftmost symbol of the word is examined—if the symbol is '''1''', the current production is appended to the right end of the word; if the symbol is '''0''', no characters are appended to the word; in either case, the leftmost symbol is then deleted.  The system halts if and when the word becomes empty.{{refn|In a chapter 14 titled "Very Simple Bases for Computability", {{harvtxt|Minsky|1967}} presents a very readable (and exampled) subsection 14.6 ''The Problem of "Tag" and Monogenic Canonical Systems'' ([https://archive.org/details/computationfinit0000mins/page/267 pp. 267–273]) (this sub-section is indexed as "tag system"). Minsky relates his frustrating experiences with the general problem: "Post found this (00, 1101) problem "intractable," and so did I, even with the help of a computer." He comments that an "effective way to decide, for any string S, whether this process will ever repeat when started with S" is unknown although a few specific cases have been proven unsolvable. In particular he mentions Cocke's Theorem and Corollary 1964.}}

===Example===
<pre>
Cyclic Tag System
 Productions: (010, 000, 1111)

Computation
 Initial Word: 11001
    Production         Word
    ----------         --------------
       010             11001
       000              1001010
       1111              001010000
       010                01010000
       000                 1010000
       1111                 010000000
       010                   10000000
        .                      .
        .                      .
</pre>

Cyclic tag systems were created by [Matthew Cook](/source/Matthew_Cook) and were used in Cook's demonstration that the [Rule 110 cellular automaton](/source/Rule_110) is universal.{{sfn|Cook|2004}} A key part of the demonstration was that cyclic tag systems can emulate a [Turing-complete](/source/Turing-complete) class of tag systems.

==Emulation of tag systems by cyclic tag systems==

An ''m''-tag system with alphabet {''a<sub>1</sub>'', ..., ''a<sub>n</sub>''} and corresponding productions {''P<sub>1</sub>'', ..., ''P<sub>n</sub>''} is emulated by a cyclic tag system with ''m*n'' productions (''Q<sub>1</sub>'', ..., ''Q<sub>n</sub>'', -, -, ..., -), where all but the first ''n'' productions are the empty string (denoted by '{{mono|-}}').  The ''Q<sub>k</sub>'' are encodings of the respective ''P<sub>k</sub>'', obtained by replacing each symbol of the tag system alphabet by a length-''n'' binary string as follows (these are to be applied also to the initial word of a tag system computation):

 ''a<sub>1</sub>'' = 100...00
 ''a<sub>2</sub>'' = 010...00
 .
 .
 .
 ''a<sub>n</sub>'' = 000...01

That is, ''a<sub>k</sub>'' is encoded as a binary string with a {{mono|1}} in the k<sup>th</sup> position from the left, and {{mono|0}}'s elsewhere.  Successive lines of a tag system computation will then occur encoded as every (''m*n'')<sup>th</sup> line of its emulation by the cyclic tag system.

===Example===

This is a very small example to illustrate the emulation technique.
<pre>
2-tag system
    Production rules: (a --> bb, b --> abH, H --> H)
    Alphabet encoding: a = 100, b = 010, H = 001 
    Production encodings: (bb = 010 010, abH = 100 010 001, H = 001)

Cyclic tag system 
    Productions: (010 010, 100 010 001, 001, -, -, -)

Tag system computation
    Initial word: ba
                    abH
                      Hbb (halt)

Cyclic tag system computation
    Initial word: 010 100 (=ba)

    Production       Word
    ----------       -------------------------------
  * 010 010          010 100  (=ba)
    100 010 001       10 100
    001                0 100 100 010 001
    -                    100 100 010 001
    -                     00 100 010 001
    -                      0 100 010 001
  * 010 010                  100 010 001  (=abH)
    100 010 001               00 010 001 010 010
    001                        0 010 001 010 010
    -                            010 001 010 010
    -                             10 001 010 010
    -                              0 001 010 010
  * 010 010       emulated halt -->  001 010 010  (=Hbb)
    100 010 001                       01 010 010
    001                                1 010 010
    -                                    010 010 001
    ...                                    ...
</pre>  
Every sixth line (marked by '{{mono|*}}') produced by the cyclic tag system is the encoding of a corresponding line of the tag system computation, until the emulated halt is reached.

== See also ==
* [Queue automaton](/source/Queue_automaton)
* [Conway's Game of Life](/source/Conway's_Game_of_Life)

==Notes==
{{Reflist}}

==References==
* {{cite journal |last1=Cocke|first1=John|author-link1=John Cocke (computer scientist)|last2=Minsky|first2=Marvin|author-link2=Marvin Minsky|date=1964|title=Universality of Tag Systems with P=2|journal=Journal of the Association for Computing Machinery|volume=11|pages=15–20|doi=10.1145/321203.321206|hdl=1721.1/6107 |s2cid=2799125 |hdl-access=free}}
* {{Cite journal |last=Cook |first=Matthew |author-link=Matthew Cook|year=2004 |title=Universality in Elementary Cellular Automata |url=https://www.complex-systems.com/abstracts/v15_i01_a01/ |url-status=live |journal=Complex Systems |volume=15 |pages=1–40 |doi=10.25088/ComplexSystems.15.1.1 |archiveurl=https://web.archive.org/web/20160528014857/http://www.complex-systems.com/pdf/15-1-1.pdf |archivedate=28 May 2016|url-access=subscription }}
* {{cite journal |last=De Mol|first=Liesbeth|date=January 2008|title=Tag systems and Collatz-like functions|journal=Theoretical Computer Science|volume=390|issue=1|pages=92–101|doi=10.1016/j.tcs.2007.10.020|hdl=1854/LU-436211|hdl-access=free}}
* {{cite journal|last=Minsky|first=Marvin L.|author-link=Marvin Minsky|date=November 1961|title=Recursive Unsolvability of Post's Problem of "Tag" and other Topics in Theory of Turing Machines|journal=[Annals of Mathematics](/source/Annals_of_Mathematics)|series=2|volume=74|issue=3|pages=437–455|doi=10.2307/1970290|jstor=1970290}}
* {{cite book |last=Minsky|first=Marvin L.|author-link=Marvin Minsky|date=1967|title=Computation: Finite and Infinite Machines|url=https://archive.org/details/computationfinit0000mins/page/267|publisher=[Prentice–Hall](/source/Prentice%E2%80%93Hall)|location=Englewood Cliffs, N.J.|pages=267–273|isbn=978-0131655638|lccn=67-12342}}
* {{cite journal|last=Post|first=Emil|author-link=Emil Post|title=Formal reductions of the combinatorial decision problem|journal=[American Journal of Mathematics](/source/American_Journal_of_Mathematics)|volume=65|issue=2|url=https://archive.org/details/sim_american-journal-of-mathematics_1943-04_65_2/page/197|pages=197–215|year=1943|doi=10.2307/2371809 |jstor=2371809 }} (Tag systems are introduced on [https://archive.org/details/sim_american-journal-of-mathematics_1943-04_65_2/page/203 p.&nbsp;203ff].)
* {{cite journal|last=Rogozhin|first=Yurii|title=Small Universal Turing Machines|journal=[Theoretical Computer Science](/source/Theoretical_Computer_Science)|volume=168|issue=2|pages=215–240|date=20 November 1996|doi=10.1016/S0304-3975(96)00077-1|doi-access=free}}
* {{cite journal|last=Wang|first=Hao|author-link=Hao Wang (academic)|title=Tag Systems and Lag Systems|journal=[Mathematische Annalen](/source/Mathematische_Annalen)|volume=152|pages=65–74|year=1963|doi=10.1007/BF01343730 |s2cid=120383146 }}

== External links ==
* https://mathworld.wolfram.com/TagSystem.html
* https://mathworld.wolfram.com/CyclicTagSystem.html
* https://www.wolframscience.com/nks/p95/ (cyclic tag systems)
* https://www.wolframscience.com/nks/p669/ (emulation of tag systems)

Category:Models of computation

---
Adapted from the Wikipedia article [Tag system](https://en.wikipedia.org/wiki/Tag_system) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Tag_system?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
