<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>len-len</title>
	<atom:link href="http://lhen24.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://lhen24.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 05 Mar 2009 01:07:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='lhen24.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>len-len</title>
		<link>http://lhen24.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://lhen24.wordpress.com/osd.xml" title="len-len" />
	<atom:link rel='hub' href='http://lhen24.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Automata and Language Theory</title>
		<link>http://lhen24.wordpress.com/2009/03/05/automata-and-language-theory/</link>
		<comments>http://lhen24.wordpress.com/2009/03/05/automata-and-language-theory/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 00:59:16 +0000</pubDate>
		<dc:creator>Len-len</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lhen24.wordpress.com/?p=7</guid>
		<description><![CDATA[String (computer science) In computer programming and some branches of mathematics, a string is an ordered sequence of symbols. These symbols are chosen from a predetermined set or alphabet. In computer programming, a string is generally understood as a data type storing a sequence of data values, usually bytes, in which elements usually stand for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lhen24.wordpress.com&amp;blog=6790546&amp;post=7&amp;subd=lhen24&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1 style="margin:auto 0;"><span style="font-size:26pt;" lang="EN"><span style="font-family:Times New Roman;">String (computer science)</span></span></h1>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">In </span><a title="Computer programming" href="http://en.wikipedia.org/wiki/Computer_programming"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer programming</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and some branches of </span><a title="Mathematics" href="http://en.wikipedia.org/wiki/Mathematics"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">mathematics</span></span></a><span style="font-size:small;font-family:Times New Roman;">, a <strong>string</strong> is an ordered </span><a title="Sequence" href="http://en.wikipedia.org/wiki/Sequence"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">sequence</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of </span><a title="Symbols" href="http://en.wikipedia.org/wiki/Symbols"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">symbols</span></span></a><span style="font-size:small;font-family:Times New Roman;">. These symbols are chosen from a predetermined </span><a title="Set" href="http://en.wikipedia.org/wiki/Set"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">set</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or </span><a title="Alphabet" href="http://en.wikipedia.org/wiki/Alphabet"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">alphabet</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">.</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">In </span><a title="Computer programming" href="http://en.wikipedia.org/wiki/Computer_programming"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer programming</span></span></a><span style="font-size:small;font-family:Times New Roman;">, a string is generally understood as a </span><a title="Data type" href="http://en.wikipedia.org/wiki/Data_type"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">data type</span></span></a><span style="font-size:small;font-family:Times New Roman;"> storing a sequence of data values, usually bytes, in which elements usually stand for characters according to a </span><a title="Character encoding" href="http://en.wikipedia.org/wiki/Character_encoding"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">character encoding</span></span></a><span style="font-size:small;font-family:Times New Roman;">, which differentiates it from the more general </span><a title="Array" href="http://en.wikipedia.org/wiki/Array"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">array</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> data type. In this context, the terms <strong>binary string</strong> and <strong>byte string</strong> are used to suggest strings in which the stored data does not (necessarily) represent text.</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">A </span><a title="Variable" href="http://en.wikipedia.org/wiki/Variable"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">variable</span></span></a><span style="font-size:small;font-family:Times New Roman;"> declared to have a string data type usually causes storage to be allocated in memory that is capable of holding some predetermined number of symbols. When a string appears literally in </span><a title="Source code" href="http://en.wikipedia.org/wiki/Source_code"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">source code</span></span></a><span style="font-size:small;font-family:Times New Roman;">, it is known as a </span><a title="String literal" href="http://en.wikipedia.org/wiki/String_literal"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">string literal</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> and has a representation that denotes it as such.</span></span></span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:large;"><span style="font-family:Arial;"><span class="mw-headline"><span style="font-style:normal;" lang="EN">Formal theory</span></span><span style="font-style:normal;" lang="EN"></span></span></span></h2>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Let Σ be an <span><a title="Alphabet (computer science)" href="http://en.wikipedia.org/wiki/Alphabet_(computer_science)"><span style="color:windowtext;text-decoration:none;">alphabet</span></a></span>, a </span><a title="Empty set" href="http://en.wikipedia.org/wiki/Empty_set"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">non-empty</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><a title="Finite set" href="http://en.wikipedia.org/wiki/Finite_set"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><a title="Set" href="http://en.wikipedia.org/wiki/Set"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">set</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Elements of Σ are called <span>symbols</span> or <span>characters</span>. A <strong>string</strong> (or <strong>word</strong>) over Σ is any finite </span><a title="Sequence" href="http://en.wikipedia.org/wiki/Sequence"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">sequence</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> of characters from Σ. For example, if Σ = {0, 1}, then <span>0101</span> is a string over Σ.</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">The <span><a title="Length" href="http://en.wikipedia.org/wiki/Length"><span style="color:windowtext;text-decoration:none;">length</span></a></span> of a string is the number of characters in the string (the length of the sequence) and can be any </span><a title="Non-negative integer" href="http://en.wikipedia.org/wiki/Non-negative_integer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">non-negative integer</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">. The <span><a title="Empty string" href="http://en.wikipedia.org/wiki/Empty_string"><span style="color:windowtext;text-decoration:none;">empty string</span></a></span> is the unique string over Σ of length 0, and is denoted <span>ε</span> or <span>λ</span>.</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">The set of all strings over Σ of length <span>n</span> is denoted Σ<sup><span>n</span></sup>. For example, if Σ = {0, 1}, then Σ<sup>2</sup> = {00, 01, 10, 11}. Note that Σ<sup>0</sup> = {ε} for any alphabet Σ.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">The set of all strings over Σ of any length is the </span><a title="Kleene star" href="http://en.wikipedia.org/wiki/Kleene_star"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Kleene closure</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> of Σ and is denoted Σ*. In terms of Σ<sup><span>n</span></sup>,</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">For example, if Σ = {0, 1}, Σ* = {ε, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, …}. Although Σ* itself is </span><a title="Countably infinite" href="http://en.wikipedia.org/wiki/Countably_infinite"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">countably infinite</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, all elements of Σ* have finite length.</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">A set of strings over Σ (i.e. any </span><a title="Subset" href="http://en.wikipedia.org/wiki/Subset"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">subset</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> of Σ*) is called a <span><a title="Formal language" href="http://en.wikipedia.org/wiki/Formal_language"><span style="color:windowtext;text-decoration:none;">formal language</span></a></span> over Σ. For example, if Σ = {0, 1}, the set of strings with an even number of zeros ({ε, 1, 00, 11, 001, 010, 100, 111, 0000, 0011, 0101, 0110, 1001, 1010, 1100, 1111, …}) is a formal language over Σ.</span></span></span></p>
<h3 style="margin:auto 0;"><a name="Concatenation_and_substrings"></a><span style="font-family:Times New Roman;"><span class="mw-headline"><span style="font-size:14pt;" lang="EN">Concatenation and substrings</span></span><span style="font-size:14pt;" lang="EN"></span></span></h3>
<p style="text-indent:.5in;"><span lang="EN"><a title="Concatenation" href="http://en.wikipedia.org/wiki/Concatenation"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Concatenation</span></span></a></span><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> is an important </span><a title="Binary operation" href="http://en.wikipedia.org/wiki/Binary_operation"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">binary operation</span></span></a><span style="font-size:small;font-family:Times New Roman;"> on Σ*. For any two strings <span>s</span> and <span>t</span> in Σ*, their concatenation is defined as the sequence of characters in <span>s</span> followed by the sequence of characters in <span>t</span>, and is denoted <span>st</span>. For example, if Σ = {a, b, …, z}, <span>s</span> = </span></span><tt><span style="font-size:10pt;" lang="EN">bear</span></tt><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">, and <span>t</span> = </span></span><tt><span style="font-size:10pt;" lang="EN">hug</span></tt><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">, then <span>st</span> = </span></span><tt><span style="font-size:10pt;" lang="EN">bearhug</span></tt><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> and <span>ts</span> = </span></span><tt><span style="font-size:10pt;" lang="EN">hugbear</span></tt><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">.</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">String concatenation is an </span><a title="Associative" href="http://en.wikipedia.org/wiki/Associative"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">associative</span></span></a><span style="font-size:small;font-family:Times New Roman;">, but non-</span><a title="Commutative" href="http://en.wikipedia.org/wiki/Commutative"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">commutative</span></span></a><span style="font-size:small;font-family:Times New Roman;"> operation. The empty string serves as the </span><a title="Identity element" href="http://en.wikipedia.org/wiki/Identity_element"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">identity element</span></span></a><span style="font-size:small;font-family:Times New Roman;">; for any string <span>s</span>, ε<span>s</span> = <span>s</span>ε = <span>s</span>. Therefore, the set Σ* and the concatenation operation form a </span><a title="Monoid" href="http://en.wikipedia.org/wiki/Monoid"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">monoid</span></span></a><span style="font-size:small;font-family:Times New Roman;">, the </span><a title="Free monoid" href="http://en.wikipedia.org/wiki/Free_monoid"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">free monoid</span></span></a><span style="font-size:small;font-family:Times New Roman;"> generated by Σ. In addition, the length function defines a </span><a title="Monoid homomorphism" href="http://en.wikipedia.org/wiki/Monoid_homomorphism"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">monoid homomorphism</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> from Σ* to the non-negative integers.</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">A string <span>s</span> is said to be a <span><a title="Substring" href="http://en.wikipedia.org/wiki/Substring"><span style="color:windowtext;text-decoration:none;">substring</span></a></span> or <span>factor</span> of <span>t</span> if there exist (possibly empty) strings <span>u</span> and <span>v</span> such that <span>t</span> = <span>usv</span>. The </span><a title="Binary relation" href="http://en.wikipedia.org/wiki/Binary_relation"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">relation</span></span></a><span style="font-size:small;font-family:Times New Roman;"> &#8220;is a substring of&#8221; defines a </span><a title="Partial order" href="http://en.wikipedia.org/wiki/Partial_order"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">partial order</span></span></a><span style="font-size:small;font-family:Times New Roman;"> on Σ*, the </span><a title="Least element" href="http://en.wikipedia.org/wiki/Least_element"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">least element</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> of which is the empty string.</span></span></span></p>
<h3 style="margin:auto 0;"><a name="Lexicographical_ordering"></a><span style="font-family:Times New Roman;"><span class="mw-headline"><span style="font-size:14pt;" lang="EN">Lexicographical ordering</span></span><span style="font-size:14pt;" lang="EN"></span></span></h3>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">It is often necessary to define an </span><a title="Ordering" href="http://en.wikipedia.org/wiki/Ordering"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ordering</span></span></a><span style="font-size:small;font-family:Times New Roman;"> on the set of strings. If the alphabet Σ has a </span><a title="Total order" href="http://en.wikipedia.org/wiki/Total_order"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">total order</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (cf. </span><a title="Alphabetical order" href="http://en.wikipedia.org/wiki/Alphabetical_order"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">alphabetical order</span></span></a><span style="font-size:small;font-family:Times New Roman;">) one can define a </span><a title="Total order" href="http://en.wikipedia.org/wiki/Total_order"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">total order</span></span></a><span style="font-size:small;font-family:Times New Roman;"> on Σ* called </span><a title="Lexicographical order" href="http://en.wikipedia.org/wiki/Lexicographical_order"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">lexicographical order</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">. Note that since Σ is finite, it is always possible to define a well ordering on Σ and thus on Σ*. For example, if Σ = {0, 1} and 0 &lt; 1, then the lexicographical ordering of Σ* is ε &lt; 0 &lt; 00 &lt; 000 &lt; … &lt; 011 &lt; 0110 &lt; … &lt; 01111 &lt; … &lt; 1 &lt; 10 &lt; 100 &lt; … &lt; 101 &lt; … &lt; 111 …</span></span></span></p>
<h3 style="margin:auto 0;"><a name="String_operations"></a><span style="font-family:Times New Roman;"><span class="mw-headline"><span style="font-size:14pt;" lang="EN">String operations</span></span><span style="font-size:14pt;" lang="EN"></span></span></h3>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">A number of additional operations on strings commonly occur in the formal theory. These are given in the article on </span><a title="String operations" href="http://en.wikipedia.org/wiki/String_operations"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">string operations</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">.</span></span></span></p>
<h3 style="margin:auto 0;"><a name="Topology"></a><span style="font-family:Times New Roman;"><span class="mw-headline"><span style="font-size:14pt;" lang="EN">Topology</span></span><span style="font-size:14pt;" lang="EN"></span></span></h3>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">Strings admit the following interpretation as nodes on a graph:</span></span></span></p>
<ul type="disc">
<li class="MsoNormal"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Fixed length strings can be viewed as nodes on a </span><a title="Hypercube" href="http://en.wikipedia.org/wiki/Hypercube"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">hypercube</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">; </span></span></span></li>
<li class="MsoNormal"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Variable length strings (of finite length) can be viewed as nodes on the </span><a title="K-ary tree" href="http://en.wikipedia.org/wiki/K-ary_tree"><span style="font-size:small;"><span style="font-family:Times New Roman;"><span style="color:windowtext;text-decoration:none;">k</span><span style="color:windowtext;text-decoration:none;">-ary tree</span></span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, where <span>k</span> is the number of symbols in Σ; </span></span></span></li>
<li class="MsoNormal"><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">Infinite strings can be viewed as infinite paths on the <span>k</span>-ary tree. </span></span></span></li>
</ul>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">The natural topology on the set of fixed length strings or variable length strings is the discrete topology, but the natural topology on the set of infinite strings is the </span><a title="Limit topology" href="http://en.wikipedia.org/wiki/Limit_topology"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">limit topology</span></span></a><span style="font-size:small;font-family:Times New Roman;">, viewing the set of infinite strings as the </span><a title="Inverse limit" href="http://en.wikipedia.org/wiki/Inverse_limit"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">inverse limit</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of the sets of finite strings. This is the construction used for the </span><a title="P-adic" href="http://en.wikipedia.org/wiki/P-adic"><span style="font-size:small;"><span style="font-family:Times New Roman;"><span style="color:windowtext;text-decoration:none;">p</span><span style="color:windowtext;text-decoration:none;">-adic numbers</span></span></span></a><span style="font-size:small;font-family:Times New Roman;"> and some constructions of the </span><a title="Cantor set" href="http://en.wikipedia.org/wiki/Cantor_set"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Cantor set</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, and yields the same topology.</span></span></span></p>
<h2 style="margin:12pt 0 3pt;"><a name="String_datatypes"></a><span style="font-size:large;"><span style="font-family:Arial;"><span class="mw-headline"><span style="font-style:normal;" lang="EN">String datatypes</span></span><span style="font-style:normal;" lang="EN"></span></span></span></h2>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">A <strong>string datatype</strong> is a </span><a title="Datatype" href="http://en.wikipedia.org/wiki/Datatype"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">datatype</span></span></a><span style="font-size:small;font-family:Times New Roman;"> modeled on the idea of a formal string. Strings are such an important and useful datatype that they are implemented in nearly every </span><a title="Programming language" href="http://en.wikipedia.org/wiki/Programming_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">programming language</span></span></a><span style="font-size:small;font-family:Times New Roman;">. In some languages they are available as </span><a title="Primitive type" href="http://en.wikipedia.org/wiki/Primitive_type"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">primitive types</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and in others as </span><a title="Composite type" href="http://en.wikipedia.org/wiki/Composite_type"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">composite types</span></span></a><span style="font-size:small;font-family:Times New Roman;">. The </span><a title="Syntax" href="http://en.wikipedia.org/wiki/Syntax"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">syntax</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> of most high-level programming languages allows for a string, usually quoted in some way, to represent an instance of a string datatype; such a meta-string is called a <span>literal</span> or <span><a title="String literal" href="http://en.wikipedia.org/wiki/String_literal"><span style="color:windowtext;text-decoration:none;">string literal</span></a></span>.</span></span></span></p>
<h3 style="margin:auto 0;"><a name="String_length"></a><span style="font-size:medium;"><span style="font-family:Times New Roman;"><span class="mw-headline"><span lang="EN">String length</span></span><span lang="EN"></span></span></span></h3>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Although formal strings can have an arbitrary (but finite) length, the length of strings in real languages is often constrained to an artificial maximum. In general, there are two types of string datatypes: <span>fixed length strings</span> which have a fixed maximum length and which use the same amount of memory whether this maximum is reached or not, and <span>variable length strings</span> whose length is not arbitrarily fixed and which use varying amounts of memory depending on their actual size. Most strings in modern </span><a title="Programming languages" href="http://en.wikipedia.org/wiki/Programming_languages"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">programming languages</span></span></a><span style="font-size:small;font-family:Times New Roman;"> are variable length strings. Despite the name, even variable length strings are limited in length; although, generally, the limit depends only on the amount of </span><a title="Computer memory" href="http://en.wikipedia.org/wiki/Computer_memory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">memory</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> available.</span></span></span></p>
<h3 style="margin:auto 0;"><a name="Character_encoding"></a><span style="font-family:Times New Roman;"><span class="mw-headline"><span style="font-size:14pt;" lang="EN">Character encoding</span></span><span style="font-size:14pt;" lang="EN"></span></span></h3>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Historically, string datatypes allocated one </span><a title="Byte" href="http://en.wikipedia.org/wiki/Byte"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">byte</span></span></a><span style="font-size:small;font-family:Times New Roman;"> per character, and although the exact character set varied by region, </span><a title="Character encoding" href="http://en.wikipedia.org/wiki/Character_encoding"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">character encodings</span></span></a><span style="font-size:small;font-family:Times New Roman;"> were similar enough that programmers could generally get away with ignoring this — groups of character sets used by the same system in different regions usually either had a character in the same place, or did not have it at all. These character sets were typically based on </span><a title="ASCII" href="http://en.wikipedia.org/wiki/ASCII"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ASCII</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or </span><a title="EBCDIC" href="http://en.wikipedia.org/wiki/EBCDIC"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">EBCDIC</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">.</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><a title="Logograph" href="http://en.wikipedia.org/wiki/Logograph"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Logographic</span></span></a><span style="font-size:small;font-family:Times New Roman;"> languages such as </span><a title="Chinese language" href="http://en.wikipedia.org/wiki/Chinese_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Chinese</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a title="Japanese language" href="http://en.wikipedia.org/wiki/Japanese_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Japanese</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and </span><a title="Korean language" href="http://en.wikipedia.org/wiki/Korean_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Korean</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (known collectively as </span><a title="CJK" href="http://en.wikipedia.org/wiki/CJK"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">CJK</span></span></a><span style="font-size:small;font-family:Times New Roman;">) need far more than 256 characters (the limit of a one 8-bit </span><a title="Byte" href="http://en.wikipedia.org/wiki/Byte"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">byte</span></span></a><span style="font-size:small;font-family:Times New Roman;"> per-character encoding) for reasonable representation. The normal solutions involved keeping single-byte representations for </span><a title="ASCII" href="http://en.wikipedia.org/wiki/ASCII"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ASCII</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and using two-byte representations for CJK </span><a title="Ideographs" href="http://en.wikipedia.org/wiki/Ideographs"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ideographs</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Use of these with existing code led to problems with matching and cutting of strings, the severity of which depended on how the character encoding was designed. Some encodings such as the </span><a title="EUC" href="http://en.wikipedia.org/wiki/EUC"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">EUC</span></span></a><span style="font-size:small;font-family:Times New Roman;"> family guarantee that a byte value in the ASCII range will only represent that ASCII character, making the encoding safe for systems that use those characters as field separators. Other encodings such as </span><a title="ISO-2022" href="http://en.wikipedia.org/wiki/ISO-2022"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ISO-2022</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a title="Shift-JIS" href="http://en.wikipedia.org/wiki/Shift-JIS"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Shift-JIS</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> do not make such guarantees, making matching on byte codes unsafe. Another issue is that if the beginning of a string is deleted, important instructions for the decoder or information on position in a multibyte sequence may be lost. Another is that if strings are joined together (especially after having their ends truncated by code not aware of the encoding), the first string may not leave the encoder in a state suitable for dealing with the second string.</span></span></span></p>
<p><span lang="EN"><a title="Unicode" href="http://en.wikipedia.org/wiki/Unicode"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Unicode</span></span></a><span style="font-size:small;font-family:Times New Roman;"> has simplified the picture somewhat. Most languages have a datatype for Unicode strings (usually </span><a title="UTF-16" href="http://en.wikipedia.org/wiki/UTF-16"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">UTF-16</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> as it was usually added before Unicode supplemental planes were introduced). Converting between Unicode and local encodings requires an understanding of the local encoding, which may be problematic for existing systems where strings of various encodings are being transmitted together with no real marking as to what encoding they are in.</span></span></span></p>
<h3 style="margin:auto 0;"><a name="Implementations"></a><span style="font-size:medium;"><span style="font-family:Times New Roman;"><span class="mw-headline"><span lang="EN">Implementations</span></span><span lang="EN"></span></span></span></h3>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Some languages like </span><a title="C++" href="http://en.wikipedia.org/wiki/C%2B%2B"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">C++</span></span></a><span style="font-size:small;font-family:Times New Roman;"> implement strings as </span><a title="Generic programming" href="http://en.wikipedia.org/wiki/Generic_programming"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">templates</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> that can be used with any datatype, but this is the exception, not the rule.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">If an object-oriented language represents strings as objects, they are called <span>mutable</span> if the value can change at runtime and <span>immutable</span> if the value is frozen after creation. For example, </span><a title="Ruby (programming language)" href="http://en.wikipedia.org/wiki/Ruby_(programming_language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Ruby</span></span></a><span style="font-size:small;font-family:Times New Roman;"> has mutable strings, while </span><a title="Python (programming language)" href="http://en.wikipedia.org/wiki/Python_(programming_language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Python</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">&#8216;s strings are immutable.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Other languages, most notably </span><a title="Prolog" href="http://en.wikipedia.org/wiki/Prolog"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Prolog</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a title="Erlang (programming language)" href="http://en.wikipedia.org/wiki/Erlang_(programming_language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Erlang</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, avoid implementing a string datatype, instead adopting the convention of representing strings as lists of character codes.</span></span></span></p>
<h3 style="margin:auto 0;"><a name="Representations"></a><span style="font-family:Times New Roman;"><span class="mw-headline"><span style="font-size:14pt;" lang="EN">Representations</span></span><span style="font-size:14pt;" lang="EN"></span></span></h3>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Representations of strings depend heavily on the choice of character repertoire and the method of character encoding. Older string implementations were designed to work with repertoire and encoding defined by </span><a title="ASCII" href="http://en.wikipedia.org/wiki/ASCII"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ASCII</span></span></a><span style="font-size:small;font-family:Times New Roman;">, or more recent extensions like the </span><a title="ISO 8859" href="http://en.wikipedia.org/wiki/ISO_8859"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ISO 8859</span></span></a><span style="font-size:small;font-family:Times New Roman;"> series. Modern implementations often use the extensive repertoire defined by </span><a title="Unicode" href="http://en.wikipedia.org/wiki/Unicode"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Unicode</span></span></a><span style="font-size:small;font-family:Times New Roman;"> along with a variety of complex encodings such as </span><a title="UTF-8" href="http://en.wikipedia.org/wiki/UTF-8"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">UTF-8</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a title="UTF-16" href="http://en.wikipedia.org/wiki/UTF-16"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">UTF-16</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Most string implementations are very similar to variable-length </span><a title="Array" href="http://en.wikipedia.org/wiki/Array"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">arrays</span></span></a><span style="font-size:small;font-family:Times New Roman;"> with the entries storing the </span><a title="Character code" href="http://en.wikipedia.org/wiki/Character_code"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">character codes</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of corresponding characters. The principal difference is that, with certain encodings, a single logical character may take up more than one entry in the array. This happens for example with </span><a title="UTF-8" href="http://en.wikipedia.org/wiki/UTF-8"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">UTF-8</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, where single characters can take anywhere from one to four bytes. In these cases, the logical length of the string differs from the logical length of the array.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">The length of a string can be stored implicitly by using a special terminating character; often this is the </span><a title="Null character" href="http://en.wikipedia.org/wiki/Null_character"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">null character</span></span></a><span style="font-size:small;font-family:Times New Roman;"> having value zero, a convention used and perpetuated by the popular </span><a title="C (programming language)" href="http://en.wikipedia.org/wiki/C_(programming_language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">C programming language</span></span></a><sup><a href="http://en.wikipedia.org/wiki/String_(computer_science)#cite_note-0#cite_note-0"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">[1]</span></span></a></sup><span style="font-size:small;font-family:Times New Roman;">. Hence, this representation is commonly referred to as </span><a title="C string" href="http://en.wikipedia.org/wiki/C_string"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">C string</span></span></a><span style="font-size:small;font-family:Times New Roman;">. The length of a string can also be stored explicitly, for example by prefixing the string with the length as a </span><a title="Byte" href="http://en.wikipedia.org/wiki/Byte"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">byte</span></span></a><span style="font-size:small;font-family:Times New Roman;"> value — a convention used in </span><a title="Pascal (programming language)" href="http://en.wikipedia.org/wiki/Pascal_(programming_language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Pascal</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">; consequently some people call it a P-string.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">In terminated strings, the terminating code is not an allowable character in any string.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">The term <strong>bytestring</strong> usually indicates a general-purpose string of bytes — rather than strings of only (readable) characters, strings of bits, or such. Byte strings often imply that bytes can take any value and any data can be stored as-is, meaning that there should be no value interpreted as a termination value.</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Here is an example of a <strong>null-terminated string</strong> stored in a 10-byte </span><a title="Buffer (computer science)" href="http://en.wikipedia.org/wiki/Buffer_(computer_science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">buffer</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, along with its ASCII representation:</span></span></span></p>
<table class="MsoNormalTable" style="background:#f9f9f9;border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">F</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">R</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">A</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">N</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">K</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">NUL</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">k</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">e</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">f</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">w</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">46</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">52</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">41</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">4E</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">4B</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">00</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">6B</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">66</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">66</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">77</span></p>
</td>
</tr>
</tbody>
</table>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">The length of a string in the above example is 5 characters, but it occupies 6 bytes. Characters after the terminator do not form part of the representation; they may be either part of another string or just garbage. (Strings of this form are sometimes called <span>ASCIZ strings</span>, after the original </span><a title="Assembly language" href="http://en.wikipedia.org/wiki/Assembly_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">assembly language</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> directive used to declare them.)</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">Here is the equivalent (old style) <strong>Pascal string</strong> stored in a 10-byte buffer, along with its ASCII representation:</span></span></span></p>
<table class="MsoNormalTable" style="background:#f9f9f9;border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">length</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">F</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">R</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">A</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">N</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">K</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">k</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">e</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">f</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">w</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">05</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">46</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">52</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">41</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">4E</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;background-color:transparent;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">4B</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">6B</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">66</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">66</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#dddddd;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">77</span></p>
</td>
</tr>
</tbody>
</table>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">Both character termination and length codes limit strings: for example, C character arrays that contain Nul characters cannot be handled directly by C string library functions: strings using a length code are limited to the maximum value of the length code.</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">Both of these limitations can be overcome by clever programming, of course, but such workarounds are by definition not standard.</span></span></span></p>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Historically, rough equivalents of the C termination method appear in both hardware and software. For example &#8220;data processing&#8221; machines like the </span><a title="IBM 1401" href="http://en.wikipedia.org/wiki/IBM_1401"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">IBM 1401</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> used a special word mark bit to delimit strings at the left, where the operation would start at the right. This meant that while the IBM 1401 had a seven-bit word in &#8220;reality&#8221;, almost no-one ever thought to use this as a feature, and override the assignment of the seventh bit to (for example) handle ASCII codes.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">It is possible to create data structures and functions that manipulate them that do not have the problems associated with character termination and can in principle overcome length code bounds. It is also possible to optimize the string represented using techniques from run length encoding (replacing repeated characters by the character value and a length) and Hamming encoding.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">While these representations are common, others are possible. Using </span><a title="Rope (computer science)" href="http://en.wikipedia.org/wiki/Rope_(computer_science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ropes</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> makes certain string operations, such as insertions, deletions, and concatenations more efficient.</span></span></span></p>
<h2 style="margin:12pt 0 3pt;"><a name="Vectors"></a><span style="font-size:large;"><span style="font-family:Arial;"><span class="mw-headline"><span style="font-style:normal;" lang="EN">Vectors</span></span><span style="font-style:normal;" lang="EN"></span></span></span></h2>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">While character strings are very common uses of strings, a string in computer science may refer generically to any vector of homogenously typed data. A string of bits or bytes, for example, may be used to represent data retrieved from a communications medium. This data may or may not be represented by a string-specific datatype, depending on the needs of the application, the desire of the programmer, and the capabilities of the programming language being used.</span></span></span></p>
<h2 style="margin:12pt 0 3pt;"><a name="String_processing_algorithms"></a><span style="font-size:large;"><span style="font-family:Arial;"><span class="mw-headline"><span style="font-style:normal;" lang="EN">String processing algorithms</span></span><span style="font-style:normal;" lang="EN"></span></span></span></h2>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">There are many </span><a title="Algorithm" href="http://en.wikipedia.org/wiki/Algorithm"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">algorithms</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> for processing strings, each with various trade-offs. Some categories of algorithms include</span></span></span></p>
<ul type="disc">
<li class="MsoNormal"><span lang="EN"><a title="String searching algorithm" href="http://en.wikipedia.org/wiki/String_searching_algorithm"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">string searching algorithms</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> for finding a given substring or pattern; </span></span></span></li>
<li class="MsoNormal"><span lang="EN"><a title="String manipulation algorithm" href="http://en.wikipedia.org/wiki/String_manipulation_algorithm"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">string manipulation algorithms</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">; </span></span></span></li>
<li class="MsoNormal"><span lang="EN"><a title="Sorting algorithm" href="http://en.wikipedia.org/wiki/Sorting_algorithm"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">sorting algorithms</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">; </span></span></span></li>
<li class="MsoNormal"><span lang="EN"><a title="Regular expression" href="http://en.wikipedia.org/wiki/Regular_expression"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular expression</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> algorithms; and </span></span></span></li>
<li class="MsoNormal"><span lang="EN"><a title="Parser" href="http://en.wikipedia.org/wiki/Parser"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">parsing</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> a string. </span></span></span></li>
</ul>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Advanced string algorithms often employ complex mechanisms and data structures, among them </span><a title="Suffix tree" href="http://en.wikipedia.org/wiki/Suffix_tree"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">suffix trees</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a title="Finite state machine" href="http://en.wikipedia.org/wiki/Finite_state_machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite state machines</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">.</span></span></span></p>
<h2 style="margin:12pt 0 3pt;"><a name="Character_string_oriented_languages_and_"></a><span style="font-size:large;"><span style="font-family:Arial;"><span class="mw-headline"><span style="font-style:normal;" lang="EN">Character string oriented languages and utilities</span></span><span style="font-style:normal;" lang="EN"></span></span></span></h2>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">Character strings are such a useful datatype that several languages have been designed in order to make string processing applications easy to write. Examples include the following languages:</span></span></span></p>
<table class="MsoNormalTable" style="width:100%;" border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td style="width:25%;background-color:transparent;border:#d4d0c8;padding:0;" width="25%" valign="top">
<ul type="disc">
<li class="MsoNormal"><a title="AWK programming language" href="http://en.wikipedia.org/wiki/AWK_programming_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">awk</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
<li class="MsoNormal"><a title="Icon programming language" href="http://en.wikipedia.org/wiki/Icon_programming_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Icon</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
<li class="MsoNormal"><a title="MUMPS" href="http://en.wikipedia.org/wiki/MUMPS"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">MUMPS</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
<li class="MsoNormal"><a title="Perl" href="http://en.wikipedia.org/wiki/Perl"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Perl</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
<li class="MsoNormal"><a title="Rexx" href="http://en.wikipedia.org/wiki/Rexx"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Rexx</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
</ul>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:0;" valign="top">
<ul type="disc">
<li class="MsoNormal"><a title="Ruby programming language" href="http://en.wikipedia.org/wiki/Ruby_programming_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Ruby</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
<li class="MsoNormal"><a title="Sed" href="http://en.wikipedia.org/wiki/Sed"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">sed</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
<li class="MsoNormal"><a title="SNOBOL" href="http://en.wikipedia.org/wiki/SNOBOL"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">SNOBOL</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
<li class="MsoNormal"><a title="Tcl" href="http://en.wikipedia.org/wiki/Tcl"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Tcl</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
</ul>
</td>
</tr>
</tbody>
</table>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Many </span><a title="Unix" href="http://en.wikipedia.org/wiki/Unix"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">UNIX</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> utilities perform simple string manipulations and can be used to easily program some powerful string processing algorithms. Files and finite streams may be viewed as strings.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Some </span><a title="Application Programming Interface" href="http://en.wikipedia.org/wiki/Application_Programming_Interface"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Application Programming Interfaces</span></span></a><span style="font-size:small;font-family:Times New Roman;"> like </span><a title="Multimedia Control Interface" href="http://en.wikipedia.org/wiki/Multimedia_Control_Interface"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Multimedia Control Interface</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a title="Embedded SQL" href="http://en.wikipedia.org/wiki/Embedded_SQL"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">embedded SQL</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or </span><a title="Printf" href="http://en.wikipedia.org/wiki/Printf"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">printf</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> use strings to hold commands that will be interpreted.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Recent </span><a title="Scripting programming language" href="http://en.wikipedia.org/wiki/Scripting_programming_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">scripting programming languages</span></span></a><span style="font-size:small;font-family:Times New Roman;">, including </span><a title="Perl" href="http://en.wikipedia.org/wiki/Perl"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Perl</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a title="Python (programming language)" href="http://en.wikipedia.org/wiki/Python_(programming_language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Python</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a title="Ruby programming language" href="http://en.wikipedia.org/wiki/Ruby_programming_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Ruby</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and </span><a title="Tcl" href="http://en.wikipedia.org/wiki/Tcl"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Tcl</span></span></a><span style="font-size:small;font-family:Times New Roman;"> employ </span><a title="Regular expression" href="http://en.wikipedia.org/wiki/Regular_expression"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular expressions</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> to facilitate text operations.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Some languages such as </span><a title="Perl" href="http://en.wikipedia.org/wiki/Perl"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Perl</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a title="Ruby programming language" href="http://en.wikipedia.org/wiki/Ruby_programming_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Ruby</span></span></a><span style="font-size:small;font-family:Times New Roman;"> support </span><a title="String interpolation (page does not exist)" href="http://en.wikipedia.org/w/index.php?title=String_interpolation&amp;action=edit&amp;redlink=1"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">string interpolation</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, which permits arbitrary expressions to be evaluated and included in string literals.</span></span></span></p>
<h2 style="margin:12pt 0 3pt;"><a name="Character_string_functions"></a><span style="font-size:large;"><span class="mw-headline"><span style="font-style:normal;font-family:&quot;" lang="EN">Character string functions</span></span><span style="font-style:normal;font-family:&quot;" lang="EN"></span></span></h2>
<p style="text-indent:.5in;"><span lang="EN"><a title="String Functions (Computer Science)" href="http://en.wikipedia.org/wiki/String_Functions_(Computer_Science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">String functions</span></span></a><span style="font-size:small;font-family:Times New Roman;"> are used to manipulate a string or change or edit the contents of a string. They also are used to query information about a string. They are usually used within the context of a </span><a title="Programming language" href="http://en.wikipedia.org/wiki/Programming_language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer programming language</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">The most basic example of a string function is the </span></span><code><span style="font-size:10pt;" lang="EN">length(string)</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> function, which returns the length of a string (not counting any terminator characters or any of the string&#8217;s internal structural information) and does not modify the string. For example, </span></span><code><span style="font-size:10pt;" lang="EN">length("hello</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> </span></span><code><span style="font-size:10pt;" lang="EN">world")</span></code><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;"> returns 11.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">There are many string functions which exist in other languages with similar or exactly the same syntax or parameters. For example in many languages the length function is usually represented as </span></span><code><span style="font-size:10pt;" lang="EN">len(string)</span></code><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">. Even though string functions are very useful to a computer programmer, a computer programmer using these functions should be mindful that a string function in one language could in another language behave differently or have a similar or completely different function name, parameters, syntax, and results.</span></span></span></p>
<p class="MsoNormal" style="margin:0;"><span class="hw1"><span style="font-size:26pt;color:black;font-family:Arial;"><strong>Programming Language</strong></span></span></p>
<p class="MsoNormal" style="margin:0;"><span class="hw1"><span style="font-size:26pt;color:black;font-family:Arial;"><strong> </strong></span></span></p>
<p class="MsoNormal" style="margin:0;"><span class="hw1"><span style="font-size:14pt;color:black;font-family:Arial;"><strong>Language</strong></span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">syntax, grammar, and symbols or words used to give instructions to a </span><a href="http://encyclopedia2.thefreedictionary.com/computer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:13pt;color:black;font-style:normal;font-family:&quot;">Development of Low-Level Languages</span></h2>
<p style="text-indent:.5in;"><span style="font-size:small;font-family:Times New Roman;">All computers operate by following machine language programs, a long sequence of instructions called machine code that is addressed to the hardware of the computer and is written in binary notation, which uses only the digits 1 and 0. First-generation languages, called machine languages, required the writing of long strings of binary numbers to represent such operations as &#8220;add,&#8221; &#8220;subtract,&#8221; &#8220;and compare.&#8221; Later improvements allowed octal, decimal, or hexadecimal representation of the binary strings.</span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Because writing programs in machine language is impractical (it is tedious and error prone), symbolic, or assembly, languages—second-generation languages—were introduced in the early 1950s. They use simple mnemonics such as A for &#8220;add&#8221; or M for &#8220;multiply,&#8221; which are translated into machine language by a </span><a href="http://encyclopedia2.thefreedictionary.com/computer-prog"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer program</span></span></a><span style="font-size:small;font-family:Times New Roman;"> called an assembler. The assembler then turns that program into a machine language program. An extension of such a language is the macro instruction, a mnemonic (such as &#8220;READ&#8221;) for which the assembler substitutes a series of simpler mnemonics. The resulting machine language programs, however, are specific to one type of computer and will usually not run on a computer with a different type of central processing unit (CPU).</span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Evolution of High-Level Languages</span></span></h2>
<p style="text-indent:.5in;"><span style="font-size:small;font-family:Times New Roman;">The lack of portability between different computers led to the development of high-level languages—so called because they permitted a programmer to ignore many low-level details of the computer&#8217;s hardware. Further, it was recognized that the closer the syntax, rules, and mnemonics of the programming language could be to &#8220;natural language&#8221; the less likely it became that the programmer would inadvertently introduce errors (called &#8220;bugs&#8221;) into the program. Hence, in the mid-1950s a third generation of languages came into use. These algorithmic, or procedural, languages are designed for solving a particular type of problem. Unlike machine or symbolic languages, they vary little between computers. They must be translated into machine code by a program called a compiler or interpreter.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Early computers were used almost exclusively by scientists, and the first high-level language, Fortran [<span>For</span>mula <span>tran</span>slation], was developed (1953–57) for scientific and engineering applications by John Backus at the IBM Corp. A program that handled recursive algorithms better, LISP [<span>LIS</span>t <span>P</span>rocessing], was developed by John McCarthy at the Massachusetts Institute of Technology in the early 1950s; implemented in 1959, it has become the standard language for the artificial intelligence community. COBOL [<span>CO</span>mmon <span>B</span>usiness <span>O</span>riented <span>L</span>anguage], the first language intended for commercial applications, is still widely used; it was developed by a committee of computer manufacturers and users under the leadership of Grace Hopper, a U.S. Navy programmer, in 1959. ALGOL [<span>ALGO</span>rithmic <span>L</span>anguage], developed in Europe about 1958, is used primarily in mathematics and science, as is APL [<span>A P</span>rogramming <span>L</span>anguage], published in the United States in 1962 by Kenneth Iverson. PL/1 [<span>P</span>rogramming <span>L</span>anguage <span>1</span>], developed in the late 1960s by the IBM Corp., and ADA [for Ada Augusta, countess of Lovelace, biographer of Charles </span><a href="http://encyclopedia2.thefreedictionary.com/Babbage,+Charles"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Babbage</span></span></a><span style="font-size:small;font-family:Times New Roman;">, (1972-1871.English mathematician) developed in 1981 by the U.S. Dept. of Defense, are designed for both business and scientific use.</span></p>
<p style="text-indent:.5in;"><span style="font-size:small;font-family:Times New Roman;">BASIC [<span>B</span>eginner's <span>A</span>ll-purpose <span>S</span>ymbolic <span>I</span>nstruction <span>C</span>ode] was developed by two Dartmouth College professors, John Kemeny and Thomas Kurtz, as a teaching tool for undergraduates (1966); it subsequently became the primary language of the personal computer revolution. In 1971, Swiss professor Nicholas Wirth developed a more structured language for teaching that he named Pascal (for French mathematician Blaise </span><a href="http://encyclopedia2.thefreedictionary.com/Pascal,+Blaise"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Pascal</span></span></a><span style="font-size:small;font-family:Times New Roman;">, who built the first successful mechanical calculator). Modula 2, a Pascallike language for commercial and mathematical applications, was introduced by Wirth in 1982. Ten years before that, to implement the UNIX operating system, Dennis Ritchie of Bell Laboratories produced a language that he called C; along with its extensions, called C++, developed by Bjarne Stroustrup of Bell Laboratories, it has perhaps become the most widely used general-purpose language among professional programmers because of its ability to deal with the rigors of </span><a href="http://encyclopedia2.thefreedictionary.com/object-oriented+programming"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">object-oriented programming</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Java is an object-oriented language similar to C++ but simplified to eliminate features that are prone to programming errors. Java was developed specifically as a network-oriented language, for writing programs that can be safely downloaded through the </span><a href="http://encyclopedia2.thefreedictionary.com/Internet,+the"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Internet</span></span></a><span style="font-size:small;font-family:Times New Roman;">  and immediately run without fear of </span><a href="http://encyclopedia2.thefreedictionary.com/computer-vir"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer viruses</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Using small Java programs called applets, </span><a href="http://encyclopedia2.thefreedictionary.com/World+Wide+Web"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">World Wide Web</span></span></a><span style="font-size:small;font-family:Times New Roman;"> pages can be developed that include a full range of </span><a href="http://encyclopedia2.thefreedictionary.com/multimedia"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">multimedia</span></span></a><span style="font-size:small;font-family:Times New Roman;"> functions.</span></p>
<p style="text-indent:.5in;"><span style="font-size:small;font-family:Times New Roman;">Fourth-generation languages are nonprocedural—they specify what is to be accomplished without describing how. The first one, FORTH, developed in 1970 by American astronomer Charles Moore, is used in scientific and industrial control applications. Most fourth-generation languages are written for specific purposes. Fifth-generation languages, which are still in their infancy, are an outgrowth of </span><a href="http://encyclopedia2.thefreedictionary.com/artificial+intelligence"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">artificial intelligence</span></span></a><span style="font-size:small;"><span class="hint2"><span style="color:windowtext;font-family:&quot;"><span style="background-color:#fdf5e6;"> </span></span></span><span style="font-family:Times New Roman;">research. PROLOG [<span>PRO</span>gramming <span>LOG</span>ic], developed by French computer scientist Alain Colmerauer and logician Philippe Roussel in the early 1970s, is useful for programming logical processes and making deductions automatically.</span></span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Many other languages have been designed to meet specialized needs. GPSS [<span>G</span>eneral <span>P</span>urpose <span>S</span>ystem <span>S</span>imulator] is used for modeling physical and environmental events, and SNOBOL [<span>S</span>tring-<span>O</span>riented <span>S</span>ymbolic <span>L</span>anguage] is designed for pattern matching and list processing. LOGO, a version of LISP, was developed in the 1960s to help children learn about computers. PILOT [<span>P</span>rogrammed <span>I</span>nstruction <span>L</span>earning, <span>O</span>r <span>T</span>esting] is used in writing instructional software, and Occam is a nonsequential language that optimizes the execution of a program&#8217;s instructions in </span><a href="http://encyclopedia2.thefreedictionary.com/parallel+processing"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">parallel-processing</span></span></a><span style="font-size:small;font-family:Times New Roman;"> systems.</span></p>
<p><span style="font-size:small;font-family:Times New Roman;">There are also procedural languages that operate solely within a larger program to customize it to a user&#8217;s particular needs. These include the programming languages of several database and statistical programs, the scripting languages of communications programs, and the macro languages of </span><a href="http://encyclopedia2.thefreedictionary.com/word+processing"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">word-processing</span></span></a><span style="font-size:small;font-family:Times New Roman;"> programs.</span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:16pt;font-style:normal;font-family:&quot;">Compilers and Interpreters</span></h2>
<p><span style="font-size:small;font-family:Times New Roman;">Once the program is written and has had any errors repaired (a process called debugging), it may be executed in one of two ways, depending on the language. With some languages, such as C or Pascal, the program is turned into a separate machine language program by a compiler, which functions much as an assembler does. Other languages, such as LISP, do not have compilers but use an interpreter to read and interpret the program a line at a time and convert it into machine code. A few languages, such as BASIC, have both compilers and interpreters. Source code, the form in which a program is written in a high-level language, can easily be transferred from one type of computer to another, and a compiler or interpreter specific to the machine configuration can convert the source code to object, or machine, code.</span></p>
<h1 style="margin:auto 0;"><span style="font-weight:normal;font-size:26pt;"><span style="font-family:Times New Roman;">Programming Language</span></span></h1>
<p><span style="font-size:small;font-family:Times New Roman;">Language in which a computer programmer writes instructions for a computer to execute. Some languages, such as </span><a title="COBOL" href="http://encyclopedia2.thefreedictionary.com/COBOL"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">COBOL</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a title="FORTRAN" href="http://encyclopedia2.thefreedictionary.com/FORTRAN"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">FORTRAN</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a title="Pascal" href="http://encyclopedia2.thefreedictionary.com/Pascal"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Pascal</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and </span><a title="C" href="http://encyclopedia2.thefreedictionary.com/C"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">C</span></span></a><span style="font-size:small;font-family:Times New Roman;">, are known as procedural languages because they use a sequence of commands to specify how the machine is to solve a problem. Others, such as </span><a title="LISP" href="http://encyclopedia2.thefreedictionary.com/LISP"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">LISP</span></span></a><span style="font-size:small;font-family:Times New Roman;">, are functional, in that programming is done by invoking procedures (sections of </span><a title="code" href="http://encyclopedia2.thefreedictionary.com/code"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">code</span></span></a><span style="font-size:small;font-family:Times New Roman;"> executed within a program). Languages that support </span><a title="object-oriented programming" href="http://encyclopedia2.thefreedictionary.com/object-oriented+programming"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">object-oriented programming</span></span></a><span style="font-size:small;font-family:Times New Roman;"> take the data to be manipulated as their point of departure. Programming languages can also be classified as high-level or low-level. Low-level languages address the computer in a way that it can understand directly, but they are very far from human language. High-level languages deal in concepts that humans devise and can understand, but they must be translated by means of a </span><a title="compiler" href="http://encyclopedia2.thefreedictionary.com/compiler"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">compiler</span></span></a><span style="font-size:small;font-family:Times New Roman;"> into language the computer understands.</span></p>
<p><span style="font-size:26pt;"><span style="font-family:Times New Roman;">Programming Languages</span></span></p>
<p style="margin-bottom:12pt;text-indent:.5in;"><span style="font-size:small;font-family:Times New Roman;">A language used to write instructions for the computer. It lets the programmer express data processing in a symbolic manner without regard to machine-specific details.</p>
<p><strong>From Source Code to Machine Language</strong><br />
The statements that are written by the programmer are called &#8220;source language,&#8221; and they are translated into the computer&#8217;s &#8220;machine language&#8221; by programs called &#8220;assemblers,&#8221; &#8220;compilers&#8221; and &#8220;interpreters.&#8221; For example, when a programmer writes MULTIPLY HOURS TIMES RATE, the verb MULTIPLY must be turned into a code that means multiply, and the nouns HOURS and RATE must be turned into memory locations where those items of data are actually located.<br />
<strong>Grammar and Syntax</strong><br />
Like human languages, each programming language has its own grammar and syntax. There are many dialects of the same language, and each dialect requires its own translation system. Standards have been set by ANSI for many programming languages, and ANSI-standard languages are dialect free. However, it can take years for new features to be included in ANSI standards, and new dialects inevitably spring up as a result.</p>
<p><strong>Low Level and High Level</strong><br />
Programming languages fall into two categories: low-level assembly languages and high-level languages. Assembly languages are available for each CPU family, and each assembly instruction is translated into one machine instruction by the assembler program. With high-level languages, a programming statement may be translated into one or several machine instructions by the compiler.</p>
<p>Following is a brief summary of the major high-level languages. Look up each one for more details. For a list of high-level programming languages designed for client/server development, see </span><a href="http://encyclopedia2.thefreedictionary.com/client/server%20development%20system"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">client/server development system</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">ActionScript</span></strong><br />
<span style="font-size:small;">Programming language for Flash programs. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/Flash"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Flash</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia2.thefreedictionary.com/ActionScript"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ActionScript</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">Ada</span></strong><br />
<span style="font-size:small;">Comprehensive, Pascal-based language used by the Department of Defense. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/Ada"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Ada</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">ALGOL</span></strong><br />
<span style="font-size:small;">International language for expressing algorithms. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/ALGOL"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ALGOL</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">APL</span></strong><br />
<span style="font-size:small;">Used for statistics and mathematical matrices. Requires special keyboard symbols. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/APL"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">APL</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><span style="font-size:14pt;">BASIC</span><br />
<span style="font-size:small;">Developed as a timesharing language in the 1960s. It has been widely used in microcomputer programming in the past, and various dialects of BASIC have been incorporated into many different applications. Microsoft&#8217;s Visual Basic is widely used. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/BASIC"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">BASIC</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia2.thefreedictionary.com/Visual%20Basic"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Visual Basic</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</span></p>
<p style="margin-bottom:12pt;"><span style="font-family:Times New Roman;"><span style="font-size:14pt;">C</span><br />
<span style="font-size:small;">Developed in the 1980s at AT&amp;T. Widely used to develop commercial applications. Unix is written in C. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/C"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">C</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">C++</span></strong><br />
<span style="font-size:small;">Object-oriented version of C that is popular because it combines object-oriented capability with traditional C programming syntax. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/C++"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">C++</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.<br />
</span><strong><span style="font-size:14pt;">C#</span></strong><br />
<span style="font-size:small;">Pronounced &#8220;C-sharp.&#8221; A Microsoft .NET language based on C++ with elements from Visual Basic and Java. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/.NET"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">.NET</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">COBOL</span></strong><br />
<span style="font-size:small;">Developed in the 1960s. Widely used for mini and mainframe programming. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/COBOL"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">COBOL</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">dBASE</span></strong><br />
<span style="font-size:small;">Used to be widely used in business applications, but FoxPro (Microsoft&#8217;s dBASE) has survived the longest. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/Visual%20FoxPro"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Visual FoxPro</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia2.thefreedictionary.com/FoxBase"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">FoxBase</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia2.thefreedictionary.com/Clipper"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Clipper</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia2.thefreedictionary.com/Quicksilver"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Quicksilver</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">F#</span></strong><br />
<span style="font-size:small;">Pronounced &#8220;F-sharp.&#8221; A Microsoft .NET scripting language based on ML. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/F"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">F#</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">FORTH</span></strong><br />
<span style="font-size:small;">Developed in the 1960s, FORTH has been used in process control and game applications. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/FORTH"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">FORTH</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">FORTRAN</span></strong><br />
<span style="font-size:small;">Developed in 1954 by IBM, it was the first major scientific programming language and continues to be widely used. Some commercial applications have been developed in FORTRAN. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/FORTRAN"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">FORTRAN</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">Java</span></strong><br />
<span style="font-size:small;">The programming language developed by Sun and repositioned for Web use. It is widely used on the server side, although client applications are increasingly used. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/Java"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Java</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">JavaScript</span></strong><br />
<span style="font-size:small;">A scripting language widely used on the Web. JavaScript is embedded into many HTML pages. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/JavaScript"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">JavaScript</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">LISP</span></strong><br />
<span style="font-size:small;">Developed in 1960. Used for AI applications. Its syntax is very different than other languages. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/LISP"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">LISP</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">Logo</span></strong><br />
<span style="font-size:small;">Developed in the 1960s, it was noted for its ease of use and &#8220;turtle graphics&#8221; drawing functions. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/Logo"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Logo</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">M</span></strong><br />
<span style="font-size:small;">Originally MUMPS (Massachusetts Utility MultiProgramming System), it includes its own database. It is widely used in medical applications. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/M"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">M</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">Modula-2</span></strong><br />
<span style="font-size:small;">Enhanced version of Pascal introduced in 1979. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/Modula-2"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Modula-2</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">Pascal</span></strong><br />
<span style="font-size:small;">Originally an academic language developed in the 1970s. Borland commercialized it with its Turbo Pascal. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/Pascal"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Pascal</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">Perl</span></strong><br />
<span style="font-size:small;">A scripting language widely used on the Web to write CGI scripts. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/Perl"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Perl</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">Prolog</span></strong><br />
<span style="font-size:small;">Developed in France in 1973. Used throughout Europe and Japan for AI applications. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/Prolog"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Prolog</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">Python</span></strong><br />
<span style="font-size:small;">A scripting language used for system utilities and Internet scripts. Developed in Amsterdam by Guido van Rossum. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/Python"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Python</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">REXX</span></strong><br />
<span style="font-size:small;">Runs on IBM mainframes and OS/2. Used as a general purpose macro language. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/REXX"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">REXX</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">VBScript</span></strong><br />
<span style="font-size:small;">Subset of Visual Basic used on the Web similar to JavaScript. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/VBScript"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">VBScript</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">Visual Basic</span></strong><br />
<span style="font-size:small;">Version of BASIC for Windows programming from Microsoft that has been widely used. See </span></span><a href="http://encyclopedia2.thefreedictionary.com/Visual%20Basic"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Visual Basic</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">Web Languages</span></strong><br />
<span style="font-size:small;">Languages such as JavaScript, Jscript, Perl and CGI are used to automate Web pages as well as link them to other applications running in servers.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><strong><span style="font-size:14pt;">Millions of Languages!</span></strong><span style="font-size:14pt;"></span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Programmers must use standard names for the instruction verbs (add, compare, etc.) in the language they use. In addition, a company generally uses standardized names for the data elements in its databases. However, programmers typically &#8220;make up&#8221; names for all the functions (subroutines) in the program. Since programmers are loathe to document their code, the readability of the names chosen for these routines is critical.</p>
<p>In a single program, the programmer could make up hundreds of function names as well as names for data structures that hold fixed sums, predefined tables and display messages.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<h1 style="margin:auto 0;"><span style="font-size:26pt;"><span style="font-family:Times New Roman;">Set in mathematics</span></span></h1>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-family:Times New Roman;"><span class="hw1"><span style="font-size:14pt;"><strong>Set </strong></span></span><span style="font-size:small;">in mathematics, collection of entities, called elements of the set, that may be real objects or conceptual entities. Set theory not only is involved in many areas of mathematics but has important applications in other fields as well, e.g., computer technology and atomic and nuclear physics. </span></span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Definition of Sets</span></span></h2>
<p style="text-indent:.5in;"><span style="font-size:small;font-family:Times New Roman;">A set must be well defined; i.e., for any given object, it must be unambiguous whether or not the object is an element of the set. For example, if a set contains all the chairs in a designated room, then any chair can be determined either to be in or not in the set. If there were no chairs in the room, the set would be called the empty, or null, set, i.e., one containing no elements. A set is usually designated by a capital letter. If <span>A</span> is the set of even numbers between 1 and 9, then <span>A</span>={2, 4, 6, 8}. The braces, {}, are commonly used to enclose the listed elements of a set. The elements of a set may be described without actually being listed. If <span>B</span> is the set of real numbers that are solutions of the equation <span>x</span><sup>2</sup>=9, then the set can be written as <span>B</span>={<span>x</span>:<span>x</span><sup>2</sup>=9} or <span>B</span>={<span>x</span>|<span>x</span><sup>2</sup>=9}, both of which are read: <span>B</span> is the set of all <span>x</span> such that <span>x</span><sup>2</sup>=9; hence <span>B</span> is the set {3,−3}.</span></p>
<p><span style="font-size:small;"><span style="font-family:Times New Roman;">Membership in a set is indicated by the symbol </span><span style="font-family:Arial;">∈</span><span style="font-family:Times New Roman;"> and nonmembership by </span><span style="font-family:&quot;">∉</span><span style="font-family:Times New Roman;">; thus, </span><span><span style="font-family:Times New Roman;">x</span></span><span style="font-family:Arial;">∈</span><span style="font-family:Times New Roman;"><span>A</span> means that element <span>x</span> is a member of the set <span>A</span> (read simply as &#8220;<span>x</span> is a member of <span>A</span>&#8220;) and </span><span><span style="font-family:Times New Roman;">y</span></span><span style="font-family:&quot;">∉</span><span style="font-family:Times New Roman;"><span>A</span> means <span>y</span> is not a member of <span>A.</span> The symbols </span><span style="font-family:Arial;">⊂</span><span style="font-family:Times New Roman;"> and </span><span style="font-family:Arial;">⊃</span><span style="font-family:Times New Roman;"> are used to indicate that one set <span>A</span> is contained within or contains another set <span>B;</span></span><span style="font-family:Times New Roman;"> <span>A</span></span><span style="font-family:Arial;">⊂</span><span style="font-family:Times New Roman;"><span>B</span> means that <span>A</span> is contained within, or is a subset of, <span>B;</span> and </span><span><span style="font-family:Times New Roman;">A</span></span><span style="font-family:Arial;">⊃</span><span style="font-family:Times New Roman;"><span>B</span> means that <span>A</span> contains, or is a superset of, <span>B.</span></span></span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Operations on Sets</span></span></h2>
<p><span style="font-size:small;"><span style="font-family:Times New Roman;">There are three basic set operations: intersection, union, and complementation. The intersection of two sets is the set containing the elements common to the two sets and is denoted by the symbol ∩. The union of two sets is the set containing all elements belonging to either one of the sets or to both, denoted by the symbol </span><span style="font-family:Arial;">∪</span><span style="font-family:Times New Roman;">. Thus, if <span>C</span>={1, 2, 3, 4} and <span>D</span>={3, 4, 5}, then <span>C</span>∩<span>D</span>={3, 4} and </span><span><span style="font-family:Times New Roman;">C</span></span><span style="font-family:Arial;">∪</span><span style="font-family:Times New Roman;"><span>D</span>={1, 2, 3, 4, 5}. <span style="text-decoration:underline;">These two operations each obey the <a href="http://encyclopedia2.thefreedictionary.com/associative+law"><span style="color:windowtext;">associative law</span></a> and the <a href="http://encyclopedia2.thefreedictionary.com/commutative+law"><span style="color:windowtext;">commutative law</span></a>, and together they obey the <a href="http://encyclopedia2.thefreedictionary.com/distributive+law"><span style="color:windowtext;">distributive law</span></a>.</span></span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">In any discussion the set of all elements under consideration must be specified, and it is called the universal set. If the universal set is <span>U</span>={1, 2, 3, 4, 5} and <span>A</span>={1, 2, 3}, then the complement of <span>A</span> (written <span>A′</span>) is the set of all elements in the universal set that are not in <span>A,</span> or <span>A′</span>={4, 5}. The intersection of a set and its complement is the empty set (denoted by </span><span style="font-family:&quot;">∅</span><span style="font-family:Times New Roman;">), or </span><span style="font-family:Times New Roman;"><span>A</span>∩<span>A′</span>=</span><span style="font-family:&quot;">∅</span><span style="font-family:Times New Roman;">; the union of a set and its complement is the universal set, or </span><span><span style="font-family:Times New Roman;">A</span></span><span style="font-family:Arial;">∪</span><span style="font-family:Times New Roman;"><span>A′</span>=<span>U.</span> </span></span><a href="http://encyclopedia2.thefreedictionary.com/symbolic+logic"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">symbolic logic</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">.<span class="hint1"><span style="color:windowtext;font-family:&quot;"><span style="background-color:#fdf5e6;"> </span></span></span></span></span></p>
<h1 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Set</span></span></h1>
<p style="text-indent:.5in;"><span style="font-size:small;font-family:Times New Roman;">In mathematics and logic, any collection of objects (elements), which may be mathematical (e.g., numbers, </span><a title="function" href="http://encyclopedia2.thefreedictionary.com/function"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">functions</span></span></a><span style="font-size:small;font-family:Times New Roman;">) or not. The intuitive idea of a set is probably even older than that of </span><a title="number" href="http://encyclopedia2.thefreedictionary.com/number"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">number</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">. Members of a herd of animals, for example, could be matched with stones in a sack without members of either set actually being counted. The notion extends into the infinite. For example, the set of integers from 1 to 100 is finite, whereas the set of all integers is infinite. A set is commonly represented as a list of all its members enclosed in braces. A set with no members is called an empty, or null, set, and is denoted </span><span style="font-family:&quot;">∅</span><span style="font-family:Times New Roman;">. Because an infinite set cannot be listed, it is usually represented by a formula that generates its elements when applied to the elements of the set of counting numbers. Thus, {2<span>x</span> | <span>x</span> = 1,2,3,&#8230;} represents the set of positive even numbers (the vertical bar means “such that”).</span></span></p>
<h1 style="margin:auto 0;"><span style="text-decoration:underline;"><span style="font-size:16pt;"><span style="font-family:Times New Roman;">SET</span></span></span></h1>
<p><span style="font-family:Times New Roman;"><span style="font-size:small;">(</span><span style="font-size:16pt;">S</span><span style="font-size:16pt;">ecure <span>E</span>lectronic <span>T</span>ransaction</span><span style="font-size:small;">) </span></span></p>
<p style="text-indent:.5in;"><span style="font-size:small;font-family:Times New Roman;">A standard protocol from MasterCard and Visa for securing online credit card payments via the Internet. It is a three-way transaction: the user, merchant and bank must use the SET protocols.</p>
<p>Credit card data and a digital certificate (for authentication) is stored in a plug-in to the user&#8217;s Web browser. The order is received by a SET-enabled merchant server that passes encrypted payment information to the bank. Approval is electronically sent to the merchant.</span></p>
<p><span style="font-family:Times New Roman;"><span class="hw1"><span style="font-weight:normal;font-size:16pt;">set</span></span><strong><span style="font-size:16pt;"> </span></strong></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>1.</strong> <span>Maths</span> <span>logic</span> </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>a.</strong> a collection of numbers, objects, etc., that is treated as an entity: {3, the moon} is the set the two members of which are the number 3 and the moon </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>b.</strong> (in some formulations) a class that can itself be a member of other classes </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>2.</strong> any apparatus that receives or transmits television or radio signals </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>3.</strong> <span>Tennis</span> <span>squash</span> <span>badminton</span> one of the units of a match, in tennis one in which one player or pair of players must win at least six games </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>4.</strong>  </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>a.</strong> the number of couples required for a formation dance </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>b.</strong> a series of figures that make up a formation dance </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>5.</strong>  </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>a.</strong> a band&#8217;s or performer&#8217;s concert repertoire on a given occasion </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>b.</strong> a continuous performance </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<table class="MsoNormalTable" style="background:white;" border="0" cellpadding="0">
<tbody>
<tr>
<td style="width:1%;background-color:transparent;border:#d4d0c8;padding:.75pt;" width="1%" valign="top">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;">1.</span></strong></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">(security)</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>SET</strong> &#8211; Secure Electronic Transaction.</span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
<tr>
<td style="width:1%;background-color:transparent;border:#d4d0c8;padding:.75pt;" width="1%" valign="top">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;">2.</span></strong></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">(electronics)</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>SET</strong> &#8211; </span></span><a href="http://encyclopedia2.thefreedictionary.com/Single+Electron+Tunneling"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Single Electron Tunneling</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
<tr>
<td style="width:1%;background-color:transparent;border:#d4d0c8;padding:.75pt;" width="1%" valign="top">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;">3.</span></strong></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">(standard)</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>SET</strong> &#8211; </span></span><a href="http://encyclopedia2.thefreedictionary.com/Standard+d'Echange+et+de+Transfert"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Standard d&#8217;Echange et de Transfert</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
<tr>
<td style="width:1%;background-color:transparent;border:#d4d0c8;padding:.75pt;" width="1%" valign="top">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;">4.</span></strong></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>set</strong> &#8211; A collection of objects, known as the elements of the set, specified in such a way that we can tell in principle whether or not a given object belongs to it. E.g. the set of all prime numbers, the set of zeros of the cosine function.</p>
<p>For each set there is a </span></span><a href="http://encyclopedia2.thefreedictionary.com/predicate"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">predicate</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (or property) which is true for (possessed by) exactly those objects which are elements of the set. The predicate may be defined by the set or vice versa. Order and repetition of elements within the set are irrelevant so, for example, 1, 2, 3 = 3, 2, 1 = 1, 3, 1, 2, 2.</p>
<p>Some common set of numbers are given the following names:</p>
<p>N = the natural numbers 0, 1, 2, &#8230;</p>
<p>Z = the integers &#8230;, -2, -1, 0, 1, 2, &#8230;</p>
<p>Q = the rational numbers p/q where p, q are in Z and q /= 0.</p>
<p>R = the real numbers</p>
<p>C = the complex numbers.</p>
<p>The empty set is the set with no elements. The intersection of two sets X and Y is the set containing all the elements x such that x is in X and x is in Y. The union of two sets is the set containing all the elements x such that x is in X or x is in Y.</span></td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:26pt;"><span style="font-family:Times New Roman;">RELATION(MATHEMATICS)</span></span></strong></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><strong><span style="font-size:26pt;"><span style="font-family:Times New Roman;"> </span></span></strong></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">In mathematics, the concept of a <strong>relation</strong> or <strong>relationship</strong> is a generalization of <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/binary+relation"><span style="color:windowtext;text-decoration:none;">2-place relation</span></a>s</span></em>, such as the relation of <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/equality+(mathematics)"><span style="color:windowtext;text-decoration:none;">equality</span></a>,</span></em> denoted by the sign &#8220;=&#8221; in a statement like &#8220;5 + 7 = 12,&#8221; or the relation of <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/order+theory"><span style="color:windowtext;text-decoration:none;">order</span></a>,</span></em> denoted by the sign &#8220;&lt;&#8221; in a statement like &#8220;5 &lt; 12&#8243;. Relations that involve two <em><span style="font-style:normal;">places</span></em> or <em><span style="font-style:normal;">roles</span></em> are called <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/binary+relation"><span style="color:windowtext;text-decoration:none;">binary relations</span></a></span></em> by some and <em><span style="font-style:normal;">dyadic relations</span></em> by others, the latter being historically prior but also useful when necessary to avoid confusion with </span><a href="http://encyclopedia.thefreedictionary.com/binary+numeral+system"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">binary (base 2) numerals</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>The next step up is to consider relations that can involve more than two places or roles, but still a finite number of them. These are called <em><span style="font-style:normal;">finite place</span></em> or <strong>finitary</strong> relations. A finitary relation that involves <em><span style="font-style:normal;">k</span></em> places is variously called a <em><span style="font-style:normal;">k-ary</span></em>, a <em><span style="font-style:normal;">k-adic</span></em>, or a <em><span style="font-style:normal;">k-dimensional</span></em> relation. The number <em><span style="font-style:normal;">k</span></em> is then called the <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/arity"><span style="color:windowtext;text-decoration:none;">arity</span></a></span></em>, the <em><span style="font-style:normal;">adicity</span></em>, or the <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/dimension"><span style="color:windowtext;text-decoration:none;">dimension</span></a></span></em> of the relation, respectively. See the formal definitions below. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Informal introduction</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">The definition of <em><span style="font-style:normal;">relation</span></em> given in the next Section formally captures a concept that is actually quite familiar from everyday life. For example, consider the relationship, involving three roles that people might play, expressed in a statement of the form &#8220;<em><span style="font-style:normal;">X</span></em> thinks that <em><span style="font-style:normal;">Y</span></em> likes <em><span style="font-style:normal;">Z</span></em> &#8221;. The facts of a concrete situation could be organized in a Table like the following: </span></p>
<div>
<table class="MsoNormalTable" style="background:lightcyan;width:60%;" border="1" cellspacing="0" cellpadding="0" width="60%">
<tbody>
<tr>
<td style="border-right:windowtext 1pt solid;border-top:#d4d0c8 1pt inset;background:paleturquoise;border-left:windowtext 1pt solid;border-bottom:#d4d0c8;padding:3pt;" colspan="3">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;">Relation S : X thinks that Y likes Z</span></strong></p>
</td>
</tr>
<tr>
<td style="background:paleturquoise;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Person X</span></span></strong></p>
</td>
<td style="background:paleturquoise;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Person Y</span></span></strong></p>
</td>
<td style="background:paleturquoise;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Person Z </span></span></strong></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Alice</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Bob</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Denise</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Charles</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Alice</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Bob</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Charles</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Charles</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Alice</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Denise</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Denise</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Denise</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<p><span style="font-size:small;font-family:Times New Roman;">Each row of the Table records a fact or makes an assertion of the form &#8220;<em><span style="font-style:normal;">X</span></em> thinks that <em><span style="font-style:normal;">Y</span></em> likes <em><span style="font-style:normal;">Z</span></em> &#8221;. For instance, the first row says, in effect, &#8220;Alice thinks that Bob likes Denise&#8221;. The Table represents a relation <em><span style="font-style:normal;">S</span></em> over the set <em><span style="font-style:normal;">P</span></em> of people under discussion: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">P</span></em> = {Alice, Bob, Charles, Denise}.</span></span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">The data of the Table are equivalent to the following set of ordered triples: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">S</span></em> = {(Alice, Bob, Denise), (Charles, Alice, Bob), (Charles, Charles, Alice), (Denise, Denise, Denise)}.</span></span></p>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">By a slight overuse of notation, it is usual to write <em><span style="font-style:normal;">S</span></em>(Alice, Bob, Denise) to say the same thing as the first row of the Table. The relation <em><span style="font-style:normal;">S</span></em> is a <em><span style="font-style:normal;">ternary</span></em> relation, since there are <em><span style="font-style:normal;">three</span></em> items involved in each row. The relation itself is a mathematical object defined in terms of concepts from </span><a href="http://encyclopedia.thefreedictionary.com/set+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">set theory</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (i.e., the relation is a subset of the </span><a href="http://encyclopedia.thefreedictionary.com/Cartesian+product"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Cartesian product</span></span></a><span style="font-size:small;font-family:Times New Roman;"> on {Person X, Person Y, Person Z}), that carries all of the information from the Table in one neat package. Mathematically, then, a relation is simply a &#8220;</span><a href="http://encyclopedia.thefreedictionary.com/set+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">set</span></span></a><span style="font-size:small;font-family:Times New Roman;">&#8220;.</p>
<p>The Table for relation <em><span style="font-style:normal;">S</span></em> is an extremely simple example of a </span><a href="http://encyclopedia.thefreedictionary.com/relational+database"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">relational database</span></span></a><span style="font-size:small;font-family:Times New Roman;">. The theoretical aspects of databases are the specialty of one branch of </span><a href="http://encyclopedia.thefreedictionary.com/computer+science"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer science</span></span></a><span style="font-size:small;font-family:Times New Roman;">, while their practical impacts have become all too familiar in our everyday lives. Computer scientists, logicians, and mathematicians, however, tend to see different things when they look at these concrete examples and samples of the more general concept of a relation.</p>
<p>For one thing, databases are designed to deal with empirical data, and experience is always finite, whereas mathematics is nothing if not concerned with infinity, at the very least, potential infinity. This difference in perspective brings up a number of ideas that are usefully introduced at this point, if by no means covered in depth. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;">Example: divisibility</span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">A more typical example of a 2-place relation in mathematics is the relation of <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/divisor"><span style="color:windowtext;text-decoration:none;">divisibility</span></a></span></em> between two positive integers <em><span style="font-style:normal;">n</span></em> and <em><span style="font-style:normal;">m</span></em> that is expressed in statements like &#8220;<em><span style="font-style:normal;">n</span></em> divides <em><span style="font-style:normal;">m</span></em>&#8221; or &#8220;<em><span style="font-style:normal;">n</span></em> goes into <em><span style="font-style:normal;">m</span></em>.&#8221; This is a relation that comes up so often that a special symbol &#8220;|&#8221; is reserved to express it, allowing one to write &#8220;<em><span style="font-style:normal;">n</span></em>|<em><span style="font-style:normal;">m</span></em>&#8221; for &#8220;<em><span style="font-style:normal;">n</span></em> divides <em><span style="font-style:normal;">m</span></em>.&#8221;</p>
<p>To express the binary relation of divisibility in terms of sets, we have the set <em><span style="font-style:normal;">P</span></em> of positive integers, <em><span style="font-style:normal;">P</span></em> = {1, 2, 3, …}, and we have the binary relation <em><span style="font-style:normal;">D</span></em> on <em><span style="font-style:normal;">P</span></em> such that the ordered pair (<em><span style="font-style:normal;">n</span></em>, <em><span style="font-style:normal;">m</span></em>) is in the relation <em><span style="font-style:normal;">D</span></em> just in case <em><span style="font-style:normal;">n</span></em>|<em><span style="font-style:normal;">m</span></em>. In other turns of phrase that are frequently used, one says that the number <em><span style="font-style:normal;">n</span></em> is related by <em><span style="font-style:normal;">D</span></em> to the number <em><span style="font-style:normal;">m</span></em> just in case <em><span style="font-style:normal;">n</span></em> is a factor of <em><span style="font-style:normal;">m</span></em>, that is, just in case <em><span style="font-style:normal;">n</span></em> divides <em><span style="font-style:normal;">m</span></em> with no remainder. The relation <em><span style="font-style:normal;">D</span></em>, regarded as a set of ordered pairs, consists of all pairs of numbers (<em><span style="font-style:normal;">n</span></em>, <em><span style="font-style:normal;">m</span></em>) such that <em><span style="font-style:normal;">n</span></em> divides <em><span style="font-style:normal;">m</span></em>.</p>
<p>For example, 2 is a factor of 4, and 6 is a factor of 72, which can be written either as 2|4 and 6|72 or as <em><span style="font-style:normal;">D</span></em>(2, 4) and <em><span style="font-style:normal;">D</span></em>(6, 72). </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Formal definitions</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">There are two definitions of <em><span style="font-style:normal;">k</span></em>-place relations that are commonly encountered in mathematics. In order of simplicity, the first of these definitions is as follows:</p>
<p><strong>Definition 1.</strong> A <strong>relation</strong> <em><span style="font-style:normal;">L</span></em> over the </span><a href="http://encyclopedia.thefreedictionary.com/set"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">sets</span></span></a><span style="font-size:small;font-family:Times New Roman;"> <em><span style="font-style:normal;">X</span></em><sub>1</sub>, …, <em><span style="font-style:normal;">X<sub>k</sub></span></em> is a </span><a href="http://encyclopedia.thefreedictionary.com/subset"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">subset</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of their </span><a href="http://encyclopedia.thefreedictionary.com/cartesian+product"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">cartesian product</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, written <em><span style="font-style:normal;">L</span></em> </span><span style="font-family:Arial;">⊆</span><span style="font-family:Times New Roman;"> <em><span style="font-style:normal;">X</span></em><sub>1</sub> × … × <em><span style="font-style:normal;">X<sub>k</sub></span></em>. Under this definition, then, a <em><span style="font-style:normal;">k</span></em>-ary relation is simply a set of <em><span style="font-style:normal;">k</span></em>-</span></span><a href="http://encyclopedia.thefreedictionary.com/tuple"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">tuples</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">.</p>
<p>The second definition makes use of an idiom that is common in mathematics, stipulating that &#8220;such and such is an <em><span style="font-style:normal;">n</span></em>-tuple&#8221; in order to ensure that such and such a mathematical object is determined by the specification of <em><span style="font-style:normal;">n</span></em> component mathematical objects. In the case of a relation <em><span style="font-style:normal;">L</span></em> over <em><span style="font-style:normal;">k</span></em> sets, there are <em><span style="font-style:normal;">k</span></em> + 1 things to specify, namely, the <em><span style="font-style:normal;">k</span></em> sets plus a subset of their cartesian product. In the idiom, this is expressed by saying that <em><span style="font-style:normal;">L</span></em> is a (<em><span style="font-style:normal;">k</span></em>+1)-tuple.</p>
<p><strong>Definition 2.</strong> A <strong>relation</strong> <em><span style="font-style:normal;">L</span></em> over the sets <em><span style="font-style:normal;">X</span></em><sub>1</sub>, …, <em><span style="font-style:normal;">X<sub>k</sub></span></em> is a (<em><span style="font-style:normal;">k</span></em>+1)-tuple <em><span style="font-style:normal;">L</span></em> = (<em><span style="font-style:normal;">X</span></em><sub>1</sub>, …, <em><span style="font-style:normal;">X<sub>k</sub></span></em>, <em><span style="font-style:normal;">G</span></em>(<em><span style="font-style:normal;">L</span></em>)), where <em><span style="font-style:normal;">G</span></em>(<em><span style="font-style:normal;">L</span></em>) is a subset of the cartesian product <em><span style="font-style:normal;">X</span></em><sub>1</sub> × … × <em><span style="font-style:normal;">X<sub>k</sub></span></em>. <em><span style="font-style:normal;">G</span></em>(<em><span style="font-style:normal;">L</span></em>) is called the <em><span style="font-style:normal;">graph</span></em> of <em><span style="font-style:normal;">L</span></em>.</p>
<p>Elements of a relation are more briefly denoted by using boldface characters, for example, the constant element </span></span><span style="font-size:small;font-family:Times New Roman;">= (a<sub>1</sub>, …, a<em><sub><span style="font-style:normal;">k</span></sub></em>) or the variable element </span><span style="font-size:small;font-family:Times New Roman;">= (<em><span style="font-style:normal;">x</span></em><sub>1</sub>, …, <em><span style="font-style:normal;">x<sub>k</sub></span></em>).</p>
<p>A statement of the form &#8220;</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">is in the relation <em><span style="font-style:normal;">L</span></em> &#8221; is taken to mean that </span><span style="font-size:small;font-family:Times New Roman;">is in <em><span style="font-style:normal;">L</span></em> under the first definition and that </span><span style="font-size:small;font-family:Times New Roman;">is in <em><span style="font-style:normal;">G</span></em>(<em><span style="font-style:normal;">L</span></em>) under the second definition.</p>
<p>The following considerations apply under either definition: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">* The sets <em><span style="font-style:normal;">X<sub>j</sub></span></em> for <em><span style="font-style:normal;">j</span></em> = 1 to <em><span style="font-style:normal;">k</span></em> are called the <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/domain+(mathematics)"><span style="color:windowtext;text-decoration:none;">domain</span></a>s</span></em> of the relation. In the case of the first definition, the relation itself does not uniquely determine a given sequence of domains.</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">* If all of the domains <em><span style="font-style:normal;">X<sub>j</sub></span></em> are the same set <em><span style="font-style:normal;">X</span></em>, then <em><span style="font-style:normal;">L</span></em> is more simply referred to as a <em><span style="font-style:normal;">k</span></em>-ary relation over <em><span style="font-style:normal;">X</span></em>.</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">* If any of the domains <em><span style="font-style:normal;">X<sub>j</sub></span></em> is empty, then the cartesian product is empty, and the only relation over such a sequence of domains is the empty relation <em><span style="font-style:normal;">L</span></em> = </span><span style="font-size:small;font-family:Times New Roman;">. As a result, naturally occurring applications of the relation concept typically involve a stipulation that all of the domains be nonempty.</span></p>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">As a rule, whatever definition best fits the application at hand will be chosen for that purpose, and anything that falls under it will be called a &#8216;relation&#8217; for the duration of that discussion. If it becomes necessary to distinguish the two alternatives, the latter type of object can be referred to as an <em><span style="font-style:normal;">embedded</span></em> or <em><span style="font-style:normal;">included</span></em> relation.</p>
<p>If <em><span style="font-style:normal;">L</span></em> is a relation over the domains <em><span style="font-style:normal;">X</span></em><sub>1</sub>, …, <em><span style="font-style:normal;">X<sub>k</sub></span></em>, it is conventional to consider a sequence of terms called <em><span style="font-style:normal;">variables</span></em>, <em><span style="font-style:normal;">x</span></em><sub>1</sub>, …, <em><span style="font-style:normal;">x<sub>k</sub></span></em>, that are said to <em><span style="font-style:normal;">range over</span></em> the respective domains.</p>
<p>A <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/boolean+domain"><span style="color:windowtext;text-decoration:none;">boolean domain</span></a></span></em> <strong>B</strong> is a generic 2-element set, say, <strong>B</strong> = {0, 1}, whose elements are interpreted as logical values, typically 0 = false and 1 = true.</p>
<p>The <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/characteristic+function"><span style="color:windowtext;text-decoration:none;">characteristic function</span></a></span></em> of the relation <em><span style="font-style:normal;">L</span></em>, written <em><span style="font-style:normal;">f<sub>L</sub></span></em> or χ(<em><span style="font-style:normal;">L</span></em>), is the </span><a href="http://encyclopedia.thefreedictionary.com/boolean-valued+function"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">boolean-valued function</span></span></a><span style="font-size:small;font-family:Times New Roman;"> <em><span style="font-style:normal;">f<sub>L</sub></span></em> : <em><span style="font-style:normal;">X</span></em><sub>1</sub> × … × <em><span style="font-style:normal;">X<sub>k</sub></span></em> → <strong>B</strong>, defined in such a way that <em><span style="font-style:normal;">f<sub>L</sub></span></em>(</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">) = 1 just in case the <em><span style="font-style:normal;">k</span></em>-tuple </span><span style="font-size:small;font-family:Times New Roman;">is in the relation <em><span style="font-style:normal;">L</span></em>. The characteristic function of a relation may also be called its <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/indicator+function"><span style="color:windowtext;text-decoration:none;">indicator function</span></a></span></em>, especially in probability and statistics.</p>
<p>It is conventional in applied mathematics, computer science, and statistics to refer to a boolean-valued function like <em><span style="font-style:normal;">f<sub>L</sub></span></em> as a <em><span style="font-style:normal;">k</span></em>-place <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/predicate+(mathematics)"><span style="color:windowtext;text-decoration:none;">predicate</span></a></span></em>. From the more abstract viewpoints of </span><a href="http://encyclopedia.thefreedictionary.com/formal+logic"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">formal logic</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/model+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">model theory</span></span></a><span style="font-size:small;font-family:Times New Roman;">, the relation <em><span style="font-style:normal;">L</span></em> is seen as constituting a <em><span style="font-style:normal;">logical model</span></em> or a <em><span style="font-style:normal;">relational structure</span></em> that serves as one of many possible </span><a href="http://encyclopedia.thefreedictionary.com/interpretation"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">interpretations</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of a corresponding <em><span style="font-style:normal;">k</span></em>-place <em><span style="font-style:normal;">predicate symbol</span></em>, as that term is used in <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/first-order+logic"><span style="color:windowtext;text-decoration:none;">predicate calculus</span></a></span></em>.</p>
<p>Due to the convergence of many different styles of study on the same areas of interest, the reader will find much variation in usage here. The variation presented in this article treats a relation as the </span><a href="http://encyclopedia.thefreedictionary.com/set+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">set-theoretic</span></span></a><span style="font-size:small;font-family:Times New Roman;"> <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/extension+(semantics)"><span style="color:windowtext;text-decoration:none;">extension</span></a></span></em> of a relational concept or term. Another variation reserves the term &#8216;relation&#8217; to the corresponding logical entity, either the <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/comprehension+(logic)"><span style="color:windowtext;text-decoration:none;">logical comprehension</span></a></span></em>, which is the totality of <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/intension"><span style="color:windowtext;text-decoration:none;">intensions</span></a></span></em> or abstract <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/property+(philosophy)"><span style="color:windowtext;text-decoration:none;">properties</span></a></span></em> that all of the elements of the relation in extension have in common, or else the symbols that are taken to denote these elements and intensions. Further, but hardly finally, some writers of the latter persuasion introduce terms with more concrete connotations, like &#8216;relational structure&#8217;, for the set-theoretic extension of a given relational concept. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Example: coplanarity</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">For lines <em><span style="font-style:normal;">L</span></em> in three-dimensional space, there is a ternary relation picking out the triples of lines that are </span><a href="http://encyclopedia.thefreedictionary.com/coplanar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">coplanar</span></span></a><span style="font-size:small;font-family:Times New Roman;">. This <em><span style="font-style:normal;">does not</span></em> reduce to the binary </span><a href="http://encyclopedia.thefreedictionary.com/symmetric+relation"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">symmetric relation</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of coplanarity of pairs of lines.</p>
<p>In other words, writing <em><span style="font-style:normal;">P</span></em>(<em><span style="font-style:normal;">L</span></em>, <em><span style="font-style:normal;">M</span></em>, <em><span style="font-style:normal;">N</span></em>) when the lines <em><span style="font-style:normal;">L</span></em>, <em><span style="font-style:normal;">M</span></em>, and <em><span style="font-style:normal;">N</span></em> lie in a plane, and <em><span style="font-style:normal;">Q</span></em>(<em><span style="font-style:normal;">L</span></em>, <em><span style="font-style:normal;">M</span></em>) for the binary relation, it is not true that <em><span style="font-style:normal;">Q</span></em>(<em><span style="font-style:normal;">L</span></em>, <em><span style="font-style:normal;">M</span></em>), <em><span style="font-style:normal;">Q</span></em>(<em><span style="font-style:normal;">M</span></em>, <em><span style="font-style:normal;">N</span></em>) and <em><span style="font-style:normal;">Q</span></em>(<em><span style="font-style:normal;">N</span></em>, <em><span style="font-style:normal;">L</span></em>) together imply <em><span style="font-style:normal;">P</span></em>(<em><span style="font-style:normal;">L</span></em>, <em><span style="font-style:normal;">M</span></em>, <em><span style="font-style:normal;">N</span></em>); although the converse is certainly true (any pair out of three coplanar lines is coplanar, <em><span style="font-style:normal;">a fortiori</span></em>). There are two geometrical reasons for this.</p>
<p>In one case, for example taking the <em><span style="font-style:normal;">x</span></em>-axis, <em><span style="font-style:normal;">y</span></em>-axis and <em><span style="font-style:normal;">z</span></em>-axis, the three lines are concurrent, i.e. intersect at a single point. In another case, <em><span style="font-style:normal;">L</span></em>, <em><span style="font-style:normal;">M</span></em>, and <em><span style="font-style:normal;">N</span></em> can be three edges of an infinite </span><a href="http://encyclopedia.thefreedictionary.com/triangular+prism"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">triangular prism</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>What is true is that if each pair of lines intersects, and the points of intersection are distinct, then pairwise coplanarity implies coplanarity of the triple. </span></p>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">Relations are classified according to the number of sets in the cartesian product, in other words the number of terms in the expression: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">* Unary relation or </span><a href="http://encyclopedia.thefreedictionary.com/property+(philosophy)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">property</span></span></a><span style="font-size:small;font-family:Times New Roman;">: <em><span style="font-style:normal;">L</span></em>(<em><span style="font-style:normal;">u</span></em>)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;">* Binary relation: <em><span style="font-style:normal;">L</span></em>(<em><span style="font-style:normal;">u</span></em>, <em><span style="font-style:normal;">v</span></em>) or <em><span style="font-style:normal;">u</span></em> <em><span style="font-style:normal;">L</span></em> <em><span style="font-style:normal;">v</span></em></span></span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">* Ternary relation: <em><span style="font-style:normal;">L</span></em>(<em><span style="font-style:normal;">u</span></em>, <em><span style="font-style:normal;">v</span></em>, <em><span style="font-style:normal;">w</span></em>)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">* Quaternary relation: <em><span style="font-style:normal;">L</span></em>(<em><span style="font-style:normal;">u</span></em>, <em><span style="font-style:normal;">v</span></em>, <em><span style="font-style:normal;">w</span></em>, <em><span style="font-style:normal;">x</span></em>)</span></p>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">Relations with more than four terms are usually referred to as <em><span style="font-style:normal;">k</span></em>-ary, for example, &#8220;a 5-ary relation&#8221;.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:26pt;"><span style="font-family:Times New Roman;">String operation</span></span></strong></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">In </span><a href="http://encyclopedia.thefreedictionary.com/computer+science"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer science</span></span></a><span style="font-size:small;font-family:Times New Roman;">, in the area of </span><a href="http://encyclopedia.thefreedictionary.com/formal+language+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">formal language theory</span></span></a><span style="font-size:small;font-family:Times New Roman;">, frequent use is made of a variety of </span><a href="http://encyclopedia.thefreedictionary.com/string+functions"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">string functions</span></span></a><span style="font-size:small;font-family:Times New Roman;">; however, the notation used is different from that used on </span><a href="http://encyclopedia.thefreedictionary.com/computer+programming"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer programming</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and some commonly used functions in the theoretical realm are rarely used when programming. This article defines some of these basic terms. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;">Alphabet of a string</span></h2>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">The <strong>alphabet of a string</strong> is a list of all of the letters that occur in a particular string. If <em><span style="font-style:normal;">s</span></em> is a string, its </span><a href="http://encyclopedia.thefreedictionary.com/alphabet+(computer+science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">alphabet</span></span></a><span style="font-size:small;font-family:Times New Roman;"> is denoted by </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<h2 style="margin:12pt 0 3pt;"><span style="font-weight:normal;font-style:normal;font-family:&quot;"><span style="font-size:large;">String substitution</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">Let <em><span style="font-style:normal;">L</span></em> be a </span><a href="http://encyclopedia.thefreedictionary.com/language+(computer+science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">language</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and let </span><span style="font-size:small;font-family:Times New Roman;">be its alphabet. A <strong>string substitution</strong> or simply a <strong>substitution</strong> is a mapping <em><span style="font-style:normal;">f</span></em> that maps letters in </span><span style="font-size:small;font-family:Times New Roman;">to languages (possibly in a different alphabet). Thus, for example, given a letter </span><span style="font-size:small;font-family:Times New Roman;">, one has </span><span style="font-size:small;font-family:Times New Roman;">where </span><span style="font-size:small;font-family:Times New Roman;">is some language whose alphabet is </span><span style="font-size:small;font-family:Times New Roman;">. This mapping may be extended to strings as </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">for the </span><a href="http://encyclopedia.thefreedictionary.com/empty+string"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">empty string</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><span style="font-size:small;font-family:Times New Roman;">, and </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<span style="font-size:small;font-family:Times New Roman;">for string </span><span style="font-size:small;font-family:Times New Roman;">. String substitution may be extended to the entire language as </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">An example of string substitution occurs in </span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular languages</span></span></a><span style="font-size:small;font-family:Times New Roman;">, which are closed under string substitution. That is, if the letters of a regular language are substituted by other regular languages, the result is still a regular language. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">String homomorphism</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">A <strong>string homomorphism</strong> is a string substitution such that each letter is replaced by a single string. That is, </span><span style="font-size:small;font-family:Times New Roman;">, where <em><span style="font-style:normal;">s</span></em> is a string, for each letter <em><span style="font-style:normal;">a</span></em>. String homomorphisms are </span><a href="http://encyclopedia.thefreedictionary.com/homomorphism"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">homomorphisms</span></span></a><span style="font-size:small;font-family:Times New Roman;">, preserving the </span><a href="http://encyclopedia.thefreedictionary.com/binary+operation"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">binary operation</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of </span><a href="http://encyclopedia.thefreedictionary.com/string+concatenation"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">string concatenation</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Given a language <em><span style="font-style:normal;">L</span></em>, the set </span><span style="font-size:small;font-family:Times New Roman;">is called the <strong>homomorphic image</strong> of <em><span style="font-style:normal;">L</span></em>. The <strong>inverse homomorphic image</strong> of a string <em><span style="font-style:normal;">s</span></em> is defined as </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">while the inverse homomorphic image of a language <em><span style="font-style:normal;">L</span></em> is defined as </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">Note that, in general, </span><span style="font-size:small;font-family:Times New Roman;">, while one does have </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">and </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:0;">
<span style="font-size:small;font-family:Times New Roman;">for any language <em><span style="font-style:normal;">L</span></em>. Simple single-letter </span><a href="http://encyclopedia.thefreedictionary.com/substitution+cipher"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">substitution ciphers</span></span></a><span style="font-size:small;font-family:Times New Roman;"> are examples of string homomorphisms. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">String projection</span></span></h2>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">If <em><span style="font-style:normal;">s</span></em> is a string, and </span><span style="font-size:small;font-family:Times New Roman;">is an alphabet, the <strong>string projection</strong> of <em><span style="font-style:normal;">s</span></em> is the string that results by removing all letters which are not in </span><span style="font-size:small;font-family:Times New Roman;">. It is written as </span><span style="font-size:small;font-family:Times New Roman;">. It is formally defined by removal of letters from the right hand side: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">Here </span><span style="font-size:small;font-family:Times New Roman;">denotes the </span><a href="http://encyclopedia.thefreedictionary.com/empty+string"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">empty string</span></span></a><span style="font-size:small;font-family:Times New Roman;">. The projection of a string is essentially the same as a </span><a href="http://encyclopedia.thefreedictionary.com/projection+in+relational+algebra"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">projection in relational algebra</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>String projection may be promoted to the <strong>projection of a language</strong>. Given a </span><a href="http://encyclopedia.thefreedictionary.com/formal+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">formal language</span></span></a><span style="font-size:small;font-family:Times New Roman;"> <em><span style="font-style:normal;">L</span></em>, its projection is given by </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Right quotient</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">The <strong>right quotient</strong> of a letter <em><span style="font-style:normal;">a</span></em> from a string <em><span style="font-style:normal;">s</span></em> is the truncation of the letter <em><span style="font-style:normal;">a</span></em> in the string <em><span style="font-style:normal;">s</span></em>, from the right hand side. It is denoted as </span><span style="font-size:small;font-family:Times New Roman;">. If the string does not have <em><span style="font-style:normal;">a</span></em> on the right hand side, the result is the empty string. Thus: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<span style="font-size:small;font-family:Times New Roman;">The quotient of the empty string may be taken: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<span style="font-size:small;font-family:Times New Roman;">Similarly, given a subset </span><span style="font-size:small;font-family:Times New Roman;">of a monoid </span><span style="font-size:small;font-family:Times New Roman;">, one may define the quotient subset as </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:0;">
<span style="font-size:small;font-family:Times New Roman;">Left quotients may be defined similarly, with operations taking place on the left of a string. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Syntactic relation</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">The right quotient of a subset </span><span style="font-size:small;font-family:Times New Roman;">of a monoid </span><span style="font-size:small;font-family:Times New Roman;">defines an </span><a href="http://encyclopedia.thefreedictionary.com/equivalence+relation"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">equivalence relation</span></span></a><span style="font-size:small;font-family:Times New Roman;">, called the <strong>right <a href="http://encyclopedia.thefreedictionary.com/syntactic+relation"><span style="color:windowtext;text-decoration:none;">syntactic relation</span></a></strong> of <em><span style="font-style:normal;">S</span></em>. It is given by </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<span style="font-size:small;font-family:Times New Roman;">The relation is clearly of finite index (has a finite number of equivalence classes) if and only if the family right quotients is finite; that is, if </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:0;">
<span style="font-size:small;font-family:Times New Roman;">is finite. In this case, <em><span style="font-style:normal;">S</span></em> is a </span><a href="http://encyclopedia.thefreedictionary.com/recognizable+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">recognizable language</span></span></a><span style="font-size:small;font-family:Times New Roman;">, that is, a language that can be recognized by a </span><a href="http://encyclopedia.thefreedictionary.com/finite+state+automaton"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite state automaton</span></span></a><span style="font-size:small;font-family:Times New Roman;">. This is discussed in greater detail in the article on </span><a href="http://encyclopedia.thefreedictionary.com/syntactic+monoid"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">syntactic monoids</span></span></a><span style="font-size:small;font-family:Times New Roman;">. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Right cancellation</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">The <strong>right cancellation</strong> of a letter <em><span style="font-style:normal;">a</span></em> from a string <em><span style="font-style:normal;">s</span></em> is the removal of the first occurrence of the letter <em><span style="font-style:normal;">a</span></em> in the string <em><span style="font-style:normal;">s</span></em>, starting from the right hand side. It is denoted as </span><span style="font-size:small;font-family:Times New Roman;">and is recursively defined as </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<span style="font-size:small;font-family:Times New Roman;">The empty string is always cancellable: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">Clearly, right cancellation and projection </span><a href="http://encyclopedia.thefreedictionary.com/commute"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">commute</span></span></a><span style="font-size:small;font-family:Times New Roman;">: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Prefixes</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">The <strong>prefixes of a string</strong> is the set of all </span><a href="http://encyclopedia.thefreedictionary.com/prefix+(computer+science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">prefixes</span></span></a><span style="font-size:small;font-family:Times New Roman;"> to a string, with respect to a given language: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<span style="font-size:small;font-family:Times New Roman;">The <strong>prefix closure of a language</strong> is </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<span style="font-size:small;font-family:Times New Roman;">A language is called <strong>prefix closed</strong> if </span><span style="font-size:small;font-family:Times New Roman;">. Clearly, the prefix closure operator is </span><a href="http://encyclopedia.thefreedictionary.com/idempotent"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">idempotent</span></span></a><span style="font-size:small;font-family:Times New Roman;">: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The <strong>prefix relation</strong> is a </span><a href="http://encyclopedia.thefreedictionary.com/binary+relation"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">binary relation</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><span style="font-size:small;font-family:Times New Roman;">such that </span><span style="font-size:small;font-family:Times New Roman;">if and only if </span><span style="font-size:small;font-family:Times New Roman;">.</p>
<p></span><a href="http://encyclopedia.thefreedictionary.com/Prefix+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Prefix grammars</span></span></a><span style="font-size:small;font-family:Times New Roman;"> generate languages that are prefix-closed (with respect to the grammar!).</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:26pt;"><span style="font-family:Times New Roman;">LANGUGE OPERATION</span></span></strong></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:small;">In computer science, an operation is called an </span><strong><span style="font-size:14pt;"><a href="http://encyclopedia.thefreedictionary.com/instruction+(computer+science)"><span style="color:windowtext;text-decoration:none;">instruction</span></a></span></strong></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">In </span><a href="http://encyclopedia.thefreedictionary.com/computer+science"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer science</span></span></a><span style="font-size:small;font-family:Times New Roman;">, an <strong>instruction</strong> is a single operation of a </span><a href="http://encyclopedia.thefreedictionary.com/central+processing+unit"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">processor</span></span></a><span style="font-size:small;font-family:Times New Roman;"> defined by an </span><a href="http://encyclopedia.thefreedictionary.com/instruction+set+architecture"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">instruction set architecture</span></span></a><span style="font-size:small;font-family:Times New Roman;">. In a broader sense, an &#8220;instruction&#8221; may be any representation of an element of an executable program, such as a </span><a href="http://encyclopedia.thefreedictionary.com/bytecode"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">bytecode</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>On traditional architectures, an instruction includes an </span><a href="http://encyclopedia.thefreedictionary.com/opcode"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">opcode</span></span></a><span style="font-size:small;font-family:Times New Roman;"> specifying the operation to be performed, such as &#8220;add contents of memory to register&#8221;, and zero or more operand specifiers, which may specify </span><a href="http://encyclopedia.thefreedictionary.com/processor+register"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">registers</span></span></a><span style="font-size:small;font-family:Times New Roman;">, memory locations, or literal data. The operand specifiers may have </span><a href="http://encyclopedia.thefreedictionary.com/addressing+mode"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">addressing modes</span></span></a><span style="font-size:small;font-family:Times New Roman;"> determining their meaning or may be in fixed fields.</p>
<p>In </span><a href="http://encyclopedia.thefreedictionary.com/very+long+instruction+word"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">very long instruction word</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (VLIW) architectures, which include many </span><a href="http://encyclopedia.thefreedictionary.com/microcode"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">microcode</span></span></a><span style="font-size:small;font-family:Times New Roman;"> architectures, multiple simultaneous operations and operands are specified in a single instruction.</p>
<p>The size or length of an instruction varies widely, from as little as four bits in some </span><a href="http://encyclopedia.thefreedictionary.com/microcontroller"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">microcontrollers</span></span></a><span style="font-size:small;font-family:Times New Roman;"> to many hundreds of bits in some VLIW systems. Most modern processors used in </span><a href="http://encyclopedia.thefreedictionary.com/personal+computer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">personal computers</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/mainframe"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">mainframes</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and </span><a href="http://encyclopedia.thefreedictionary.com/supercomputer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">supercomputers</span></span></a><span style="font-size:small;font-family:Times New Roman;"> have instruction sizes between 16 and 64 bits. In some architectures, notably most </span><a href="http://encyclopedia.thefreedictionary.com/Reduced+Instruction+Set+Computer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Reduced Instruction Set Computers</span></span></a><span style="font-size:small;font-family:Times New Roman;">, instructions are a fixed length, typically corresponding with that architecture&#8217;s </span><a href="http://encyclopedia.thefreedictionary.com/word+(computing)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">word size</span></span></a><span style="font-size:small;font-family:Times New Roman;">. In other architectures, instructions have variable length, typically integral multiples of a </span><a href="http://encyclopedia.thefreedictionary.com/byte"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">byte</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or a </span><a href="http://encyclopedia.thefreedictionary.com/halfword"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">halfword</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>The instructions constituting a program are rarely specified using their internal, numeric form; they may be specified by programmers using an </span><a href="http://encyclopedia.thefreedictionary.com/assembly+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">assembly language</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or, more commonly, may be generated by </span><a href="http://encyclopedia.thefreedictionary.com/compiler"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">compilers</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><strong><span style="font-size:26pt;">Finite</span></strong><strong><span style="font-size:26pt;"> State</span></strong><strong><span style="font-size:26pt;"> Machine (FMS)</span></strong></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">A <strong>finite state machine (FSM)</strong> or <strong>finite state automaton</strong> (plural: <em><span style="font-style:normal;">automata</span></em>) or simply a <strong>state machine</strong> is a model of behavior composed of a finite number of </span><a href="http://encyclopedia.thefreedictionary.com/state+(computer+science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">state</span></span></a><span style="font-size:small;font-family:Times New Roman;">s, transitions between those states, and actions. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;">Concepts and vocabulary</span></h2>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">A state stores information about the past, i.e. it reflects the input changes from the system start to the present moment. A transition indicates a state change and is described by a condition that would need to be fulfilled to enable the transition. An action is a description of an activity that is to be performed at a given moment. There are several action types: </span></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Entry action: which is performed <em><span style="font-style:normal;">when entering</span></em> the state</span></span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Exit action: which is performed <em><span style="font-style:normal;">when exiting</span></em> the state</span></span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Input action: which is performed depending on present state and input conditions</span></span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Transition action: which is performed when performing a certain transition</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 12pt;">
<p><span style="font-size:small;font-family:Times New Roman;">A FSM can be represented using a </span><a href="http://encyclopedia.thefreedictionary.com/state+diagram"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">state diagram</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (or state transition diagram) as in figure 1 above. Besides this, several </span><a href="http://encyclopedia.thefreedictionary.com/state+transition+table"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">state transition table</span></span></a><span style="font-size:small;font-family:Times New Roman;"> types are used. The most common representation is shown below: the combination of current state (B) and condition (Y) shows the next state (C). The complete actions information can be added only using footnotes. An FSM definition including the full actions information is possible using state tables (see also </span><a href="http://encyclopedia.thefreedictionary.com/VFSM"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">VFSM</span></span></a><span style="font-size:small;font-family:Times New Roman;">). </span></p>
<div>
<table class="MsoNormalTable" style="background:white;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;" colspan="4">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">State transition table</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">   Current State -&gt;<br />
Condition</span></td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">State A</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">State B</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">State C</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Condition X</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">&#8230;</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">&#8230;</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">&#8230;</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Condition Y</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">&#8230;</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">State C</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">&#8230;</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Condition Z</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">&#8230;</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">&#8230;</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">&#8230;</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">In addition to their use in modeling reactive systems presented here, finite state automata are significant in many different areas, including </span><a href="http://encyclopedia.thefreedictionary.com/electrical+engineering"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">electrical engineering</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/linguistics"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">linguistics</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/computer+science"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer science</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/philosophy"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">philosophy</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/biology"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">biology</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/mathematic"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">mathematics</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and </span><a href="http://encyclopedia.thefreedictionary.com/logic"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">logic</span></span></a><span style="font-size:small;font-family:Times New Roman;">. A complete survey of their applications is outside the scope of this article. Finite state machines are a class of automata studied in </span><a href="http://encyclopedia.thefreedictionary.com/automata+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">automata theory</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and the theory of computation. In computer science, finite state machines are widely used in modeling of application behavior, design of hardware digital systems, software engineering, compilers, network protocols, and the study of computation and languages. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Classification</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">There are two different groups: Acceptors/Recognizers and Transducers. </span></p>
<h3 style="margin:auto 0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"> </span></span></h3>
<h3 style="margin:auto 0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"> </span></span></h3>
<h3 style="margin:auto 0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"> </span></span></h3>
<h3 style="margin:auto 0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;">Acceptors and recognizers</span></span></h3>
<p class="MsoNormal" style="background:white;margin:0;"><a title="Fig. 2 Acceptor FSM: parsing the word &quot;nice&quot;" href="eml2('2/25/','Fsm_parsing_word_nice.jpg')"><span style="color:windowtext;text-decoration:none;"></span></a></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;">Fig. 2 Acceptor FSM: parsing the word &#8220;nice&#8221;</span></p>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>Acceptors</strong> and <strong>recognizers</strong> (also <strong>sequence detectors</strong>) produce a binary output, saying either <em><span style="font-style:normal;">yes</span></em> or <em><span style="font-style:normal;">no</span></em> to answer whether the input is accepted by the machine or not. All states of the FSM are said to be either accepting or not accepting. At the time when all input is processed, if the current state is an accepting state, the input is accepted; otherwise it is rejected. As a rule the input are symbols (characters); actions are not used. The example in figure 2 shows a finite state machine which accepts the word &#8220;nice&#8221;, in this FSM the only accepting state is number 7.</p>
<p>The machine can also be described as defining a language, which would contain every word accepted by the machine but none of the rejected ones; we say then that the language is <em><span style="font-style:normal;">accepted</span></em> by the machine. By definition, the languages accepted by FSMs are the </span></span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular languages</span></span></a><span style="font-size:small;font-family:Times New Roman;"> &#8211; that is, a language is regular if there is some FSM that accepts it (cf. Kleene&#8217;s Theorem). </span></p>
<h4 style="margin:12pt 0 3pt;"><span style="font-size:large;font-family:Times New Roman;">Start state</span></h4>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">The start state is usually shown drawn with an arrow &#8220;pointing at it from nowhere&#8221; (Sipser (2006) p.34) </span></p>
<h4 style="margin:12pt 0 3pt;"><span style="font-size:large;font-family:Times New Roman;">Accept state</span></h4>
<p class="MsoNormal" style="text-indent:.5in;margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">An <strong>accept state</strong> (sometimes referred to as an <strong>accepting state</strong>) is a state at which the machine has successfully performed its procedure. It is usually represented by a double circle.</p>
<p>An example of an accepting state appears on the left in this diagram of a </span><a href="http://encyclopedia.thefreedictionary.com/deterministic+finite+automaton"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">deterministic finite automaton</span></span></a><span style="font-size:small;font-family:Times New Roman;"> which determines if the </span><a href="http://encyclopedia.thefreedictionary.com/Binary+numeral+system"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">binary</span></span></a><span style="font-size:small;font-family:Times New Roman;"> input contains an even number of 0s: </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">S</span></em><sub>1</sub> (which is also the start state) indicates the state at which an even number of 0s has been input and is therefore defined as an accepting state. </span></span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;"> </span></span></h3>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;"> </span></span></h3>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;"> </span></span></h3>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;"> </span></span></h3>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;"> </span></span></h3>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Transducers</span></span></h3>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><a href="http://encyclopedia.thefreedictionary.com/Finite+state+transducer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Transducers</span></span></a><span style="font-size:small;font-family:Times New Roman;"> generate output based on a given input and/or a state using actions. They are used for control applications. Here two types are distinguished: </span></p>
<p class="MsoNormal" style="background:white;margin:0;"><a title="Fig. 3 Transducer FSM: Moore model example" href="eml2('4/44/','Fsm_moore_model_door_control.jpg')"><span style="color:windowtext;text-decoration:none;"></span></a></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;">Fig. 3 Transducer FSM: Moore model example</span></p>
<p class="MsoNormal" style="margin:0;"><span><a href="http://encyclopedia.thefreedictionary.com/Moore+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Moore machine</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">: The FSM uses only entry actions, i.e. output depends only on the state. The advantage of the Moore model is a simplification of the behaviour. The example in figure 3 shows a Moore FSM of an elevator door. The state machine recognizes two commands: &#8220;command_open&#8221; and &#8220;command_close&#8221; which trigger state changes. The entry action (E:) in state &#8220;Opening&#8221; starts a motor opening the door, the entry action in state &#8220;Closing&#8221; starts a motor in the other direction closing the door. States &#8220;Opened&#8221; and &#8220;Closed&#8221; don&#8217;t perform any actions. They signal to the outside world (e.g. to other state machines) the situation: &#8220;door is open&#8221; or &#8220;door is closed&#8221;.</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="background:white;margin:0;"><a title="Fig. 4 Transducer FSM: Mealy model example" href="eml2('9/99/','Fsm_mealy_model_door_control.jpg')"><span style="color:windowtext;text-decoration:none;"></span></a></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;">Fig. 4 Transducer FSM: Mealy model example</span></p>
<p class="MsoNormal" style="margin:0;"><span><a href="http://encyclopedia.thefreedictionary.com/Mealy+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Mealy machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">: The FSM uses only input actions, i.e. output depends on input and state. The use of a Mealy FSM leads often to a reduction of the number of states. The example in figure 4 shows a Mealy FSM implementing the same behaviour as in the Moore example (the behaviour depends on the implemented FSM execution model and will work e.g. for </span><a href="http://encyclopedia.thefreedictionary.com/Virtual+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">virtual FSM</span></span></a><span style="font-size:small;font-family:Times New Roman;"> but not for </span><a href="http://encyclopedia.thefreedictionary.com/event+driven+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">event driven FSM</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">). There are two input actions (I:): &#8220;start motor to close the door if command_close arrives&#8221; and &#8220;start motor in the other direction to open the door if command_open arrives&#8221;.</span></span></span></p>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">In practice mixed models are often used.</p>
<p>More details about the differences and usage of Moore and Mealy models, including an executable example, can be found in the external technical note </span><a href="http://www.stateworks.com/active/content/en/technology/technical_notes.php#tn10" target="_blank"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">&#8220;Moore or Mealy model?&#8221;</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;"></p>
<p>A further distinction is between </span><strong><span style="font-size:14pt;">deterministic</span></strong><span style="font-size:14pt;"> (</span></span><a href="http://encyclopedia.thefreedictionary.com/Deterministic+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">DFA</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;">) and </span><strong><span style="font-size:14pt;">non-deterministic</span></strong><span style="font-size:small;"> (</span></span><a href="http://encyclopedia.thefreedictionary.com/NDFA"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">NDFA</span></span></a><span style="font-size:small;font-family:Times New Roman;">, GNFA) automata. In deterministic automata, for each state there is exactly one transition for each possible input. In non-deterministic automata, there can be none or more than one transition from a given state for a given possible input. This distinction is relevant in practice, but not in theory, as there exists an algorithm which can transform any NDFA into an equivalent DFA, although this transformation typically significantly increases the complexity of the automaton.</p>
<p>The FSM with only one state is called a combinatorial FSM and uses only input actions. This concept is useful in cases where a number of FSM are required to work together, and where it is convenient to consider a purely combinatorial part as a form of FSM to suit the design tools. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;">FSM logic</span></h2>
<p class="MsoNormal" style="background:white;margin:0;"><a title="Fig. 5 FSM Logic" href="eml2('d/de/','Finite_state_machine_definition.gif')"><span style="color:windowtext;text-decoration:none;"></span></a></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;">Fig. 5 FSM Logic</span></p>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">The next state and output of an FSM is a function of the input and of the current state. The FSM logic is shown in Figure 5. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;">Mathematical model</span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Depending on the type there are several definitions. An <strong>acceptor</strong> finite state machine is a </span><a href="http://encyclopedia.thefreedictionary.com/Tuple"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">quintuple</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><span style="font-size:small;font-family:Times New Roman;">, where: </span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the input </span><a href="http://encyclopedia.thefreedictionary.com/alphabet+(computer+science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">alphabet</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (a finite non empty set of symbols). </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is a finite non empty set of states. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is an initial state, an element of </span><span style="font-size:small;font-family:Times New Roman;">. In a </span><a href="http://encyclopedia.thefreedictionary.com/Nondeterministic+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Nondeterministic finite state machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><span style="font-size:small;font-family:Times New Roman;">is a set of initial states. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the state transition function: </span><span style="font-size:small;font-family:Times New Roman;">. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the set of final states, a (possibly empty) subset of </span><span style="font-size:small;font-family:Times New Roman;">. </span></li>
</ul>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">A <strong>transducer</strong> finite state machine is a six tuple </span><span style="font-size:small;font-family:Times New Roman;">, where: </span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the input </span><a href="http://encyclopedia.thefreedictionary.com/alphabet+(computer+science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">alphabet</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (a finite non empty set of symbols). </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the output alphabet (a finite non empty set of symbols). </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is a finite non empty set of states. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the initial state, an element of </span><span style="font-size:small;font-family:Times New Roman;">. In a </span><a href="http://encyclopedia.thefreedictionary.com/Nondeterministic+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Nondeterministic finite state machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><span style="font-size:small;font-family:Times New Roman;">is a set of initial states. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the state transition function: </span><span style="font-size:small;font-family:Times New Roman;">. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the output function. </span></li>
</ul>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">If the output function is a function of a state and input alphabet (</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">) that definition corresponds to the <strong>Mealy model</strong>, and can be modelled as a </span><a href="http://encyclopedia.thefreedictionary.com/Mealy+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Mealy machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">. If the output function depends only on a state (</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">) that definition corresponds to the <strong>Moore</strong><strong> model</strong>, and can be modelled as a </span><a href="http://encyclopedia.thefreedictionary.com/Moore+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Moore machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">. A finite state machine with no output function at all is known as a </span><a href="http://encyclopedia.thefreedictionary.com/semiautomaton"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">semiautomaton</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or </span><a href="http://encyclopedia.thefreedictionary.com/transition+system"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">transition system</span></span></a><span style="font-size:small;font-family:Times New Roman;">. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;">Optimization</span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Optimizing an FSM means finding the machine with the minimum number of states that performs the same function. One possibility is by using an </span><a href="http://encyclopedia.thefreedictionary.com/Implication+table"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Implication table</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or the </span><a href="http://encyclopedia.thefreedictionary.com/Moore+reduction+procedure"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Moore reduction procedure</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Another possibility is </span><a href="http://www.cs.jhu.edu/~hajic/courses/cs226/alg.html" target="_blank"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">bottom-up algorithm for Acyclic FSAs</span></span></a><span style="font-size:small;font-family:Times New Roman;">. </span></p>
<p class="MsoNormal" style="margin:0;"><span><span style="font-size:small;font-family:Times New Roman;"> </span></span></p>
<h3 style="margin:auto 0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;">Software applications</span></span></h3>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The following concepts are commonly used to build software applications with finite state machines: </span></p>
<ul type="disc">
<li class="MsoNormal"><a href="http://encyclopedia.thefreedictionary.com/event+driven+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">event driven FSM</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
<li class="MsoNormal"><a href="http://encyclopedia.thefreedictionary.com/virtual+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">virtual FSM (VFSM)</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
<li class="MsoNormal"><a href="http://encyclopedia.thefreedictionary.com/Automata-Based+Programming"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Automata-Based Programming</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
</ul>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">History</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Starting in the 1970s, </span><a href="http://encyclopedia.thefreedictionary.com/Leslie+Lamport"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Leslie Lamport</span></span></a><span style="font-size:small;font-family:Times New Roman;">, an early leader within the distributed systems research community, used finite state machines as the basis for an algorithm he called </span><a href="http://encyclopedia.thefreedictionary.com/state+machine+replication"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">state machine replication</span></span></a><span style="font-size:small;font-family:Times New Roman;">. In this approach, a deterministic computer program or service is replaced with a set of replicas that use some form of atomic broadcast to perform operations in a manner tolerant of failures.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<h1 style="margin:auto 0;"><span style="font-size:26pt;"><span style="font-family:Times New Roman;"> </span></span></h1>
<h1 style="margin:auto 0;"><span style="font-size:26pt;"><span style="font-family:Times New Roman;"> </span></span></h1>
<h1 style="margin:auto 0;"><span style="font-size:26pt;"><span style="font-family:Times New Roman;"> </span></span></h1>
<h1 style="margin:auto 0;"><span style="font-size:26pt;"><span style="font-family:Times New Roman;">Deterministic finite-state machine</span></span></h1>
<h1 style="margin:auto 0;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;"><span> </span></span></span></h1>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">In the theory of computation, a </span><a href="http://encyclopedia.thefreedictionary.com/deterministic+automaton"><strong><span style="font-size:14pt;color:windowtext;text-decoration:none;"><span style="font-family:Times New Roman;">deterministic</span></span></strong></a><span style="font-size:small;font-family:Times New Roman;"> finite state machine or deterministic finite automaton (DFA) is a </span><a href="http://encyclopedia.thefreedictionary.com/finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite state machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> where for each pair of state and input symbol there is one and only one transition to a next state. DFAs recognize the set of </span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular languages</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and no other languages.</p>
<p>A DFA will take in a string of input symbols. For each input symbol it will then transition to a state given by following a transition function. When the last input symbol has been received it will either accept or reject the string depending on whether the DFA is in an accepting state or a non-accepting state. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;"> </span></h2>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Formal definition</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">A DFA is a 5-</span><a href="http://encyclopedia.thefreedictionary.com/n-tuple"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">tuple</span></span></a><span style="font-size:small;font-family:Times New Roman;">, (<em><span style="font-style:normal;">S</span></em>, Σ, <em><span style="font-style:normal;">T</span></em>, <em><span style="font-style:normal;">s</span></em>, <em><span style="font-style:normal;">A</span></em>), consisting of </span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a finite set of </span><a href="http://encyclopedia.thefreedictionary.com/State+(computer+science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">states</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (<em><span style="font-style:normal;">S</span></em>) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a finite set called the alphabet (Σ) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a transition </span><a href="http://encyclopedia.thefreedictionary.com/function+(mathematics)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">function</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (<em><span style="font-style:normal;">T</span></em> : <em><span style="font-style:normal;">S</span></em> × Σ → <em><span style="font-style:normal;">S</span></em>) </span></li>
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;">a start state (<em><span style="font-style:normal;">s</span></em> </span><span style="font-family:Arial;">∈</span><span style="font-family:Times New Roman;"> <em><span style="font-style:normal;">S</span></em>) </span></span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a set of </span><a href="http://encyclopedia.thefreedictionary.com/accept+state"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">accept states</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> (<em><span style="font-style:normal;">A</span></em> </span><span style="font-family:Arial;">⊆</span><span style="font-family:Times New Roman;"> <em><span style="font-style:normal;">S</span></em>) </span></span></li>
</ul>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Let <strong>M</strong> be a DFA such that <strong>M</strong> = (<em><span style="font-style:normal;">S</span></em>, Σ, <em><span style="font-style:normal;">T</span></em>, <em><span style="font-style:normal;">s</span></em>, <em><span style="font-style:normal;">A</span></em>), and <em><span style="font-style:normal;">X = x<sub>0</sub>x<sub>1</sub> &#8230; x<sub>n</sub></span></em> be a string over the alphabet Σ. <strong>M</strong> accepts the string <em><span style="font-style:normal;">X</span></em> if a sequence of states, <em><span style="font-style:normal;">r<sub>0</sub>,r<sub>1</sub>, &#8230;, r<sub>n</sub></span></em>, exists in <em><span style="font-style:normal;">S</span></em> with the following conditions: </span></p>
<ol type="1">
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">r<sub>0</sub></span></em> = <em><span style="font-style:normal;">s</span></em> </span></span></li>
<li class="MsoNormal"><span style="font-family:Times New Roman;"><span style="font-size:small;"><em><span style="font-style:normal;">r<sub>i+1</sub></span></em> = <em><span style="font-style:normal;">T</span></em>(<em><span style="font-style:normal;">r<sub>i</sub></span></em>, <em><span style="font-style:normal;">x<sub>i</sub></span></em>), for <em><span style="font-style:normal;">i</span></em> = <em><span style="font-style:normal;">0, &#8230;, n-1</span></em> </span></span></li>
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">r<sub>n</sub></span></em> </span><span style="font-family:Arial;">∈</span><span style="font-family:Times New Roman;"> <em><span style="font-style:normal;">A</span></em>. </span></span></li>
</ol>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">As shown in the first condition, the machine starts in the start state <em><span style="font-style:normal;">s</span></em>. The second condition says that given each character of string <em><span style="font-style:normal;">X</span></em>, the machine will transition from state to state as ruled by the transition function <em><span style="font-style:normal;">T</span></em>. The last condition says that the machine accepts if the last input of <em><span style="font-style:normal;">X</span></em> causes the machine to be in one of the accepting states. Otherwise, it is said to reject the string. The set of strings it accepts form a </span><a href="http://encyclopedia.thefreedictionary.com/Formal+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">language</span></span></a><span style="font-size:small;font-family:Times New Roman;">, which is the language the DFA recognises.</p>
<p>A DFA without a list of accept states and without a designated starting state is known as a </span><a href="http://encyclopedia.thefreedictionary.com/transition+system"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">transition system</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or </span><a href="http://encyclopedia.thefreedictionary.com/semiautomaton"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">semiautomaton</span></span></a><span style="font-size:small;font-family:Times New Roman;">. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;">Example</span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The following example is of a DFA <em><span style="font-style:normal;">M</span></em>, with a binary alphabet, which requires that the input contains an even number of 0s.</p>
<p><em><span style="font-style:normal;">M</span></em> = (<em><span style="font-style:normal;">S</span></em>, Σ, <em><span style="font-style:normal;">T</span></em>, <em><span style="font-style:normal;">s</span></em>, <em><span style="font-style:normal;">A</span></em>) where </span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">S</span></em> = {<em><span style="font-style:normal;">S</span></em><sub>1</sub>, <em><span style="font-style:normal;">S</span></em><sub>2</sub>}, </span></span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Σ = {0, 1}, </span></li>
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">s</span></em> = <em><span style="font-style:normal;">S</span></em><sub>1</sub>, </span></span></li>
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">A</span></em> = {<em><span style="font-style:normal;">S</span></em><sub>1</sub>}, and </span></span></li>
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">T</span></em> is defined by the following </span></span><a href="http://encyclopedia.thefreedictionary.com/state+transition+table"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">state transition table</span></span></a><span style="font-size:small;font-family:Times New Roman;">: </span></li>
</ul>
<table class="MsoNormalTable" style="background:white;margin:auto auto auto .5in;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;">0</span></strong></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;">1</span></strong></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><strong><span style="font-style:normal;">S</span></strong></em><strong><sub>1</sub></strong></span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">S</span></em><sub>2</sub></span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">S</span></em><sub>1</sub></span></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><strong><span style="font-style:normal;">S</span></strong></em><strong><sub>2</sub></strong></span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">S</span></em><sub>1</sub></span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">S</span></em><sub>2</sub></span></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0;">
<span style="font-size:small;font-family:Times New Roman;">Simply put, the state <em><span style="font-style:normal;">S</span></em><sub>1</sub> represents that there has been an even number of 0s in the input so far, while <em><span style="font-style:normal;">S</span></em><sub>2</sub> signifies an odd number. A 1 in the input does not change the state of the automaton. When the input ends, the state will show whether the input contained an even number of 0s or not.</p>
<p>The language of <em><span style="font-style:normal;">M</span></em> is the </span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular language</span></span></a><span style="font-size:small;font-family:Times New Roman;"> given by the </span><a href="http://encyclopedia.thefreedictionary.com/regular+expression"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular expression</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (1<sup>*</sup>(0(1)<sup>*</sup>0)<sup>*</sup>)<sup>*</sup> </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Advantages and disadvantages</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">DFAs are one of the most practical models of computation, since there is a trivial linear time, constant-space, </span><a href="http://encyclopedia.thefreedictionary.com/online+algorithm"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">online algorithm</span></span></a><span style="font-size:small;font-family:Times New Roman;"> to simulate a DFA on a stream of input. Given two DFAs there are efficient algorithms to find a DFA recognizing the union, intersection, and complements of the languages they recognize. There are also efficient algorithms to determine whether a DFA accepts any strings, whether a DFA accepts all strings, whether two DFAs recognize the same language, and to find the DFA with a minimum number of states for a particular regular language.</p>
<p>DFAs are equivalent in computing power to </span><a href="http://encyclopedia.thefreedictionary.com/nondeterministic+finite+automata"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">nondeterministic finite automata</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>On the other hand, DFAs are of strictly limited power in the languages they can recognize — many simple languages, including any problem that requires more than constant space to solve, cannot be recognized by a DFA. The classical example of a simply described language that no DFA can recognize is bracket language, that is language that consists of properly paired brackets, such as (()()). More formally the language consisting of strings of the form <em><span style="font-style:normal;">a<sup>n</sup>b<sup>n</sup></span></em> — some finite number of a&#8217;s, followed by an equal number of b&#8217;s. It can be shown that no DFA can have enough states to recognize such a language. </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<h1 style="margin:auto 0;"><span style="font-size:26pt;"><span style="font-family:Times New Roman;">Nondeterministic Finite Automata </span></span></h1>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:small;">In the theory of computation, a </span><span style="font-size:14pt;">nondeterministic finite state machine</span><span style="font-size:14pt;"> or <span>nondeterministic finite automaton (NFA</span></span><span style="font-size:small;"><strong>)</strong> is a </span></span><a href="http://encyclopedia.thefreedictionary.com/finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite state machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> where for each pair of state and input symbol there may be several possible next states. This distinguishes it from the </span><a href="http://encyclopedia.thefreedictionary.com/deterministic+finite+automaton"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">deterministic finite automaton</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (DFA), where the next possible state is uniquely determined. Although the DFA and NFA have distinct definitions, it may be shown in the formal theory that they are equivalent, in that, for any given NFA, one may construct an equivalent DFA, and vice-versa: this is the </span><a href="http://encyclopedia.thefreedictionary.com/powerset+construction"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">powerset construction</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Both types of automata recognize only </span><a href="http://encyclopedia.thefreedictionary.com/regular+languages"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular languages</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Non-deterministic finite state machines are sometimes studied by the name </span><a href="http://encyclopedia.thefreedictionary.com/subshifts+of+finite+type"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">subshifts of finite type</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Non-deterministic finite state machines are generalized by </span><a href="http://encyclopedia.thefreedictionary.com/probabilistic+automata"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">probabilistic automata</span></span></a><span style="font-size:small;font-family:Times New Roman;">, which assign a probability to each state transition.</p>
<p>Nondeterministic finite automata were introduced by </span><a href="http://encyclopedia.thefreedictionary.com/Michael+O.+Rabin"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Michael O. Rabin</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/Dana+Scott"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Dana Scott</span></span></a><span style="font-size:small;font-family:Times New Roman;"> in 1959</span><a name="ref_rf-1"></a><sup><a href="http://encyclopedia.thefreedictionary.com/Nondeterministic+finite+state+machine#endnote_rf-1"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">[1]</span></span></a></sup><span style="font-size:small;font-family:Times New Roman;">, who showed their equivalence to deterministic automata. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Intuitive introduction</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">An NFA, just as a DFA, consumes a string of input symbols. For each input symbol it transforms to a new state until all input symbols have been consumed.</p>
<p>Unlike a DFA, it is non-deterministic in that, for any input symbol, its next state is not uniquely determined, but may be any one of several possible states. Thus, in the formal definition, it is common to talk of a subset of the </span><a href="http://encyclopedia.thefreedictionary.com/power+set"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">power set</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of states: the transition is not so much to a single state, but to some subset of all possible states, considered at once.</p>
<p>An extension of the NFA is the <strong>NFA-lambda</strong> (also known as <strong>NFA-epsilon</strong> or the <strong>NFA with epsilon moves</strong>), which allows a transform to a new state without consuming any input symbols. For example, if it is in state 1, with the next input symbol an <em><span style="font-style:normal;">a</span></em>, it can move to state 2 without consuming any input symbols, and thus one has an ambiguity: is the system in state 1, or state 2, before consuming the letter <em><span style="font-style:normal;">a</span></em>? Because of this ambiguity, it is more convenient to talk of the set of possible states the system may be in. Thus, before consuming letter <em><span style="font-style:normal;">a</span></em>, the NFA-epsilon may be in any one of the states out of the set {1,2}. Equivalently, one may imagine that the NFA is in state 1 and 2 &#8216;at the same time&#8217;: and this gives an informal hint of the </span><a href="http://encyclopedia.thefreedictionary.com/powerset+construction"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">powerset construction</span></span></a><span style="font-size:small;font-family:Times New Roman;">: the DFA equivalent to an NFA is defined as the one that is in the state <em><span style="font-style:normal;">q</span></em>={1,2}. Transformations to new states without consuming an input symbol are called <strong>lambda transitions</strong> or <strong>epsilon transitions</strong>. They are usually labelled with the Greek letter λ or ε.</p>
<p>The notion of accepting an input is similar to that for the DFA. When the last input symbol is consumed, the NFA accepts if and only if there is <em><span style="font-style:normal;">some</span></em> set of transitions that will take it to an accepting state. Equivalently, it rejects, if, no matter what transitions are applied, it would not end in an accepting state. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Formal definition</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Two similar types of NFA&#8217;s are commonly defined: the NFA and the <em><span style="font-style:normal;">NFA with ε-moves</span></em>. The ordinary NFA is defined as a </span><a href="http://encyclopedia.thefreedictionary.com/n-tuple"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">5-tuple</span></span></a><span style="font-size:small;font-family:Times New Roman;">, (<em><span style="font-style:normal;">Q</span></em>, Σ, <em><span style="font-style:normal;">T</span></em>, <em><span style="font-style:normal;">q<sub>0</sub></span></em>, <em><span style="font-style:normal;">F</span></em>), consisting of </span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a finite </span><a href="http://encyclopedia.thefreedictionary.com/set"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">set</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of states <em><span style="font-style:normal;">Q</span></em> </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a finite set of </span><a href="http://encyclopedia.thefreedictionary.com/input+symbol"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">input symbols</span></span></a><span style="font-size:small;font-family:Times New Roman;"> Σ </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a transition </span><a href="http://encyclopedia.thefreedictionary.com/function+(mathematics)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">function</span></span></a><span style="font-size:small;font-family:Times New Roman;"> <em><span style="font-style:normal;">T</span></em> : <em><span style="font-style:normal;">Q</span></em> × Σ → <em><span style="font-style:normal;">P</span></em>(<em><span style="font-style:normal;">Q</span></em>). </span></li>
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;">an <em><span style="font-style:normal;">initial</span></em> (or <em><span style="font-style:normal;">start</span></em>) state <em><span style="font-style:normal;">q<sub>0</sub></span></em> such that <em><span style="font-style:normal;">q</span></em><sub>0</sub> </span><span style="font-family:Arial;">∈</span><span style="font-family:Times New Roman;"> <em><span style="font-style:normal;">Q</span></em> </span></span></li>
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;">a set of states <em><span style="font-style:normal;">F</span></em> distinguished as <em><span style="font-style:normal;">accepting</span></em> (or <em><span style="font-style:normal;">final</span></em>) <em><span style="font-style:normal;">states</span></em> <em><span style="font-style:normal;">F</span></em> </span><span style="font-family:Arial;">⊆</span><span style="font-family:Times New Roman;"> <em><span style="font-style:normal;">Q</span></em>. </span></span></li>
</ul>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">Here, <em><span style="font-style:normal;">P</span></em>(<em><span style="font-style:normal;">Q</span></em>) denotes the </span><a href="http://encyclopedia.thefreedictionary.com/power+set"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">power set</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of <em><span style="font-style:normal;">Q</span></em>. The <em><span style="font-style:normal;">NFA with ε-moves</span></em> (also sometimes called <em><span style="font-style:normal;">NFA-epsilon</span></em> or <em><span style="font-style:normal;">NFA-lambda</span></em>) replaces the transition function with one that allows the </span><a href="http://encyclopedia.thefreedictionary.com/empty+string"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">empty string</span></span></a><span style="font-size:small;font-family:Times New Roman;"> ε as a possible input, so that one has instead </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">T</span></em> : <em><span style="font-style:normal;">Q</span></em> × (Σ </span><span style="font-family:Arial;">∪</span><span style="font-family:Times New Roman;">{ε}) → <em><span style="font-style:normal;">P</span></em>(<em><span style="font-style:normal;">Q</span></em>).</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">It can be shown that ordinary NFA and NFA with epsilon moves are equivalent, in that, given either one, one can construct the other, which recognizes the same language. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Properties</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">The machine starts in an arbitrary initial state and reads in a string of symbols from its alphabet. The automaton uses the </span><a href="http://encyclopedia.thefreedictionary.com/state+transition+function"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">state transition function</span></span></a><span style="font-size:small;font-family:Times New Roman;"> <em><span style="font-style:normal;">T</span></em> to determine the next state using the current state, and the symbol just read or the empty string. However, &#8220;the next state of an NFA depends not only on the current input event, but also on an arbitrary number of subsequent input events. Until these subsequent events occur it is not possible to determine which state the machine is in&#8221; </span><a name="ref_rf-2"></a><sup><a href="http://encyclopedia.thefreedictionary.com/Nondeterministic+finite+state+machine#endnote_rf-2"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">[2]</span></span></a></sup><span style="font-size:small;font-family:Times New Roman;">. If, when the automaton has finished reading, it is in an accepting state, the NFA is said to accept the string, otherwise it is said to reject the string.</p>
<p>The set of all strings accepted by an NFA is the language the NFA accepts. This language is a </span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular language</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>For every NFA a </span><a href="http://encyclopedia.thefreedictionary.com/deterministic+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">deterministic finite state machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (DFA) can be found that accepts the same language. Therefore it is possible to convert an existing NFA into a DFA for the purpose of implementing a (perhaps) simpler machine. This can be performed using the </span><a href="http://encyclopedia.thefreedictionary.com/powerset+construction"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">powerset construction</span></span></a><span style="font-size:small;font-family:Times New Roman;">, which may lead to an exponential rise in the number of necessary states. A formal proof of the powerset construction is given </span><a href="http://encyclopedia.thefreedictionary.com/Nondeterministic+finite+state+machine%2FProofs"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">here</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>For non-deterministic automata with a </span><a href="http://encyclopedia.thefreedictionary.com/countably+infinite"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">countably infinite</span></span></a><span style="font-size:small;font-family:Times New Roman;"> set of states, the powerset construction gives a deterministic automaton with a </span><a href="http://encyclopedia.thefreedictionary.com/continuum+(mathematics)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">continuum</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of states (since the powerset of the countable infinity is the continuum: </span><span style="font-size:small;font-family:Times New Roman;">). In such a case, the set of states must be endowed with a </span><a href="http://encyclopedia.thefreedictionary.com/topological+space"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">topology</span></span></a><span style="font-size:small;font-family:Times New Roman;"> in order for the state transitions to be meaningful. Such systems are studied as </span><a href="http://encyclopedia.thefreedictionary.com/topological+automata"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">topological automata</span></span></a><span style="font-size:small;font-family:Times New Roman;">. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Properties of NFA-ε</span></span></h2>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">For all </span><span style="font-size:small;font-family:Times New Roman;">one writes </span><span style="font-size:small;font-family:Times New Roman;">if and only if </span><span style="font-size:small;font-family:Times New Roman;">can be reached from </span><span style="font-size:small;font-family:Times New Roman;">by going along zero or more </span><span style="font-size:small;font-family:Times New Roman;">arrows. In other words, </span><span style="font-size:small;font-family:Times New Roman;">if and only if there exists </span><span style="font-size:small;font-family:Times New Roman;">where </span><span style="font-size:small;font-family:Times New Roman;">such that </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">.</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">For any </span><span style="font-size:small;font-family:Times New Roman;">, the set of states that can be reached from <em><span style="font-style:normal;">p</span></em> is called the <strong>epsilon-closure</strong> or <strong>ε-closure</strong> of <em><span style="font-style:normal;">p</span></em>, and is written as </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">.</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">For any subset </span><span style="font-size:small;font-family:Times New Roman;">, define the ε-closure of <em><span style="font-style:normal;">P</span></em> as </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">.</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The epsilon-transitions are transitive, in that it may be shown that, for all </span><span style="font-size:small;font-family:Times New Roman;">and </span><span style="font-size:small;font-family:Times New Roman;">, if </span><span style="font-size:small;font-family:Times New Roman;">and </span><span style="font-size:small;font-family:Times New Roman;">, then </span><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>Similarly, if </span><span style="font-size:small;font-family:Times New Roman;">and </span><span style="font-size:small;font-family:Times New Roman;">then </span></p>
<p><span style="font-size:small;"><span style="font-family:Times New Roman;">Let <em><span style="font-style:normal;">x</span></em> be a string over the alphabet Σ. An NFA-ε <em><span style="font-style:normal;">M</span></em> accepts the string <em><span style="font-style:normal;">x</span></em> if there exist both a representation of <em><span style="font-style:normal;">x</span></em> of the form <em><span style="font-style:normal;">x<sub>1</sub>x<sub>2</sub> &#8230; x<sub>n</sub></span></em>, where <em><span style="font-style:normal;">x<sub>i</sub></span></em> </span><span style="font-family:Arial;">∈</span><span style="font-family:Times New Roman;"> (Σ </span><span style="font-family:Arial;">∪</span><span style="font-family:Times New Roman;">{ε}), and a sequence of states <em><span style="font-style:normal;">p<sub>0</sub>,p<sub>1</sub>, &#8230;, p<sub>n</sub></span></em>, where </span><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">p<sub>i</sub></span></em> </span><span style="font-family:Arial;">∈</span><span style="font-family:Times New Roman;"> <em><span style="font-style:normal;">Q</span></em>, meeting the following conditions: </span></span></p>
<ol type="1">
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">p<sub>0</sub></span></em> </span></span><span style="font-size:small;font-family:Times New Roman;">E({<em><span style="font-style:normal;">q<sub>0</sub></span></em>}) </span></li>
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">p<sub>i</sub></span></em> </span></span><span style="font-size:small;font-family:Times New Roman;">E(<em><span style="font-style:normal;">T</span></em>(<em><span style="font-style:normal;">p<sub>i-1</sub></span></em>, <em><span style="font-style:normal;">x<sub>i</sub> </span></em>)) for <em><span style="font-style:normal;">i</span></em> = <em><span style="font-style:normal;">1, &#8230;, n</span></em> </span></li>
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">p<sub>n</sub></span></em> </span></span><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">F</span></em>. </span></span></li>
</ol>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">In particular, note that some of the letters <em><span style="font-style:normal;">x<sub>i</sub></span></em> can be {ε}; they are chosen not from Σ alone, but from Σ </span><span style="font-family:Arial;">∪</span><span style="font-family:Times New Roman;">{ε}. </span></span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Implementation</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">There are many ways to implement a NFA: </span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Convert to the equivalent DFA. In some cases this may cause exponential blowup in the size of the automaton and thus auxiliary space proportional to the number of states in the NFA (as storage of the state value requires at most one bit for every state in the NFA) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Keep a </span><a href="http://encyclopedia.thefreedictionary.com/set+data+structure"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">set data structure</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of all states which the machine might currently be in. On the consumption of the last input symbol, if one of these states is a final state, the machine accepts the string. In the worst case, this may require auxiliary space proportional to the number of states in the NFA; if the set structure uses one bit per NFA state, then this solution is exactly equivalent to the above. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Create multiple copies. For each n way decision, the NFA creates up to </span><span style="font-size:small;font-family:Times New Roman;">copies of the machine. Each will enter a separate state. If, upon consuming the last input symbol, at least one copy of the NFA is in the accepting state, the NFA will accept. (This, too, requires linear storage with respect to the number of NFA states, as there can be one machine for every NFA state.) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Explicitly propagate tokens through the transition structure of the NFA and match whenever a token reaches the final state. This is sometimes useful when the NFA should encode additional context about the events that triggered the transition. (For an implementation that uses this technique to keep track of object references have a look at </span><a href="http://citeseer.ist.psu.edu/allan05adding.html" target="_blank"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Tracematches</span></span></a><span style="font-size:small;font-family:Times New Roman;">.) </span></li>
</ul>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Example</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The following example explains a NFA <em><span style="font-style:normal;">M</span></em>, with a binary alphabet, which determines if the input contains an even number of 0s or an even number of 1s. Let <em><span style="font-style:normal;">M</span></em> = (<em><span style="font-style:normal;">Q</span></em>, Σ, <em><span style="font-style:normal;">T</span></em>, <em><span style="font-style:normal;">s<sub>0</sub></span></em>, <em><span style="font-style:normal;">F</span></em>) where </span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Σ = {0, 1}, </span></li>
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">Q</span></em> = {<em><span style="font-style:normal;">s</span></em><sub>0</sub>, <em><span style="font-style:normal;">s</span></em><sub>1</sub>, <em><span style="font-style:normal;">s</span></em><sub>2</sub>, <em><span style="font-style:normal;">s</span></em><sub>3</sub>, <em><span style="font-style:normal;">s</span></em><sub>4</sub>}, </span></span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">E({<em><span style="font-style:normal;">s</span></em><sub>0</sub>}) = { s<sub>0</sub>, s<sub>1</sub>, s<sub>3</sub> } </span></li>
<li class="MsoNormal"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">F</span></em> = {<em><span style="font-style:normal;">s</span></em><sub>1</sub>, <em><span style="font-style:normal;">s</span></em><sub>3</sub>}, and </span></span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">The transition function <em><span style="font-style:normal;">T</span></em> can be defined by this </span><a href="http://encyclopedia.thefreedictionary.com/state+transition+table"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">state transition table</span></span></a><span style="font-size:small;font-family:Times New Roman;">: </span></li>
</ul>
<div>
<table class="MsoNormalTable" style="background:white;" border="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;">0</span></strong></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;">1</span></strong></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;">ε</span></strong></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><strong><span style="font-style:normal;">S</span></strong></em><strong><sub>0</sub></strong></span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{}</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{}</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{<em><span style="font-style:normal;">S</span></em><sub>1</sub>, <em><span style="font-style:normal;">S</span></em><sub>3</sub>}</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><strong><span style="font-style:normal;">S</span></strong></em><strong><sub>1</sub></strong></span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{<em><span style="font-style:normal;">S</span></em><sub>2</sub>}</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{<em><span style="font-style:normal;">S</span></em><sub>1</sub>}</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{}</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><strong><span style="font-style:normal;">S</span></strong></em><strong><sub>2</sub></strong></span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{<em><span style="font-style:normal;">S</span></em><sub>1</sub>}</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{<em><span style="font-style:normal;">S</span></em><sub>2</sub>}</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{}</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><strong><span style="font-style:normal;">S</span></strong></em><strong><sub>3</sub></strong></span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{<em><span style="font-style:normal;">S</span></em><sub>3</sub>}</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{<em><span style="font-style:normal;">S</span></em><sub>4</sub>}</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{}</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><strong><span style="font-style:normal;">S</span></strong></em><strong><sub>4</sub></strong></span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{<em><span style="font-style:normal;">S</span></em><sub>4</sub>}</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{<em><span style="font-style:normal;">S</span></em><sub>3</sub>}</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">{}</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;"></p>
<p></span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">The </span><a href="http://encyclopedia.thefreedictionary.com/state+diagram"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">state diagram</span></span></a><span style="font-size:small;font-family:Times New Roman;"> for <em><span style="font-style:normal;">M</span></em> is: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><a title="Enlarge picture" href="eml2('0/0e/','651px-NFAexample.svg.png')"><span style="color:windowtext;text-decoration:none;"></span></a></p>
<p class="MsoNormal" style="margin:3pt 0 0;">
<p><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">M</span></em> can be viewed as the union of two </span></span><a href="http://encyclopedia.thefreedictionary.com/deterministic+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">DFA</span></span></a><span style="font-size:small;font-family:Times New Roman;">s: one with states {<em><span style="font-style:normal;">S</span></em><sub>2</sub>, <em><span style="font-style:normal;">S</span></em><sub>1</sub>} and the other with states {<em><span style="font-style:normal;">S</span></em><sub>3</sub>, <em><span style="font-style:normal;">S</span></em><sub>4</sub>}.</p>
<p>The language of <em><span style="font-style:normal;">M</span></em> can be described by the </span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular language</span></span></a><span style="font-size:small;font-family:Times New Roman;"> given by this </span><a href="http://encyclopedia.thefreedictionary.com/regular+expression"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular expression</span></span></a><span style="font-size:small;font-family:Times New Roman;">: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Application of NFA-ε</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">NFA&#8217;s and DFA&#8217;s are equivalent in that if a language is recognized by an NFA, it is also recognized by a DFA and vice versa. The establishment of such equivalence is important and useful. It is useful because constructing an NFA to recognize a given language is sometimes much easier than constructing a DFA for that language. It is important because NFA&#8217;s can be used to reduce the complexity of the mathematical work required to establish many important properties in the theory of computation. For example, it is much easier to prove the following properties using NFA&#8217;s than DFA&#8217;s:</p>
<p>(i) The union of two </span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular languages</span></span></a><span style="font-size:small;font-family:Times New Roman;"> is regular. ( See formal proof. )</p>
<p>(ii) The concatenation of two </span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular languages</span></span></a><span style="font-size:small;font-family:Times New Roman;"> is regular. ( See formal proof. )</p>
<p>(iii) The </span><a href="http://encyclopedia.thefreedictionary.com/Kleene+closure"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Kleene Closure</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of a </span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular language</span></span></a><span style="font-size:small;font-family:Times New Roman;"> is regular. ( See formal proof. )</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">In </span><a href="http://encyclopedia.thefreedictionary.com/computing"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computing</span></span></a><span style="font-size:small;font-family:Times New Roman;">, a <strong>regular expression</strong> is a </span><a href="http://encyclopedia.thefreedictionary.com/string+(computer+science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">string</span></span></a><span style="font-size:small;font-family:Times New Roman;"> that is used to describe or match a </span><a href="http://encyclopedia.thefreedictionary.com/set+(computer+science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">set</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of strings, according to certain </span><a href="http://encyclopedia.thefreedictionary.com/syntax"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">syntax</span></span></a><span style="font-size:small;font-family:Times New Roman;"> rules.</p>
<p>Regular expressions are used by many </span><a href="http://encyclopedia.thefreedictionary.com/text+editor"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">text editors</span></span></a><span style="font-size:small;font-family:Times New Roman;">, utilities, and programming languages to search and manipulate text based on patterns. For example, </span><a href="http://encyclopedia.thefreedictionary.com/Perl"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Perl</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/Tcl"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Tcl</span></span></a><span style="font-size:small;font-family:Times New Roman;"> have a powerful regular expression engine built directly into their syntax. Several utilities provided by </span><a href="http://encyclopedia.thefreedictionary.com/Unix"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Unix</span></span></a><span style="font-size:small;font-family:Times New Roman;"> distributions—including the editor </span><a href="http://encyclopedia.thefreedictionary.com/ed+(text+editor)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ed</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and the filter </span><a href="http://encyclopedia.thefreedictionary.com/grep"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">grep</span></span></a><span style="font-size:small;font-family:Times New Roman;">—were the first to popularize the concept of regular expressions. &#8220;Regular expression&#8221; is often shortened to <strong>regex</strong> or <strong>regexp</strong> (singular), or <strong>regexes</strong>, <strong>regexps</strong>, or <strong>regexen</strong> (plural). Some authors distinguish between <strong>regular expression</strong> and <strong>regexp</strong>, restricting the former to true regular expressions, which describe regular languages, while using the latter for any regular expression-like pattern, including those that describe languages that are not regular. As only some authors observe this distinction, it is not safe to rely upon it.</p>
<p>As an example of the syntax, the regular expression <code><span style="font-family:&quot;">\bex</span></code> can be used to search for all instances of the string &#8220;<em><span style="font-style:normal;">ex</span></em>&#8221; that occur at word boundaries (signified by the <code><span style="font-family:&quot;">\b</span></code>). Thus in the string, &#8220;Texts for experts,&#8221; <code><span style="font-family:&quot;">\bex</span></code> matches the &#8220;<em><span style="font-style:normal;">ex</span></em>&#8221; in &#8220;experts,&#8221; but not in &#8220;Texts&#8221; (because the &#8220;<em><span style="font-style:normal;">ex</span></em>&#8221; occurs inside the word there and not immediately after a word boundary).</p>
<p>Many modern computing systems provide </span><a href="http://encyclopedia.thefreedictionary.com/wildcard+character"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">wildcard characters</span></span></a><span style="font-size:small;font-family:Times New Roman;"> in matching filenames from a </span><a href="http://encyclopedia.thefreedictionary.com/file+system"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">file system</span></span></a><span style="font-size:small;font-family:Times New Roman;">. This is a core capability of many </span><a href="http://encyclopedia.thefreedictionary.com/shell+(computing)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">command-line shells</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and is also known as </span><a href="http://encyclopedia.thefreedictionary.com/glob+(programming)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">globbing</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Wildcards differ from regular expressions in that they generally only express very restrictive forms of alternation.</span></p>
<p class="MsoNormal" style="margin:0;"><span><span style="font-size:small;font-family:Times New Roman;"> </span></span></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Basic concepts</span></span></strong></p>
<p class="MsoNormal" style="text-indent:.5in;margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">A regular expression, often called a <em><span style="font-style:normal;">pattern</span></em>, is an expression that describes a set of strings. They are usually used to give a concise description of a set, without having to list all elements. For example, the set containing the three strings &#8220;<em><span style="font-style:normal;">Handel</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">Händel</span></em>&#8220;, and &#8220;<em><span style="font-style:normal;">Haendel</span></em>&#8221; can be described by the pattern <code><span style="font-family:&quot;">H(ä|ae?)ndel</span></code> (or alternatively, it is said that the pattern <em><span style="font-style:normal;">matches</span></em> each of the three strings). In most formalisms, if there is any regex that matches a particular set then there is an infinite number of such expressions. Most formalisms provide the following operations to construct regular expressions. </span></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Alternation</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">A vertical bar separates alternatives. For example, <code><span style="font-family:&quot;">gray|grey</span></code> can match &#8220;<em><span style="font-style:normal;">gray</span></em>&#8221; or &#8220;<em><span style="font-style:normal;">grey</span></em>&#8220;.</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Grouping</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">Parentheses are used to define the scope and precedence of the operators (among other uses). For example, <code><span style="font-family:&quot;">gray|grey</span></code> and <code><span style="font-family:&quot;">gr(a|e)y</span></code> are equivalent patterns which both describe the set of &#8220;<em><span style="font-style:normal;">gray</span></em>&#8221; and &#8220;<em><span style="font-style:normal;">grey</span></em>&#8220;.</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Quantification</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">A quantifier after a token (such as a character) or group specifies how often that preceding element is allowed to occur. The most common quantifiers are <code><span style="font-family:&quot;">?</span></code>, <code><span style="font-family:&quot;">*</span></code>, and <code><span style="font-family:&quot;">+</span></code>.</span></p>
<table class="MsoNormalTable" style="background:white;margin:auto auto auto .5in;" border="0" cellpadding="0">
<tbody>
<tr>
<td style="width:11.25pt;background-color:transparent;border:#d4d0c8;padding:.75pt;" width="15" valign="top">
<p class="MsoNormal" style="margin:0;"><code><strong><span style="font-family:&quot;"><span style="font-size:small;">?</span></span></strong></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The question mark indicates there is <strong>zero or one</strong> of the preceding element. For example, <code><span style="font-family:&quot;">colou?r</span></code> matches both &#8220;<em><span style="font-style:normal;">color</span></em>&#8221; and &#8220;<em><span style="font-style:normal;">colour</span></em>&#8220;.</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><code><strong><span style="font-family:&quot;"><span style="font-size:small;">*</span></span></strong></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The asterisk indicates there are <strong>zero or more</strong> of the preceding element. For example, <code><span style="font-family:&quot;">ab*c</span></code> matches &#8220;<em><span style="font-style:normal;">ac</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">abc</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">abbc</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">abbbc</span></em>&#8220;, and so on.</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><code><strong><span style="font-family:&quot;"><span style="font-size:small;">+</span></span></strong></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The plus sign indicates that there is <strong>one or more</strong> of the preceding element. For example, <code><span style="font-family:&quot;">ab+c</span></code> matches &#8220;<em><span style="font-style:normal;">abc</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">abbc</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">abbbc</span></em>&#8220;, and so on, but not &#8220;<em><span style="font-style:normal;">ac</span></em>&#8220;.</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0 0 0 .5in;">
<p><span style="font-size:small;font-family:Times New Roman;">These constructions can be combined to form arbitrarily complex expressions, much like one can construct arithmetical expressions from numbers and the operations <strong>+</strong>, <strong>-</strong>, <strong>*</strong>, and <strong>/</strong>. For example, <code><span style="font-family:&quot;">H(ae?|ä)ndel</span></code> and <code><span style="font-family:&quot;">H(a|ae|ä)ndel</span></code> are both valid patterns which match the same strings as the earlier example, <code><span style="font-family:&quot;">H(ä|ae?)ndel</span></code>.</p>
<p>The precise </span><a href="http://encyclopedia.thefreedictionary.com/syntax"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">syntax</span></span></a><span style="font-size:small;font-family:Times New Roman;"> for regular expressions varies among tools and with context; more detail is given in the <em><span style="font-style:normal;">Syntax</span></em> section. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;"> </span></span></h2>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">History</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">The origins of regular expressions lie in </span><a href="http://encyclopedia.thefreedictionary.com/automata+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">automata theory</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/formal+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">formal language theory</span></span></a><span style="font-size:small;font-family:Times New Roman;">, both of which are part of </span><a href="http://encyclopedia.thefreedictionary.com/theoretical+computer+science"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">theoretical computer science</span></span></a><span style="font-size:small;font-family:Times New Roman;">. These fields study models of computation (automata) and ways to describe and classify formal languages. In the 1950s, mathematician </span><a href="http://encyclopedia.thefreedictionary.com/Stephen+Cole+Kleene"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Stephen Cole Kleene</span></span></a><span style="font-size:small;font-family:Times New Roman;"> described these models using his mathematical notation called <em><span style="font-style:normal;">regular sets</span></em>. </span><a href="http://encyclopedia.thefreedictionary.com/Ken+Thompson"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Ken Thompson</span></span></a><span style="font-size:small;font-family:Times New Roman;"> built this notation into the editor </span><a href="http://encyclopedia.thefreedictionary.com/QED+(text+editor)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">QED</span></span></a><span style="font-size:small;font-family:Times New Roman;"> as a means to match patterns in text files. He later added this capability to the Unix editor </span><a href="http://encyclopedia.thefreedictionary.com/ed+(text+editor)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ed</span></span></a><span style="font-size:small;font-family:Times New Roman;">, which eventually led to the popular search tool </span><a href="http://encyclopedia.thefreedictionary.com/grep"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">grep</span></span></a><span style="font-size:small;font-family:Times New Roman;">&#8216;s use of regular expressions (&#8220;grep&#8221; is a word derived from the command for regular expression searching in the ed editor: <code><span style="font-family:&quot;">g/</span></code><em><span style="font-style:normal;">re</span></em><code><span style="font-family:&quot;">/p</span></code> where <em><span style="font-style:normal;">re</span></em> stands for regular expression). Since that time, many variations of Thompson&#8217;s original adaptation of regular expressions have been widely used in Unix and Unix-like utilities including </span><a href="http://encyclopedia.thefreedictionary.com/expr"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">expr</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/AWK+(programming+language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">AWK</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/Emacs"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Emacs</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/vi"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">vi</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and </span><a href="http://encyclopedia.thefreedictionary.com/Lex+programming+tool"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">lex</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p></span><a href="http://encyclopedia.thefreedictionary.com/Perl"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Perl</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/Tcl"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Tcl</span></span></a><span style="font-size:small;font-family:Times New Roman;"> regular expressions were derived from a regex library written by </span><a href="http://encyclopedia.thefreedictionary.com/Henry+Spencer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Henry Spencer</span></span></a><span style="font-size:small;font-family:Times New Roman;">, though Perl later expanded on Spencer&#8217;s library to add many new features.<sup><a href="http://encyclopedia.thefreedictionary.com/Regular+expression#endnote_rf-1"><span style="color:windowtext;text-decoration:none;">[1]</span></a></sup> </span><a href="http://encyclopedia.thefreedictionary.com/Philip+Hazel"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Philip Hazel</span></span></a><span style="font-size:small;font-family:Times New Roman;"> developed </span><a href="http://encyclopedia.thefreedictionary.com/Perl+Compatible+Regular+Expressions"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">PCRE</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (Perl Compatible Regular Expressions), which attempts to closely mimic Perl&#8217;s regular expression functionality, and is used by many modern tools including </span><a href="http://encyclopedia.thefreedictionary.com/PHP"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">PHP</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/Apache+HTTP+Server"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Apache HTTP Server</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Part of the effort in the design of </span><a href="http://encyclopedia.thefreedictionary.com/Perl+6"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Perl 6</span></span></a><span style="font-size:small;font-family:Times New Roman;"> is to improve Perl&#8217;s regular expression integration, and to increase their scope and capabilities to allow the definition of </span><a href="http://encyclopedia.thefreedictionary.com/parsing+expression+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">parsing expression grammars</span></span></a><span style="font-size:small;font-family:Times New Roman;">.<sup><a href="http://encyclopedia.thefreedictionary.com/Regular+expression#endnote_rf-2"><span style="color:windowtext;text-decoration:none;">[2]</span></a></sup> The result is a mini-language called </span><a href="http://encyclopedia.thefreedictionary.com/Perl+6+rules"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Perl 6 rules</span></span></a><span style="font-size:small;font-family:Times New Roman;">, which are used to define Perl 6 grammar as well as provide a tool to programmers in the language. These rules maintain existing features of Perl 5.x regular expressions, but also allow BNF-style definition of a </span><a href="http://encyclopedia.thefreedictionary.com/recursive+descent+parser"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">recursive descent parser</span></span></a><span style="font-size:small;font-family:Times New Roman;"> via sub-rules.</p>
<p>The use of regular expressions in structured information standards for document and database modeling started in the 1960s and expanded in the 1980s when industry standards like </span><a href="http://encyclopedia.thefreedictionary.com/Standard+Generalized+Markup+Language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ISO SGML</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (precursored by ANSI &#8220;GCA 101-1983&#8243;) consolidated. The kernel of the structure specification language standards are regular expressions. Simple use is evident in the </span><a href="http://encyclopedia.thefreedictionary.com/Document+Type+Definition"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">DTD</span></span></a><span style="font-size:small;font-family:Times New Roman;"> element group syntax. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Formal language theory</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Regular expressions can be expressed in terms of </span><a href="http://encyclopedia.thefreedictionary.com/Formal+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">formal language theory</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Regular expressions consist of constants and operators that denote sets of strings and operations over these sets, respectively. Given a finite alphabet Σ the following constants are defined: </span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><span style="font-family:Times New Roman;">(<em><span style="font-style:normal;">empty set</span></em>) </span><span class="unicode"><span style="font-family:&quot;">∅</span></span><span style="font-family:Times New Roman;"> denoting the set </span><span class="unicode"><span style="font-family:&quot;">∅</span></span><span style="font-family:Times New Roman;"> </span></span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">(<em><span style="font-style:normal;">empty string</span></em>) ε denoting the set {ε} </span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">(<em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/string+literal"><span style="color:windowtext;text-decoration:none;">literal character</span></a></span></em>) <em><span style="font-style:normal;">a</span></em> in Σ denoting the set {<em><span style="font-style:normal;">a</span></em>} </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The following operations are defined: </span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">(<em><span style="font-style:normal;">concatenation</span></em>) <em><span style="font-style:normal;">RS</span></em> denoting the set { αβ | α in <em><span style="font-style:normal;">R</span></em> and β in <em><span style="font-style:normal;">S</span></em> }. For example {&#8220;ab&#8221;|&#8221;c&#8221;}{&#8220;d&#8221;|&#8221;ef&#8221;} = {&#8220;abd&#8221;, &#8220;abef&#8221;, &#8220;cd&#8221;, &#8220;cef&#8221;}. </span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">(<em><span style="font-style:normal;">alternation</span></em>) <em><span style="font-style:normal;">R|S</span></em> denoting the set union of <em><span style="font-style:normal;">R</span></em> and <em><span style="font-style:normal;">S</span></em>. </span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;font-family:Times New Roman;">(<em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/Kleene+star"><span style="color:windowtext;text-decoration:none;">Kleene star</span></a></span></em>) <em><span style="font-style:normal;">R</span></em>* denoting the smallest </span><a href="http://encyclopedia.thefreedictionary.com/subset"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">superset</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of <em><span style="font-style:normal;">R</span></em> that contains ε and is </span><a href="http://encyclopedia.thefreedictionary.com/Closure+(mathematics)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">closed</span></span></a><span style="font-size:small;font-family:Times New Roman;"> under string concatenation. This is the set of all strings that can be made by concatenating zero or more strings in <em><span style="font-style:normal;">R</span></em>. For example, {&#8220;ab&#8221;, &#8220;c&#8221;}* = {ε, &#8220;ab&#8221;, &#8220;c&#8221;, &#8220;abab&#8221;, &#8220;abc&#8221;, &#8220;cab&#8221;, &#8220;cc&#8221;, &#8220;ababab&#8221;, &#8230; }. </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">The above constants and operators form a </span><a href="http://encyclopedia.thefreedictionary.com/Kleene+algebra"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Kleene algebra</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">.</p>
<p>Many textbooks use the symbols </span><span class="unicode"><span style="font-family:Arial;">∪</span></span><span style="font-family:Times New Roman;">, <span class="unicode">+</span>, or </span><span class="unicode"><span style="font-family:Arial;">∨</span></span></span><span style="font-size:small;font-family:Times New Roman;"> for alternation instead of the vertical bar.</p>
<p>To avoid brackets it is assumed that the Kleene star has the highest priority, then concatenation and then set union. If there is no ambiguity then brackets may be omitted. For example, <code><span style="font-family:&quot;">(ab)c</span></code> can be written as <code><span style="font-family:&quot;">abc</span></code>, and <code><span style="font-family:&quot;">a|(b(c*))</span></code> can be written as <code><span style="font-family:&quot;">a|bc*</span></code>. </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>Examples:</strong> </span></span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><code><span style="font-family:&quot;">a|b*</span></code><span style="font-family:Times New Roman;"> denotes {ε, <em><span style="font-style:normal;">a</span></em>, <em><span style="font-style:normal;">b</span></em>, <em><span style="font-style:normal;">bb</span></em>, <em><span style="font-style:normal;">bbb</span></em>, &#8230;} </span></span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><code><span style="font-family:&quot;">(a|b)*</span></code><span style="font-family:Times New Roman;"> denotes the set of all strings consisting of any number of <em><span style="font-style:normal;">a</span></em> and <em><span style="font-style:normal;">b</span></em> symbols, including the empty string </span></span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><code><span style="font-family:&quot;">ab*(c|ε)</span></code><span style="font-family:Times New Roman;"> denotes the set of strings starting with <em><span style="font-style:normal;">a</span></em>, then zero or more <em><span style="font-style:normal;">b</span></em>s and finally optionally a <em><span style="font-style:normal;">c</span></em>. </span></span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">The formal definition of regular expressions is purposely parsimonious and avoids defining the redundant quantifiers <code><span style="font-family:&quot;">?</span></code> and <code><span style="font-family:&quot;">+</span></code>, which can be expressed as follows: <code><span style="font-family:&quot;">a+</span></code> = <code><span style="font-family:&quot;">aa*</span></code>, and <code><span style="font-family:&quot;">a?</span></code> = <code><span style="font-family:&quot;">(a|ε)</span></code>. Sometimes the complement operator ~ is added; ~<em><span style="font-style:normal;">R</span></em> denotes the set of all strings over Σ* that are not in <em><span style="font-style:normal;">R</span></em>. The complement operator is redundant, as it can always be expressed by using the other operators (although the process for computing such a representation is complex, and the result may be exponentially larger).</p>
<p>Regular expressions in this sense can express the </span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular languages</span></span></a><span style="font-size:small;font-family:Times New Roman;">, exactly the class of languages accepted by </span><a href="http://encyclopedia.thefreedictionary.com/finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite state automata</span></span></a><span style="font-size:small;font-family:Times New Roman;">. There is, however, a significant difference in compactness. Some classes of regular languages can only be described by automata that grow </span><a href="http://encyclopedia.thefreedictionary.com/exponential+growth"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">exponentially</span></span></a><span style="font-size:small;font-family:Times New Roman;"> in size, while the length of the required regular expressions only grow linearly. Regular expressions correspond to the type-3 </span><a href="http://encyclopedia.thefreedictionary.com/formal+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">grammars</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of the </span><a href="http://encyclopedia.thefreedictionary.com/Chomsky+hierarchy"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Chomsky hierarchy</span></span></a><span style="font-size:small;font-family:Times New Roman;">. On the other hand, there is a simple mapping between regular expressions and </span><a href="http://encyclopedia.thefreedictionary.com/nondeterministic+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">nondeterministic finite automata</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (NFAs) that does not lead to such a blowup in size; for this reason NFAs are often used as alternative representations of regular expressions.</p>
<p>We can also study expressive power within the formalism. As the examples show, different regular expressions can express the same language: the formalism is redundant.</p>
<p>It is possible to write an </span><a href="http://encyclopedia.thefreedictionary.com/algorithm"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">algorithm</span></span></a><span style="font-size:small;font-family:Times New Roman;"> which for two given regular expressions decides whether the described languages are essentially equal, reduces each expression to a minimal deterministic finite state machine, and determines whether they are </span><a href="http://encyclopedia.thefreedictionary.com/isomorphism"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">isomorphic</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (equivalent).</p>
<p>To what extent can this redundancy be eliminated? Can we find an interesting subset of regular expressions that is still fully expressive? Kleene star and set union are obviously required, but perhaps we can restrict their use. This turns out to be a surprisingly difficult problem. As simple as the regular expressions are, it turns out there is no method to systematically rewrite them to some normal form. The lack of axiomatization in the past led to the </span><a href="http://encyclopedia.thefreedictionary.com/star+height+problem"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">star height problem</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Recently, Dexter Kozen axiomatized regular expressions with </span><a href="http://encyclopedia.thefreedictionary.com/Kleene+algebra"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Kleene algebra</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>It is worth noting that many real-world &#8220;regular expression&#8221; engines implement features that cannot be expressed in the regular expression algebra; see </span><a href="http://encyclopedia.thefreedictionary.com/Regular+expression#Patterns for non-regular languages"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">below</span></span></a><span style="font-size:small;font-family:Times New Roman;"> for more on this. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;"> </span></span></h2>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;"> </span></span></h2>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Syntax</span></span></h2>
<h3 style="margin:auto 0 auto .5in;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;">Traditional Unix regular expressions</span></span></h3>
<p class="MsoNormal" style="margin:0 0 12pt .5in;"><span style="font-size:small;font-family:Times New Roman;">The basic </span><a href="http://encyclopedia.thefreedictionary.com/Unix"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Unix</span></span></a><span style="font-size:small;font-family:Times New Roman;"> regular expression syntax is now defined as obsolete by </span><a href="http://encyclopedia.thefreedictionary.com/POSIX"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">POSIX</span></span></a><span style="font-size:small;font-family:Times New Roman;">, but is still widely used for backwards compatibility. Many regular-expression-aware Unix utilities including </span><a href="http://encyclopedia.thefreedictionary.com/grep"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">grep</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/sed"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">sed</span></span></a><span style="font-size:small;font-family:Times New Roman;"> use it by default while providing support for extended regular expressions with </span><a href="http://encyclopedia.thefreedictionary.com/command+line+argument"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">command line arguments</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>In the basic syntax, most characters are treated as </span><a href="http://encyclopedia.thefreedictionary.com/literal"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">literals</span></span></a><span style="font-size:small;font-family:Times New Roman;"> — they match only themselves (i.e., <code><span style="font-family:&quot;">a</span></code> matches &#8220;<em><span style="font-style:normal;">a</span></em>&#8220;). The exceptions, listed below, are called </span><a href="http://encyclopedia.thefreedictionary.com/metacharacter"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">metacharacters</span></span></a><span style="font-size:small;font-family:Times New Roman;">. </span></p>
<table class="MsoNormalTable" style="background:white;margin:auto auto auto .5in;" border="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">.</span></span></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Matches any single character except newline. Within square brackets, the dot character matches a literal dot. For example, <code><span style="font-family:&quot;">a.c</span></code> matches &#8220;<em><span style="font-style:normal;">abc</span></em>&#8220;, etc., but <code><span style="font-family:&quot;">[a.c]</span></code> matches only &#8220;<em><span style="font-style:normal;">a</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">.</span></em>&#8220;, or &#8220;<em><span style="font-style:normal;">c</span></em>&#8220;.</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[ ]</span></span></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Matches a single character that is contained within the brackets. For example, <code><span style="font-family:&quot;">[abc]</span></code> matches &#8220;<em><span style="font-style:normal;">a</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">b</span></em>&#8220;, or &#8220;<em><span style="font-style:normal;">c</span></em>&#8220;. <code><span style="font-family:&quot;">[a-z]</span></code> specifies a range which matches any lowercase letter from &#8220;<em><span style="font-style:normal;">a</span></em>&#8221; to &#8220;<em><span style="font-style:normal;">z</span></em>&#8220;. These forms can be mixed: <code><span style="font-family:&quot;">[abcx-z]</span></code> matches &#8220;<em><span style="font-style:normal;">a</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">b</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">c</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">x</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">y</span></em>&#8220;, and &#8220;<em><span style="font-style:normal;">z</span></em>&#8220;, as does <code><span style="font-family:&quot;">[a-cx-z]</span></code>. The <code><span style="font-family:&quot;">-</span></code> character is treated as a literal character if it is the last or the first character within the brackets, or if it is escaped with a backslash: <code><span style="font-family:&quot;">[abc-]</span></code>, <code><span style="font-family:&quot;">[-abc]</span></code>, or <code><span style="font-family:&quot;">[a\-bc]</span></code>. The <code><span style="font-family:&quot;">[</span></code> character can be included anywhere within the brackets. To match the <code><span style="font-family:&quot;">]</span></code> character, the easiest way is to escape it with a backslash, e.g., <code><span style="font-family:&quot;">[\]]</span></code>. Some tools allow you to avoid the backslash if the closing bracket is first in the enclosing square brackets, e.g., <code><span style="font-family:&quot;">[][ab]</span></code> matches &#8220;<em><span style="font-style:normal;">]</span></em>&#8220;, &#8220;<em><span style="font-style:normal;">[</span></em>", "<em><span style="font-style:normal;">a</span></em>", or "<em><span style="font-style:normal;">b</span></em>".</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[^ ]</span></span></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Matches a single character that is not contained within the brackets. For example, <code><span style="font-family:&quot;">[^abc]</span></code> matches any character other than "<em><span style="font-style:normal;">a</span></em>", "<em><span style="font-style:normal;">b</span></em>", or "<em><span style="font-style:normal;">c</span></em>". <code><span style="font-family:&quot;">[^a-z]</span></code> matches any single character that is not a lowercase letter from "<em><span style="font-style:normal;">a</span></em>" to "<em><span style="font-style:normal;">z</span></em>". As above, literal characters and ranges can be mixed.</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">^</span></span></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Matches the starting position within the string. In multiline mode, it matches the starting position of any line.</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">$</span></span></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Matches the ending position of the string or the position just before a string-terminating newline. In multiline mode, it matches the ending position of any line.</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">( )</span></span></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Defines a marked subexpression. The string matched within the parentheses can be recalled later (see the next entry, <code><span style="font-family:&quot;">\</span></code><em><span style="font-style:normal;">n</span></em>. A marked subexpression is also called a block or capturing group. This feature is not found in all instances of regular expressions, and in many Unix utilities including </span><a href="http://encyclopedia.thefreedictionary.com/sed"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">sed</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/vi"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">vi</span></span></a><span style="font-size:small;font-family:Times New Roman;">, a backslash must precede the open and close parentheses for them to be interpreted with special meaning.</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><code><span style="font-family:&quot;">\</span></code><em><span style="font-style:normal;"><span style="font-family:Times New Roman;">n</span></span></em></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Matches what the <em><span style="font-style:normal;">n</span></em>th marked subexpression matched, where <em><span style="font-style:normal;">n</span></em> is a digit from 1 to 9. This construct is theoretically <strong>irregular</strong> and was not adopted in the POSIX extended regular expression (ERE) syntax. Some tools allow referencing more than nine capturing groups.</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">*</span></span></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Matches the preceding element zero or more times. For example, <code><span style="font-family:&quot;">ab*c</span></code> matches "<em><span style="font-style:normal;">ac</span></em>", "<em><span style="font-style:normal;">abc</span></em>", "<em><span style="font-style:normal;">abbbc</span></em>", etc. <code><span style="font-family:&quot;">[xyz]*</span></code> matches "", "<em><span style="font-style:normal;">x</span></em>", "<em><span style="font-style:normal;">y</span></em>", "<em><span style="font-style:normal;">z</span></em>", "<em><span style="font-style:normal;">zx</span></em>", "<em><span style="font-style:normal;">zyx</span></em>", "<em><span style="font-style:normal;">xyzzy</span></em>", and so on. <code><span style="font-family:&quot;">(ab)*</span></code> matches "", "<em><span style="font-style:normal;">ab</span></em>", "<em><span style="font-style:normal;">abab</span></em>", "<em><span style="font-style:normal;">ababab</span></em>", and so on.</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><code><span style="font-family:&quot;">{</span></code><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">m</span></em><code><span style="font-family:&quot;">,</span></code><em><span style="font-style:normal;">n</span></em><code><span style="font-family:&quot;">}</span></code></span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Matches the preceding element at least <em><span style="font-style:normal;">m</span></em> and not more than <em><span style="font-style:normal;">n</span></em> times. For example, <code><span style="font-family:&quot;">a{3,5}</span></code> matches only "<em><span style="font-style:normal;">aaa</span></em>", "<em><span style="font-style:normal;">aaaa</span></em>", and "<em><span style="font-style:normal;">aaaaa</span></em>". This is not found in a few, older instances of regular expressions.</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0 0 0 .5in;">
<p><span style="font-size:small;font-family:Times New Roman;">Note that particular implementations of regular expressions interpret backslash differently in front of some of the metacharacters. For example, egrep and Perl interpret non-backslashed parentheses, vertical bars, and curly brackets as metacharacters, reserving the backslashed versions to mean the literal characters themselves. Old versions of <em><span style="font-style:normal;">grep</span></em> did not support the alternation operator <code><span style="font-family:&quot;">|</span></code>.</p>
<p><strong>Examples:</strong> </span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><code><span style="font-family:&quot;">.at</span></code><span style="font-family:Times New Roman;"> matches any three-character string ending with "at", including "<em><span style="font-style:normal;">hat</span></em>", "<em><span style="font-style:normal;">cat</span></em>", and "<em><span style="font-style:normal;">bat</span></em>". </span></span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><code><span style="font-family:&quot;">[hc]at</span></code><span style="font-family:Times New Roman;"> matches "<em><span style="font-style:normal;">hat</span></em>" and "<em><span style="font-style:normal;">cat</span></em>". </span></span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><code><span style="font-family:&quot;">[^b]at</span></code><span style="font-family:Times New Roman;"> matches all strings matched by <code><span style="font-family:&quot;">.at</span></code> except "<em><span style="font-style:normal;">bat</span></em>". </span></span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><code><span style="font-family:&quot;">^[hc]at</span></code><span style="font-family:Times New Roman;"> matches "<em><span style="font-style:normal;">hat</span></em>" and "<em><span style="font-style:normal;">cat</span></em>", but only at the beginning of the string or line. </span></span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><code><span style="font-family:&quot;">[hc]at$</span></code><span style="font-family:Times New Roman;"> matches "<em><span style="font-style:normal;">hat</span></em>" and "<em><span style="font-style:normal;">cat</span></em>", but only at the end of the string or line. </span></span></p>
<h3 style="margin:auto 0 auto .5in;"><span style="font-size:12pt;"><span style="font-family:Times New Roman;">POSIX extended regular expressions</span></span></h3>
<p class="MsoNormal" style="margin:0 0 12pt .5in;"><a href="http://encyclopedia.thefreedictionary.com/POSIX"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">POSIX</span></span></a><span style="font-size:small;font-family:Times New Roman;"> extended regular expressions (ERE), as defined by </span><a href="http://encyclopedia.thefreedictionary.com/Institute+of+Electrical+and+Electronics+Engineers"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">IEEE</span></span></a><span style="font-size:small;font-family:Times New Roman;"> POSIX standard </span><a href="http://encyclopedia.thefreedictionary.com/Single+UNIX+Specification"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">1003</span></span></a><span style="font-size:small;font-family:Times New Roman;">.2, are similar in syntax to the traditional Unix regular expressions, with some exceptions. The following metacharacters are added: </span></p>
<table class="MsoNormalTable" style="background:white;margin:auto auto auto .5in;" border="0" cellpadding="0">
<tbody>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">?</span></span></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Matches the preceding element zero or one time. For example, <code><span style="font-family:&quot;">ba?</span></code> matches "<em><span style="font-style:normal;">b</span></em>" or "<em><span style="font-style:normal;">ba</span></em>".</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">+</span></span></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Matches the preceding element one or more times. For example, <code><span style="font-family:&quot;">ba+</span></code> matches "<em><span style="font-style:normal;">ba</span></em>", "<em><span style="font-style:normal;">baa</span></em>", "<em><span style="font-style:normal;">baaa</span></em>", and so on.</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">|</span></span></code></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:.75pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The choice (aka alternation or set union) operator matches either the expression before or the expression after the operator. For example, <code><span style="font-family:&quot;">abc|def</span></code> matches "<em><span style="font-style:normal;">abc</span></em>" or "<em><span style="font-style:normal;">def</span></em>".</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0 0 0 .5in;">
<p><span style="font-size:small;font-family:Times New Roman;">Additionally, some backslashes are removed: <code><span style="font-family:&quot;">\{...\}</span></code> becomes <code><span style="font-family:&quot;">{...}</span></code>, and <code><span style="font-family:&quot;">\(...\)</span></code> becomes <code><span style="font-family:&quot;">(...)</span></code>.</p>
<p><strong>Examples:</strong> </span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><code><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span></code><span style="font-size:small;"><code><span style="font-family:&quot;">[hc]+at matches "</span></code><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">hat</span></em><code><span style="font-family:&quot;">", "</span></code><em><span style="font-style:normal;">cat</span></em><code><span style="font-family:&quot;">", "</span></code><em><span style="font-style:normal;">hhat</span></em><code><span style="font-family:&quot;">", "</span></code><em><span style="font-style:normal;">chat</span></em><code><span style="font-family:&quot;">", "</span></code><em><span style="font-style:normal;">hcat</span></em><code><span style="font-family:&quot;">", "</span></code><em><span style="font-style:normal;">ccchat</span></em><code><span style="font-family:&quot;">", and so on, but not "</span></code><em><span style="font-style:normal;">at</span></em></span><code><span style="font-family:&quot;">". </span></code></span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><code><span style="font-family:&quot;">[hc]?at</span></code><span style="font-family:Times New Roman;"> matches "<em><span style="font-style:normal;">hat</span></em>", "<em><span style="font-style:normal;">cat</span></em>", and "<em><span style="font-style:normal;">at</span></em>". </span></span></p>
<p class="MsoNormal" style="text-indent:-.25in;margin:0 0 0 1in;"><span style="font-size:10pt;font-family:Symbol;"><span>·<span style="font:7pt &quot;">         </span></span></span><span style="font-size:small;"><code><span style="font-family:&quot;">cat|dog</span></code><span style="font-family:Times New Roman;"> matches "<em><span style="font-style:normal;">cat</span></em>" or "<em><span style="font-style:normal;">dog</span></em>". </span></span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><code><span style="font-family:&quot;"><span style="font-size:small;">Since the characters (, ), [, ], ., *, ?, +, ^, |, and $ are used as special symbols, they have to be </span><a href="http://encyclopedia.thefreedictionary.com/escape+sequence"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">escaped</span></span></a><span style="font-size:small;"> if they are meant literally. This is done by preceding them with \, which therefore also has to be escaped this way if meant literally. </span></span></code></p>
<p><code><span style="font-family:&quot;"><span style="font-size:small;">Extended POSIX regular expressions can often be used with modern Unix utilities by including the </span><a href="http://encyclopedia.thefreedictionary.com/command+line"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">command line</span></span></a><span style="font-size:small;"> flag </span></span></code><span style="font-family:Times New Roman;"><span style="font-size:small;"><var><span style="font-style:normal;">-E</span></var><code><span style="font-family:&quot;">. </span></code></span></span></p>
<h4 style="margin:12pt 0 3pt .5in;"><span style="font-size:large;font-family:Times New Roman;">POSIX bracket expressions</span></h4>
<p class="MsoNormal" style="margin:0 0 12pt .5in;"><span style="font-size:small;"><code><span style="font-family:&quot;">Since many ranges of characters depend on the chosen locale setting (i.e., in some settings letters are organized as </span></code><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">abc...zABC...Z</span></em><code><span style="font-family:&quot;">, while in some others as </span></code><em><span style="font-style:normal;">aAbBcC...zZ</span></em></span><code><span style="font-family:&quot;">), the POSIX standard defines some classes or categories of characters as shown in the following table: </span></code></span></p>
<table class="MsoNormalTable" style="background:white;border-collapse:collapse;margin:auto auto auto .5in;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background:#f2f2f2;border:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">POSIX</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">ASCII</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Description </span></span></strong></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:alnum:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[A-Za-z0-9]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Alphanumeric characters</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:alpha:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[A-Za-z]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Alphabetic characters</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:blank:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[ \t]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Space and tab</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:cntrl:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[\x00-\x1F\x7F]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Control characters</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:digit:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[0-9]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Digits</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:graph:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[\x21-\x7E]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Visible characters</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:lower:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[a-z]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Lowercase letters</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:print:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[\x20-\x7E]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Visible characters and spaces</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:punct:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[!"#$%&amp;'()*+,-./:;?@[\\\]_`{|}~]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Punctuation characters</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:space:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[ \t\r\n\v\f]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Whitespace characters</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:upper:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[A-Z]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Uppercase letters</span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[:xdigit:]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><code><span style="font-family:&quot;"><span style="font-size:small;">[A-Fa-f0-9]</span></span></code></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Hexadecimal digits</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0 0 0 .5in;">
<p><span style="font-size:small;"><code><span style="font-family:&quot;">For example, [[:upper:]ab] matches the uppercase letters and lowercase "</span></code><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">a</span></em><code><span style="font-family:&quot;">" and "</span></code><em><span style="font-style:normal;">b</span></em></span><code><span style="font-family:&quot;">". </span></code></p>
<p><code><span style="font-family:&quot;">In Perl regular expressions, [:print:] matches [:graph:] union [:space:]. An additional non-POSIX class understood by some tools is [:word:], which is usually defined as [:alnum:] plus underscore. This reflects the fact that in many programming languages these are the characters that may be used in identifiers. The editor <a href="http://encyclopedia.thefreedictionary.com/Vim+(text+editor)"><span style="color:windowtext;text-decoration:none;">Vim</span></a> further distinguishes </span></code><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">word</span></em><code><span style="font-family:&quot;"> and </span></code><em><span style="font-style:normal;">word-head</span></em></span><code><span style="font-family:&quot;"> classes (using the notation \w and \h) since in many programming languages the characters that can begin an identifier are not the same as those that can occur in other positions. </span></code></span></p>
<h3 style="margin:auto 0 auto .5in;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Perl-derivative regular expressions</span></span></h3>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><code><span style="font-family:&quot;"><a href="http://encyclopedia.thefreedictionary.com/Perl"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">Perl</span></span></a><span style="font-size:small;"> has a richer and more predictable syntax than the POSIX basic (BRE) and extended (ERE) regular expression standards. An example of its predictability is that \ always escapes a non-alphanumeric character. An example of functionality possible through Perl but not POSIX-compliant regular expressions is the concept of lazy quantification (see the next section). </span></span></code></p>
<p><code><span style="font-family:&quot;"><span style="font-size:small;">Due largely to its expressive power, many other utilities have adopted syntaxes very similar to Perl's — for example, </span><a href="http://encyclopedia.thefreedictionary.com/Java+(programming+language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">Java</span></span></a><span style="font-size:small;">, </span><a href="http://encyclopedia.thefreedictionary.com/JavaScript"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">JavaScript</span></span></a><span style="font-size:small;">, </span><a href="http://encyclopedia.thefreedictionary.com/Perl+Compatible+Regular+Expressions"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">PCRE</span></span></a><span style="font-size:small;">, </span><a href="http://encyclopedia.thefreedictionary.com/Python+(programming+language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">Python</span></span></a><span style="font-size:small;">, </span><a href="http://encyclopedia.thefreedictionary.com/Ruby+(programming+language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">Ruby</span></span></a><span style="font-size:small;">, and </span><a href="http://encyclopedia.thefreedictionary.com/Microsoft"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">Microsoft</span></span></a><span style="font-size:small;">'s </span><a href="http://encyclopedia.thefreedictionary.com/.NET+Framework"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">.NET Framework</span></span></a><span style="font-size:small;"> all use regular expression syntax similar to Perl's. Some languages and tools such as </span><a href="http://encyclopedia.thefreedictionary.com/PHP"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">PHP</span></span></a><span style="font-size:small;"> support multiple regular expression engine types. Perl-derivative regular expression implementations are not identical, and many implement only a subset of Perl's features. With Perl 5.9.x (development track for Perl 5.10), this process has come full circle with Perl incorporating syntax extensions originally from Python, the .NET Framework, and Java. </span></span></code></p>
<h4 style="margin:12pt 0 3pt;"><span style="font-size:large;font-family:Times New Roman;">Lazy quantification</span></h4>
<p class="MsoNormal" style="margin:0 0 12pt;"><span style="font-size:small;"><code><span style="font-family:&quot;">The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item in double brackets in this example of MediaWiki syntax: </span></code></p>
<p><code><span style="font-family:&quot;">Another whale explosion occurred on <a href="http://encyclopedia.thefreedictionary.com/January+26"><span style="color:windowtext;text-decoration:none;">January 26</span></a>, <a href="http://encyclopedia.thefreedictionary.com/2004"><span style="color:windowtext;text-decoration:none;">2004</span></a>. </span></code></p>
<p><code><span style="font-family:&quot;">...would very likely come up with the pattern \[\[.*]], or similar (note that the opening square brackets must be escaped with backslashes). However, this pattern will actually return "</span></code><em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/January+26"><span style="color:windowtext;text-decoration:none;"><span style="font-family:Times New Roman;">January 26</span></span></a><span style="font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/2004"><span style="color:windowtext;text-decoration:none;"><span style="font-family:Times New Roman;">2004</span></span></a></span></em><code><span style="font-family:&quot;">" instead of the "</span></code><em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/January+26"><span style="color:windowtext;text-decoration:none;"><span style="font-family:Times New Roman;">January 26</span></span></a></span></em><code><span style="font-family:&quot;">" which might be expected, because the * quantifier is greedy — it will consume as many characters as possible from the input, and "</span></code><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">January 26]], 2004</span></em><code><span style="font-family:&quot;">" has more characters than "</span></code><em><span style="font-style:normal;">January 26</span></em></span><code><span style="font-family:&quot;">". </span></code></p>
<p><code><span style="font-family:&quot;">Though this problem can be avoided in a number of ways (e.g., by specifying the text that is </span></code><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">not</span></em><code><span style="font-family:&quot;"> to be matched: \[\^\*), modern regular expression tools allow a quantifier to be specified as </span></code><em><span style="font-style:normal;">non-greedy</span></em><code><span style="font-family:&quot;"> (also known as </span></code><em><span style="font-style:normal;">lazy</span></em><code><span style="font-family:&quot;">, </span></code><em><span style="font-style:normal;">reluctant</span></em><code><span style="font-family:&quot;">, or </span></code><em><span style="font-style:normal;">minimal</span></em></span><code><span style="font-family:&quot;">) by putting a question mark after the quantifier (e.g., \[\[.*?]]). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more <a href="http://encyclopedia.thefreedictionary.com/backtracking"><span style="color:windowtext;text-decoration:none;">backtracking</span></a>. <a name="Patterns_for_non-regular_languages"></a></span></code></span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Patterns for non-regular languages</span></span></h3>
<p class="MsoNormal" style="margin:0 0 12pt;"><code><span style="font-family:&quot;"><span style="font-size:small;">Many patterns provide an expressive power that far exceeds the </span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">regular languages</span></span></a><span style="font-size:small;">. For example, the ability to group subexpressions with parentheses and recall the value they match in the same expression means that a pattern can match strings of repeated words like "</span></span></code><span style="font-family:Times New Roman;"><span style="font-size:small;"><em><span style="font-style:normal;">papa</span></em><code><span style="font-family:&quot;">" or "</span></code><em><span style="font-style:normal;">WikiWiki</span></em><code><span style="font-family:&quot;">", called </span></code></span><em><span style="font-style:normal;"><span style="font-size:small;">squares</span></span></em></span><code><span style="font-family:&quot;"><span style="font-size:small;"> in formal language theory. The pattern for these strings is (.*)\1. However, the language of squares is not regular, nor is it </span><a href="http://encyclopedia.thefreedictionary.com/context-free+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">context-free</span></span></a><span style="font-size:small;">. </span><a href="http://encyclopedia.thefreedictionary.com/Pattern+matching"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">Pattern matching</span></span></a><span style="font-size:small;"> with an unbounded number of back references, as supported by numerous modern tools, is </span><a href="http://encyclopedia.thefreedictionary.com/NP-hard"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">NP-hard</span></span></a><span style="font-size:small;">. </span></span></code></p>
<p><span style="font-size:small;"><code><span style="font-family:&quot;">However, many tools, libraries, and engines that provide such constructions still use the term </span></code><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">regular expression</span></em><code><span style="font-family:&quot;"> for their patterns. This has led to a nomenclature where the term regular expression has different meanings in <a href="http://encyclopedia.thefreedictionary.com/formal+language"><span style="color:windowtext;text-decoration:none;">formal language theory</span></a> and pattern matching. For this reason, some people have taken to using the term </span></code><em><span style="font-style:normal;">regex</span></em><code><span style="font-family:&quot;"> or simply </span></code><em><span style="font-style:normal;">pattern</span></em></span><code><span style="font-family:&quot;"> to describe the latter. <a href="http://encyclopedia.thefreedictionary.com/Larry+Wall"><span style="color:windowtext;text-decoration:none;">Larry Wall</span></a> (author of Perl) writes in Apocalypse 5: </span></code></span></p>
<div>
<table class="MsoNormalTable" style="border-collapse:collapse;margin:auto auto auto .5in;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:15pt;background-color:transparent;border:#d4d0c8;padding:7.5pt;" width="20" valign="top">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;"> </span></strong></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt 7.5pt;" valign="top">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">'Regular expressions' [...] are only marginally related to real regular expressions. Nevertheless, the term has grown with the capabilities of our pattern matching engines, so I'm not going to try to fight linguistic necessity here. I will, however, generally call them "regexes" (or "regexen", when I'm in an Anglo-Saxon mood).</span></p>
</td>
<td style="width:15pt;background-color:transparent;border:#d4d0c8;padding:7.5pt;" width="20" valign="bottom">
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:small;font-family:Times New Roman;"> </span></strong></p>
</td>
</tr>
</tbody>
</table>
</div>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Implementations and running times</span></span></h3>
<p class="MsoNormal" style="margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">There are at least two fundamentally different </span><a href="http://encyclopedia.thefreedictionary.com/algorithm"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">algorithms</span></span></a><span style="font-size:small;"> that decide if and how a given regular expression matches a string. </span></span></code></p>
<p><code><span style="font-family:&quot;"><span style="font-size:small;">The oldest and fastest relies on a result in formal language theory that allows every </span><a href="http://encyclopedia.thefreedictionary.com/nondeterministic+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">nondeterministic finite state machine</span></span></a><span style="font-size:small;"> (NFA) to be transformed into a </span><a href="http://encyclopedia.thefreedictionary.com/deterministic+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">deterministic finite state machine</span></span></a><span style="font-size:small;"> (DFA). The algorithm performs or simulates this transformation and then runs the resulting DFA on the input string, one symbol at a time. The latter process takes time linear to the length of the input string. More precisely, an input string of size </span></span></code><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">n</span></em><code><span style="font-family:&quot;"> can be tested against a regular expression of size </span></code><em><span style="font-style:normal;">m</span></em><code><span style="font-family:&quot;"> in time </span></code><em><span style="font-style:normal;">O</span></em><code><span style="font-family:&quot;">(</span></code><em><span style="font-style:normal;">n+2<sup>m</sup></span></em><code><span style="font-family:&quot;">) or </span></code><em><span style="font-style:normal;">O</span></em><code><span style="font-family:&quot;">(</span></code><em><span style="font-style:normal;">nm</span></em><code><span style="font-family:&quot;">), depending on the details of the implementation. This algorithm is often referred to as DFA. It is fast, but can only be used for matching and not for recalling grouped subexpressions, lazy quantification, and several other features commonly found in modern regular expression libraries. </span></code></span></p>
<p><code><span style="font-family:&quot;">The other algorithm is to match the pattern against the input string by <a href="http://encyclopedia.thefreedictionary.com/backtracking"><span style="color:windowtext;text-decoration:none;">backtracking</span></a>. This algorithm is commonly called NFA, but this terminology can be confusing. Its running time can be exponential, which simple implementations exhibit when matching against expressions like (a|aa)*b that contain both alternation and unbounded quantification and force the algorithm to consider an exponential number of sub-cases. More complex implementations will often identify and speed up or abort common cases where they would otherwise run slowly. </span></code></p>
<p><code><span style="font-family:&quot;">Although backtracking implementations give an exponential guarantee in the worst case, they provide much greater flexibility and expressive power. For example, any implementation which allows the use of backreferences, or implements the various improvements introduced by Perl, must use a backtracking implementation. </span></code></p>
<p><code><span style="font-family:&quot;">Some implementations try to provide the best of both algorithms by first running a fast DFA match to see if the string matches the regular expression at all, and only in that case perform a potentially slower backtracking match. </span></code></span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Regular expressions and Unicode</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">Regular expressions were originally used with </span><a href="http://encyclopedia.thefreedictionary.com/American+Standard+Code+for+Information+Interchange"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">ASCII</span></span></a><span style="font-size:small;"> characters. Many regular expression engines can now handle </span><a href="http://encyclopedia.thefreedictionary.com/Unicode"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">Unicode</span></span></a><span style="font-size:small;">. In most respects it makes no difference what the character set is, but some issues do arise when extending regular expressions to support Unicode. </span></span></code></p>
<p><code><span style="font-family:&quot;"><span style="font-size:small;">One issue is which Unicode format is supported. Some regular expression libraries expect the </span><a href="http://encyclopedia.thefreedictionary.com/UTF-8"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">UTF-8</span></span></a><span style="font-size:small;"> encoding, while others might expect UTF-16, obsolete UCS-2, or </span><a href="http://encyclopedia.thefreedictionary.com/UTF-32"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">UTF-32</span></span></a><span style="font-size:small;">. </span></span></code></p>
<p><span style="font-size:small;"><code><span style="font-family:&quot;">A second issue is whether the full Unicode range is supported. Many regular expression engines support only the Basic Multilingual Plane, that is, the characters which can be encoded with only 16 bits. Currently, only a few regular expression engines can handle the full 21-bit Unicode range. </span></code></p>
<p><code><span style="font-family:&quot;">A third issue is variation in how ASCII-oriented constructs are extended to Unicode. For example, in ASCII-based implementations, character ranges of the form [x-y] are valid wherever </span></code><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">x</span></em><code><span style="font-family:&quot;"> and </span></code><em><span style="font-style:normal;">y</span></em></span><code><span style="font-family:&quot;"> are codepoints in the range [0x00,0x7F] and codepoint(x) ≤ codepoint(y). The natural extension of such character ranges to Unicode would simply change the requirement that the endpoints lie in [0x00,0x7F] to the requirement that they lie in [0,0x10FFFF]. However, in practice this is often not the case. Some implementations, such as that of <a href="http://encyclopedia.thefreedictionary.com/gawk"><span style="color:windowtext;text-decoration:none;">gawk</span></a>, do not allow character ranges to cross Unicode blocks. A range like [0x61,0x7F] is valid since both endpoints fall within the Basic Latin block, as is [0x0530,0x0560] since both endpoints fall within the Armenian block, but a range like [0x0061,0x0532] is invalid since it includes multiple Unicode blocks. Other engines, such as that of the <a href="http://encyclopedia.thefreedictionary.com/Vim+(text+editor)"><span style="color:windowtext;text-decoration:none;">Vim</span></a> editor, allow block-crossing but limit the number of characters in a range to 128. </span></code></p>
<p><code><span style="font-family:&quot;">Another area in which there is variation is in the interpretation of case-insensitive flags. Some such flags affect only the ASCII characters. Other flags affect all characters. Some engines have two different flags, one for ASCII, the other for Unicode. Exactly which characters belong to the POSIX classes also varies. </span></code></p>
<p><code><span style="font-family:&quot;">Another response to Unicode has been the introduction of character classes for Unicode blocks and Unicode general character properties. In <a href="http://encyclopedia.thefreedictionary.com/Perl"><span style="color:windowtext;text-decoration:none;">Perl</span></a> and the <a href="http://java.sun.com/javase/6/docs/api/java/util/regex/package-summary.html" target="_blank"><span style="color:windowtext;text-decoration:none;">java.util.regex</span></a> library, classes of the form \p{InX} match characters in block </span></code><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">X</span></em><code><span style="font-family:&quot;"> and \P{InX} match the opposite. Similarly, \p{Armenian} matches any character in the Armenian block, and \p{X} matches any character with the general character property </span></code><em><span style="font-style:normal;">X</span></em></span><code><span style="font-family:&quot;">. For example, \p{Lu} matches any upper-case letter. </span></code></span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Uses of regular expressions</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><code><span style="font-family:&quot;"><span style="font-size:small;">Regular expressions are useful in the production of </span><a href="http://encyclopedia.thefreedictionary.com/code+completion"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">code completion</span></span></a><span style="font-size:small;"> systems and </span><a href="http://encyclopedia.thefreedictionary.com/syntax+highlighting"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">syntax highlighting</span></span></a><span style="font-size:small;"> in </span><a href="http://encyclopedia.thefreedictionary.com/integrated+development+environment"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">integrated development environments</span></span></a><span style="font-size:small;"> (IDEs), data validation and many other tasks. </span></span></code></p>
<p><code><span style="font-family:&quot;"><span style="font-size:small;">While regular expressions would be useful on </span><a href="http://encyclopedia.thefreedictionary.com/search+engine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">search engines</span></span></a><span style="font-size:small;"> such as </span><a href="http://encyclopedia.thefreedictionary.com/Google"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">Google</span></span></a><span style="font-size:small;"> or </span><a href="http://encyclopedia.thefreedictionary.com/Live+Search"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">Live Search</span></span></a><span style="font-size:small;">, processing them across the entire database could consume massive amounts of resources depending on the complexity and design of the regex. Although in many cases system administrators can run regex-based queries internally, most search engines do not offer regex support to the public. A notable exception is </span><a href="http://encyclopedia.thefreedictionary.com/Google+Code+Search"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;">Google Code Search</span></span></a><span style="font-size:small;">. </span></span></code></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">In </span><a href="http://encyclopedia.thefreedictionary.com/formal+language+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">formal language theory</span></span></a><span style="font-size:small;font-family:Times New Roman;">, a <strong>context-free grammar</strong> (<strong>CFG</strong>) is a </span><a href="http://encyclopedia.thefreedictionary.com/formal+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">grammar</span></span></a><span style="font-size:small;font-family:Times New Roman;"> in which every </span><a href="http://encyclopedia.thefreedictionary.com/Production+(computer+science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">production</span></span></a><span style="font-size:small;font-family:Times New Roman;"> rule is of the form </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">V</span></em> → <em><span style="font-style:normal;">w</span></em></span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">where <em><span style="font-style:normal;">V</span></em> is a single </span><a href="http://encyclopedia.thefreedictionary.com/nonterminal"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">nonterminal</span></span></a><span style="font-size:small;font-family:Times New Roman;"> symbol, and <em><span style="font-style:normal;">w</span></em> is a string of terminals and/or nonterminals (possibly empty). The term "context-free" expresses the fact that nonterminals can be rewritten without regard to the context in which they occur. A </span><a href="http://encyclopedia.thefreedictionary.com/formal+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">formal language</span></span></a><span style="font-size:small;font-family:Times New Roman;"> is </span><a href="http://encyclopedia.thefreedictionary.com/context-free+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">context-free</span></span></a><span style="font-size:small;font-family:Times New Roman;"> if some context-free grammar generates it.</p>
<p>Context-free grammars play a central role in the description and design of </span><a href="http://encyclopedia.thefreedictionary.com/programming+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">programming languages</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/compiler"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">compilers</span></span></a><span style="font-size:small;font-family:Times New Roman;">. They are also used for analyzing the </span><a href="http://encyclopedia.thefreedictionary.com/syntax"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">syntax</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of </span><a href="http://encyclopedia.thefreedictionary.com/natural+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">natural languages</span></span></a><span style="font-size:small;font-family:Times New Roman;">. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Background</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><span>            </span>Since the time of Pā</span><span style="font-family:Tahoma;">ṇ</span><span style="font-family:Times New Roman;">ini, at least, linguists have described the </span></span><a href="http://encyclopedia.thefreedictionary.com/grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">grammars</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of languages in terms of their </span><a href="http://encyclopedia.thefreedictionary.com/block+structure"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">block structure</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and described how sentences are </span><a href="http://encyclopedia.thefreedictionary.com/recursion"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">recursively</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;"> built up from smaller phrases, and eventually individual words or word elements.</p>
<p></span><strong><span style="font-size:26pt;">Context-Free Grammar</span></strong></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:small;">The </span><strong><span style="font-size:14pt;">context-free grammar</span></strong><span style="font-size:small;"> (or "phrase-structure grammar"</span></span><a name="ref_chomsky1956"></a><span style="font-size:small;font-family:Times New Roman;">) as Chomsky called it) formalism developed by </span><a href="http://encyclopedia.thefreedictionary.com/Noam+Chomsky"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong><span style="color:windowtext;text-decoration:none;">Noam </span></strong><span style="color:windowtext;text-decoration:none;">Chomsky</span></span></span></a><span style="font-size:small;font-family:Times New Roman;">,<sup><a href="http://encyclopedia.thefreedictionary.com/Context-free+grammar#endnote_chomsky1956"><span style="color:windowtext;text-decoration:none;">[0]</span></a></sup> in the mid-</span><a href="http://encyclopedia.thefreedictionary.com/1950s"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">1950s</span></span></a><span style="font-size:small;font-family:Times New Roman;">, took the manner in which linguistics had described this grammatical structure, and then turned it into rigorous mathematics. A context-free grammar provides a simple and precise mechanism for describing the methods by which phrases in some natural language are built from smaller blocks, capturing the "block structure" of sentences in a natural way. Its simplicity makes the formalism amenable to rigorous mathematical study, but it comes at a price: important features of natural language syntax such as </span><a href="http://encyclopedia.thefreedictionary.com/agreement"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">agreement</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/reference"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">reference</span></span></a><span style="font-size:small;font-family:Times New Roman;"> cannot be expressed in a natural way, or not at all.</p>
<p>Block structure was introduced into computer </span><a href="http://encyclopedia.thefreedictionary.com/programming+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">programming languages</span></span></a><span style="font-size:small;font-family:Times New Roman;"> by the </span><a href="http://encyclopedia.thefreedictionary.com/Algol+(programming+language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Algol</span></span></a><span style="font-size:small;font-family:Times New Roman;"> project, which, as a consequence, also featured a context-free grammar to describe the resulting Algol syntax. This became a standard feature of computer languages, and the notation for grammars used in concrete descriptions of computer languages came to be known as Backus-Naur Form, after two members of the Algol language design committee.</p>
<p></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The "block structure" aspect that context-free grammars capture is so fundamental to grammar that the terms syntax and grammar are often identified with context-free grammar rules, especially in computer science. Formal constraints not captured by the grammar are then considered to be part of the "semantics" of the language.</p>
<p>Context-free grammars are simple enough to allow the construction of efficient parsing algorithms which, for a given string, determine whether and how it can be generated from the grammar. An </span><a href="http://encyclopedia.thefreedictionary.com/Earley+parser"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Earley parser</span></span></a><span style="font-size:small;font-family:Times New Roman;"> is an example of such an algorithm, while the widely used </span><a href="http://encyclopedia.thefreedictionary.com/LR+parser"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">LR</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/LL+parser"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">LL parsers</span></span></a><span style="font-size:small;font-family:Times New Roman;"> are more efficient algorithms that only deal with more restrictive subsets of context-free grammars. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Formal definitions</span></span></h2>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><span>         </span>A context-free grammar <em><span style="font-style:normal;">G</span></em> is a 4-</span></span><a href="http://encyclopedia.thefreedictionary.com/tuple"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">tuple</span></span></a><span style="font-size:small;font-family:Times New Roman;">:</p>
<p></span><span style="font-size:small;font-family:Times New Roman;">where</p>
<p>1. </span><span style="font-size:small;font-family:Times New Roman;">is a finite set of <em><span style="font-style:normal;">non-terminal</span></em> characters or variables. They represent different types of phrase or clause in the sentence.</p>
<p>2. </span><span style="font-size:small;font-family:Times New Roman;">is a finite set of <em><span style="font-style:normal;">terminal</span></em>s, disjoint with </span><span style="font-size:small;font-family:Times New Roman;">, which make up the actual content of the sentence.</p>
<p>3. </span><span style="font-size:small;font-family:Times New Roman;">is the start variable, used to represent the whole sentence (or program). It must be an element of </span><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>4. </span><span style="font-size:small;font-family:Times New Roman;">is a relation from </span><span style="font-size:small;font-family:Times New Roman;">to </span><span style="font-size:small;font-family:Times New Roman;">such that </span><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>In addition, </span><span style="font-size:small;font-family:Times New Roman;">is a finite set. The members of </span><span style="font-size:small;font-family:Times New Roman;">are called the <em><span style="font-style:normal;">rule</span></em>s or <em><span style="font-style:normal;">production</span></em>s of the grammar. The asterisk represents the </span><a href="http://encyclopedia.thefreedictionary.com/Kleene+star"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Kleene star</span></span></a><span style="font-family:Times New Roman;"><span style="font-size:small;"> operation.</p>
<p></span><strong><span style="font-size:14pt;">Additional Definition 1</span></strong></span><span style="font-size:small;font-family:Times New Roman;"></p>
<p><span>         </span>For any strings </span><span style="font-size:small;font-family:Times New Roman;">, we say </span><span style="font-size:small;font-family:Times New Roman;">yields </span><span style="font-size:small;font-family:Times New Roman;">, written as </span><span style="font-size:small;font-family:Times New Roman;">, if </span><span style="font-size:small;font-family:Times New Roman;">such that </span><span style="font-size:small;font-family:Times New Roman;">and </span><span style="font-size:small;font-family:Times New Roman;">. Thus, </span><span style="font-size:small;font-family:Times New Roman;">is the result of applying the rule </span><span style="font-size:small;font-family:Times New Roman;">to </span><span style="font-family:Times New Roman;"><span style="font-size:small;">.</p>
<p></span><strong><span style="font-size:14pt;">Additional Definition 2</span></strong></span><span style="font-size:small;font-family:Times New Roman;"></p>
<p>For any </span><span style="font-size:small;font-family:Times New Roman;">(or </span><span style="font-size:small;font-family:Times New Roman;">in some textbooks) if </span><span style="font-size:small;font-family:Times New Roman;">such that </span></p>
<p><strong><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Additional Definition 3</span></span></strong><span style="font-size:small;font-family:Times New Roman;"></p>
<p>The language of a grammar </span><span style="font-size:small;font-family:Times New Roman;">is the set </span></p>
<p class="MsoNormal" style="margin:0;">
<strong><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Additional Definition 4</span></span></strong><span style="font-size:small;font-family:Times New Roman;"></p>
<p>A language </span><span style="font-size:small;font-family:Times New Roman;">is said to be a context-free language (CFL) if there exists a CFG, </span><span style="font-size:small;font-family:Times New Roman;">such that . </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-family:&quot;"><em><span style="font-size:large;">Examples</span></em></span></h2>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Example 1</span></span></h3>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">A simple context-free grammar is given as: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">S → aSb | ab;</span></p>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">where | is used to separate multiple options for the same non-terminal; so this is the same as </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">S → aSb</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">S → ab</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The terminals here are <em><span style="font-style:normal;">a</span></em> and <em><span style="font-style:normal;">b</span></em>, while the only non-terminal is S. This grammar generates the language </span><span style="font-size:small;font-family:Times New Roman;">which is not </span><a href="http://encyclopedia.thefreedictionary.com/regular+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">regular</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>The special character ε stands for the empty string. By changing the above grammar to :S → aSb | ε we obtain a grammar generating the language instead. This differs only in that it contains the empty string while the original grammar did not. </span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Example 2</span></span></h3>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">Here is a context-free grammar for syntactically correct infix algebraic expressions in the variables x, y and z: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">S → x | y | z | S + S | S - S | S * S | S/S | (S)</span></p>
<p class="MsoNormal" style="margin:0;">
<span style="font-size:small;font-family:Times New Roman;">This grammar can, for example, generate the string "( x + y ) * x - z * y / ( x + x )" as follows: "S" is the initial string. "S - S" is the result of applying the fifth transformation [S → S - S] to the nonterminal S. "S * S - S / S" is the result of applying the sixth transform to the first S and the seventh one to the second S. "( S ) * S - S / ( S )" is the result of applying the final transform to certain of the nonterminals. "( S + S ) * S - S * S / ( S + S )" is the result of the fourth and fifth transforms to certain nonterminals. "( x + y ) * x - z * y / ( x + x )" is the final result, obtained by using the first three transformations to turn the S nonterminals into the terminals x, y, and z.</p>
<p>This grammar is </span><a href="http://encyclopedia.thefreedictionary.com/ambiguous+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ambiguous</span></span></a><span style="font-size:small;font-family:Times New Roman;">, meaning that one can generate the same string with more than one </span><a href="http://encyclopedia.thefreedictionary.com/parse+tree"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">parse tree</span></span></a><span style="font-size:small;font-family:Times New Roman;">. For example, "x + y * z" might have either the + or the * parsed first; presumably these will produce different results. </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-family:Times New Roman;"><span style="font-size:14pt;">Example 3</span></span></strong></p>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">A context-free grammar for the language consisting of all strings over {a,b} for which the number of a's and b's are different is </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">S → U | V</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">U → TaU | TaT</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">V → TbV | TbT</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">T → aTbT | bTaT | ε</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Here, the nonterminal T can generate all strings with the same number of a's as b's, the nonterminal U generates all strings with more a's than b's and the nonterminal V generates all strings with fewer a's than b's. </span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Example 4</span></span></h3>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">Another example of a context-free language is . This is not a regular language, but it is context free as it can be generated by the following context-free grammar: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">S → bSbb | A</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">A → aA | ε</span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Other examples</span></span></h3>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Context-free grammars are not limited in application to mathematical ("formal") languages. For example, it has been suggested that a class of </span><a href="http://encyclopedia.thefreedictionary.com/Tamil+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Tamil</span></span></a><span style="font-size:small;font-family:Times New Roman;"> poetry called </span><a href="http://encyclopedia.thefreedictionary.com/Venpa"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Venpa</span></span></a><span style="font-size:small;font-family:Times New Roman;"> is governed by a context-free grammar.<sup><a href="http://encyclopedia.thefreedictionary.com/Context-free+grammar#endnote_rf-2"><span style="color:windowtext;text-decoration:none;">[2]</span></a></sup> </span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Derivations and syntax trees</span></span></h3>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">There are two common ways to describe how a given string can be derived from the start symbol of a given grammar. The simplest way is to list the consecutive strings of symbols, beginning with the start symbol and ending with the string, and the rules that have been applied. If we introduce a strategy such as "always replace the left-most nonterminal first" then for context-free grammars the list of applied grammar rules is by itself sufficient. This is called the <em><span style="font-style:normal;">leftmost derivation</span></em> of a string. For example, if we take the following grammar: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">(1) S → S + S</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">(2) S → 1</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">(3) S → a</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<p><span style="font-size:small;font-family:Times New Roman;">and the string "1 + 1 + a" then a left derivation of this string is the list [ (1), (1), (2), (2), (3) ]. Analogously the <em><span style="font-style:normal;">rightmost derivation</span></em> is defined as the list that we get if we always replace the rightmost nonterminal first. In this case this could be the list [ (1), (3), (1), (2), (2)].</p>
<p>The distinction between leftmost derivation and rightmost derivation is important because in most </span><a href="http://encyclopedia.thefreedictionary.com/parsing"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">parser</span></span></a><span style="font-size:small;font-family:Times New Roman;">s the transformation of the input is defined by giving a piece of code for every grammar rule that is executed whenever the rule is applied. Therefore it is important to know whether the parser determines a leftmost or a rightmost derivation because this determines the order in which the pieces of code will be executed. See for an example </span><a href="http://encyclopedia.thefreedictionary.com/LL+parser"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">LL parsers</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/LR+parser"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">LR parsers</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>A derivation also imposes in some sense a hierarchical structure on the string that is derived. For example, if the string "1 + 1 + a" is derived according to the leftmost derivation: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">S→S+S (1)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">  →S+S+S (1)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">  →1+S+S (2)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">  →1+1+S (2)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">  →1+1+a (3)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<span style="font-size:small;font-family:Times New Roman;">the structure of the string would be: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;">{ { { 1 }<sub>S</sub> + { 1 }<sub>S</sub> }<sub>S</sub> + { a }<sub>S</sub> }<sub>S</sub></span></span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">where { ... }<sub>S</sub> indicates a substring recognized as belonging to S. This hierarchy can also be seen as a tree:</p>
<p>S /| / | / | S '+' S /|\ | / | \ | S '+' S 'a' | | '1' '1'</p>
<p>This tree is called a <em><span style="font-style:normal;">concrete syntax tree</span></em> (see also </span><a href="http://encyclopedia.thefreedictionary.com/abstract+syntax+tree"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">abstract syntax tree</span></span></a><span style="font-size:small;font-family:Times New Roman;">) of the string. In this case the presented leftmost and the rightmost derivations define the same syntax tree; however, there is another (leftmost) derivation of the same string </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">S→ S + S (1)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">  → 1 + S (2)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">  → 1 + S + S (1)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">  → 1 + 1 + S (2)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">  → 1 + 1 + a (3)</span></p>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">and this defines the following syntax tree:</p>
<p>S /| / | / | S '+' S | /| | / | '1' S '+' S | | '1' 'a'</p>
<p>If, for certain strings in the language of the grammar, there is more than one parsing tree, then the grammar is said to be an <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/ambiguous+grammar"><span style="color:windowtext;text-decoration:none;">ambiguous grammar</span></a></span></em>. Such grammars are usually hard to parse because the parser cannot always decide which grammar rule it has to apply. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Normal forms</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">Every context-free grammar that does not generate the empty string can be transformed into one in which no rule has the empty string as a product [a rule with ε as a product is called an ε-production]. If it does generate the empty string, it will be necessary to include the rule , but there need be no other ε-rule. Every context-free grammar with no ε-production has an equivalent grammar in </span><a href="http://encyclopedia.thefreedictionary.com/Chomsky+normal+form"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Chomsky normal form</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or </span><a href="http://encyclopedia.thefreedictionary.com/Greibach+normal+form"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Greibach normal form</span></span></a><span style="font-size:small;font-family:Times New Roman;">. "Equivalent" here means that the two grammars generate the same language.</p>
<p>Because of the especially simple form of production rules in Chomsky Normal Form grammars, this normal form has both theoretical and practical implications. For instance, given a context-free grammar, one can use the Chomsky Normal Form to construct a polynomial-time algorithm which decides whether a given string is in the language represented by that grammar or not (the </span><a href="http://encyclopedia.thefreedictionary.com/CYK+algorithm"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">CYK algorithm</span></span></a><span style="font-size:small;font-family:Times New Roman;">). </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Undecidable problems</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">Although some operations on context-free grammars are decidable due to their limited power, CFGs do have interesting undecidable problems. One of the simplest and most cited is the problem of deciding whether a CFG accepts the language of all strings. A reduction can be demonstrated to this problem from the well-known undecidable problem of determining whether a </span><a href="http://encyclopedia.thefreedictionary.com/Turing+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Turing machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> accepts a particular input. The reduction uses the concept of a <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/computation+history"><span style="color:windowtext;text-decoration:none;">computation history</span></a></span></em>, a string describing an entire computation of a </span><a href="http://encyclopedia.thefreedictionary.com/Turing+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Turing machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">. We can construct a CFG that generates all strings that are not accepting computation histories for a particular Turing machine on a particular input, and thus it will accept all strings only if the machine does not accept that input.</p>
<p>As a consequence of this, it is also undecidable whether two CFGs describe the same language, since we can't even decide whether a CFG is equivalent to the trivial CFG deciding the language of all strings.</p>
<p>Another point worth mentioning is that the problem of determining if a </span><a href="http://encyclopedia.thefreedictionary.com/context-sensitive+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">context-sensitive grammar</span></span></a><span style="font-size:small;font-family:Times New Roman;"> describes a context-free language is undecidable. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Extensions</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">An obvious way to extend the context-free grammar formalism is to allow nonterminals to have arguments, the values of which are passed along within the rules. This allows natural language features such as </span><a href="http://encyclopedia.thefreedictionary.com/agreement"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">agreement</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/reference"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">reference</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and programming language analogons such as the correct use and definition of identifiers, to be expressed in a natural way. E.g. we can now easily express that in English sentences, the subject and verb must agree in number.</p>
<p>In computer science, examples of this approach include affix grammars, </span><a href="http://encyclopedia.thefreedictionary.com/attribute+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">attribute grammars</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/indexed+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">indexed grammars</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and Van Wijngaarden </span><a href="http://encyclopedia.thefreedictionary.com/two-level+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">two-level grammars</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>Similar extensions exist in linguistics.</p>
<p>Another extension is to allow additional symbols to appear at the left hand side of rules, constraining their application. This produces the formalism of </span><a href="http://encyclopedia.thefreedictionary.com/context-sensitive+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">context-sensitive grammars</span></span></a><span style="font-size:small;font-family:Times New Roman;">. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Linguistic applications</span></span></h2>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><a href="http://encyclopedia.thefreedictionary.com/Noam+Chomsky"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Chomsky</span></span></a><span style="font-size:small;font-family:Times New Roman;"> himself initially hoped to overcome the limitations of context-free grammars by adding </span><a href="http://encyclopedia.thefreedictionary.com/transformational+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">transformation rules</span></span></a><span style="font-size:small;font-family:Times New Roman;">.<sup><a href="http://encyclopedia.thefreedictionary.com/Context-free+grammar#endnote_chomsky1956"><span style="color:windowtext;text-decoration:none;">[0]</span></a></sup></p>
<p>Such rules are another standard device in traditional linguistics; e.g. </span><a href="http://encyclopedia.thefreedictionary.com/grammatical+voice"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">passivization</span></span></a><span style="font-size:small;font-family:Times New Roman;"> in English. However, arbitrary transformations must be disallowed, since they are much too powerful (Turing complete). Much of </span><a href="http://encyclopedia.thefreedictionary.com/generative+grammar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">generative grammar</span></span></a><span style="font-size:small;font-family:Times New Roman;"> has been devoted to finding ways of refining the descriptive mechanisms of phrase-structure grammar and transformation rules such that exactly the kinds of things can be expressed that natural language actually allows.</p>
<p>His general position regarding the non-context-freeness of natural language has held up since then</span><a name="ref_shieber1985"></a><sup><a href="http://encyclopedia.thefreedictionary.com/Context-free+grammar#endnote_shieber1985"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">[3]</span></span></a></sup><span style="font-size:small;font-family:Times New Roman;">, although his specific examples regarding the inadequacy of CFGs in terms of their weak generative capacity were later disproved.</span><a name="ref_pullum-gazdar1982"></a><sup><a href="http://encyclopedia.thefreedictionary.com/Context-free+grammar#endnote_pullum-gazdar1982"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">[4]</span></span></a></sup><span style="font-size:small;font-family:Times New Roman;"> </span><a href="http://encyclopedia.thefreedictionary.com/Gerald+Gazdar"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Gerald Gazdar</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/Geoffrey+Pullum"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Geoffrey Pullum</span></span></a><span style="font-size:small;font-family:Times New Roman;"> have argued that despite a few non-context-free constructions in natural language (such as cross-serial dependencies in </span><a href="http://encyclopedia.thefreedictionary.com/Swiss+German"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Swiss German</span></span></a><sup><a href="http://encyclopedia.thefreedictionary.com/Context-free+grammar#endnote_shieber1985"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">[3]</span></span></a></sup><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/reduplication"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">reduplication</span></span></a><span style="font-size:small;font-family:Times New Roman;"> in </span><a href="http://encyclopedia.thefreedictionary.com/Bambara+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Bambara</span></span></a><a name="ref_culy1985"></a><sup><a href="http://encyclopedia.thefreedictionary.com/Context-free+grammar#endnote_culy1985"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">[5]</span></span></a></sup><span style="font-size:small;"><span style="font-family:Times New Roman;">), the vast majority of forms in natural language are indeed context-free.<sup><a href="http://encyclopedia.thefreedictionary.com/Context-free+grammar#endnote_pullum-gazdar1982"><span style="color:windowtext;text-decoration:none;">[4]</span></a></sup></span></span></p>
<p class="MsoNormal" style="margin:0;"><sup><span style="font-size:small;font-family:Times New Roman;"> </span></sup></p>
<p class="MsoNormal" style="margin:0;"><span style="font-family:Times New Roman;"><strong><span style="font-size:26pt;">Pushdown Automaton</span></strong><sup><span style="font-size:26pt;"></span></sup></span></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-size:small;font-family:Times New Roman;">In </span><a href="http://encyclopedia.thefreedictionary.com/automata+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">automata theory</span></span></a><span style="font-size:small;font-family:Times New Roman;">, a <strong>pushdown automaton</strong> (PDA) is a </span><a href="http://encyclopedia.thefreedictionary.com/finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite automaton</span></span></a><span style="font-size:small;font-family:Times New Roman;"> that can make use of a </span><a href="http://encyclopedia.thefreedictionary.com/Stack+(data+structure)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">stack</span></span></a><span style="font-size:small;font-family:Times New Roman;"> containing data. </span></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:14pt;"><span style="font-family:Times New Roman;"> </span></span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Operation</span></span></strong></p>
<p class="MsoNormal" style="margin:0;"><strong><span style="font-size:14pt;"><span style="font-family:Times New Roman;"> </span></span></strong></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Pushdown automata differ from normal finite state machines in two ways: </span></p>
<ol type="1">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">They can use the top of the stack to decide which transition to take. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">They can manipulate the stack as part of performing a transition. </span></li>
</ol>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">Pushdown automata choose a transition by indexing a table by input signal, current state, and the top of the stack. Normal finite state machines just look by input signal and current state: they have no stack to work with. Pushdown automata add the stack as a parameter for choice. Given an input signal, current state, and a given symbol at the top of the stack, a transition path is chosen.</p>
<p>Pushdown automata can also manipulate the stack, as part of performing a transition. Normal finite state machines choose a new state, the result of following the transition. The manipulation can be to push a particular symbol to the top of the stack, or to pop off the top of the stack. The automaton can alternatively ignore the stack, and leave it as it is. The choice of manipulation (or no manipulation) is determined by the transition table.</p>
<p>Put together: Given an input signal, current state, and stack symbol, the automaton can follow a transition to another state, and optionally manipulate (push or pop) the stack.</p>
<p>The (underlying) finite automaton is specifically a </span><a href="http://encyclopedia.thefreedictionary.com/nondeterministic+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">nondeterministic finite state machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">, giving what is technically known as a "nondeterministic pushdown automaton" (NPDA). If a </span><a href="http://encyclopedia.thefreedictionary.com/deterministic+finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">deterministic finite state machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> is used, then the result is a </span><a href="http://encyclopedia.thefreedictionary.com/deterministic+pushdown+automaton"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">deterministic pushdown automaton</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (DPDA), a strictly weaker device. Nondeterminism means that there may be more than just one transition available to follow, given an input signal, state, and stack symbol.</p>
<p>If we allow a finite automaton access to two stacks instead of just one, we obtain a more powerful device, equivalent in power to a </span><a href="http://encyclopedia.thefreedictionary.com/Turing+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Turing machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">. A </span><a href="http://encyclopedia.thefreedictionary.com/linear+bounded+automaton"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">linear bounded automaton</span></span></a><span style="font-size:small;font-family:Times New Roman;"> is a device which is more powerful than a pushdown automaton but less so than a Turing machine.</p>
<p>Pushdown automata are equivalent to </span><a href="http://encyclopedia.thefreedictionary.com/context-free+grammars"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">context-free grammars</span></span></a><span style="font-size:small;font-family:Times New Roman;">: for every context-free grammar, there exists a pushdown automaton such that the language generated by the grammar is identical with the language generated by the automaton, and for every pushdown automaton there exists a context-free grammar such that the language generated by the automaton is identical with the language generated by the grammar. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Formal Definition</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">A PDA is formally defined as a 6-tuple:</p>
<p></span><span style="font-size:small;font-family:Times New Roman;">where </span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is a finite set of states </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is a finite set of the input alphabet </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is a finite set of the stack alphabet </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">: </span><span style="font-size:small;font-family:Times New Roman;">is the transition function </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the start state </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the set of accept states </span></li>
<li class="MsoNormal"></li>
<li class="MsoNormal"></li>
</ul>
<p class="MsoNormal" style="margin:3pt 0 0;"><em><strong><span style="font-size:14pt;font-style:normal;"><span style="font-family:Times New Roman;">Computation Definition 1</span></span></strong></em><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong> </strong></p>
<p>For any PDA, </span></span><span style="font-size:small;font-family:Times New Roman;">, a computation path is an ordered</p>
<p>(n+1)-tuple, </span><span style="font-size:small;font-family:Times New Roman;">, where </span><span style="font-size:small;font-family:Times New Roman;">Q, n</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">0, which satisfies the following conditions:</p>
<p>(i) </span><span style="font-size:small;font-family:Times New Roman;">for i = 0, 1, 2,......, n-1, </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">where </span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<p><span style="font-size:small;font-family:Times New Roman;">(ii) </span><span style="font-size:small;font-family:Times New Roman;">such that </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"> </p>
<p class="MsoNormal" style="margin:3pt 0 0;">
<p><span style="font-size:small;font-family:Times New Roman;">Intuitively, a PDA, at any point in the computation process, faces a multiple possibilities of whether to read a symbol from the top of the stack and replace it with another symbol, or read a symbol from the top of the stack and remove it without replacement, or not read any symbol from the stack but only push another symbol to it, or does nothing. All these are governed by the simutaneous equations </span><span style="font-size:small;font-family:Times New Roman;">and </span><span style="font-size:small;font-family:Times New Roman;">. </span><span style="font-size:small;font-family:Times New Roman;">is called the stack content immediately before the </span><span style="font-size:small;font-family:Times New Roman;">transitional move and </span><span style="font-size:small;font-family:Times New Roman;">is the symbol to be removed from the top of the stack. </span><span style="font-size:small;font-family:Times New Roman;">is the stack content immediately after the </span><span style="font-size:small;font-family:Times New Roman;">transitional move and </span><span style="font-size:small;font-family:Times New Roman;">is the symbol to be added to the stack during the </span><span style="font-size:small;font-family:Times New Roman;">transitional move.</p>
<p>Both </span><span style="font-size:small;font-family:Times New Roman;">and </span><span style="font-size:small;font-family:Times New Roman;">can be </span><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>If </span><span style="font-size:small;font-family:Times New Roman;">and </span><span style="font-size:small;font-family:Times New Roman;">, the PDA reads a symbol from the stack and replace it with another one.</p>
<p>If </span><span style="font-size:small;font-family:Times New Roman;">and </span><span style="font-size:small;font-family:Times New Roman;">, the PDA reads a symbol from the stack and remove it without replacement.</p>
<p>If </span><span style="font-size:small;font-family:Times New Roman;">and </span><span style="font-size:small;font-family:Times New Roman;">, the PDA simply adds a symbol to the stack.</p>
<p>If </span><span style="font-size:small;font-family:Times New Roman;">and </span><span style="font-family:Times New Roman;"><span style="font-size:small;">, the PDA leaves the stack unchanged.</p>
<p>Note that when n=0, the computation path is just the singleton (q<sub>0</sub>).</p>
<p></span><em><strong><span style="font-size:14pt;font-style:normal;">Computation Definition 2</span></strong></em></span><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong> </strong></p>
<p>For any input w = w<sub>1</sub>w<sub>2</sub>...w<sub>m</sub>, w<sub>i</sub> </span></span><span style="font-size:small;font-family:Times New Roman;">, m</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">0, M accepts w if </span><span style="font-size:small;font-family:Times New Roman;">a computation path </span><span style="font-size:small;font-family:Times New Roman;">and a finite sequence r<sub>0</sub>, r<sub>1</sub>, r<sub>2</sub>,...r<sub>m</sub> </span><span style="font-size:small;font-family:Times New Roman;">Q, m</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">n, such that</p>
<p>(i) For each i = 0, 1, 2,...m, r<sub>i</sub> is on the computation path. That is, </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">f(i) where i</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">f(i)</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;"><span style="font-family:Times New Roman;">n such that r<sub>i</sub> = q<sub>f(i)</sub></span></span></p>
<p class="MsoNormal" style="margin:3pt 0 0;">
<p><span style="font-size:small;font-family:Times New Roman;">(ii) (q<sub>f(i)+1</sub>, b<sub>f(i)+1</sub>) </span><span style="font-size:small;font-family:Times New Roman;">(r<sub>i</sub>, w<sub>i+1</sub>, a<sub>f(i)+1</sub>) for each i = 0, 1, 2,...m-1. </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">where a<sub>f(i)+1</sub> and b<sub>f(i)+1</sub> are defined as in Computation Definition 1.</span></p>
<p class="MsoNormal" style="margin:3pt 0 0;">
<p><span style="font-size:small;font-family:Times New Roman;">(iii) (q<sub>j+1</sub>, b<sub>j+1</sub>) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>j</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, a<sub>j+1</sub>) if q<sub>j</sub> </span><span style="font-size:small;font-family:Times New Roman;">{r<sub>0</sub>, r<sub>1</sub>,...r<sub>m</sub>} </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">where a<sub>j+1</sub> and b<sub>j+1</sub> are defined as in Computation Definition 1.</span></p>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">(iv) r<sub>m</sub> = q<sub>n</sub> and r<sub>m</sub> </span><span style="font-size:small;font-family:Times New Roman;">F</p>
<p>Note that the above definitions do not provide a mechanism to test for an empty stack. To do so, one would need to write a special symbol on the stack at the beginning of every computation so that the PDA would recognize that the stack is effectively empty whenever it detects the special symbol. Formally, this is done by introducing the transition </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>0</sub>, </span><span style="font-size:small;font-family:Times New Roman;">= {(q<sub>1</sub>, $)} where $ is the special symbol. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Example</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The following is the formal description of the PDA which recognizes the language </span><span style="font-size:small;font-family:Times New Roman;">:</p>
<p></span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Q = {q<sub>1</sub>, q<sub>2</sub>, q<sub>3</sub>, q<sub>4</sub>}</p>
<p></span><span style="font-size:small;font-family:Times New Roman;">= {0, 1}</p>
<p></span><span style="font-size:small;font-family:Times New Roman;">= {0, $}</p>
<p>F = {q<sub>1</sub>, q<sub>4</sub>}</p>
<p></span><span style="font-size:small;font-family:Times New Roman;">(q<sub>1</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, </span><span style="font-size:small;font-family:Times New Roman;">) = {(q<sub>2</sub>, $), (q<sub>1</sub>, </span><span style="font-size:small;font-family:Times New Roman;">)}</p>
<p></span><span style="font-size:small;font-family:Times New Roman;">(q<sub>2</sub>, 0, </span><span style="font-size:small;font-family:Times New Roman;">) = {(q<sub>2</sub>, 0)}</p>
<p></span><span style="font-size:small;font-family:Times New Roman;">(q<sub>2</sub>, 1, 0) = {(q<sub>3</sub>, </span><span style="font-size:small;font-family:Times New Roman;">)}</p>
<p></span><span style="font-size:small;font-family:Times New Roman;">(q<sub>3</sub>, 1, 0) = {(q<sub>3</sub>, </span><span style="font-size:small;font-family:Times New Roman;">)}</p>
<p></span><span style="font-size:small;font-family:Times New Roman;">(q<sub>3</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, $) = {(q<sub>4</sub>, </span><span style="font-size:small;font-family:Times New Roman;">)}</p>
<p></span><span style="font-size:small;font-family:Times New Roman;">(q, w, a) = </span><span style="font-size:small;font-family:Times New Roman;">for any other values of state, input and stack symbols. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Understanding the computation process</span></span></h2>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">The following illustrates how the above PDA computes on different input strings.</p>
<p>(a) Input string = 0011 </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">(i) write </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>1</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, </span><span style="font-size:small;font-family:Times New Roman;">) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>2</sub>, $) to represent (q<sub>2</sub>, $) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>1</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, </span><span style="font-size:small;font-family:Times New Roman;">)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">: s<sub>0</sub> = </span><span style="font-size:small;font-family:Times New Roman;">, s<sub>1</sub> = $, t = </span><span style="font-size:small;font-family:Times New Roman;">, a = </span><span style="font-size:small;font-family:Times New Roman;">, b = $</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;">: set r<sub>0</sub> = q<sub>2</sub></span></span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">(ii) </span><span style="font-size:small;font-family:Times New Roman;">(r<sub>0</sub>, 0, </span><span style="font-size:small;font-family:Times New Roman;">) = </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>2</sub>, 0, </span><span style="font-size:small;font-family:Times New Roman;">) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>2</sub>, 0)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">: s<sub>1</sub> = $, a = </span><span style="font-size:small;font-family:Times New Roman;">, t = $, b = 0, s<sub>2</sub> = 0$</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;">: set r<sub>1</sub> = q<sub>2</sub></span></span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">(iii) </span><span style="font-size:small;font-family:Times New Roman;">(r<sub>1</sub>, 0, </span><span style="font-size:small;font-family:Times New Roman;">) = </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>2</sub>, 0, </span><span style="font-size:small;font-family:Times New Roman;">) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>2</sub>, 0)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">: s<sub>2</sub> = 0$, a = </span><span style="font-size:small;font-family:Times New Roman;">, t = 0$, b = 0, s<sub>3</sub> = 00$</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;">: set r<sub>2</sub> = q<sub>2</sub></span></span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">(iv) </span><span style="font-size:small;font-family:Times New Roman;">(r<sub>2</sub>, 1, 0) = </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>2</sub>, 1, 0) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>3</sub>, </span><span style="font-size:small;font-family:Times New Roman;">)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">: s<sub>3</sub> = 00$, a = 0, t = 0$, b = </span><span style="font-size:small;font-family:Times New Roman;">, s<sub>4</sub> = 0$</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;">: set r<sub>3</sub> = q<sub>3</sub></span></span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">(v) </span><span style="font-size:small;font-family:Times New Roman;">(r<sub>3</sub>, 1, 0) = </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>3</sub>, 1, 0) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>3</sub>, </span><span style="font-size:small;font-family:Times New Roman;">)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">: s<sub>4</sub> = 0$, a = 0, t = $, b = </span><span style="font-size:small;font-family:Times New Roman;">, s<sub>5</sub> = $</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">(vi) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>3</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, $) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>4</sub>, </span><span style="font-size:small;font-family:Times New Roman;">)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">: s<sub>5</sub> = $, a = $, t = </span><span style="font-size:small;font-family:Times New Roman;">, b = </span><span style="font-size:small;font-family:Times New Roman;">, s<sub>6</sub> = </span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;">: set r<sub>4</sub> = q<sub>4</sub></span></span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">Since q<sub>4</sub> is an accept state, 0011 is accepted.</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">In summary, computation path = (q<sub>1</sub>, q<sub>2</sub>, q<sub>2</sub>, q<sub>2</sub>, q<sub>3</sub>, q<sub>3</sub>, q<sub>4</sub>)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">and (r<sub>0</sub>, r<sub>1</sub>, r<sub>2</sub>, r<sub>3</sub>, r<sub>4</sub>) = (q<sub>2</sub>, q<sub>2</sub>, q<sub>2</sub>, q<sub>3</sub>, q<sub>4</sub>)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<p><span style="font-size:small;font-family:Times New Roman;">(b) Input string = 001 </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">Computation moves (i), (ii), (iii), (iv) would have to be the same as in case (a), otherwise, the PDA would have come to a dead end before reaching (v).</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">(v) </span><span style="font-size:small;font-family:Times New Roman;">(r<sub>3</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, a) = </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>3</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, a)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">: Since s<sub>4</sub> = 0$, either a = </span><span style="font-size:small;font-family:Times New Roman;">or a = 0</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">: In either case, </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>3</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, a) = </span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">: Therefore, computation comes to an end at r<sub>3</sub> = q<sub>3</sub> which is not an accept state. Therefore, 001 is rejected.</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<p><span style="font-size:small;font-family:Times New Roman;">(c) Input string = </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;">Set r<sub>0</sub> = q<sub>1</sub>, r<sub>1</sub> = q<sub>1</sub></span></span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">(r<sub>0</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, </span><span style="font-size:small;font-family:Times New Roman;">) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>1</sub>, </span><span style="font-size:small;font-family:Times New Roman;">)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">Since q<sub>1</sub> is an accept state, </span><span style="font-size:small;font-family:Times New Roman;">is accepted.</span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Generalized Pushdown Automaton (GPDA)</span></span></h2>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">A GPDA is a PDA which writes an entire string to the stack or removes an entire string from the stack in one step.</p>
<p>A GPDA is formally defined as a 6-tuple </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">where Q, </span><span style="font-size:small;font-family:Times New Roman;">, </span><span style="font-size:small;font-family:Times New Roman;">, q<sub>0</sub> and F are defined the same way as a PDA.</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">: </span><span style="font-size:small;font-family:Times New Roman;">is the transition function.</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;">
<span style="font-size:small;font-family:Times New Roman;">Computation rules for a GPDA are the same as a PDA except that the a<sub>i+1</sub>'s and b<sub>i+1</sub>'s are now strings intead of symbols.</p>
<p>GPDA's and PDA's are equivalent in that if a language is recognized by a PDA, it is also recognized by a GPDA and vice versa.</p>
<p>One can formulate an analytic proof for the equivalence of GPDA's and PDA's using the following simulation:</p>
<p>Let </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>1</sub>, w, x<sub>1</sub>x<sub>2</sub>...x<sub>m</sub>) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>2</sub>, y<sub>1</sub>y<sub>2</sub>...y<sub>n</sub>) be a transition of the GPDA</p>
<p>where q<sub>1</sub>, q<sub>2</sub> </span><span style="font-size:small;font-family:Times New Roman;">Q, w </span><span style="font-size:small;font-family:Times New Roman;">, x<sub>1</sub>x<sub>2</sub>...x<sub>m</sub> </span><span style="font-size:small;font-family:Times New Roman;">, m</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">0, y<sub>1</sub>y<sub>2</sub>...y<sub>n</sub> </span><span style="font-size:small;font-family:Times New Roman;">, n</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">0.</p>
<p>Construct the following transitions for the PDA: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">:</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">(q<sub>1</sub>, w, x<sub>1</sub>) </span><span style="font-size:small;font-family:Times New Roman;">(p<sub>1</sub>, </span><span style="font-size:small;font-family:Times New Roman;">)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">:</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">(p<sub>1</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, x<sub>2</sub>) </span><span style="font-size:small;font-family:Times New Roman;">(p<sub>2</sub>, </span><span style="font-size:small;font-family:Times New Roman;">)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">:::</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">:</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">(p<sub>m-1</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, x<sub>m</sub>) </span><span style="font-size:small;font-family:Times New Roman;">(p<sub>m</sub>, </span><span style="font-size:small;font-family:Times New Roman;">)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">:</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">(p<sub>m</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, </span><span style="font-size:small;font-family:Times New Roman;">) </span><span style="font-size:small;font-family:Times New Roman;">(p<sub>m+1</sub>, y<sub>n</sub>)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">:</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">(p<sub>m+1</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, </span><span style="font-size:small;font-family:Times New Roman;">) </span><span style="font-size:small;font-family:Times New Roman;">(p<sub>m+2</sub>, y<sub>n-1</sub>)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">:::</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">:</span><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span><span style="font-size:small;font-family:Times New Roman;">(p<sub>m+n-1</sub>, </span><span style="font-size:small;font-family:Times New Roman;">, </span><span style="font-size:small;font-family:Times New Roman;">) </span><span style="font-size:small;font-family:Times New Roman;">(q<sub>2</sub>, y<sub>1</sub>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">For the test of artificial intelligence, see </span><a href="http://encyclopedia.thefreedictionary.com/Turing+test"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Turing test</span></span></a><span style="font-size:small;font-family:Times New Roman;">. For the instrumental rock band, see </span><a href="http://encyclopedia.thefreedictionary.com/Turing+Machine+(band)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Turing Machine (band)</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</span></p>
<p class="MsoNormal" style="margin:0;">
<strong><span style="font-size:26pt;"><span style="font-family:Times New Roman;">Turing Machine</span></span></strong></p>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-family:Times New Roman;"><strong><span style="font-size:14pt;">Turing machines</span></strong><span style="font-size:small;"> are extremely basic abstract symbol-manipulating devices which, despite their simplicity, can be adapted to simulate the logic of any </span></span><a href="http://encyclopedia.thefreedictionary.com/computer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer</span></span></a><span style="font-size:small;font-family:Times New Roman;"> that could possibly be constructed. They were described in </span><a href="http://encyclopedia.thefreedictionary.com/1936"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">1936</span></span></a><span style="font-size:small;font-family:Times New Roman;"> by </span><a href="http://encyclopedia.thefreedictionary.com/Alan+Turing"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Alan Turing</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Though they were intended to be technically feasible, Turing machines were not meant to be a practical computing technology, but a </span><a href="http://encyclopedia.thefreedictionary.com/thought+experiment"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">thought experiment</span></span></a><span style="font-size:small;font-family:Times New Roman;"> about the limits of mechanical computation; thus they were not actually constructed. Studying their </span><a href="http://encyclopedia.thefreedictionary.com/abstract+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">abstract properties</span></span></a><span style="font-size:small;font-family:Times New Roman;"> yields many insights into </span><a href="http://encyclopedia.thefreedictionary.com/computer+science"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer science</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/computational+complexity+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">complexity theory</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>A Turing machine that is able to simulate any other Turing machine is called a </span><a href="http://encyclopedia.thefreedictionary.com/Universal+Turing+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Universal Turing machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (<strong>UTM</strong>, or simply a <strong>universal machine</strong>). A more mathematically-oriented definition with a similar "universal" nature was introduced by </span><a href="http://encyclopedia.thefreedictionary.com/Alonzo+Church"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Alonzo Church</span></span></a><span style="font-size:small;font-family:Times New Roman;">, whose work on </span><a href="http://encyclopedia.thefreedictionary.com/lambda+calculus"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">lambda calculus</span></span></a><span style="font-size:small;font-family:Times New Roman;"> intertwined with Turing's in a formal theory of </span><a href="http://encyclopedia.thefreedictionary.com/computation"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computation</span></span></a><span style="font-size:small;font-family:Times New Roman;"> known as the Church-Turing thesis. The thesis states that Turing machines indeed capture the informal notion of effective method in logic and mathematics, and provide a precise definition of an </span><a href="http://encyclopedia.thefreedictionary.com/algorithm"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">algorithm</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or 'mechanical procedure'. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Informal description</span></span></h2>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><em><span style="font-style:normal;"><span style="font-size:small;font-family:Times New Roman;">For visualizations of Turing machines, see </span><a href="http://encyclopedia.thefreedictionary.com/Turing+machine+gallery"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Turing machine gallery</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</span></span></em></p>
<p class="MsoNormal" style="margin:0 0 12pt;">
<p><span style="font-size:small;font-family:Times New Roman;">The concept of the Turing machine is based on the idea of a person executing a well-defined procedure by changing the contents of an unlimited paper tape, which is divided into squares that can contain one of a finite set of symbols. The person needs to remember one of a finite set of states and the procedure is formulated in very basic steps in the form of "If your state is 42 and the symbol you see is a '0' then replace this with a '1', move one symbol to the right, and assume state 17 as your new state." </span></p>
<p class="MsoNormal" style="background:white;margin:0;"><a title="Enlarge picture" href="eml2('9/9f/','Turing_machine_2a.gif')"><span style="color:windowtext;text-decoration:none;"></span></a></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;">In some models the tape moves and the unused tape is truly <em><span style="font-style:normal;">blank</span></em>. The instruction to be performed (q<sub>4</sub>) is shown over the scanned square. (Drawing after Kleene (1952) p.375.)</span></p>
<p class="MsoNormal" style="margin:0 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="background:white;margin:0;"><a title="Enlarge picture" href="eml2('2/27/','Turing_machine_2b.gif')"><span style="color:windowtext;text-decoration:none;"></span></a></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;">In some models the <em><span style="font-style:normal;">head</span></em> moves along the stationary tape. The instruction to be performed (q<sub>1</sub>) is shown inside the head. In this model the "blank" tape is all 0's. The shaded squares, including the blank scanned by the head, and the squares marked 1, 1, B, and the head symbol, constitute the system state. (Drawing after Minsky (1967) p. 121).</span></p>
<p class="MsoNormal" style="margin:0;">
<span style="font-size:small;font-family:Times New Roman;">More precisely, a Turing machine consists of: </span></p>
<ol type="1">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">A <strong>TAPE</strong> which is divided into cells, one next to the other. Each cell contains a symbol from some finite alphabet. The alphabet contains a special <em><span style="font-style:normal;">blank</span></em> symbol (here written as 'B') and one or more other symbols. The tape is assumed to be arbitrarily extendable to the left and to the right, i.e., the Turing machine is always supplied with as much tape as it needs for its computation. Cells that have not been written to before are assumed to be filled with the blank symbol. In some models the tape has a left end marked with a special symbol; the tape extends or is indefinitely extensible to the right. The symbols are sometimes referred to as <em><span style="font-style:normal;">colors</span></em>. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">A <strong>HEAD</strong> that can read and write symbols on the tape and move the tape left and right one (and only one) cell at a time. In some models the head moves and the tape is stationary. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">A <strong>TABLE</strong> ("action table", or <em><span style="font-style:normal;">transition function</span></em>) of instructions (usually quintuples or 5-tuples but sometimes 4-tuples) that, given the <em><span style="font-style:normal;">state</span></em> the machine is currently in <em><span style="font-style:normal;">and</span></em> the <em><span style="font-style:normal;">symbol</span></em> it is reading on the tape tells the machine to do the following in sequence (for the 5-tuple models): (i) either erase or write a symbol, <em><span style="font-style:normal;">and then</span></em> (ii) move the head ('L' for one step left <em><span style="font-style:normal;">or</span></em> 'R' for one step right), <em><span style="font-style:normal;">and then</span></em> (iii) assume the same or a <em><span style="font-style:normal;">new state</span></em> as prescribed. In the 4-tuple models the TABLE tells the machine to (ia) erase or to write a symbol <em><span style="font-style:normal;">or</span></em> (ib) move the head left or right, <em><span style="font-style:normal;">and then</span></em> (ii) assume the same or a new state as prescribed, but not both actions (ia) and (ib) in the same instruction. In some models, if there is no entry in the table for the current combination of symbol and state then the machine will halt; other models require all entries to be filled. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">A <strong>state register</strong> that stores the state of the Turing table. The number of different states is always finite and there is one special <em><span style="font-style:normal;">start state</span></em> with which the state register is initialized. Turing defined this as a "note of instructions" to preserve the computation of the "computer" (a person) who is working in a "desultory manner": </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">:"This note is the counterpart of the 'state of mind'." (Undecidable, p. 139) </span></li>
</ol>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"></p>
<p></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Note that every part of the machine—its state- and symbol-collections—and its actions—printing, erasing and tape motion—is <em><span style="font-style:normal;">finite</span></em>, <em><span style="font-style:normal;">discrete</span></em> and <em><span style="font-style:normal;">distinguishable</span></em>; it is the potentially unlimited amount of tape that gives it an unbounded amount of </span><a href="http://encyclopedia.thefreedictionary.com/Computer+storage"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">storage space</span></span></a><span style="font-size:small;font-family:Times New Roman;">. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Examples of Turing machines</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">To see examples of the following models, see </span><a href="http://encyclopedia.thefreedictionary.com/Turing+machine+examples"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Turing machine examples</span></span></a><span style="font-size:small;font-family:Times New Roman;">: </span></p>
<ol type="1">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Turing's very first machine </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Copy routine </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">3-state </span><a href="http://encyclopedia.thefreedictionary.com/busy+beaver"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">busy beaver</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span></li>
</ol>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Formal definition of single-tape Turing machine</span></span></h2>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">A nutshell formal description of a "Turing machine": </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"A Turing machine is a finite-state machine associated with an external storage or memory medium." (Minsky (1967), p. 117)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"A Turing machine is essentially a finite-state sequential machine that has the ability to communicate with an external store of information." (Booth (1967), p. 354)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The </span><a href="http://encyclopedia.thefreedictionary.com/finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite state machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> is represented by the state-table together with its state register. The "external storage medium" is the tape. The input to the state machine is the scanned symbol on the tape. The output of the state machine is a symbol to print or the erase command and tape motion-command left or right.</p>
<p>Hopcroft and Ullman (1979, p. 148) formally define a (one-tape) Turing machine as a 7-</span><a href="http://encyclopedia.thefreedictionary.com/tuple"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">tuple</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><span style="font-size:small;font-family:Times New Roman;">where </span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is a finite set of <em><span style="font-style:normal;">states</span></em> </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is a finite set of the <em><span style="font-style:normal;">tape alphabet/symbols</span></em> </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the <em><span style="font-style:normal;">blank symbol</span></em> (the only symbol allowed to occur on the tape infinitely often at any step during the computation) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">, a subset of </span><span style="font-size:small;font-family:Times New Roman;">not including b is the set of <em><span style="font-style:normal;">input symbols</span></em> </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is a </span><a href="http://encyclopedia.thefreedictionary.com/partial+function"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">partial function</span></span></a><span style="font-size:small;font-family:Times New Roman;"> called the <em><span style="font-style:normal;"><a href="http://encyclopedia.thefreedictionary.com/transition+function"><span style="color:windowtext;text-decoration:none;">transition function</span></a></span></em>, where L is left shift, R is right shift. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the <em><span style="font-style:normal;">initial state</span></em> </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">is the set of <em><span style="font-style:normal;">final</span></em> or <em><span style="font-style:normal;">accepting states</span></em> </span></li>
</ul>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">The 7-tuple for the 3-state </span><a href="http://encyclopedia.thefreedictionary.com/busy+beaver"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">busy beaver</span></span></a><span style="font-size:small;font-family:Times New Roman;"> looks like this (see more about this busy beaver at </span><a href="http://encyclopedia.thefreedictionary.com/Turing+machine+examples"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Turing machine examples</span></span></a><span style="font-size:small;font-family:Times New Roman;">): </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">Q = { <strong>A</strong>, <strong>B</strong>, <strong>C</strong>, <strong>HALT</strong> }</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">Γ = { 0, 1 }</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">b = 0 = "blank"</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">Σ = { }, empty set</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">δ = see state-table below</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">q<sub>0</sub> = <strong>A</strong> = initial state</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">F = the one element set of final states {<strong>HALT</strong>}</span></p>
<p class="MsoNormal" style="margin:0 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<table class="MsoNormalTable" style="background:white;border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr style="height:26.25pt;">
<td style="border-right:#d4d0c8;border-top:#d4d0c8;background:#f2f2f2;border-left:#d4d0c8;border-bottom:black 1pt;height:26.25pt;padding:2.4pt;" colspan="10">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">State table for 3 state, 2 symbol busy beaver</span></p>
</td>
<td style="height:26.25pt;background-color:transparent;border:#d4d0c8;" width="0" height="35"></td>
</tr>
<tr>
<td style="background:#f2f2f2;border:#aaaaaa 1pt solid;padding:2.4pt;" rowspan="2">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Tape symbol</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;" colspan="3">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Current state A</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;" colspan="3">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Current state B</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;" colspan="3">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Current state C </span></span></strong></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;" width="0">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Write symbol</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Move tape</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Next state</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Write symbol</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Move tape</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Next state</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Write symbol</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Move tape</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Next state </span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;" width="0">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">0</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">R</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">B</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">A</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>B</strong> </span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;" width="0">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">C</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">R</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">B</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">N</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>HALT</strong> </span></span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;" width="0">
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:3pt 0 0;">
<p><span style="font-size:small;font-family:Times New Roman;">This specification is insufficient, however. van Emde Boas (1990) observes that: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"The set-theoretical object [his formal seven-tuple description similar to the above] provides only partial information on how the machine will behave and what its computations will look like" (p. 6).</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Examples readily demonstrate that, as well as the behavior of the components of the informal description, the <em><span style="font-style:normal;">form</span></em> of the input and output "parameters", and the position of the head at the start must be specified as well. For example, Turing (1936) places his "figures" "1" and "0" on alternate squares. Other models form the input as tight-packed unary 1s with blanks between the various strings, yet others place strings of 0's, each spaced by 1, on truly blank tape, etc.; the output may or may not appear in a similar manner. Thus to fully "describe" a "computation" of a Turing machine Stone (1972) states it is necessary to state the following: </span></p>
<ol type="1">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">The tape alphabet </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">The form in which the parameters are presented on the tape </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">The initial state of the Turing machine </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">The form in which answers will be represented on the tape when the Turing machine halts </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">The machine program" (Stone, p. 10) </span></li>
</ol>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Turing instructions—quintuples (5-tuples)</span></span></h3>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">Definitions in literature sometimes differ slightly, to make arguments or proofs easier or clearer, but this is always done in such a way that the resulting machine has the same computational power. For example, changing the set </span><span style="font-size:small;font-family:Times New Roman;">to </span><span style="font-size:small;font-family:Times New Roman;">, where <em><span style="font-style:normal;">N</span></em> ("None" or "No-operation) would allow the machine to stay on the same tape cell instead of moving left or right, does not increase the machine's computational power.</p>
<p>The most common convention represents each "Turing instruction" in a "Turing table" by one of nine 5-tuples, per the convention of Turing/Davis (Turing (1936 in <em><span style="font-style:normal;">Undecidable</span></em>, p. 126-127 and Davis (2000) p. 152): </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;">(definition 1): <strong>(q<sub>i</sub>, S<sub>j</sub>, S<sub>k</sub>/E/N, L/R/N, q<sub>m</sub>)</strong></span></span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;">: <strong>(</strong> current state <strong>q<sub>i</sub></strong> <strong>,</strong> symbol scanned <strong>S<sub>j</sub></strong> <strong>,</strong> print symbol S<sub>k</sub> <strong>PS<sub>k</sub></strong>/erase <strong>E</strong>/none <strong>N</strong> <strong>,</strong> move_tape_one_ square left <strong>L</strong>/right <strong>R</strong>/None <strong>N</strong> <strong>,</strong> new state <strong>q<sub>m</sub></strong> <strong>)</strong></span></span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><span> </span>(definition 2): <strong>(q<sub>i</sub>, S<sub>j</sub>, q<sub>m</sub>, S<sub>k</sub>/E/N, L/R/N)</strong></span></span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;">: <strong>(</strong> current state <strong>q<sub>i</sub></strong>, symbol scanned <strong>S<sub>j</sub></strong> <strong>,</strong> new state <strong>q<sub>m</sub></strong> <strong>,</strong> print symbol S<sub>k</sub> <strong>PS<sub>k</sub></strong>/erase <strong>E</strong>/none <strong>N</strong> <strong>,</strong> move_tape_one_square left <strong>L</strong>/none <strong>N</strong>/right <strong>R</strong> <strong>)</strong></span></span></p>
<p class="MsoNormal" style="margin:0 0 12pt;">
<span style="font-size:small;font-family:Times New Roman;">For remainder of this article we will use "definition 1" i.e. the Turing/Davis convention</span></p>
<table class="MsoNormalTable" style="background:white;border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background:#f2f2f2;border:#d4d0c8;padding:2.4pt;" colspan="6">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Example: state table for the 3-state 2-symbol busy beaver reduced to 5-tuples</span></p>
</td>
</tr>
<tr>
<td style="background:#f2f2f2;border:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Current state</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Scanned symbol</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Print symbol</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Move tape</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Final (i.e. next) state</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">5-tuples </span></span></strong></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">A</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">0</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">R</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">B</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(<strong>A</strong>, 0, 1, R, <strong>B</strong>) </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">A</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">C</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(<strong>A</strong>, 1, 1, L, <strong>C</strong>) </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">B</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">0</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">A</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(<strong>B</strong>, 0, 1, L, <strong>A</strong>) </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">B</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">R</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">B</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(<strong>B</strong>, 1, 1, R, <strong>B</strong>) </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">C</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">0</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">B</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(<strong>C</strong>, 0, 1, L, <strong>B</strong>) </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">C</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">N</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">H</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(<strong>C</strong>, 1, 1, N, <strong>H</strong>) </span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0 0 12pt;">
<p><span style="font-size:small;font-family:Times New Roman;">In the following table, Turing's original model allowed only the first three lines that he called N1, N2, N3 (cf Turing in <em><span style="font-style:normal;">Undecidable</span></em>, p. 126). He allowed for erasure of the "scanned square" by naming a 0th symbol S<sub>0</sub> = "erase" or "blank", etc. However, he did not allow for non-printing, so every instruction-line includes "print symbol S<sub>k</sub>" or "erase" (cf footnote 12 in Post (1947), <em><span style="font-style:normal;">Undecidable</span></em> p. 300). The abbreviations are Turing's (<em><span style="font-style:normal;">Undecidable</span></em> p.119). Subsequent to Turing's original paper in 1936–1937, machine-models have allowed all nine possible five-tuples: </span></p>
<p class="MsoNormal" style="margin:0 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<table class="MsoNormalTable" style="background:white;border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background:#f9f9f9;border:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f9f9f9;border-left:#d4d0c8;width:15%;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;" width="15%">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Current m-configuration (Turing state)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Tape symbol</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Print-operation</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Tape-motion</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f9f9f9;border-left:#d4d0c8;width:15%;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;" width="15%">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Final m-configuration (Turing state)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">5-tuple</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">5-tuple comments</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">4-tuple </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">N1</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>i</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">S<sub>j</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Print(S<sub>k</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Left L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>m</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, S<sub>k</sub>, L, q<sub>m</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">"blank" = S<sub>0</sub>, 1=S<sub>1</sub>, etc.</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">N2</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>i</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">S<sub>j</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Print(S<sub>k</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Right R</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>m</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, S<sub>k</sub>, R, q<sub>m</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">"blank" = S<sub>0</sub>, 1=S<sub>1</sub>, etc.</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">N3</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>i</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">S<sub>j</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Print(S<sub>k</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">None N</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>m</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, S<sub>k</sub>, N, q<sub>m</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">"blank" = S<sub>0</sub>, 1=S<sub>1</sub>, etc.</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, S<sub>k</sub>, q<sub>m</sub>) </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">4</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>i</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">S<sub>j</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">None N</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Left L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>m</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, N, L, q<sub>m</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, L, q<sub>m</sub>) </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">5</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>i</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">S<sub>j</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">None N</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Right R</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>m</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, N, R, q<sub>m</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, R, q<sub>m</sub>) </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">6</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>i</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">S<sub>j</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">None N</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">None N</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>m</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, N, N, q<sub>m</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Direct "jump"</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, N, q<sub>m</sub>) </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">7</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>i</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">S<sub>j</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Erase</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Left L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>m</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, E, L, q<sub>m</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">8</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>i</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">S<sub>j</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Erase</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Right R</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>m</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, E, R, q<sub>m</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">9</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>i</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">S<sub>j</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Erase</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">None N</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;">q<sub>m</sub></span></span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, E, N, q<sub>m</sub>)</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">(q<sub>i</sub>, S<sub>j</sub>, E, q<sub>m</sub>) </span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">We can construct any Turing table (list of instructions) from the above nine 5-tuples. For technical reasons usually we can dispense with the three non-printing or "N" instructions (4, 5, 6). For examples see </span><a href="http://encyclopedia.thefreedictionary.com/Turing+machine+examples"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Turing machine examples</span></span></a><span style="font-size:small;font-family:Times New Roman;">.</p>
<p>Less frequently we encounter the use of 4-tuples—these represent a further atomization of the Turing instructions (cf Post (1947), Boolos &amp; Jeffrey (1974, 1999), Davis-Sigal-Weyuker (1994)); also see more at Post-Turing machine. </span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">The "state"</span></span></h3>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">The word "state" used in context of Turing machines can be a source of confusion. Most commentators after Turing have used "state" to mean the name/designator of the current instruction to be performed—i.e. the contents of the state register. But Turing (1936) made a strong distinction between a record of what he called the machine's "m-configuration", and the machine's (or person's) "state of progress" through the computation. What Turing called "the state formula" includes both the current instruction and <em><span style="font-style:normal;">all</span></em> the symbols on the tape: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"Thus the state of progress of the computation at any stage is completely determined by the note of instructions and the symbols on the tape. That is, the <strong>state of the system</strong> may be described by a single expression (sequence of symbols) consisting of the symbols on the tape followed by Δ (which we suppose not to appear elsewhere) and then by the note of instructions. This expression is called the 'state formula' (<em><span style="font-style:normal;">Undecidable</span></em>, p.139–140, emphasis added)</span></p>
<p class="MsoNormal" style="margin:3pt 0 0;">
<p><span style="font-size:small;font-family:Times New Roman;">Earlier in his paper Turing carried this even further: he gives an example where he places a symbol of the current "m-configuration"—the instruction's label—beneath the scanned square, together with all the symbols on the tape (<em><span style="font-style:normal;">Undecidable</span></em>, p.121); this he calls "the <em><span style="font-style:normal;">complete configuration</span></em>" (<em><span style="font-style:normal;">Undecidable</span></em>, p. 118). To print the "complete configuration" on one line he places the state-label/m-configuration to the <em><span style="font-style:normal;">left</span></em> of the scanned symbol.</p>
<p>We see a variant of this in Kleene (1952) where Kleene shows how to write the </span><a href="http://encyclopedia.thefreedictionary.com/G%C3%B6del+number"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Gödel number</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of a machine's "situation": he places the "m-configuration" symbol q<sub>4</sub> over the scanned square in roughly the center of the 6 non-blank squares on the tape (see the Turing-tape figure in this article) and puts it to the <em><span style="font-style:normal;">right</span></em> of the scanned square. But Kleene refers to "q<sub>4</sub>" itself as "the machine state" (Kleene, p. 374-375). Hopcroft and Ullman call this composite the "instantaneous description" and follow the Turing convention of putting the "current state" (instruction-label, m-configuration) to the <em><span style="font-style:normal;">left</span></em> of the scanned symbol (p.149).</p>
<p><strong>Example: total state of 3-state 2-symbol busy beaver after 3 "moves"</strong> (taken from example "run" in the figure below): </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">: 1<strong>A</strong>1</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">This means: after three moves the tape has … 000110000 … on it, the head is scanning the right-most 1, and the state is <strong>A</strong>. Blanks (in this case represented by "0"s) can be part of the total state as shown here: <strong>B</strong>01 ; the tape has a single 1 on it, but the head is scanning the 0 ("blank") to its left and the state is <strong>B</strong>.</p>
<p>Thus when we speak of "state" in the context of Turing machines we should clarify whether we are describing: (i) the current instruction, or (ii) the list of symbols on the tape together with the current instruction, or (iii) the list of symbols on the tape together with the current instruction placed to the left of the scanned symbol or to the right of the scanned symbol.</p>
<p>Hodges—Turing's biographer—has observed this confusion, and his commentary on it appears in a footnote (cf Hodges (1983) p. 107). Turing machine "state" diagrams</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<table class="MsoNormalTable" style="background:white;border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="background:#f2f2f2;border:#d4d0c8;padding:2.4pt;" colspan="10">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">The table for the 3-state busy beaver ("P" = print/write a "1")</span></p>
</td>
</tr>
<tr>
<td style="background:#f2f2f2;border:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Tape symbol</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;" colspan="3">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Current state A</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;" colspan="3">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Current state B</span></span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#aaaaaa 1pt solid;background:#f2f2f2;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;" colspan="3">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;"><span style="font-family:Times New Roman;">Current state C </span></span></strong></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Write symbol</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Move tape</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Next state</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Write symbol</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Move tape</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Next state</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Write symbol</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Move tape</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">Next state </span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">0</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">P</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">R</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">B</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">P</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">A</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">P</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>B</strong> </span></span></p>
</td>
</tr>
<tr>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#aaaaaa 1pt solid;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">1</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">P</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">L</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">C</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">P</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">R</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><strong><span style="font-size:small;font-family:Times New Roman;">B</span></strong></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">P</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;font-family:Times New Roman;">N</span></p>
</td>
<td style="border-right:#aaaaaa 1pt solid;border-top:#d4d0c8;background:#f9f9f9;border-left:#d4d0c8;border-bottom:#aaaaaa 1pt solid;padding:2.4pt;">
<p class="MsoNormal" style="margin:12pt 0;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong>HALT</strong> </span></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin:0 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="background:white;margin:0;"><a title="Enlarge picture" href="eml2('6/65/','State_diagram_3_state_busy_beaver_2B.gif')"><span style="color:windowtext;text-decoration:none;"></span></a></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;">The "3-state busy beaver" Turing Machine in a </span><a href="http://encyclopedia.thefreedictionary.com/Finite+State+Machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite state representation</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Each circle represents a "state" of the TABLE—an "m-configuration" or "instruction". "Direction" of a state <em><span style="font-style:normal;">transition</span></em> is shown by an arrow. The label (e.g.. <strong>0/P,R</strong>) near the outgoing state (at the "tail" of the arrow) specifies the scanned symbol that causes a particular transition (e.g. <strong>0</strong>) followed by a slash <strong>/</strong>, followed by the subsequent "behaviors" of the machine, e.g. "<strong>P</strong> <strong>P</strong>rint" then move tape "<strong>R</strong> <strong>R</strong>ight". No general accepted format exists. The convention shown is after McClusky (1965), Booth (1965), Hill and Peterson (1974).</span></p>
<p class="MsoNormal" style="margin:0 0 12pt;">
<span style="font-size:small;font-family:Times New Roman;">To the right: the above TABLE as expressed as a "state transition" diagram".</p>
<p>Usually large TABLES are better left as tables (Booth, p. 74). They are more readily simulated by computer in tabular form (Booth, p. 74). However, certain concepts—e.g. machines with "reset" states and machines with repeating patterns (cf Hill and Peterson p. 244ff)—can be more readily seen when viewed as a drawing.</p>
<p>Whether a drawing represents an improvement on its TABLE must be decided by the reader for the particular context. See </span><a href="http://encyclopedia.thefreedictionary.com/Finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Finite state machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> for more. </span></p>
<p class="MsoNormal" style="background:white;margin:0;"><a title="The evolution of the busy-beaver's computation starts at the top and proceeds to the bottom." href="eml2('f/f9/','State_diagram_3_state_busy_beaver_4_.JPG')"><span style="color:windowtext;text-decoration:none;"></span></a></p>
<p class="MsoNormal" style="background:white;margin:0;"><span style="font-size:small;font-family:Times New Roman;">The evolution of the busy-beaver's computation starts at the top and proceeds to the bottom.</span></p>
<p class="MsoNormal" style="margin:0 0 12pt;">
<p><span style="font-size:small;font-family:Times New Roman;">The reader should again be cautioned that such diagrams represent a snapshot of their TABLE frozen in time, <em><span style="font-style:normal;">not</span></em> the course ("trajectory") of a computation <em><span style="font-style:normal;">through</span></em> time and/or space. While every time the busy beaver machine "runs" it will always follow the same state-trajectory, this is not true for the "copy" machine that can be provided with variable input "parameters".</p>
<p>The diagram "Progress of the computation" shows the 3-state busy beaver's "state" (instruction) progress through its computation from start to finish. On the far right is the Turing "complete configuration" (Kleene "situation", Hopcroft-Ullman "instantaneous description") at each step. If we were to stop the machine and clear to blank both the "state register" and entire tape, these "configurations" could be used to rekindle a computation anywhere in its progress (cf Turing (1936) <em><span style="font-style:normal;">Undecidable</span></em> pp. 139–140). </span><a name="Models_equivalent_to_the_Turing_machine_"></a></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Models equivalent to the Turing machine model</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Many machines that might be thought to have more computational capability than a simple universal Turing machine can be shown to have no more power (Hopcroft and Ullman p. 159, cf Minsky (1967)). They might compute faster, perhaps, or use less memory, or their instruction set might be smaller, but they cannot compute more powerfully (i.e. more mathematical functions). (Recall that the Church-Turing thesis <em><span style="font-style:normal;">hypothesizes</span></em> this to be true: that anything that can be “computed” can be computed by some Turing machine.)</p>
<p>A Turing machine is equivalent to a </span><a href="http://encyclopedia.thefreedictionary.com/pushdown+automaton"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">pushdown automaton</span></span></a><span style="font-size:small;font-family:Times New Roman;"> made more powerful by relaxing the </span><a href="http://encyclopedia.thefreedictionary.com/LIFO"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">last-in-first-out</span></span></a><span style="font-size:small;font-family:Times New Roman;"> requirement of its stack. (Interestingly, this seemingly minor relaxation enables the Turing machine to perform such a wide variety of computations that it can serve as a model for the computational capabilities of all modern computer software.)</p>
<p>At the other extreme, some very simple models turn out to be Turing-equivalent, i.e. to have the same computational power as the Turing machine model.</p>
<p>Common equivalent models are the multi-tape Turing machine, machines with input and output, and the </span><a href="http://encyclopedia.thefreedictionary.com/Non-deterministic+Turing+machine"><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="color:windowtext;font-style:normal;text-decoration:none;">non-deterministic</span></em><span style="color:windowtext;text-decoration:none;"> Turing machine</span></span></span></a><span style="font-size:small;font-family:Times New Roman;"> (NDTM) as opposed to the <em><span style="font-style:normal;">deterministic</span></em> Turing machine (DTM) for which the action table has at most one entry for each combination of symbol and state.</p>
<p>For more on this topic see </span><a href="http://encyclopedia.thefreedictionary.com/Turing+machine+equivalents"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Turing machine equivalents</span></span></a><span style="font-size:small;font-family:Times New Roman;">, in particular </span><a href="http://encyclopedia.thefreedictionary.com/Register+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Register machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and Post-Turing machine.</p>
<p></span><a href="http://encyclopedia.thefreedictionary.com/Read+only+right+moving+Turing+Machines"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Read only right moving Turing Machines</span></span></a><span style="font-size:small;font-family:Times New Roman;"> are equivalent to NDFA's (as well as DFA's by conversion using the </span><a href="http://encyclopedia.thefreedictionary.com/NDFA+to+DFA+conversion+algorithm"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">NDFA to DFA conversion algorithm</span></span></a><span style="font-size:small;font-family:Times New Roman;">). </p>
<p></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">For practical and didactical intentions the </span><a href="http://encyclopedia.thefreedictionary.com/Turing+machine#Models equivalent to the Turing machine model"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">equivalent</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><a href="http://encyclopedia.thefreedictionary.com/register+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">register machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> can be used as a usual </span><a href="http://encyclopedia.thefreedictionary.com/Assembly+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">assembly</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><a href="http://encyclopedia.thefreedictionary.com/programming+language"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">programming language</span></span></a><span style="font-size:small;font-family:Times New Roman;">. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;">Choice c-machines, Oracle o-machines</span></h2>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">Early in his paper (1936) Turing makes a distinction between an "automatic machine"—its "motion … completely determined by the configuration" and a "choice machine": </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"…whose motion is only partially determined by the configuration … When such a machine reaches one of these ambiguous configurations, it cannot go on until some arbitrary choice has been made by an external operator. This would be the case if we were using machines to deal with axiomatic systems" (p. 118 Undecidable)</span></p>
<p class="MsoNormal" style="margin:0;">
<span style="font-size:small;font-family:Times New Roman;">Turing (1936) does not elaborate further excepting a footnote in which he describes how to use an a-machine to "find all the provable formulae of the [Hilbert] calculus" rather than use a choice machine. He "suppose[s] that the choices are always between two possibilities 0 and 1. Each proof will then be determined by a sequence of choices i<sub>1</sub>, i<sub>2</sub>, …, i<sub>n</sub> (i<sub>1</sub> = 0 or 1, i<sub>2</sub> = 0 or 1, …, i<sub>n</sub> = 0 or 1), and hence the number 2<sup>n</sup> + i<sub>1</sub>2<sup>n-1</sup> + i<sub>2</sub>2<sup>n-2</sup> + … +in completely determines the proof. The automatic machine carries out successively proof 1, proof 2, proof 3, …"(Footnote ‡ <em><span style="font-style:normal;">The Undecidable</span></em>:138)</p>
<p>This is indeed the technique by which a deterministic (i.e. a-) Turing machine can be used to mimic the action of a </span><a href="http://encyclopedia.thefreedictionary.com/nondeterministic+Turing+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">nondeterministic Turing machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">; Turing solved the matter in a footnote and appears to dismiss it from further consideration.</p>
<p>An </span><a href="http://encyclopedia.thefreedictionary.com/oracle+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">oracle machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or o-machine is a Turing a-machine that pauses its computation at state "<strong>o</strong>" while, to complete its calculation, it "awaits the decision" of "the oracle"—an unspecified entity "apart from saying that it cannot be a machine" (Turing (1939), Undecidable p. 166–168). The concept is now actively used by mathematicians. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Universal Turing machines</span></span></h2>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><em><span style="display:none;font-style:normal;"><span style="font-size:small;font-family:Times New Roman;">Main article: </span><a href="http://encyclopedia.thefreedictionary.com/Universal+Turing+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Universal Turing machine</span></span></a></span></em><span style="display:none;"></span></p>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">As Turing wrote in <em><span style="font-style:normal;">Undecidable</span></em>, p. 128: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"It is possible to invent a <em><span style="font-style:normal;">single machine</span></em> which can be used to compute <em><span style="font-style:normal;">any</span></em> computable sequence. If this machine <strong>U</strong> is supplied with the tape on the beginning of which is written the string of quintuples separated by semicolons of some computing machine <strong>M</strong>, then <strong>U</strong> will compute the same sequence as <strong>M</strong>." (italics added)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">We now take this remarkable finding for granted. But at the time (1936) it was astonishing. The model of computation that Turing called his "universal machine"—"<strong>U</strong>" for short—is considered by some (cf Davis (2000)) to have been the fundamental theoretical breakthrough that led to the notion of the </span><a href="http://encyclopedia.thefreedictionary.com/stored+program"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">stored program</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><a href="http://encyclopedia.thefreedictionary.com/computer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer</span></span></a><span style="font-size:small;font-family:Times New Roman;">. </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"Turing's paper … contains, in essence, the invention of the modern computer and some of the programming techniques that accompanied it" (Minsky (1967), p. 104).</span></p>
<p class="MsoNormal" style="margin:0;">
<span style="font-size:small;font-family:Times New Roman;">As part of his </span><a href="http://encyclopedia.thefreedictionary.com/A+New+Kind+of+Science"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">New Kind of Science</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a href="http://encyclopedia.thefreedictionary.com/Stephen+Wolfram"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Stephen Wolfram</span></span></a><span style="font-size:small;font-family:Times New Roman;"> announced his discovery of a 2-state 5-symbol universal Turing machine. Wolfram's example is the smallest universal Turing machine so far since it has the smallest product (2,5)=10 of any known universal Turing machine.</p>
<p>On May 14th, 2007, Wolfram announced a US$25,000 prize for the proof or disproof of the conjecture that an even simpler, 2-state 3-symbol Turing machine is universal </span><a href="http://www.wolframscience.com/prizes/tm23/" target="_blank"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">[1]</span></span></a><span style="font-size:small;font-family:Times New Roman;">. If a proof is found, this would be the smallest possible universal Turing Machine. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Comparison with real machines</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">It is often said that Turing machines, unlike simpler automata, are as powerful as real machines, and are able to execute any operation that a real program can. What is missed in this statement is that almost any particular program running on <em><span style="font-style:normal;">a particular machine</span></em> is in fact nothing but a </span><a href="http://encyclopedia.thefreedictionary.com/deterministic+finite+automaton"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">deterministic finite automaton</span></span></a><span style="font-size:small;font-family:Times New Roman;">, since the machine it runs on can only be in finitely many <em><span style="font-style:normal;">configurations</span></em>. Turing machines would actually only be equivalent to a machine that had an unlimited amount of storage space. We might ask, then, why Turing machines are useful models of real computers. There are a number of ways to answer this: </span></p>
<ol type="1">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Anything a real computer can compute, a Turing machine can also compute. For example: "A Turing machine can simulate any type of subroutine found in programming languages, including recursive procedures and any of the known parameter-passing mechanisms" (Hopcroft and Ullman p. 157). Thus, a statement about the limitations of Turing machines will also apply to real computers. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">The difference lies only with the ability of a Turing machine to manipulate an unbounded amount of data. However, given a finite amount of time, a Turing machine (like a real machine) can only manipulate a finite amount of data. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Like a Turing machine, a real machine can have its storage space enlarged as needed, by acquiring more disks or other storage media. If the supply of these runs short, the Turing machine may become less useful as a model. But the fact is that neither Turing machines nor real machines need astronomical amounts of storage space in order to perform useful computation. The processing time required is usually much more of a problem. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Real machines are much more complex than a Turing machine. For example, a Turing machine describing an algorithm may have a few hundred states, while the equivalent </span><a href="http://encyclopedia.thefreedictionary.com/deterministic+finite+automaton"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">deterministic finite automaton</span></span></a><span style="font-size:small;font-family:Times New Roman;"> on a given real machine has quadrillions. This makes the DFA representation infeasible to analyze. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Turing machines describe algorithms independent of how much memory they utilize. There is a limit to the memory possessed by any current machine, but this limit can rise arbitrarily in time. Turing machines allow us to make statements about algorithms which will (theoretically) hold forever, regardless of advances in <em><span style="font-style:normal;">conventional</span></em> computing machine architecture. </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Turing machines simplify the statement of algorithms. Algorithms running on Turing-equivalent abstract machines are usually more general than their counterparts running on real machines, because they have arbitrary-precision data types available and never have to deal with unexpected conditions (including, but not limited to, running out of memory). </span></li>
</ol>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">One way in which Turing machines are a poor model for programs is that many real programs, such as </span><a href="http://encyclopedia.thefreedictionary.com/operating+system"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">operating systems</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/word+processor"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">word processors</span></span></a><span style="font-size:small;font-family:Times New Roman;">, are written to receive unbounded input over time, and therefore do not halt. Turing machines do not model such ongoing computation well (but can still model portions of it, such as individual procedures). </span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Limitations of Turing machines in computational complexity theory</span></span></h3>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><em><span style="font-style:normal;"><span style="font-size:small;font-family:Times New Roman;">Further information: </span><a href="http://encyclopedia.thefreedictionary.com/Computational+complexity+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Computational complexity theory</span></span></a></span></em></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">A limitation of Turing Machines is that they do not model the strengths of a particular arrangement well. For instance, modern stored-program computers are actually instances of a more specific form of </span><a href="http://encyclopedia.thefreedictionary.com/abstract+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">abstract machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> known as the </span><a href="http://encyclopedia.thefreedictionary.com/random+access+stored+program+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">random access stored program machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> or RASP machine model. Like the </span><a href="http://encyclopedia.thefreedictionary.com/Universal+Turing+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Universal Turing machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> the RASP stores its "program" in "memory" external to its finite-state machine's "instructions". Unlike the Universal Turing Machine, the RASP has an infinite number of distinguishable, numbered but unbounded "registers"—memory "cells" that can contain any integer (cf Elgot and Robinson (1964), Hartmanis (1971), and in particular Cook-Rechow (1973); references at </span><a href="http://encyclopedia.thefreedictionary.com/random+access+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">random access machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">). The RASP's finite-state machine is equipped with the capability for indirect addressing (e.g. the contents of one register can "point to" the address of any other, arbitrary register); thus the RASP's "program" can address any register in the register-sequence. The upshot of this distinction is that there are computational optimizations that can be performed based on the memory indices, which are not possible in a general Turing Machine; thus when Turing Machines are used as the basis for bounding running times, a 'false lower bound' can be proven on certain algorithms' running times (due to the false simplifying assumption of a Turing Machine). An example of this is </span><a href="http://encyclopedia.thefreedictionary.com/binary+search"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">binary search</span></span></a><span style="font-size:small;font-family:Times New Roman;">, which violates the Turing machine's linear Ω(<em><span style="font-style:normal;">n</span></em>) lower bound on searching an ordered list. </span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Historical background: computational machinery</span></span></h3>
<p class="MsoNormal" style="margin:3pt 0 0;"><strong><span style="font-size:14pt;"><a href="http://encyclopedia.thefreedictionary.com/Robin+Gandy"><span style="color:windowtext;text-decoration:none;"><span style="font-family:Times New Roman;">Robin Gandy</span></span></a></span></strong><span style="font-size:small;font-family:Times New Roman;">—a student of </span><a href="http://encyclopedia.thefreedictionary.com/Alan+Turing"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Alan Turing</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (1912–1954) and his life-long friend—traces the lineage of the notion of "calculating machine" back to </span><a href="http://encyclopedia.thefreedictionary.com/Babbage"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Babbage</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (circa 1834) and actually proposes "Babbage's Thesis": </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"<em><span style="font-style:normal;">That the whole of development and operations of analysis are now capable of being executed by machinery</span></em>" (italics in Babbage as cited by Gandy, p. 54)</span></p>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">Gandy's analysis of Babbage's </span><a href="http://encyclopedia.thefreedictionary.com/Analytical+Engine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Analytical Engine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> describes the following five operations (cf p. 52–53): </span></p>
<ol type="1">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">The arithmetic functions +, -, x where - indicates "proper" subtraction x - y = 0 if y &gt;= x </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Any sequence of operations is an operation </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Iteration of an operation (repeating n times an operation P) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Conditional iteration (repeating n times an operation P conditional on the "success" of test T) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">Conditional transfer (i.e. conditional "goto") </span></li>
</ol>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">Gandy states that "the functions which can be calculated by (1), (2), and (4) are precisely those which are </span><a href="http://encyclopedia.thefreedictionary.com/Turing+computable"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Turing computable</span></span></a><span style="font-size:small;font-family:Times New Roman;">." (p. 53). He cites other proposals for "universal calculating machines" included those of </span><a href="http://encyclopedia.thefreedictionary.com/Percy+Ludgate"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Percy Ludgate</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (1909), </span><a href="http://encyclopedia.thefreedictionary.com/Leonardo+Torres+y+Quevedo"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Leonardo Torres y Quevedo</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (1914), M. d'Ocagne (1922), </span><a href="http://encyclopedia.thefreedictionary.com/Louis+Couffignal"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Louis Couffignal</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (1933), </span><a href="http://encyclopedia.thefreedictionary.com/Vannevar+Bush"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Vannevar Bush</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (1936), </span><a href="http://encyclopedia.thefreedictionary.com/Howard+Aiken"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Howard Aiken</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (1937). However: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"... the emphasis is on programming a fixed iterable sequence of arithmetical operations. The fundamental importance of conditional iteration and conditional transfer for a general theory of calculating machines is not recognized ..."(Gandy p. 55)</span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">The Entscheidungsproblem (the "decision problem"): Hilbert's tenth question of 1900</span></span></h3>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;">With regards to </span><a href="http://encyclopedia.thefreedictionary.com/Hilbert's+problems"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Hilbert's problems</span></span></a><span style="font-size:small;font-family:Times New Roman;"> posed by the famous mathematician </span><a href="http://encyclopedia.thefreedictionary.com/David+Hilbert"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">David Hilbert</span></span></a><span style="font-size:small;font-family:Times New Roman;"> in 1900, an aspect of problem #10 had been floating about for almost 30 years before it was framed precisely. Hilbert's original expression for #10 is as follows: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"<strong>10. Determination of the solvability of a Diophantine equation</strong>. Given a Diophantine equation with any number of unknown quantities and with rational integral coefficients: To devise a process according to which it can be determined in a finite number of operations whether the equation is solvable in rational integers.</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"The Entscheidungsproblem [decision problem for first-order logic] is solved when we know a procedure that allows for any given logical expression to decide by finitely many operations its validity or satisfiability ... The Entscheidungsproblem must be considered the main problem of mathematical logic. ..." (quoted, with this translation and the original German, in Nachum Dershowitz and Yuri Gurevich, "A Natural Axiomatization of Church's Thesis", 2007:1 </span><a href="http://research.microsoft.com/~gurevich/annotated.html" target="_blank"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">[2]</span></span></a><span style="font-size:small;font-family:Times New Roman;">)</span></p>
<p class="MsoNormal" style="margin:3pt 0 0;">
<p><span style="font-size:small;font-family:Times New Roman;">By 1922, this notion of "</span><a href="http://encyclopedia.thefreedictionary.com/Entscheidungsproblem"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Entscheidungsproblem</span></span></a><span style="font-size:small;font-family:Times New Roman;">" had developed a bit, and H. Behmann stated that </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"... most general form of the Entscheidungsproblem [is] as follows:</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">:"A quite definite generally applicable prescription is required which will allow one to decide in a finite number of steps the truth or falsity of a given purely logical assertion ..." (Gandy p. 57 quoting Behmann)</span></p>
<p class="MsoNormal" style="margin:3pt 0 12pt;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"Behmann remarks that ... the general problem is equivalent to the problem of deciding which mathematical propositions are true." (Gandy p. 57)</span></p>
<p class="MsoNormal" style="margin:3pt 0 0;">
<p><span style="font-size:small;font-family:Times New Roman;">If one were able to solve the Entscheidungsproblem then one would have a "procedure for solving many (or even all) mathematical problems" (Gandy p. 92).</p>
<p>By the 1928 international congress of mathematicians Hilbert "made his questions quite precise. First, was mathematics <em><span style="font-style:normal;">complete</span></em> ... Second, was mathematics <em><span style="font-style:normal;">consistent</span></em> ... And thirdly, was mathematics <em><span style="font-style:normal;">decidable</span></em>?" (Hodges p. 91, Hawking p. 1121). The first two questions were answered in 1930 by </span><a href="http://encyclopedia.thefreedictionary.com/Kurt+G%C3%B6del"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Kurt Gödel</span></span></a><span style="font-size:small;font-family:Times New Roman;"> at the very same meeting where Hilbert delivered his retirement speech (much to the chagrin of Hilbert); the third — the Entscheidungsproblem — had to wait until the mid-1930's.</p>
<p>The problem was: An answer first required a precise definition of "definite general applicable prescription", what </span><a href="http://encyclopedia.thefreedictionary.com/Alonzo+Church"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Alonzo Church</span></span></a><span style="font-size:small;font-family:Times New Roman;"> would come to call "effective calculability", and in 1928 no such definition existed. But over the next 6–7 years </span><a href="http://encyclopedia.thefreedictionary.com/Emil+Post"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Emil Post</span></span></a><span style="font-size:small;font-family:Times New Roman;"> developed his definition of a worker moving from room to room writing and erasing marks per a list of instructions (Post 1936), as did Princeton professor Church and his two students </span><a href="http://encyclopedia.thefreedictionary.com/Stephen+Kleene"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Stephen Kleene</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/J.+B.+Rosser"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">J. B. Rosser</span></span></a><span style="font-size:small;font-family:Times New Roman;"> by use of Church's λ-calculus and Gödel's </span><a href="http://encyclopedia.thefreedictionary.com/recursion+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">recursion theory</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (1934). Church's paper (published 15 April 1936) showed that the Entscheidungsproblem was indeed "undecidable" and beat Turing to the punch by almost a year (Turing's paper submitted 28 May 1936, published January 1937). In the meantime, </span><a href="http://encyclopedia.thefreedictionary.com/Emil+Post"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Emil Post</span></span></a><span style="font-size:small;font-family:Times New Roman;"> submittted a brief paper in the fall of 1936 so Turing at least had priority over Post. While Church refereed Turing's paper, Turing had time to study Church's paper and add an Appendix where he sketched a proof that Church's λ-calculus and his machines would compute the same functions. </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"But what Church had done was something rather different, and in a certain sense weaker . . . the Turing construction was more direct, and provided an argument from first principles, closing the gap in Church's demonstration." (Hodges p. 112).</span></p>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">And Post had only proposed a definition of calculability and criticized Church's "definition", but had proved nothing. </span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">Alan Turing's a- (automatic-)machine</span></span></h3>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">In the spring of 1935 </span><a href="http://encyclopedia.thefreedictionary.com/Alan+M.+Turing"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Alan M. Turing</span></span></a><span style="font-size:small;font-family:Times New Roman;">, the young Master's student at King's College Cambridge UK took on the challenge; he had been stimulated by the lectures of the logician </span><a href="http://encyclopedia.thefreedictionary.com/M.+H.+A.+Newman"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">M. H. A. Newman</span></span></a><span style="font-size:small;font-family:Times New Roman;"> "and learned from them of Gödel's work and the Entscheidungsproblem ... Newman used the word 'mechanical' ... In his obituary of Turing 1955 Newman writes: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"To the question 'what is a "mechanical" process?' Turing returned the characteristic answer 'Something that can be done by a machine' and he embarked on the highly congenial task of analysing the general notion of a computing machine." (Gandy p. 74)</span></p>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">Gandy states that: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"I suppose, but do not know, that Turing, right from the start of his work, had as his goal a proof of the undecidability of the Entscheidungsproblem. He told me that the 'main idea' of the paper came to him when he was lying in Grantchester meadows in the summer of 1935. The 'main idea' might have either been his analysis of computation or his realization that there was a universal machine, and so a diagonal argument to prove unsolvability." (p. 76)</span></p>
<p class="MsoNormal" style="margin:3pt 0 0;">
<p><span style="font-size:small;font-family:Times New Roman;">While Gandy believed that Newman's statement above is "misleading", this opinion is not shared by all. Turing had had a life-long interest in machines: "Alan had dreamt of inventing typewriters as a boy; [his mother] Mrs. Turing had a typewriter; and he could well have begun by asking himself what was meant by calling a typewriter 'mechanical'" (Hodges p. 96). While at Princeton pursuing his PhD, Turing built a Boolean-logic multiplier (see below). His PhD thesis, titled "Systems of Logic Based on Ordinals", contains the following definition of "a computable function": </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"It was stated above that 'a function is effectively calculable if its values can be found by some purely mechanical process'. We may take this statement literally, understanding by a purely mechanical process one which could be carried out by a machine. It is possible to give a mathematical description, in a certain normal form, of the structures of these machines. The development of these ideas leads to the author's definition of a computable function, and to an identification of computability with effective calculabiity. It is not difficult, though somewhat laborious, to prove that these three definitions [the 3rd is the λ-calculus] are equivalent ..." (Turing (1939) in <em><span style="font-style:normal;">The Undecidable</span></em> p. 160)</span></p>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;"></p>
<p></span></p>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">When Turing returned to the UK he ultimately became jointly responsible for breaking the German secret codes created by encryption machines called "The Enigma"; he also became involved in the design of the </span><a href="http://encyclopedia.thefreedictionary.com/ACE"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ACE</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (Automatic Computing Machine), "[Turing's] ACE proposal was effectively self-contained, and its roots lay not in the </span><a href="http://encyclopedia.thefreedictionary.com/EDVAC"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">EDVAC</span></span></a><span style="font-size:small;font-family:Times New Roman;"> [the USA's initiative], but in his own universal machine" (Hodges p. 318). Arguments still continue concerning the origin and nature of what has been named by Kleene (1952) Turing's Thesis. But what Turing <em><span style="font-style:normal;">did prove</span></em> with his computational-machine model appears in his paper <em><span style="font-style:normal;">On Computable Numbers, With an Application to the Entscheidungsproblem</span></em> (1937): </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"[that] the Hilbert Entscheidungsproblem can have no solution ... I propose, therefore to show that there can be no general process for determining whether a given formula U of the functional calculus K is provable, i.e. that there can be no machine which, supplied with any one U of these formulae, will eventually say whether U is provable." (from Turing's paper reprinted in <em><span style="font-style:normal;">The Undecidable</span></em>, p. 145)</span></p>
<p class="MsoNormal" style="margin:0;">
<p><span style="font-size:small;font-family:Times New Roman;">Turing's example (his second proof): If one is to ask for a general procedure to tell us: "Does this machine ever print 0", the question is "undecidable." </span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">1937–1970: The "digital computer", the birth of "Computer science"</span></span></h3>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">In 1937, while at Princeton working on his PhD thesis, Turing built a digital (Boolean-logic) multiplier from scratch, making his own electromechanical relays (Hodges p. 138). "Alan's task was to embody the logical design of a Turing machine in a network of relay-operated switches . . ." (Hodges p. 138). While Turing might have been just curious and experimenting, quite-earnest work in the same direction was going in Germany ( </span><a href="http://encyclopedia.thefreedictionary.com/Konrad+Zuse"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Konrad Zuse</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (1938)), and in the United States (</span><a href="http://encyclopedia.thefreedictionary.com/Howard+Aiken"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Howard Aiken</span></span></a><span style="font-size:small;font-family:Times New Roman;">) and </span><a href="http://encyclopedia.thefreedictionary.com/George+Stibitz"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">George Stibitz</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (1937); the fruits of their labors were used by the Axis and Allied military in World War II (cf Hodges p. 298–299). In the early- to mid-1950's </span><a href="http://encyclopedia.thefreedictionary.com/Hao+Wang"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Hao Wang</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/Marvin+Minsky"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Marvin Minsky</span></span></a><span style="font-size:small;font-family:Times New Roman;"> reduced the Turing machine to a simpler form (a precursor to the Post-Turing machine of </span><a href="http://encyclopedia.thefreedictionary.com/Martin+Davis"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Martin Davis</span></span></a><span style="font-size:small;font-family:Times New Roman;"> ); simultaneously European researchers were reducing the new-fangled </span><a href="http://encyclopedia.thefreedictionary.com/electronic+computer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">electronic computer</span></span></a><span style="font-size:small;font-family:Times New Roman;"> to a computer-like theoretical object equivalent to what was now being called a "Turing machine" (Turing by this time had killed himself by eating a poisoned apple). In the late 1950's and early 1960's, the coincidentally-parallel developments of Melzak and Lambek (1961), Minsky (1961), and Shepherdson and Sturgis (1961) carried the European work further and reduced the Turing machine to a more friendly, computer-like abstract model called the </span><a href="http://encyclopedia.thefreedictionary.com/counter+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">counter machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">; Elgot and Robinson (1964), Hartmanis (1971), Cook and Reckhow (1973) carried this work even further with the </span><a href="http://encyclopedia.thefreedictionary.com/register+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">register machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a href="http://encyclopedia.thefreedictionary.com/random+access+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">random access machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> models —but basically all are just multi-tape Turing machines with an arithmetic-like instruction set. </span></p>
<h3 style="margin:auto 0;"><span style="font-size:14pt;"><span style="font-family:Times New Roman;">1970–present: The Turing machine as a model of computation</span></span></h3>
<p class="MsoNormal" style="margin:3pt 0 0;"><span style="font-size:small;font-family:Times New Roman;">Today the counter, register and random-access machines and their sire the Turing machine continue to be the models of choice for theorists investigating questions in the theory of computation. In particular, </span><a href="http://encyclopedia.thefreedictionary.com/computational+complexity+theory"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computational complexity theory</span></span></a><span style="font-size:small;font-family:Times New Roman;"> makes use of the Turing machine: </span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"Depending on the objects one likes to manipulate in the computations (numbers like nonnegative integers or aphanumeric strings), two models have obtained a domiant position in machine-based complexity theory:</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">:"<em><span style="font-style:normal;">the off-line multitape Turing machine</span></em>. . . , which represents the standard model for string-oriented computation, and</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">:"the <em><span style="font-style:normal;">random access machine (RAM)</span></em> as introduced by Cook and Reckhow . . . , which models the idealized Von Neumann style computer." (van Emde Boas 1990:4)</span></p>
<p class="MsoNormal" style="margin:0 0 0 .5in;"><span style="font-size:small;font-family:Times New Roman;">"Only in the related area of analysis of algorithms this role is taken over by the RAM model"(van Emde Boas 1990:16)</span></p>
<h1 style="margin:auto 0;"><span style="font-family:Times New Roman;"><span style="font-size:26pt;">Moore</span><span style="font-size:26pt;"> machine </span></span></h1>
<p class="MsoNormal" style="text-indent:.5in;margin:0;"><span style="font-family:Times New Roman;"><span style="font-size:small;">In the theory of computation, a </span><strong><span style="font-size:14pt;">Moore</span></strong><strong><span style="font-size:14pt;"> machine</span></strong><span style="font-size:small;"> is a </span></span><a href="http://encyclopedia.thefreedictionary.com/finite+state+automaton"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite state automaton</span></span></a><span style="font-size:small;font-family:Times New Roman;"> where the outputs are determined by the current </span><a href="http://encyclopedia.thefreedictionary.com/state+(computer+science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">state</span></span></a><span style="font-size:small;font-family:Times New Roman;"> alone (and do not depend directly on the input). The </span><a href="http://encyclopedia.thefreedictionary.com/state+diagram"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">state diagram</span></span></a><span style="font-size:small;font-family:Times New Roman;"> for a Moore machine will include an output signal for each state. Compare with a </span><a href="http://encyclopedia.thefreedictionary.com/Mealy+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Mealy machine</span></span></a><span style="font-size:small;font-family:Times New Roman;">, which maps <em><span style="font-style:normal;">transitions</span></em> in the machine to outputs.</p>
<p>The name <em><span style="font-style:normal;">Moore</span></em><em><span style="font-style:normal;"> machine</span></em> comes from that of its promoter, </span><a href="http://encyclopedia.thefreedictionary.com/Edward+F.+Moore"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Edward F. Moore</span></span></a><span style="font-size:small;font-family:Times New Roman;">, a state-machine pioneer who wrote "Gedanken-experiments on Sequential Machines".<sup><a href="http://encyclopedia.thefreedictionary.com/Moore+machine#endnote_rf-1"><span style="color:windowtext;text-decoration:none;">[1]</span></a></sup></p>
<p>Most digital electronic systems are designed as </span><a href="http://encyclopedia.thefreedictionary.com/clocked+sequential+system"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">clocked sequential systems</span></span></a><span style="font-size:small;font-family:Times New Roman;">. Clocked sequential systems are a restricted form of Moore machine where the state changes only when the global clock signal changes. Typically the current state is stored in </span><a href="http://encyclopedia.thefreedictionary.com/Flip-flop+(electronics)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">flip-flops</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and a global clock signal is connected to the "clock" input of the flip-flops. Clocked sequential systems are one way to solve </span><a href="http://encyclopedia.thefreedictionary.com/Metastability+in+electronics"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">metastability</span></span></a><span style="font-size:small;font-family:Times New Roman;"> problems.A typical electronic Moore machine includes a </span><a href="http://encyclopedia.thefreedictionary.com/combinatorial+logic"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">combinatorial logic</span></span></a><span style="font-size:small;font-family:Times New Roman;"> chain to decode the current state into the outputs (lambda). The instant the current state changes, those changes ripple through that chain, and almost instantaneously the outputs change (or don't change). There are design techniques to ensure that no </span><a href="http://encyclopedia.thefreedictionary.com/glitch"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">glitches</span></span></a><span style="font-size:small;font-family:Times New Roman;"> occur on the outputs during that brief period while those changes are rippling through the chain, but most systems are designed so that glitches during that brief transition time are ignored or are irrelevant. The outputs then stay the same indefinitely (</span><a href="http://encyclopedia.thefreedictionary.com/LED"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">LEDs</span></span></a><span style="font-size:small;font-family:Times New Roman;"> stay bright, power stays connected to the motors, </span><a href="http://encyclopedia.thefreedictionary.com/solenoid"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">solenoids</span></span></a><span style="font-size:small;font-family:Times New Roman;"> stay energized, etc.), until the Moore machine changes state again. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Formal definition</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">A Moore machine can be defined as a </span><a href="http://encyclopedia.thefreedictionary.com/N-tuple"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">6-tuple</span></span></a><span style="font-size:small;font-family:Times New Roman;"> { S, <em><span style="font-style:normal;">S</span></em><sub>0</sub>, Σ, Λ, <em><span style="font-style:normal;">T</span></em>, <em><span style="font-style:normal;">G</span></em> } consisting of the following: </span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a finite set of states ( <em><span style="font-style:normal;">S</span></em> ) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a start state (also called initial state) <em><span style="font-style:normal;">S</span></em><sub>0</sub> which is an element of (<em><span style="font-style:normal;">S</span></em>) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a finite set called the input alphabet ( Σ ) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a finite set called the output alphabet ( Λ ) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a transition </span><a href="http://encyclopedia.thefreedictionary.com/function+(mathematics)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">function</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (<em><span style="font-style:normal;">T</span></em> : <em><span style="font-style:normal;">S</span></em> × Σ → <em><span style="font-style:normal;">S</span></em>) mapping a state and an input to the next state </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">an output function (<em><span style="font-style:normal;">G</span></em> : <em><span style="font-style:normal;">S</span></em> → Λ) mapping each state to the output alphabet </span></li>
</ul>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">The number of states in a Moore machine will be greater than or equal to the number of states in the corresponding Mealy machine. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;"> </span></h2>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;"> </span></h2>
<h2 style="margin:12pt 0 3pt;"><span style="font-style:normal;font-family:&quot;"><span style="font-size:large;">Gedanken-experiments</span></span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">In Moore's paper "Gedanken-experiments on Sequential Machines" [1], the <strong>(n;m;p)</strong> automata (or machines) <strong>S</strong> are defined as having <strong>n</strong> states, <strong>m</strong> input symbols and <strong>p</strong> output symbols. Nine theorems are proved about the structure of <strong>S</strong>, and experiments with <strong>S</strong>. Later, <em><strong><span style="font-style:normal;">S</span></strong></em><em><span style="font-style:normal;"> machines</span></em> became known as <em><span style="font-style:normal;">Moore</span></em><em><span style="font-style:normal;"> machines</span></em>.</p>
<p>At the end of the paper, in Section <strong>Further problems</strong>, the following task is stated: <em><span style="font-style:normal;">Another directly following problem is the improvement of the bounds given at the theorems 8 and 9</span></em>.</p>
<p>Moore's <strong>Theorem 8</strong> is formulated as: ''Given an arbitrary <strong>(n;m;p)</strong> machine <strong>S</strong>, such that every two its states are distinguishable from one another. Then there exists an experiment of length </span><strong></strong><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span style="font-style:normal;">which determines the state of <strong>S</strong> at the end of the experiment.</span></em></p>
<p>In 1957 A.A. Karatsuba proved the following two theorems, which completely solved Moore's problem on the improvement of the bounds of the experiment length of his <strong>Theorem 8</strong>.</p>
<p><strong>Theorem <em><span style="font-style:normal;">A</span></em>.</strong> <em><span style="font-style:normal;">If <strong>S</strong> is an <strong>(n;m;p)</strong> machine, such that every two of its states are distinguishable from one another, then there exists a branched experiment of length at most through which one may determine the state of <strong>S</strong> at the end of the experiment.</span></em></p>
<p><strong>Theorem <em><span style="font-style:normal;">B</span></em>.</strong> <em><span style="font-style:normal;">There exists an <strong>(n;m;p)</strong> machine, every two states of which are distinguishable from one another, such that the length of the shortest experiments establishing the state of the machine at the end of the experiment is equal to .</span></em></p>
<p>Theorems <strong>A</strong> and <strong>B</strong> were used for the basis of the course work of a student of the fourth year, A.A. Karatsuba, <strong>"On a problem from the automata theory"</strong> which was distinguished by testimonial reference at the competition of student works of the faculty of mechanics and mathematics of Moscow Lomonosow State University in 1958. The paper by A.A. Karatsuba was given to the Journal Uspekhi Mat. Nauk on 17 December 1958 and was published there in June 1960 <sup><a href="http://encyclopedia.thefreedictionary.com/Moore+machine#endnote_rf-2"><span style="color:windowtext;text-decoration:none;">[2]</span></a></sup> .</p>
<p>Until the present day (2007), Karatsuba's result on the length of experiments is the only exact nonlinear result, both in automata theory, and in similar problems of computational complexity theory.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">Mealy machine</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">In the theory of computation, a <strong>Mealy machine</strong> is a </span><a href="http://encyclopedia.thefreedictionary.com/finite+state+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite state machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (and more accurately, a </span><a href="http://encyclopedia.thefreedictionary.com/finite+state+transducer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">finite state transducer</span></span></a><span style="font-size:small;font-family:Times New Roman;">) that generates an output based on its current state <em><span style="font-style:normal;">and</span></em> an input. This means that the </span><a href="http://encyclopedia.thefreedictionary.com/state+diagram"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">state diagram</span></span></a><span style="font-size:small;font-family:Times New Roman;"> will include both an input and output signal for each transition edge. In contrast, the output of a </span><a href="http://encyclopedia.thefreedictionary.com/Moore+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Moore finite state machine</span></span></a><span style="font-size:small;font-family:Times New Roman;"> depends only on the machine's current state; transitions have no input attached. However, for each Mealy machine there is an equivalent Moore machine whose states are the </span><a href="http://encyclopedia.thefreedictionary.com/Union+(set+theory)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">union</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of the Mealy machine's states and the </span><a href="http://encyclopedia.thefreedictionary.com/Cartesian+product"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Cartesian product</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of the Mealy machine's states and the input alphabet.</p>
<p>The name <em><span style="font-style:normal;">Mealy machine</span></em> comes from that of the concept's promoter, G. H. Mealy, a state-machine pioneer who wrote "A Method for Synthesizing Sequential Circuits" in 1955.<sup><a href="http://encyclopedia.thefreedictionary.com/Mealy+machine#endnote_rf-1"><span style="color:windowtext;text-decoration:none;">[1]</span></a></sup></p>
<p>Mealy machines provide a rudimentary mathematical model for cipher machines. Considering the input and output alphabet the </span><a href="http://encyclopedia.thefreedictionary.com/Latin+alphabet"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Latin alphabet</span></span></a><span style="font-size:small;font-family:Times New Roman;">, for example, then a Mealy machine can be designed that given a string of letters (a sequence of inputs) can process it into a ciphered string (a sequence of outputs). However, although you could probably use a Mealy model to describe </span><a href="http://encyclopedia.thefreedictionary.com/Enigma+machine"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Enigma</span></span></a><span style="font-size:small;font-family:Times New Roman;">, the state diagram would be too complex to provide feasible means of designing complex ciphering machines. </span></p>
<h2 style="margin:12pt 0 3pt;"><span style="font-size:12pt;font-style:normal;font-family:&quot;">Formal definition</span></h2>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;">A Mealy machine is a </span><a href="http://encyclopedia.thefreedictionary.com/n-tuple"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">6-tuple</span></span></a><span style="font-size:small;font-family:Times New Roman;">, (<em><span style="font-style:normal;">S</span></em>, <em><span style="font-style:normal;">S</span></em><sub>0</sub>, Σ, Λ, <em><span style="font-style:normal;">T</span></em>, <em><span style="font-style:normal;">G</span></em>), consisting of the following: </span></p>
<ul type="disc">
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a finite set of states (<em><span style="font-style:normal;">S</span></em>) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a start state (also called initial state) <em><span style="font-style:normal;">S</span></em><sub>0</sub> which is an element of (<em><span style="font-style:normal;">S</span></em>) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a finite set called the input alphabet (Σ) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a finite set called the output alphabet (Λ) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">a transition </span><a href="http://encyclopedia.thefreedictionary.com/function+(mathematics)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">function</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (<em><span style="font-style:normal;">T</span></em> : <em><span style="font-style:normal;">S</span></em> × Σ → <em><span style="font-style:normal;">S</span></em>) </span></li>
<li class="MsoNormal"><span style="font-size:small;font-family:Times New Roman;">an output function (<em><span style="font-style:normal;">G</span></em> : <em><span style="font-style:normal;">S</span></em> × Σ → Λ) </span></li>
</ul>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;font-family:Times New Roman;"> </span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lhen24.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lhen24.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lhen24.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lhen24.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lhen24.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lhen24.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lhen24.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lhen24.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lhen24.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lhen24.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lhen24.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lhen24.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lhen24.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lhen24.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lhen24.wordpress.com&amp;blog=6790546&amp;post=7&amp;subd=lhen24&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lhen24.wordpress.com/2009/03/05/automata-and-language-theory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/80defc718e511753b8b12475b73dbdc4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vluee</media:title>
		</media:content>
	</item>
		<item>
		<title>PROGRAMMING LANGUAGE</title>
		<link>http://lhen24.wordpress.com/2009/03/02/3/</link>
		<comments>http://lhen24.wordpress.com/2009/03/02/3/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 04:23:26 +0000</pubDate>
		<dc:creator>Len-len</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lhen24.wordpress.com/2009/03/02/3/</guid>
		<description><![CDATA[C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system. Although C was designed for writing architecturally independent system software it is also widely used for developing application software. Worldwide, C is the first or second most popular language in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lhen24.wordpress.com&amp;blog=6790546&amp;post=3&amp;subd=lhen24&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-indent:.5in;"><span style="font-size:small;"><span style="font-family:Times New Roman;"><strong><span lang="EN">C</span></strong><span lang="EN"> is a general-purpose computer <a title="Programming language" href="http://en.wikipedia.org/wiki/Programming_language"><span style="color:windowtext;text-decoration:none;">programming language</span></a> originally developed in 1972 by <span style="color:fuchsia;"><a title="Dennis Ritchie" href="http://en.wikipedia.org/wiki/Dennis_Ritchie"><span style="color:fuchsia;text-decoration:none;">Dennis Ritchie</span></a> at the <a title="Bell Telephone Laboratories" href="http://en.wikipedia.org/wiki/Bell_Telephone_Laboratories"><span style="color:fuchsia;text-decoration:none;">Bell Telephone Laboratories</span></a></span> to implement the <a title="Unix" href="http://en.wikipedia.org/wiki/Unix"><span style="color:windowtext;text-decoration:none;">Unix</span></a> <a title="Operating system" href="http://en.wikipedia.org/wiki/Operating_system"><span style="color:windowtext;text-decoration:none;">operating system</span></a>. </span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Although C was designed for writing architecturally independent </span><a title="System software" href="http://en.wikipedia.org/wiki/System_software"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">system software</span></span></a><span style="font-size:small;font-family:Times New Roman;"> it is also widely used for developing </span><a title="Application software" href="http://en.wikipedia.org/wiki/Application_software"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">application software</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Worldwide, C is the first or second most popular language in terms of number of developer positions or publicly available code. It is widely used on many different </span><a title="Software platform" href="http://en.wikipedia.org/wiki/Software_platform"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">software platforms</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and there are few </span><a title="Computer architecture" href="http://en.wikipedia.org/wiki/Computer_architecture"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">computer architectures</span></span></a><span style="font-size:small;font-family:Times New Roman;"> for which a C </span><a title="Compiler" href="http://en.wikipedia.org/wiki/Compiler"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">compiler</span></span></a><span style="font-size:small;font-family:Times New Roman;"> does not exist. C has greatly influenced many other popular programming languages, most notably </span><a title="C++" href="http://en.wikipedia.org/wiki/C%2B%2B"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">C++</span></span></a><span style="font-size:small;font-family:Times New Roman;">, which originally began as an extension to C, and </span><a title="Java (programming language)" href="http://en.wikipedia.org/wiki/Java_(programming_language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Java</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a title="C Sharp (programming language)" href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">C#</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> which borrow C lexical conventions and operators</span></span></span></p>
<h2 style="margin:auto 0;"><span style="font-size:large;"><span style="font-family:Times New Roman;"><span class="mw-headline"><span lang="EN">History</span></span></span></span></h2>
<h3 style="margin:auto 0;"><span style="font-size:medium;"><span style="font-family:Times New Roman;"><span class="mw-headline"><span lang="EN">Early developments</span></span></span></span></h3>
<p style="text-indent:.5in;"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">The initial development of C occurred at </span><a title="AT&amp;T" href="http://en.wikipedia.org/wiki/AT%26T"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">AT&amp;T</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><a title="Bell Labs" href="http://en.wikipedia.org/wiki/Bell_Labs"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Bell Labs</span></span></a><span style="font-size:small;font-family:Times New Roman;"> between 1969 and 1973; according to Ritchie, the most creative period occurred in 1972. It was named &#8220;C&#8221; because many of its features were derived from an earlier language called &#8220;</span><a title="B (programming language)" href="http://en.wikipedia.org/wiki/B_(programming_language)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">B</span></span></a><span style="font-size:small;font-family:Times New Roman;">&#8220;, which according to </span><a title="Ken Thompson (computer programmer)" href="http://en.wikipedia.org/wiki/Ken_Thompson_(computer_programmer)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Ken Thompson</span></span></a><span style="font-size:small;font-family:Times New Roman;"> was a stripped-down version of the </span><a title="BCPL" href="http://en.wikipedia.org/wiki/BCPL"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">BCPL</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> programming language.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">The origin of C is closely tied to the development of the </span><a title="Unix" href="http://en.wikipedia.org/wiki/Unix"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Unix</span></span></a><span style="font-size:small;font-family:Times New Roman;"> operating system, originally implemented in assembly language on a </span><a title="PDP-7" href="http://en.wikipedia.org/wiki/PDP-7"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">PDP-7</span></span></a><span style="font-size:small;font-family:Times New Roman;"> by Ritchie and Thompson, incorporating several ideas from colleagues. Eventually they decided to port the operating system to a </span><a title="PDP-11" href="http://en.wikipedia.org/wiki/PDP-11"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">PDP-11</span></span></a><span style="font-size:small;font-family:Times New Roman;">. B&#8217;s lack of functionality to take advantage of some of the PDP-11&#8242;s features, notably </span><a title="Byte" href="http://en.wikipedia.org/wiki/Byte"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">byte</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> addressability, led to the development of an early version of the C programming language.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">The original PDP-11 version of the Unix system was developed in assembly language. By 1973, with the addition of </span></span><code><span style="font-size:10pt;" lang="EN">struct</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> types, the C language had become powerful enough that most of the </span><a title="Unix" href="http://en.wikipedia.org/wiki/Unix"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Unix</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><a title="Kernel (computers)" href="http://en.wikipedia.org/wiki/Kernel_(computers)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">kernel</span></span></a><span style="font-size:small;font-family:Times New Roman;"> was rewritten in C. This was one of the first operating system kernels implemented in a language other than assembly. (Earlier instances include the </span><a title="Multics" href="http://en.wikipedia.org/wiki/Multics"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Multics</span></span></a><span style="font-size:small;font-family:Times New Roman;"> system (written in </span><a title="PL/I" href="http://en.wikipedia.org/wiki/PL/I"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">PL/I</span></span></a><span style="font-size:small;font-family:Times New Roman;">), and MCP (</span><a title="MCP (Burroughs Large Systems)" href="http://en.wikipedia.org/wiki/MCP_(Burroughs_Large_Systems)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Master Control Program</span></span></a><span style="font-size:small;font-family:Times New Roman;">) for the </span><a title="Burroughs large systems" href="http://en.wikipedia.org/wiki/Burroughs_large_systems"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Burroughs B5000</span></span></a><span style="font-size:small;font-family:Times New Roman;"> written in </span><a title="ALGOL" href="http://en.wikipedia.org/wiki/ALGOL"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ALGOL</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> in 1961.)</span></span></span></p>
<h3 style="margin:auto 0;"><span style="font-size:medium;"><span style="font-family:Times New Roman;"><span class="mw-headline"><span lang="EN">&amp;R C</span></span></span></span></h3>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">In 1978, </span><a title="Brian Kernighan" href="http://en.wikipedia.org/wiki/Brian_Kernighan"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Brian Kernighan</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a title="Dennis Ritchie" href="http://en.wikipedia.org/wiki/Dennis_Ritchie"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Dennis Ritchie</span></span></a><span style="font-size:small;font-family:Times New Roman;"> published the first edition of <em><a title="The C Programming Language (book)" href="http://en.wikipedia.org/wiki/The_C_Programming_Language_(book)"><span style="color:windowtext;text-decoration:none;">The C Programming Language</span></a></em>. This book, known to C programmers as &#8220;K&amp;R&#8221;, served for many years as an informal </span><a title="Specification" href="http://en.wikipedia.org/wiki/Specification"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">specification</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of the language. The version of C that it describes is commonly referred to as &#8220;K&amp;R C&#8221;. The second edition of the book covers the later </span><a title="ANSI C" href="http://en.wikipedia.org/wiki/ANSI_C"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ANSI C</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> standard.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">K&amp;R introduced several language features:</span></span></span></p>
<ul type="disc">
<li class="MsoNormal"><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">standard I/O library </span></span></span></li>
<li class="MsoNormal"><code><span style="font-size:10pt;" lang="EN">long int</span></code><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;"> data type </span></span></span></li>
<li class="MsoNormal"><code><span style="font-size:10pt;" lang="EN">unsigned int</span></code><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;"> data type </span></span></span></li>
<li class="MsoNormal"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">compound assignment operators </span></span><code><span style="font-size:10pt;" lang="EN">=</span></code><span style="font-size:small;"><span style="font-family:Times New Roman;"><em><span lang="EN">op</span></em><span lang="EN"> were changed to <em>op</em></span></span></span><code><span style="font-size:10pt;" lang="EN">=</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> to remove the semantic ambiguity created by the construct </span></span><code><span style="font-size:10pt;" lang="EN">i=-10</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">, which had been interpreted as </span></span><code><span style="font-size:10pt;" lang="EN">i =- 10</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> instead of the possibly intended </span></span><code><span style="font-size:10pt;" lang="EN">i = -10</span></code><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span></span></li>
</ul>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">Even after the publication of the 1989 C standard, for many years K&amp;R C was still considered the &#8220;lowest common denominator&#8221; to which C programmers restricted themselves when maximum portability was desired, since many older compilers were still in use, and because carefully written K&amp;R C code can be legal Standard C as well.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">In early versions of C, only functions that returned a non-integer value needed to be declared if used before the function definition; a function used without any previous declaration was assumed to return an integer, if its value was used.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">For example:</span></span></span></p>
<pre><span lang="EN"><span style="font-size:x-small;">long int SomeFunction();</span></span>
<span lang="EN"><span style="font-size:x-small;">/* int OtherFunction(); */</span></span>
<span lang="EN"><span style="font-size:x-small;"> </span></span>
<span lang="EN"><span style="font-size:x-small;">/* int */ CallingFunction()</span></span>
<span lang="EN"><span style="font-size:x-small;">{</span></span>
<span lang="EN"><span style="font-size:x-small;"><span>    </span>long int test1;</span></span>
<span lang="EN"><span style="font-size:x-small;"><span>    </span>register /* int */ test2;</span></span>
<span lang="EN"><span style="font-size:x-small;"> </span></span>
<span lang="EN"><span style="font-size:x-small;"><span>    </span>test1 = SomeFunction();</span></span>
<span lang="EN"><span style="font-size:x-small;"><span>    </span>if (test1 &gt; 0) </span></span>
<span lang="EN"><span style="font-size:x-small;"><span>          </span>test2 = 0;</span></span>
<span lang="EN"><span style="font-size:x-small;"><span>    </span>else </span></span>
<span lang="EN"><span style="font-size:x-small;"><span>          </span>test2 = OtherFunction();</span></span>
<span lang="EN"><span style="font-size:x-small;"> </span></span>
<span lang="EN"><span style="font-size:x-small;"><span>    </span>return test2;</span></span>
<span lang="EN"><span style="font-size:x-small;">}</span></span></pre>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">All the above commented-out </span></span><code><span style="font-size:10pt;" lang="EN">int</span></code><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;"> declarations could be omitted in K&amp;R C.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Since K&amp;R function declarations did not include any information about function arguments, function parameter </span><a title="Type checking" href="http://en.wikipedia.org/wiki/Type_checking"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">type checks</span></span></a><span style="font-size:small;font-family:Times New Roman;"> were not performed, although some compilers would issue a warning message if a local function was called with the wrong number of arguments, or if multiple calls to an external function used different numbers or types of arguments. Separate tools such as Unix&#8217;s </span><a title="Lint programming tool" href="http://en.wikipedia.org/wiki/Lint_programming_tool"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">lint</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> utility were developed that (among other things) could check for consistency of function use across multiple source files.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">In the years following the publication of K&amp;R C, several unofficial features were added to the language, supported by compilers from AT&amp;T and some other vendors. These included:</span></span></span></p>
<ul type="disc">
<li class="MsoNormal"><code><span style="font-size:10pt;" lang="EN"><a title="Void type" href="http://en.wikipedia.org/wiki/Void_type"><span style="color:windowtext;text-decoration:none;">void</span></a></span></code><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;"> functions </span></span></span></li>
<li class="MsoNormal"><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">functions returning </span></span><code><span style="font-size:10pt;" lang="EN"><a title="Struct" href="http://en.wikipedia.org/wiki/Struct"><span style="color:windowtext;text-decoration:none;">struct</span></a></span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> or </span></span><code><span style="font-size:10pt;" lang="EN"><a title="Union (computer science)" href="http://en.wikipedia.org/wiki/Union_(computer_science)"><span style="color:windowtext;text-decoration:none;">union</span></a></span></code><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;"> types (rather than pointers) </span></span></span></li>
<li class="MsoNormal"><span lang="EN"><a title="Assignment (computer science)" href="http://en.wikipedia.org/wiki/Assignment_(computer_science)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">assignment</span></span></a><span style="font-size:small;font-family:Times New Roman;"> for </span></span><code><span style="font-size:10pt;" lang="EN">struct</span></code><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;"> data types </span></span></span></li>
<li class="MsoNormal"><span lang="EN"><a title="Enumerated type" href="http://en.wikipedia.org/wiki/Enumerated_type"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">enumerated types</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> </span></span></span></li>
</ul>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">The large number of extensions and lack of agreement on a </span><a title="C standard library" href="http://en.wikipedia.org/wiki/C_standard_library"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">standard library</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, together with the language popularity and the fact that not even the Unix compilers precisely implemented the K&amp;R specification, led to the necessity of standardization.</span></span></span></p>
<h3 style="margin:auto 0;"><span style="font-size:medium;"><span style="font-family:Times New Roman;"><span class="mw-headline"><span lang="EN">ANSI C and ISO C</span></span></span></span></h3>
<p class="MsoNormal" style="margin:0;"><em><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Main article: </span><a title="ANSI C" href="http://en.wikipedia.org/wiki/ANSI_C"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ANSI C</span></span></a></span></em></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">During the late 1970s and 1980s, versions of C were implemented for a wide variety of </span><a title="Mainframe computer" href="http://en.wikipedia.org/wiki/Mainframe_computer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">mainframe computers</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a title="Minicomputer" href="http://en.wikipedia.org/wiki/Minicomputer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">minicomputers</span></span></a><span style="font-size:small;font-family:Times New Roman;">, and </span><a title="Microcomputer" href="http://en.wikipedia.org/wiki/Microcomputer"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">microcomputers</span></span></a><span style="font-size:small;font-family:Times New Roman;">, including the </span><a title="IBM PC" href="http://en.wikipedia.org/wiki/IBM_PC"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">IBM PC</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, as its popularity began to increase significantly.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">In 1983, the </span><a title="American National Standards Institute" href="http://en.wikipedia.org/wiki/American_National_Standards_Institute"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">American National Standards Institute</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (ANSI) formed a committee, X3J11, to establish a standard specification of C. In 1989, the standard was ratified as ANSI X3.159-1989 &#8220;Programming Language C.&#8221; This version of the language is often referred to as </span><a title="ANSI C" href="http://en.wikipedia.org/wiki/ANSI_C"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ANSI C</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, Standard C, or sometimes C89.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">In 1990, the ANSI C standard (with formatting changes) was adopted by the </span><a title="International Organization for Standardization" href="http://en.wikipedia.org/wiki/International_Organization_for_Standardization"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">International Organization for Standardization</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> (ISO) as ISO/IEC 9899:1990, which is sometimes called C90. Therefore, the terms &#8220;C89&#8243; and &#8220;C90&#8243; refer to the same programming language.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">ANSI, like other national standards bodies, no longer develops the C standard independently, but defers to the ISO C standard. National adoption of updates to the international standard typically occurs within a year of ISO publication.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">One of the aims of the C standardization process was to produce a </span><a title="Superset" href="http://en.wikipedia.org/wiki/Superset"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">superset</span></span></a><span style="font-size:small;font-family:Times New Roman;"> of K&amp;R C, incorporating many of the unofficial features subsequently introduced. The standards committee also included several additional features such as </span><a title="Function prototype" href="http://en.wikipedia.org/wiki/Function_prototype"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">function prototypes</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (borrowed from C++), </span></span><code><span style="font-size:10pt;" lang="EN">void</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> pointers, support for international </span><a title="Character encoding" href="http://en.wikipedia.org/wiki/Character_encoding"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">character sets</span></span></a><span style="font-size:small;font-family:Times New Roman;"> and </span><a title="Locale" href="http://en.wikipedia.org/wiki/Locale"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">locales</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">, and preprocessor enhancements. The syntax for parameter declarations was also augmented to include the style used in C++, although the K&amp;R interface continued to be permitted, for compatibility with existing source code.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">C89 is supported by current C compilers, and most C code being written nowadays is based on it. Any program written only in Standard C and without any hardware-dependent assumptions will run correctly on any </span><a title="System platform" href="http://en.wikipedia.org/wiki/System_platform"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">platform</span></span></a><span style="font-size:small;font-family:Times New Roman;"> with a conforming C implementation, within its resource limits. Without such precautions, programs may compile only on a certain platform or with a particular compiler, due, for example, to the use of non-standard libraries, such as </span><a title="Graphical user interface" href="http://en.wikipedia.org/wiki/Graphical_user_interface"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">GUI</span></span></a><span style="font-size:small;font-family:Times New Roman;"> libraries, or to a reliance on compiler- or platform-specific attributes such as the exact size of data types and byte </span><a title="Endianness" href="http://en.wikipedia.org/wiki/Endianness"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">endianness</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">In cases where code must be compilable by either standard-conforming or K&amp;R C-based compilers, the </span></span><code><span style="font-size:10pt;" lang="EN">__STDC__</span></code><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;"> macro can be used to split the code into Standard and K&amp;R sections to take advantage of features available only in Standard C.</span></span></span></p>
<h3 style="margin:auto 0;"><span style="font-size:medium;"><span style="font-family:Times New Roman;"><span class="mw-headline"><span lang="EN">C99</span></span></span></span></h3>
<p class="MsoNormal" style="margin:0;"><em><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">Main article: </span><a title="C99" href="http://en.wikipedia.org/wiki/C99"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">C99</span></span></a></span></em></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">After the ANSI/ISO standardization process, the C language specification remained relatively static for some time, whereas </span><a title="C++" href="http://en.wikipedia.org/wiki/C%2B%2B"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">C++</span></span></a><span style="font-size:small;font-family:Times New Roman;"> continued to evolve, largely during its own standardization effort. In 1995 Normative Amendment 1 to the 1990 C standard was published, to correct some details and to add more extensive support for international character sets. The C standard was further revised in the late 1990s, leading to the publication of ISO/IEC 9899:1999 in 1999, which is commonly referred to as &#8220;</span><a title="C99" href="http://en.wikipedia.org/wiki/C99"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">C99</span></span></a><span style="font-size:small;font-family:Times New Roman;">.&#8221; It has since been amended three times by Technical Corrigenda. The international C standard is maintained by the </span><a title="Working group" href="http://en.wikipedia.org/wiki/Working_group"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">working group</span></span></a><span style="font-size:small;font-family:Times New Roman;"> </span><a title="SC22" href="http://en.wikipedia.org/wiki/SC22"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">ISO/IEC JTC1/SC22</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;">/WG14.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">C99 introduced several new features, including </span><a title="Inline function" href="http://en.wikipedia.org/wiki/Inline_function"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">inline functions</span></span></a><span style="font-size:small;font-family:Times New Roman;">, several new </span><a title="Data type" href="http://en.wikipedia.org/wiki/Data_type"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">data types</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (including </span></span><code><span style="font-size:10pt;" lang="EN">long long int</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> and a </span></span><code><span style="font-size:10pt;" lang="EN">complex</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> type to represent </span><a title="Complex number" href="http://en.wikipedia.org/wiki/Complex_number"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">complex numbers</span></span></a><span style="font-size:small;font-family:Times New Roman;">), </span><a title="Variable-length array" href="http://en.wikipedia.org/wiki/Variable-length_array"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">variable-length arrays</span></span></a><span style="font-size:small;font-family:Times New Roman;">, support for </span><a title="Variadic macro" href="http://en.wikipedia.org/wiki/Variadic_macro"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">variadic macros</span></span></a><span style="font-size:small;font-family:Times New Roman;"> (macros of variable </span><a title="Arity" href="http://en.wikipedia.org/wiki/Arity"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">arity</span></span></a><span style="font-size:small;font-family:Times New Roman;">) and support for one-line comments beginning with </span></span><code><span style="font-size:10pt;" lang="EN">//</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">, as in </span><a title="BCPL" href="http://en.wikipedia.org/wiki/BCPL"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">BCPL</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> or C++. Many of these had already been implemented as extensions in several C compilers.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;font-family:Times New Roman;">C99 is for the most part backward compatible with C90, but is stricter in some ways; in particular, a declaration that lacks a type specifier no longer has </span></span><code><span style="font-size:10pt;" lang="EN">int</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> implicitly assumed. A standard macro </span></span><code><span style="font-size:10pt;" lang="EN">__STDC_VERSION__</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> is defined with value </span></span><code><span style="font-size:10pt;" lang="EN">199901L</span></code><span lang="EN"><span style="font-size:small;font-family:Times New Roman;"> to indicate that C99 support is available. </span><a title="GNU Compiler Collection" href="http://en.wikipedia.org/wiki/GNU_Compiler_Collection"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">GCC</span></span></a><span style="font-size:small;font-family:Times New Roman;">, </span><a title="Sun Studio (software)" href="http://en.wikipedia.org/wiki/Sun_Studio_(software)"><span style="color:windowtext;text-decoration:none;"><span style="font-size:small;font-family:Times New Roman;">Sun Studio</span></span></a><span style="font-size:small;"><span style="font-family:Times New Roman;"> and other C compilers now support many or all of the new features of C99.</span></span></span></p>
<p><span lang="EN"><span style="font-size:small;"><span style="font-family:Times New Roman;">As of 2007, work has begun in anticipation of another revision of the C standard, informally called &#8220;C1<em>x</em>&#8220;. The C standards committee has adopted guidelines to limit the adoption of new features that have not been tested by existing implementations.</span></span></span></p>
<p><span style="font-size:small;font-family:Times New Roman;"></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:14pt;font-family:&quot;">IMPORTANCE</span></p>
<p><span lang="EN">Like most imperative languages in the <a title="ALGOL" href="http://en.wikipedia.org/wiki/ALGOL"><span style="color:windowtext;text-decoration:none;">ALGOL</span></a> tradition, C has facilities for <a title="Structured programming" href="http://en.wikipedia.org/wiki/Structured_programming"><span style="color:windowtext;text-decoration:none;">structured programming</span></a> and allows <a title="Scope (programming)" href="http://en.wikipedia.org/wiki/Scope_(programming)"><span style="color:windowtext;text-decoration:none;">lexical variable scope</span></a> and <a title="Recursion" href="http://en.wikipedia.org/wiki/Recursion"><span style="color:windowtext;text-decoration:none;">recursion</span></a>, while a static <a title="Type system" href="http://en.wikipedia.org/wiki/Type_system"><span style="color:windowtext;text-decoration:none;">type system</span></a> prevents many unintended operations. In C, all executable code is contained within <a title="Subroutine" href="http://en.wikipedia.org/wiki/Subroutine"><span style="color:windowtext;text-decoration:none;">functions</span></a>. Function <a title="Parameter (computer science)" href="http://en.wikipedia.org/wiki/Parameter_(computer_science)"><span style="color:windowtext;text-decoration:none;">parameters</span></a> are always passed by value. Pass-by-reference is achieved in C by explicitly passing <a title="Pointer (computing)" href="http://en.wikipedia.org/wiki/Pointer_(computing)"><span style="color:windowtext;text-decoration:none;">pointer</span></a> values. Heterogeneous aggregate data types (</span><code><span style="font-size:10pt;" lang="EN"><a title="Struct" href="http://en.wikipedia.org/wiki/Struct"><span style="color:windowtext;text-decoration:none;">struct</span></a></span></code><span lang="EN">) allow related data elements to be combined and manipulated as a unit. C program source text is free-format, using the semicolon as a statement terminator (not a delimiter).</span></p>
<p><span lang="EN">C also exhibits the following more specific characteristics:</span></p>
<ul type="disc">
<li class="MsoNormal"><span lang="EN">non-nestable function definitions </span></li>
<li class="MsoNormal"><span lang="EN">variables may be hidden in nested blocks </span></li>
<li class="MsoNormal"><span lang="EN">partially <a title="Weak typing" href="http://en.wikipedia.org/wiki/Weak_typing"><span style="color:windowtext;text-decoration:none;">weak typing</span></a>; for instance, characters can be used as integers </span></li>
<li class="MsoNormal"><span lang="EN">low-level access to <a title="Computer memory" href="http://en.wikipedia.org/wiki/Computer_memory"><span style="color:windowtext;text-decoration:none;">computer memory</span></a> by converting machine addresses to typed <a title="Pointer (computing)" href="http://en.wikipedia.org/wiki/Pointer_(computing)"><span style="color:windowtext;text-decoration:none;">pointers</span></a> </span></li>
<li class="MsoNormal"><span lang="EN">function and data pointers supporting <em>ad hoc</em> <a title="Type polymorphism" href="http://en.wikipedia.org/wiki/Type_polymorphism"><span style="color:windowtext;text-decoration:none;">run-time polymorphism</span></a> </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Array" href="http://en.wikipedia.org/wiki/Array"><span style="color:windowtext;text-decoration:none;">array</span></a> indexing as a secondary notion, defined in terms of pointer arithmetic </span></li>
<li class="MsoNormal"><span lang="EN">a <a title="C preprocessor" href="http://en.wikipedia.org/wiki/C_preprocessor"><span style="color:windowtext;text-decoration:none;">preprocessor</span></a> for <a title="Macro (computer science)" href="http://en.wikipedia.org/wiki/Macro_(computer_science)"><span style="color:windowtext;text-decoration:none;">macro</span></a> definition, <a title="Source code" href="http://en.wikipedia.org/wiki/Source_code"><span style="color:windowtext;text-decoration:none;">source code</span></a> file inclusion, and conditional compilation </span></li>
<li class="MsoNormal"><span lang="EN">complex functionality such as <a title="Input/output" href="http://en.wikipedia.org/wiki/Input/output"><span style="color:windowtext;text-decoration:none;">I/O</span></a>, <a title="String (computer science)" href="http://en.wikipedia.org/wiki/String_(computer_science)"><span style="color:windowtext;text-decoration:none;">string</span></a> manipulation, and mathematical functions consistently delegated to <a title="Library (computer science)" href="http://en.wikipedia.org/wiki/Library_(computer_science)"><span style="color:windowtext;text-decoration:none;">library routines</span></a> </span></li>
<li class="MsoNormal"><span lang="EN">A relatively small set of reserved <a title="Keyword (computer programming)" href="http://en.wikipedia.org/wiki/Keyword_(computer_programming)"><span style="color:windowtext;text-decoration:none;">keywords</span></a> (originally 32, now 37 in C99) </span></li>
<li class="MsoNormal"><span lang="EN">A lexical structure that resembles <a title="B (programming language)" href="http://en.wikipedia.org/wiki/B_(programming_language)"><span style="color:windowtext;text-decoration:none;">B</span></a> more than <a title="ALGOL" href="http://en.wikipedia.org/wiki/ALGOL"><span style="color:windowtext;text-decoration:none;">ALGOL</span></a>, for example </span>
<ul type="circle">
<li class="MsoNormal"><code><span style="font-size:10pt;" lang="EN">{ ... }</span></code><span lang="EN"> rather than <a title="ALGOL" href="http://en.wikipedia.org/wiki/ALGOL"><span style="color:windowtext;text-decoration:none;">ALGOL</span></a>&#8216;s </span><code><span style="font-size:10pt;" lang="EN">begin ... end</span></code><span lang="EN"> </span></li>
<li class="MsoNormal"><span lang="EN">the equal-sign is for assignment (copying), much like <a title="Fortran" href="http://en.wikipedia.org/wiki/Fortran"><span style="color:windowtext;text-decoration:none;">Fortran</span></a> </span></li>
<li class="MsoNormal"><span lang="EN">two consecutive equal-signs are to test for equality (compare to </span><code><span style="font-size:10pt;" lang="EN">.EQ.</span></code><span lang="EN"> in <a title="Fortran" href="http://en.wikipedia.org/wiki/Fortran"><span style="color:windowtext;text-decoration:none;">Fortran</span></a> or the equal-sign in <a title="BASIC" href="http://en.wikipedia.org/wiki/BASIC"><span style="color:windowtext;text-decoration:none;">BASIC</span></a>) </span></li>
<li class="MsoNormal"><code><span style="font-size:10pt;" lang="EN">&amp;&amp;</span></code><span lang="EN"> and </span><code><span style="font-size:10pt;" lang="EN">||</span></code><span lang="EN"> in place of <a title="ALGOL" href="http://en.wikipedia.org/wiki/ALGOL"><span style="color:windowtext;text-decoration:none;">ALGOL</span></a>&#8216;s </span><code><span style="font-size:10pt;" lang="EN">and</span></code><span lang="EN"> and </span><code><span style="font-size:10pt;" lang="EN">or</span></code><span lang="EN"> (these are semantically distinct from the <a title="Bitwise operation" href="http://en.wikipedia.org/wiki/Bitwise_operation"><span style="color:windowtext;text-decoration:none;">bit-wise</span></a> operators </span><code><span style="font-size:10pt;" lang="EN">&amp;</span></code><span lang="EN"> and </span><code><span style="font-size:10pt;" lang="EN">|</span></code><span lang="EN"> because they will never evaluate the right operand if the result can be determined from the left alone (<a title="Short-circuit evaluation" href="http://en.wikipedia.org/wiki/Short-circuit_evaluation"><span style="color:windowtext;text-decoration:none;">short-circuit evaluation</span></a>)). </span></li>
<li class="MsoNormal"><span lang="EN">a large number of compound operators, such as </span><code><span style="font-size:10pt;" lang="EN">+=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">++</span></code><span lang="EN">, &#8230;&#8230; </span></li>
</ul>
</li>
</ul>
<h3 style="margin:auto 0;"><a id="Absent_features" name="Absent_features"></a><span style="font-size:medium;"><span class="mw-headline"><span lang="EN">Absent features</span></span><span lang="EN"></span></span></h3>
<p><span lang="EN">The relatively low-level nature of the language affords the programmer close control over what the computer does, while allowing special tailoring and aggressive optimization for a particular platform. This allows the code to run efficiently on very limited hardware, such as <a title="Embedded systems" href="http://en.wikipedia.org/wiki/Embedded_systems"><span style="color:windowtext;text-decoration:none;">embedded systems</span></a>.</span></p>
<p><span lang="EN">C does not have some features that are available in some other programming languages:</span></p>
<ul type="disc">
<li class="MsoNormal"><span lang="EN">No assignment of arrays or strings (copying can be done via standard functions; assignment of objects having </span><code><span style="font-size:10pt;" lang="EN">struct</span></code><span lang="EN"> or </span><code><span style="font-size:10pt;" lang="EN">union</span></code><span lang="EN"> type is supported) </span></li>
<li class="MsoNormal"><span lang="EN">No <a title="Garbage collection (computer science)" href="http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)"><span style="color:windowtext;text-decoration:none;">automatic garbage collection</span></a> </span></li>
<li class="MsoNormal"><span lang="EN">No requirement for <a title="Bounds checking" href="http://en.wikipedia.org/wiki/Bounds_checking"><span style="color:windowtext;text-decoration:none;">bounds checking</span></a> of arrays </span></li>
<li class="MsoNormal"><span lang="EN">No <a title="Array programming" href="http://en.wikipedia.org/wiki/Array_programming"><span style="color:windowtext;text-decoration:none;">operations on whole arrays</span></a> </span></li>
<li class="MsoNormal"><span lang="EN">No syntax for <a title="Range (computer science)" href="http://en.wikipedia.org/wiki/Range_(computer_science)"><span style="color:windowtext;text-decoration:none;">ranges</span></a>, such as the </span><code><span style="font-size:10pt;" lang="EN">A..B</span></code><span lang="EN"> notation used in several languages </span></li>
<li class="MsoNormal"><span lang="EN">No separate <a title="Boolean datatype" href="http://en.wikipedia.org/wiki/Boolean_datatype"><span style="color:windowtext;text-decoration:none;">Boolean type</span></a>: zero/nonzero is used instead<sup><a href="http://en.wikipedia.org/wiki/C_(programming_language)#cite_note-5#cite_note-5"><span style="color:windowtext;text-decoration:none;">[6]</span></a></sup> </span></li>
<li class="MsoNormal"><span lang="EN">No formal <a title="Closure (computer science)" href="http://en.wikipedia.org/wiki/Closure_(computer_science)"><span style="color:windowtext;text-decoration:none;">closures</span></a> or functions as parameters (only function and variable pointers) </span></li>
<li class="MsoNormal"><span lang="EN">No <a title="Generator (computer science)" href="http://en.wikipedia.org/wiki/Generator_(computer_science)"><span style="color:windowtext;text-decoration:none;">generators</span></a> or <a title="Coroutine" href="http://en.wikipedia.org/wiki/Coroutine"><span style="color:windowtext;text-decoration:none;">coroutines</span></a>; intra-thread control flow consists of nested function calls, except for the use of the <a title="Longjmp" href="http://en.wikipedia.org/wiki/Longjmp"><span style="color:windowtext;text-decoration:none;">longjmp</span></a> or <a title="Setcontext" href="http://en.wikipedia.org/wiki/Setcontext"><span style="color:windowtext;text-decoration:none;">setcontext</span></a> library functions </span></li>
<li class="MsoNormal"><span lang="EN">No <a title="Exception handling" href="http://en.wikipedia.org/wiki/Exception_handling"><span style="color:windowtext;text-decoration:none;">exception handling</span></a>; standard library functions signify error conditions with the global </span><code><span style="font-size:10pt;" lang="EN"><a title="Errno" href="http://en.wikipedia.org/wiki/Errno"><span style="color:windowtext;text-decoration:none;">errno</span></a></span></code><span lang="EN"> variable and/or special return values </span></li>
<li class="MsoNormal"><span lang="EN">Only rudimentary support for modular programming </span></li>
<li class="MsoNormal"><span lang="EN">No compile-time polymorphism in the form of <a title="Function (computer science)" href="http://en.wikipedia.org/wiki/Function_(computer_science)"><span style="color:windowtext;text-decoration:none;">function</span></a> or <a title="Operator" href="http://en.wikipedia.org/wiki/Operator"><span style="color:windowtext;text-decoration:none;">operator</span></a> <a title="Method overloading" href="http://en.wikipedia.org/wiki/Method_overloading"><span style="color:windowtext;text-decoration:none;">overloading</span></a> </span></li>
<li class="MsoNormal"><span lang="EN">Only rudimentary support for <a title="Generic programming" href="http://en.wikipedia.org/wiki/Generic_programming"><span style="color:windowtext;text-decoration:none;">generic programming</span></a> </span></li>
<li class="MsoNormal"><span lang="EN">Very limited support for <a title="Object-oriented programming" href="http://en.wikipedia.org/wiki/Object-oriented_programming"><span style="color:windowtext;text-decoration:none;">object-oriented programming</span></a> with regard to <a title="Polymorphism in object-oriented programming" href="http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming"><span style="color:windowtext;text-decoration:none;">polymorphism</span></a> and <a title="Inheritance (computer science)" href="http://en.wikipedia.org/wiki/Inheritance_(computer_science)"><span style="color:windowtext;text-decoration:none;">inheritance</span></a> </span></li>
<li class="MsoNormal"><span lang="EN">Limited support for <a title="Information hiding" href="http://en.wikipedia.org/wiki/Information_hiding"><span style="color:windowtext;text-decoration:none;">encapsulation</span></a> </span></li>
<li class="MsoNormal"><span lang="EN">No native support for <a title="Multithreading" href="http://en.wikipedia.org/wiki/Multithreading"><span style="color:windowtext;text-decoration:none;">multithreading</span></a> and <a title="Computer networks" href="http://en.wikipedia.org/wiki/Computer_networks"><span style="color:windowtext;text-decoration:none;">networking</span></a> </span></li>
<li class="MsoNormal"><span lang="EN">No standard libraries for <a title="Computer graphics" href="http://en.wikipedia.org/wiki/Computer_graphics"><span style="color:windowtext;text-decoration:none;">computer graphics</span></a> and several other application programming needs </span></li>
</ul>
<p><span lang="EN">A number of these features are available as extensions in some compilers, or can be supplied by third-party libraries, or can be simulated by adopting certain coding disciplines.</span></p>
<h3 style="margin:auto 0;"><a id="Undefined_behavior" name="Undefined_behavior"></a><span style="font-size:medium;"><span class="mw-headline"><span lang="EN">Undefined behavior</span></span><span lang="EN"></span></span></h3>
<p><span lang="EN">Many operations in C that have <a title="Undefined behavior" href="http://en.wikipedia.org/wiki/Undefined_behavior"><span style="color:windowtext;text-decoration:none;">undefined behavior</span></a> are not required to be diagnosed at <a title="Compile time" href="http://en.wikipedia.org/wiki/Compile_time"><span style="color:windowtext;text-decoration:none;">compile time</span></a>. In the case of C, &#8220;undefined behavior&#8221; means that the exact behavior which arises is not specified by the standard, and exactly what will happen does not have to be documented by the C implementation. A famous, although misleading, expression in the <a title="Newsgroup" href="http://en.wikipedia.org/wiki/Newsgroup"><span style="color:windowtext;text-decoration:none;">newsgroups</span></a> <a title="news:comp.std.c" href="news:comp.std.c"><span style="color:windowtext;text-decoration:none;">comp.std.c</span></a> and <a title="news:comp.lang.c" href="news:comp.lang.c"><span style="color:windowtext;text-decoration:none;">comp.lang.c</span></a> is that the program could cause &#8220;demons to fly out of your nose&#8221;.<sup><a href="http://en.wikipedia.org/wiki/C_(programming_language)#cite_note-6#cite_note-6"><span style="color:windowtext;text-decoration:none;">[7]</span></a></sup> Sometimes in practice what happens for an instance of undefined behavior is a <a title="Software bug" href="http://en.wikipedia.org/wiki/Software_bug"><span style="color:windowtext;text-decoration:none;">bug</span></a> that is hard to track down and which may corrupt the contents of memory. Sometimes a particular compiler generates reasonable and well-behaved actions that are completely different from those that would be obtained using a different C compiler. The reason some behavior has been left undefined is to allow compilers for a wide variety of <a title="Instruction set" href="http://en.wikipedia.org/wiki/Instruction_set"><span style="color:windowtext;text-decoration:none;">instruction set</span></a> architectures to generate more efficient executable code for well-defined behavior, which was deemed important for C&#8217;s primary role as a systems implementation language; thus C makes it the programmer&#8217;s responsibility to avoid undefined behavior. Examples of undefined behavior are:</span></p>
<ul type="disc">
<li class="MsoNormal"><span lang="EN">accessing outside the bounds of an array </span></li>
<li class="MsoNormal"><span lang="EN">overflowing a signed integer </span></li>
<li class="MsoNormal"><span lang="EN">reaching the end of a non-void function without finding a return statement, when the return value is used </span></li>
<li class="MsoNormal"><span lang="EN">reading the value of a variable before initializing it </span></li>
</ul>
<p><span lang="EN">These operations are all programming errors that could occur using many programming languages; C draws criticism because its standard explicitly identifies numerous cases of undefined behavior, including some where the behavior could have been made well defined, and does not specify any run-time error handling mechanism.</span></p>
<p><span lang="EN">Invoking </span><code><span style="font-size:10pt;" lang="EN"><a title="Fflush" href="http://en.wikipedia.org/wiki/Fflush"><span style="color:windowtext;text-decoration:none;">fflush</span></a>()</span></code><span lang="EN"> on a stream opened for input is an example of a different kind of undefined behavior, not necessarily a programming error but a case for which some conforming implementations may provide well-defined, useful semantics (in this example, presumably discarding input through the next new-line) as an allowed <em>extension</em>. Use of such nonstandard extensions generally limits <a title="Software portability" href="http://en.wikipedia.org/wiki/Software_portability"><span style="color:windowtext;text-decoration:none;">software portability</span></a></span></p>
<p></span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"> </p>
<h2 style="margin:auto 0;"><span class="mw-headline"><span lang="EN">Uses</span></span><span lang="EN"></span></h2>
<p style="text-indent:.5in;"><span lang="EN">C&#8217;s primary use is for &#8220;<a title="System programming" href="http://en.wikipedia.org/wiki/System_programming"><span style="color:windowtext;text-decoration:none;">system programming</span></a>&#8220;, including implementing <a title="Operating system" href="http://en.wikipedia.org/wiki/Operating_system"><span style="color:windowtext;text-decoration:none;">operating systems</span></a> and <a title="Embedded system" href="http://en.wikipedia.org/wiki/Embedded_system"><span style="color:windowtext;text-decoration:none;">embedded system</span></a> applications, due to a combination of desirable characteristics such as code portability and efficiency, ability to access specific hardware addresses, ability to <a title="Type punning" href="http://en.wikipedia.org/wiki/Type_punning"><span style="color:windowtext;text-decoration:none;">&#8220;pun&#8221;</span></a> types to match externally imposed data access requirements, and low <a title="Runtime" href="http://en.wikipedia.org/wiki/Runtime"><span style="color:windowtext;text-decoration:none;">runtime</span></a> demand on system resources.</span></p>
<p><span lang="EN">One consequence of C&#8217;s wide acceptance and efficiency is that C is used for other programs that are not directly used by end-users (compilers, libraries, interpreters, etc).</span></p>
<p><span lang="EN">C is sometimes used as an <a title="Intermediate language" href="http://en.wikipedia.org/wiki/Intermediate_language"><span style="color:windowtext;text-decoration:none;">intermediate language</span></a> by implementations of other languages. This approach may be used for convenience (by using C as an intermediate language, it is not necessary to develop machine-specific code generators; ). Some compilers which use C this way are <a title="BitC" href="http://en.wikipedia.org/wiki/BitC"><span style="color:windowtext;text-decoration:none;">BitCC</span></a>, <a title="Gambit (Scheme implementation)" href="http://en.wikipedia.org/wiki/Gambit_(Scheme_implementation)"><span style="color:windowtext;text-decoration:none;">Gambit</span></a>, the <a title="Glasgow Haskell Compiler" href="http://en.wikipedia.org/wiki/Glasgow_Haskell_Compiler"><span style="color:windowtext;text-decoration:none;">Glasgow Haskell Compiler</span></a>, <a title="Squeak" href="http://en.wikipedia.org/wiki/Squeak"><span style="color:windowtext;text-decoration:none;">Squeak</span></a>, and <a title="Vala (programming language)" href="http://en.wikipedia.org/wiki/Vala_(programming_language)"><span style="color:windowtext;text-decoration:none;">valac</span></a>.</span></p>
<p><span lang="EN">Unfortunately, C was designed as a programming language, not as a compiler target language, and is thus less than ideal for use as an intermediate language. This has led to development of C-based intermediate languages such as <a title="C--" href="http://en.wikipedia.org/wiki/C--"><span style="color:windowtext;text-decoration:none;">C&#8211;</span></a>.</span></p>
<p><span lang="EN">C has also been widely used to implement <a title="End-user (computer science)" href="http://en.wikipedia.org/wiki/End-user_(computer_science)"><span style="color:windowtext;text-decoration:none;">end-user</span></a> applications. Although as applications became larger, much of that development shifted to other languages.</span></p>
<h2 style="margin:auto 0;"><a id="Syntax" name="Syntax"></a><span class="mw-headline"><span lang="EN">Syntax</span></span><span lang="EN"></span></h2>
<p style="text-indent:.5in;"><span lang="EN">Unlike languages such as <a title="FORTRAN 77" href="http://en.wikipedia.org/wiki/FORTRAN_77"><span style="color:windowtext;text-decoration:none;">FORTRAN 77</span></a>, C source code is <a title="Free-form language" href="http://en.wikipedia.org/wiki/Free-form_language"><span style="color:windowtext;text-decoration:none;">free-form</span></a> which allows arbitrary use of whitespace to format code, rather than column-based or text-line-based restrictions. Comments may appear either between the delimiters </span><code><span style="font-size:10pt;" lang="EN">/*</span></code><span lang="EN"> and </span><code><span style="font-size:10pt;" lang="EN">*/</span></code><span lang="EN">, or (in C99) following </span><code><span style="font-size:10pt;" lang="EN">//</span></code><span lang="EN"> until the end of the line.</span></p>
<p><span lang="EN">Each source file contains declarations and function definitions. Function definitions, in turn, contain declarations and statements. Declarations either define new types using keywords such as </span><code><span style="font-size:10pt;" lang="EN">struct</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">union</span></code><span lang="EN">, and </span><code><span style="font-size:10pt;" lang="EN">enum</span></code><span lang="EN">, or assign types to and perhaps reserve storage for new variables, usually by writing the type followed by the variable name. Keywords such as </span><code><span style="font-size:10pt;" lang="EN">char</span></code><span lang="EN"> and </span><code><span style="font-size:10pt;" lang="EN">int</span></code><span lang="EN"> specify built-in types. Sections of code are enclosed in braces (</span><code><span style="font-size:10pt;" lang="EN">{</span></code><span lang="EN"> and </span><code><span style="font-size:10pt;" lang="EN">}</span></code><span lang="EN">, sometimes called &#8220;curly brackets&#8221;) to limit the scope of declarations and to act as a single statement for control structures.</span></p>
<p><span lang="EN">As an imperative language, C uses <em>statements</em> to specify actions. The most common statement is an <em>expression statement</em>, consisting of an expression to be evaluated, followed by a semicolon; as a side effect of the evaluation, functions may be <a title="Procedure call" href="http://en.wikipedia.org/wiki/Procedure_call"><span style="color:windowtext;text-decoration:none;">called</span></a> and variables may be <a title="Assignment (computer science)" href="http://en.wikipedia.org/wiki/Assignment_(computer_science)"><span style="color:windowtext;text-decoration:none;">assigned</span></a> new values. To modify the normal sequential execution of statements, C provides several control-flow statements identified by reserved keywords. <a title="Structured programming" href="http://en.wikipedia.org/wiki/Structured_programming"><span style="color:windowtext;text-decoration:none;">Structured programming</span></a> is supported by </span><code><span style="font-size:10pt;" lang="EN">if</span></code><span lang="EN">(-</span><code><span style="font-size:10pt;" lang="EN">else</span></code><span lang="EN">) conditional execution and by </span><code><span style="font-size:10pt;" lang="EN">do</span></code><span lang="EN">-</span><code><span style="font-size:10pt;" lang="EN">while</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">while</span></code><span lang="EN">, and </span><code><span style="font-size:10pt;" lang="EN">for</span></code><span lang="EN"> iterative execution (looping). The </span><code><span style="font-size:10pt;" lang="EN">for</span></code><span lang="EN"> statement has separate initialization, testing, and reinitialization expressions, any or all of which can be omitted. </span><code><span style="font-size:10pt;" lang="EN">break</span></code><span lang="EN"> and </span><code><span style="font-size:10pt;" lang="EN">continue</span></code><span lang="EN"> can be used to leave the innermost enclosing loop statement or skip to its reinitialization. There is also a non-structured </span><code><span style="font-size:10pt;" lang="EN"><a title="Goto" href="http://en.wikipedia.org/wiki/Goto"><span style="color:windowtext;text-decoration:none;">goto</span></a></span></code><span lang="EN"> statement which branches directly to the designated <a title="Label (programming language)" href="http://en.wikipedia.org/wiki/Label_(programming_language)"><span style="color:windowtext;text-decoration:none;">label</span></a> within the function. </span><code><span style="font-size:10pt;" lang="EN">switch</span></code><span lang="EN"> selects a </span><code><span style="font-size:10pt;" lang="EN">case</span></code><span lang="EN"> to be executed based on the value of an integer expression.</span></p>
<p><span lang="EN">Expressions can use a variety of built-in operators (see below) and may contain function calls. The order in which operands to most operators, as well as the arguments to functions, are evaluated is unspecified; the evaluations may even be interleaved. However, all side effects (including storage to variables) will occur before the next &#8220;<a title="Sequence point" href="http://en.wikipedia.org/wiki/Sequence_point"><span style="color:windowtext;text-decoration:none;">sequence point</span></a>&#8220;; sequence points include the end of each expression statement and the entry to and return from each function call. This permits a high degree of object code optimization by the compiler, but requires C programmers to exert more care to obtain reliable results than is needed for other programming languages.</span></p>
<p><span lang="EN">Although mimicked by many languages because of its widespread familiarity, C&#8217;s syntax has often been criticized. For example, Kernighan and Ritchie say in the second edition of <em>The C Programming Language</em>, &#8220;C, like any other language, has its blemishes. Some of the operators have the wrong precedence; some parts of the syntax could be better.&#8221;</span></p>
<p><span lang="EN">Some specific problems worth noting are:</span></p>
<ul type="disc">
<li class="MsoNormal"><span lang="EN">Not checking number and types of arguments when the function declaration has an empty parameter list. (This provides <a title="Backward compatibility" href="http://en.wikipedia.org/wiki/Backward_compatibility"><span style="color:windowtext;text-decoration:none;">backward compatibility</span></a> with <a title="The C Programming Language (book)" href="http://en.wikipedia.org/wiki/The_C_Programming_Language_(book)"><span style="color:windowtext;text-decoration:none;">K&amp;R C</span></a>, which lacked prototypes.) </span></li>
<li class="MsoNormal"><span lang="EN">Some questionable choices of operator precedence, as mentioned by Kernighan and Ritchie above, such as </span><code><span style="font-size:10pt;" lang="EN">==</span></code><span lang="EN"> binding more tightly than </span><code><span style="font-size:10pt;" lang="EN">&amp;</span></code><span lang="EN"> and </span><code><span style="font-size:10pt;" lang="EN">|</span></code><span lang="EN"> in expressions like </span><code><span style="font-size:10pt;" lang="EN">x &amp; 1 == 0</span></code><span lang="EN">. </span></li>
<li class="MsoNormal"><span lang="EN">The use of the </span><code><span style="font-size:10pt;" lang="EN">=</span></code><span lang="EN"> operator, used in mathematics for equality, to indicate assignment, following the precedent of <a title="Fortran" href="http://en.wikipedia.org/wiki/Fortran"><span style="color:windowtext;text-decoration:none;">Fortran</span></a>, <a title="PL/I" href="http://en.wikipedia.org/wiki/PL/I"><span style="color:windowtext;text-decoration:none;">PL/I</span></a>, and <a title="BASIC" href="http://en.wikipedia.org/wiki/BASIC"><span style="color:windowtext;text-decoration:none;">BASIC</span></a>, but unlike <a title="ALGOL" href="http://en.wikipedia.org/wiki/ALGOL"><span style="color:windowtext;text-decoration:none;">ALGOL</span></a> and its derivatives. Ritchie made this syntax design decision consciously, based primarily on the argument that assignment occurs more often than comparison. </span></li>
<li class="MsoNormal"><span lang="EN">Similarity of the assignment and equality operators (</span><code><span style="font-size:10pt;" lang="EN">=</span></code><span lang="EN"> and </span><code><span style="font-size:10pt;" lang="EN">==</span></code><span lang="EN">), making it easy to accidentally substitute one for the other. C&#8217;s weak type system permits each to be used in the context of the other without a compilation error (although some compilers produce warnings). For example, the conditional expression in </span><code><span style="font-size:10pt;" lang="EN">if (a=b)</span></code><span lang="EN"> is only true if </span><code><span style="font-size:10pt;" lang="EN">a</span></code><span lang="EN"> is not zero after the assignment.<sup><a href="http://en.wikipedia.org/wiki/C_(programming_language)#cite_note-7#cite_note-7"><span style="color:windowtext;text-decoration:none;">[8]</span></a></sup> </span></li>
<li class="MsoNormal"><span lang="EN">A lack of <a title="Infix notation" href="http://en.wikipedia.org/wiki/Infix_notation"><span style="color:windowtext;text-decoration:none;">infix</span></a> operators for complex objects, particularly for string operations, making programs which rely heavily on these operations (implemented as functions instead) somewhat difficult to read. </span></li>
<li class="MsoNormal"><span lang="EN">A declaration syntax that some find unintuitive, particularly for <a title="Function pointer" href="http://en.wikipedia.org/wiki/Function_pointer"><span style="color:windowtext;text-decoration:none;">function pointers</span></a>. (Ritchie&#8217;s idea was to declare identifiers in contexts resembling their use: &#8220;<a title="Declaration reflects use" href="http://en.wikipedia.org/wiki/Declaration_reflects_use"><span style="color:windowtext;text-decoration:none;">declaration reflects use</span></a>&#8220;.) </span></li>
</ul>
<h3 style="margin:auto 0;"><a id="Operators" name="Operators"></a><span style="font-size:medium;"><span class="mw-headline"><span lang="EN">Operators</span></span><span lang="EN"></span></span></h3>
<p><span lang="EN">C supports a rich set of <a title="Operator (programming)" href="http://en.wikipedia.org/wiki/Operator_(programming)"><span style="color:windowtext;text-decoration:none;">operators</span></a>, which are symbols used within an <a title="Expression (programming)" href="http://en.wikipedia.org/wiki/Expression_(programming)"><span style="color:windowtext;text-decoration:none;">expression</span></a> to specify the manipulations to be performed while evaluating that expression. C has operators for:</span></p>
<ul type="disc">
<li class="MsoNormal"><span lang="EN"><a title="Arithmetic" href="http://en.wikipedia.org/wiki/Arithmetic"><span style="color:windowtext;text-decoration:none;">arithmetic</span></a> (<a title="Addition" href="http://en.wikipedia.org/wiki/Addition"><code><span style="font-size:10pt;color:windowtext;text-decoration:none;">+</span></code></a>, <a title="Subtraction" href="http://en.wikipedia.org/wiki/Subtraction"><code><span style="font-size:10pt;color:windowtext;text-decoration:none;">-</span></code></a>, <a title="Multiplication" href="http://en.wikipedia.org/wiki/Multiplication"><code><span style="font-size:10pt;color:windowtext;text-decoration:none;">*</span></code></a>, <a title="Division (mathematics)" href="http://en.wikipedia.org/wiki/Division_(mathematics)"><code><span style="font-size:10pt;color:windowtext;text-decoration:none;">/</span></code></a>, <a title="Modulo operation" href="http://en.wikipedia.org/wiki/Modulo_operation"><code><span style="font-size:10pt;color:windowtext;text-decoration:none;">%</span></code></a>) </span></li>
<li class="MsoNormal"><span lang="EN">equality testing (<a title="Equality (mathematics)" href="http://en.wikipedia.org/wiki/Equality_(mathematics)"><code><span style="font-size:10pt;color:windowtext;text-decoration:none;">==</span></code></a>, <a title="Inequality (mathematics)" href="http://en.wikipedia.org/wiki/Inequality_(mathematics)"><code><span style="font-size:10pt;color:windowtext;text-decoration:none;">!=</span></code></a>) </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Order relation" href="http://en.wikipedia.org/wiki/Order_relation"><span style="color:windowtext;text-decoration:none;">order relations</span></a> (</span><code><span style="font-size:10pt;" lang="EN">&lt;</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">&lt;=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">&gt;</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">&gt;=</span></code><span lang="EN">) </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Boolean logic" href="http://en.wikipedia.org/wiki/Boolean_logic"><span style="color:windowtext;text-decoration:none;">boolean logic</span></a> (</span><code><span style="font-size:10pt;" lang="EN">!</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">&amp;&amp;</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">||</span></code><span lang="EN">) </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Bitwise logic" href="http://en.wikipedia.org/wiki/Bitwise_logic"><span style="color:windowtext;text-decoration:none;">bitwise logic</span></a> (</span><code><span style="font-size:10pt;" lang="EN">~</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">&amp;</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">|</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">^</span></code><span lang="EN">) </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Bitwise shift" href="http://en.wikipedia.org/wiki/Bitwise_shift"><span style="color:windowtext;text-decoration:none;">bitwise shifts</span></a> (</span><code><span style="font-size:10pt;" lang="EN">&lt;&lt;</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">&gt;&gt;</span></code><span lang="EN">) </span></li>
<li class="MsoNormal"><span lang="EN">assignment (</span><code><span style="font-size:10pt;" lang="EN">=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">+=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">-=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">*=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">/=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">%=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">&amp;=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">|=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">^=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">&lt;&lt;=</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">&gt;&gt;=</span></code><span lang="EN">) </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Increment" href="http://en.wikipedia.org/wiki/Increment"><span style="color:windowtext;text-decoration:none;">increment</span></a> and <a title="Decrement" href="http://en.wikipedia.org/wiki/Decrement"><span style="color:windowtext;text-decoration:none;">decrement</span></a> (</span><code><span style="font-size:10pt;" lang="EN">++</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">--</span></code><span lang="EN">) </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Pointer (computing)" href="http://en.wikipedia.org/wiki/Pointer_(computing)"><span style="color:windowtext;text-decoration:none;">reference and dereference</span></a> (</span><code><span style="font-size:10pt;" lang="EN">&amp;</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">*</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">[ ]</span></code><span lang="EN">) </span></li>
<li class="MsoNormal"><span lang="EN">conditional evaluation (<a title="?:" href="http://en.wikipedia.org/wiki/%3F:"><code><span style="font-size:10pt;color:windowtext;text-decoration:none;">? :</span></code></a>) </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Record (computer science)" href="http://en.wikipedia.org/wiki/Record_(computer_science)"><span style="color:windowtext;text-decoration:none;">member selection</span></a> (</span><code><span style="font-size:10pt;" lang="EN">.</span></code><span lang="EN">, </span><code><span style="font-size:10pt;" lang="EN">-&gt;</span></code><span lang="EN">) </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Type conversion" href="http://en.wikipedia.org/wiki/Type_conversion"><span style="color:windowtext;text-decoration:none;">type conversion</span></a> (</span><code><span style="font-size:10pt;" lang="EN">( )</span></code><span lang="EN">) </span></li>
<li class="MsoNormal"><span lang="EN">object size (</span><code><span style="font-size:10pt;" lang="EN"><a title="Sizeof" href="http://en.wikipedia.org/wiki/Sizeof"><span style="color:windowtext;text-decoration:none;">sizeof</span></a></span></code><span lang="EN">) </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Function argument" href="http://en.wikipedia.org/wiki/Function_argument"><span style="color:windowtext;text-decoration:none;">function argument</span></a> collection (</span><code><span style="font-size:10pt;" lang="EN">( )</span></code><span lang="EN">) </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Sequence point" href="http://en.wikipedia.org/wiki/Sequence_point"><span style="color:windowtext;text-decoration:none;">sequencing</span></a> (<a title="Comma operator" href="http://en.wikipedia.org/wiki/Comma_operator"><code><span style="font-size:10pt;color:windowtext;text-decoration:none;">,</span></code></a>) </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Order of operations" href="http://en.wikipedia.org/wiki/Order_of_operations#Mathematical_precedence"><span style="color:windowtext;text-decoration:none;">subexpression grouping</span></a> (</span><code><span style="font-size:10pt;" lang="EN">( )</span></code><span lang="EN">) </span></li>
</ul>
<p><span lang="EN">C has a <a title="Formal grammar" href="http://en.wikipedia.org/wiki/Formal_grammar"><span style="color:windowtext;text-decoration:none;">formal grammar</span></a>, specified by the C standard.</span></p>
<h2 style="margin:auto 0;"><a id=".22Hello.2C_world.22_example" name=".22Hello.2C_world.22_example"></a><span class="editsection"><span lang="EN">[</span></span><span class="mw-headline"><span lang="EN">"Hello, world" example</span></span><span lang="EN"></span></h2>
<p style="text-indent:.5in;"><span lang="EN">The "<a title="Hello, world" href="http://en.wikipedia.org/wiki/Hello,_world"><span style="color:windowtext;text-decoration:none;">hello, world</span></a>" example which appeared in the first edition of <a title="The C Programming Language (book)" href="http://en.wikipedia.org/wiki/The_C_Programming_Language_(book)"><span style="color:windowtext;text-decoration:none;">K&amp;R</span></a> has become the model for an introductory program in most programming textbooks, regardless of programming language. The program prints "hello, world" to the <a title="Standard output" href="http://en.wikipedia.org/wiki/Standard_output"><span style="color:windowtext;text-decoration:none;">standard output</span></a>, which is usually a terminal or screen display. A standard-conforming "hello, world" program is:<sup><a href="http://en.wikipedia.org/wiki/C_(programming_language)#cite_note-8#cite_note-8"><span style="color:windowtext;text-decoration:none;">[9]</span></a></sup></span></p>
<pre><span lang="EN"><span style="font-size:x-small;">#include &lt;stdio.h&gt;</span></span>
<span lang="EN"><span style="font-size:x-small;"> </span></span>
<span lang="EN"><span style="font-size:x-small;">int main(void)</span></span>
<span lang="EN"><span style="font-size:x-small;">{</span></span>
<span lang="EN"><span style="font-size:x-small;"><span>    </span>printf("hello, world\n");</span></span>
<span lang="EN"><span style="font-size:x-small;"><span>    </span>return 0;</span></span>
<span lang="EN"><span style="font-size:x-small;">}</span></span></pre>
<p><span lang="EN">The first line of the program contains a <a title="Preprocessing" href="http://en.wikipedia.org/wiki/Preprocessing"><span style="color:windowtext;text-decoration:none;">preprocessing directive</span></a>, indicated by </span><code><span style="font-size:10pt;" lang="EN">#include</span></code><span lang="EN">. This causes the preprocessor — the first tool to examine source code as it is compiled — to substitute the line with the entire text of the </span><code><span style="font-size:10pt;" lang="EN">stdio.h</span></code><span lang="EN"> standard header, which contains declarations for standard input and output functions such as </span><code><span style="font-size:10pt;" lang="EN">printf</span></code><span lang="EN">. The angle brackets surrounding </span><code><span style="font-size:10pt;" lang="EN">stdio.h</span></code><span lang="EN"> indicate that </span><code><span style="font-size:10pt;" lang="EN">stdio.h</span></code><span lang="EN"> is located using a search strategy that prefers standard headers to other headers having the same name. Double quotes may also be used to include local or project-specific header files.</span></p>
<p><span lang="EN">The next line indicates that a function named </span><code><span style="font-size:10pt;" lang="EN">main</span></code><span lang="EN"> is being defined. The </span><code><span style="font-size:10pt;" lang="EN"><a title="Main function (programming)" href="http://en.wikipedia.org/wiki/Main_function_(programming)"><span style="color:windowtext;text-decoration:none;">main</span></a></span></code><span lang="EN"> function serves a special purpose in C programs: The run-time environment calls the </span><code><span style="font-size:10pt;" lang="EN">main</span></code><span lang="EN"> function to begin program execution. The type specifier </span><code><span style="font-size:10pt;" lang="EN">int</span></code><span lang="EN"> indicates that the <em>return value,</em> the value that is returned to the invoker (in this case the run-time environment) as a result of evaluating the </span><code><span style="font-size:10pt;" lang="EN">main</span></code><span lang="EN"> function, is an integer. The keyword </span><code><span style="font-size:10pt;" lang="EN">void</span></code><span lang="EN"> as a parameter list indicates that the </span><code><span style="font-size:10pt;" lang="EN">main</span></code><span lang="EN"> function takes no arguments.<sup><a href="http://en.wikipedia.org/wiki/C_(programming_language)#cite_note-9#cite_note-9"><span style="color:windowtext;text-decoration:none;">[10]</span></a></sup></span></p>
<p><span lang="EN">The opening curly brace indicates the beginning of the definition of the </span><code><span style="font-size:10pt;" lang="EN">main</span></code><span lang="EN"> function.</span></p>
<p><span lang="EN">The next line <em>calls</em> (executes the code for) a function named </span><code><span style="font-size:10pt;" lang="EN"><a title="Printf" href="http://en.wikipedia.org/wiki/Printf"><span style="color:windowtext;text-decoration:none;">printf</span></a></span></code><span lang="EN">, which was declared in </span><code><span style="font-size:10pt;" lang="EN">stdio.h</span></code><span lang="EN"> and is supplied from a system <a title="Library (computer science)" href="http://en.wikipedia.org/wiki/Library_(computer_science)"><span style="color:windowtext;text-decoration:none;">library</span></a>. In this call, the </span><code><span style="font-size:10pt;" lang="EN">printf</span></code><span lang="EN"> function is <em>passed</em> (provided with) a single argument, the address of the first character in the string literal </span><code><span style="font-size:10pt;" lang="EN">"hello, world\n"</span></code><span lang="EN">. The string literal is an unnamed <a title="Array" href="http://en.wikipedia.org/wiki/Array"><span style="color:windowtext;text-decoration:none;">array</span></a> with elements of type </span><code><span style="font-size:10pt;" lang="EN">char</span></code><span lang="EN">, set up automatically by the compiler with a final 0-valued character to mark the end of the array (</span><code><span style="font-size:10pt;" lang="EN">printf</span></code><span lang="EN"> needs to know this). The </span><code><span style="font-size:10pt;" lang="EN">\n</span></code><span lang="EN"> is an <em>escape sequence</em> that C translates to a <em><a title="Newline" href="http://en.wikipedia.org/wiki/Newline"><span style="color:windowtext;text-decoration:none;">newline</span></a></em> character, which on output signifies the end of the current line. The return value of the </span><code><span style="font-size:10pt;" lang="EN">printf</span></code><span lang="EN"> function is of type </span><code><span style="font-size:10pt;" lang="EN">int</span></code><span lang="EN">, but it is silently discarded since it is not used. (A more careful program might test the return value to determine whether or not the </span><code><span style="font-size:10pt;" lang="EN">printf</span></code><span lang="EN"> function succeeded.) The semicolon </span><code><span style="font-size:10pt;" lang="EN">;</span></code><span lang="EN"> terminates the statement.</span></p>
<p><span lang="EN">The <em>return</em> statement terminates the execution of the </span><code><span style="font-size:10pt;" lang="EN">main</span></code><span lang="EN"> function and causes it to return the integer value 0, which is interpreted by the run-time system as an exit code indicating successful execution.</span></p>
<p><span lang="EN">The closing curly brace indicates the end of the code for the </span><code><span style="font-size:10pt;" lang="EN">main</span></code><span lang="EN"> function.</span></p>
<h2 style="margin:auto 0;"><a id="Data_structures" name="Data_structures"></a><span class="mw-headline"><span lang="EN">Data structures</span></span><span lang="EN"></span></h2>
<p style="text-indent:.5in;"><span lang="EN">C has a static <a title="Weak typing" href="http://en.wikipedia.org/wiki/Weak_typing"><span style="color:windowtext;text-decoration:none;">weak typing</span></a> <a title="Type system" href="http://en.wikipedia.org/wiki/Type_system"><span style="color:windowtext;text-decoration:none;">type system</span></a> that shares some similarities with that of other <a title="ALGOL" href="http://en.wikipedia.org/wiki/ALGOL"><span style="color:windowtext;text-decoration:none;">ALGOL</span></a> descendants such as <a title="Pascal (programming language)" href="http://en.wikipedia.org/wiki/Pascal_(programming_language)"><span style="color:windowtext;text-decoration:none;">Pascal</span></a>. There are built-in types for integers of various sizes, both signed and unsigned, <a title="Floating-point number" href="http://en.wikipedia.org/wiki/Floating-point_number"><span style="color:windowtext;text-decoration:none;">floating-point numbers</span></a>, characters, and enumerated types (</span><code><span style="font-size:10pt;" lang="EN">enum</span></code><span lang="EN">). C99 added a <a title="Boolean datatype" href="http://en.wikipedia.org/wiki/Boolean_datatype"><span style="color:windowtext;text-decoration:none;">boolean datatype</span></a>. There are also derived types including <a title="Array" href="http://en.wikipedia.org/wiki/Array"><span style="color:windowtext;text-decoration:none;">arrays</span></a>, <a title="Pointer" href="http://en.wikipedia.org/wiki/Pointer"><span style="color:windowtext;text-decoration:none;">pointers</span></a>, <a title="Record (computer science)" href="http://en.wikipedia.org/wiki/Record_(computer_science)"><span style="color:windowtext;text-decoration:none;">records</span></a> (</span><code><span style="font-size:10pt;" lang="EN">struct</span></code><span lang="EN">), and untagged <a title="Union (computer science)" href="http://en.wikipedia.org/wiki/Union_(computer_science)"><span style="color:windowtext;text-decoration:none;">unions</span></a> (</span><code><span style="font-size:10pt;" lang="EN">union</span></code><span lang="EN">).</span></p>
<p><span lang="EN">C is often used in low-level systems programming where escapes from the type system may be necessary. The compiler attempts to ensure type correctness of most expressions, but the programmer can override the checks in various ways, either by using a <em><a title="Type conversion" href="http://en.wikipedia.org/wiki/Type_conversion"><span style="color:windowtext;text-decoration:none;">type cast</span></a></em> to explicitly convert a value from one type to another, or by using pointers or unions to reinterpret the underlying bits of a value in some other way.</span></p>
<h4 style="margin:12pt 0 3pt;"><a id="Pointers" name="Pointers"></a><span style="font-size:large;"><span class="mw-headline"><span lang="EN">Pointers</span></span><span lang="EN"></span></span></h4>
<p style="text-indent:.5in;"><span lang="EN">C supports the use of pointers, a very simple type of <a title="Reference (computer science)" href="http://en.wikipedia.org/wiki/Reference_(computer_science)"><span style="color:windowtext;text-decoration:none;">reference</span></a> that records, in effect, the address or location of an object or function in memory. Pointers can be <em>dereferenced</em> to access data stored at the address pointed to, or to invoke a pointed-to function. Pointers can be manipulated using assignment and also <a title="Pointer arithmetic" href="http://en.wikipedia.org/wiki/Pointer_arithmetic"><span style="color:windowtext;text-decoration:none;">pointer arithmetic</span></a>. The run-time representation of a pointer value is typically a raw memory address (perhaps augmented by an offset-within-word field), but since a pointer&#8217;s type includes the type of the thing pointed to, expressions including pointers can be type-checked at compile time. Pointer arithmetic is automatically scaled by the size of the pointed-to data type. (See <a href="http://en.wikipedia.org/wiki/C_(programming_language)#Array-pointer_interchangeability#Array-pointer_interchangeability"><span style="color:windowtext;text-decoration:none;">Array-pointer interchangeability</span></a> below.) Pointers are used for many different purposes in C. <a title="String (computer science)" href="http://en.wikipedia.org/wiki/String_(computer_science)"><span style="color:windowtext;text-decoration:none;">Text strings</span></a> are commonly manipulated using pointers into arrays of characters. <a title="Dynamic memory allocation" href="http://en.wikipedia.org/wiki/Dynamic_memory_allocation"><span style="color:windowtext;text-decoration:none;">Dynamic memory allocation</span></a>, which is described below, is performed using pointers. Many data types, such as <a title="Tree (data structure)" href="http://en.wikipedia.org/wiki/Tree_(data_structure)"><span style="color:windowtext;text-decoration:none;">trees</span></a>, are commonly implemented as dynamically allocated </span><code><span style="font-size:10pt;" lang="EN">struct</span></code><span lang="EN"> objects linked together using pointers. Pointers to functions are useful for <a title="Callback (computer science)" href="http://en.wikipedia.org/wiki/Callback_(computer_science)"><span style="color:windowtext;text-decoration:none;">callbacks</span></a> from event handlers.</span></p>
<p><span lang="EN">A <em><a title="Null pointer" href="http://en.wikipedia.org/wiki/Null_pointer"><span style="color:windowtext;text-decoration:none;">null pointer</span></a></em> is a pointer value that points to no valid location (it is often represented by address zero). Dereferencing a null pointer is therefore meaningless, typically resulting in a run-time error. Null pointers are useful for indicating special cases such as no <em>next</em> pointer in the final node of a <a title="Linked list" href="http://en.wikipedia.org/wiki/Linked_list"><span style="color:windowtext;text-decoration:none;">linked list</span></a>, or as an error indication from functions returning pointers.</span></p>
<p><span lang="EN">Void pointers (</span><code><span style="font-size:10pt;" lang="EN">void *</span></code><span lang="EN">) point to objects of unknown type, and can therefore be used as &#8220;generic&#8221; data pointers. Since the size and type of the pointed-to object is not known, void pointers cannot be dereferenced, nor is pointer arithmetic on them allowed, although they can easily be (and in many contexts implicitly are) converted to and from any other object pointer type.</span></p>
<p><span lang="EN">Careless use of pointers is potentially dangerous. Because they are typically unchecked, a pointer variable can be made to point to any arbitrary location, which can cause undesirable effects. Although properly-used pointers point to safe places, they can be made to point to unsafe places by using invalid <a title="Data pointer" href="http://en.wikipedia.org/wiki/Data_pointer"><span style="color:windowtext;text-decoration:none;">pointer arithmetic</span></a>; the objects they point to may be deallocated and reused (<a title="Dangling pointer" href="http://en.wikipedia.org/wiki/Dangling_pointer"><span style="color:windowtext;text-decoration:none;">dangling pointers</span></a>); they may be used without having been initialized (<a title="Wild pointer" href="http://en.wikipedia.org/wiki/Wild_pointer"><span style="color:windowtext;text-decoration:none;">wild pointers</span></a>); or they may be directly assigned an unsafe value using a cast, union, or through another corrupt pointer. In general, C is permissive in allowing manipulation of and conversion between pointer types, although compilers typically provide options for various levels of checking. Some other programming languages address these problems by using more restrictive <a title="Reference (computer science)" href="http://en.wikipedia.org/wiki/Reference_(computer_science)"><span style="color:windowtext;text-decoration:none;">reference</span></a> types.</span></p>
<h4 style="margin:12pt 0 3pt;"><a id="Arrays" name="Arrays"></a><span style="font-size:large;"><span class="mw-headline"><span lang="EN">Arrays</span></span><span lang="EN"></span></span></h4>
<p style="text-indent:.5in;"><span lang="EN"><a title="Array" href="http://en.wikipedia.org/wiki/Array"><span style="color:windowtext;text-decoration:none;">Array</span></a> types in C are traditionally, of a fixed, static size specified at compile time. (The more recent C99 standard also allows a form of variable-length arrays.) However, it is also possible to allocate a block of memory (of arbitrary size) at run-time, using the standard library&#8217;s </span><code><span style="font-size:10pt;" lang="EN">malloc</span></code><span lang="EN"> function, and treat it as an array. C&#8217;s unification of arrays and pointers (see below) means that true arrays and these dynamically-allocated, simulated arrays are virtually interchangeable. Since arrays are always accessed (in effect) via pointers, array accesses are typically <em>not</em> checked against the underlying array size, although the compiler may provide bounds checking as an option. Array bounds violations are therefore possible and rather common in carelessly written code, and can lead to various repercussions, including illegal memory accesses, corruption of data, buffer overruns, and run-time exceptions.</span></p>
<p><span lang="EN">C does not have a special provision for declaring multidimensional arrays, but rather relies on recursion within the type system to declare arrays of arrays, which effectively accomplishes the same thing. The index values of the resulting &#8220;multidimensional array&#8221; can be thought of as increasing in <a title="Row-major order" href="http://en.wikipedia.org/wiki/Row-major_order"><span style="color:windowtext;text-decoration:none;">row-major order</span></a>.</span></p>
<p><span lang="EN">Although C supports static arrays, it is not required that array indices be validated (<a title="Bounds checking" href="http://en.wikipedia.org/wiki/Bounds_checking"><span style="color:windowtext;text-decoration:none;">bounds checking</span></a>). For example, one can try to write to the sixth element of an array with five elements, generally yielding undesirable results. This type of bug, called a <em><a title="Buffer overflow" href="http://en.wikipedia.org/wiki/Buffer_overflow"><span style="color:windowtext;text-decoration:none;">buffer overflow</span></a></em> or <em>buffer overrun,</em> is notorious for causing a number of security problems. On the other hand, since <a title="Bounds checking elimination" href="http://en.wikipedia.org/wiki/Bounds_checking_elimination"><span style="color:windowtext;text-decoration:none;">bounds checking elimination</span></a> technology was largely nonexistent when C was defined, bounds checking came with a severe performance penalty, particularly in numerical computation. A few years earlier, some <a title="Fortran" href="http://en.wikipedia.org/wiki/Fortran"><span style="color:windowtext;text-decoration:none;">Fortran</span></a> compilers had a switch to toggle bounds checking on or off; however, this would have been much less useful for C, where array arguments are passed as simple pointers.</span></p>
<p><span lang="EN">Multidimensional arrays are commonly used in numerical algorithms (mainly from applied <a title="Linear algebra" href="http://en.wikipedia.org/wiki/Linear_algebra"><span style="color:windowtext;text-decoration:none;">linear algebra</span></a>) to store matrices. The structure of the C array is well suited to this particular task. However, since arrays are passed merely as pointers, the bounds of the array must be known fixed values or else explicitly passed to any subroutine that requires them, and dynamically sized arrays of arrays cannot be accessed using double indexing. (A workaround for this is to allocate the array with an additional &#8220;row vector&#8221; of pointers to the columns.)</span></p>
<p><span lang="EN">C99 introduced &#8220;variable-length arrays&#8221; which address some, but not all, of the issues with ordinary C arrays.</span></p>
<p class="MsoNormal" style="margin:0;"><em><span lang="EN">See also: <a title="C string" href="http://en.wikipedia.org/wiki/C_string"><span style="color:windowtext;text-decoration:none;">C string</span></a></span></em></p>
<h4 style="margin:12pt 0 3pt;"><a id="Array-pointer_interchangeability" name="Array-pointer_interchangeability"></a><span style="font-size:large;"><span class="mw-headline"><span lang="EN">Array-pointer interchangeability</span></span><span lang="EN"></span></span></h4>
<p style="text-indent:.5in;"><span lang="EN">A distinctive (but potentially confusing) feature of C is its treatment of arrays and pointers. The array-subscript notation </span><code><span style="font-size:10pt;" lang="EN">x[i]</span></code><span lang="EN"> can also be used when </span><code><span style="font-size:10pt;" lang="EN">x</span></code><span lang="EN"> is a pointer; the interpretation (using pointer arithmetic) is to access the </span><code><span style="font-size:10pt;" lang="EN">(i+1)</span></code><span lang="EN">th of several adjacent data objects pointed to by </span><code><span style="font-size:10pt;" lang="EN">x</span></code><span lang="EN">, counting the object that </span><code><span style="font-size:10pt;" lang="EN">x</span></code><span lang="EN"> points to (which is </span><code><span style="font-size:10pt;" lang="EN">x[0]</span></code><span lang="EN">) as the first element of the array.</span></p>
<p><span lang="EN">Formally, </span><code><span style="font-size:10pt;" lang="EN">x[i]</span></code><span lang="EN"> is equivalent to </span><code><span style="font-size:10pt;" lang="EN">*(x + i)</span></code><span lang="EN">. Since the type of the pointer involved is known to the compiler at compile time, the address that </span><code><span style="font-size:10pt;" lang="EN">x + i</span></code><span lang="EN"> points to is <em>not</em> the address pointed to by </span><code><span style="font-size:10pt;" lang="EN">x</span></code><span lang="EN"> incremented by </span><code><span style="font-size:10pt;" lang="EN">i</span></code><span lang="EN"> bytes, but rather incremented by </span><code><span style="font-size:10pt;" lang="EN">i</span></code><span lang="EN"> multiplied by the size of an element that </span><code><span style="font-size:10pt;" lang="EN">x</span></code><span lang="EN"> points to. The size of these elements can be determined with the operator </span><code><span style="font-size:10pt;" lang="EN"><a title="Sizeof" href="http://en.wikipedia.org/wiki/Sizeof"><span style="color:windowtext;text-decoration:none;">sizeof</span></a></span></code><span lang="EN"> by applying it to any dereferenced element of </span><code><span style="font-size:10pt;" lang="EN">x</span></code><span lang="EN">, as in </span><code><span style="font-size:10pt;" lang="EN">n = sizeof *x</span></code><span lang="EN"> or </span><code><span style="font-size:10pt;" lang="EN">n = sizeof x[0]</span></code><span lang="EN">.</span></p>
<p><span lang="EN">Furthermore, in most expression contexts (a notable exception is </span><code><span style="font-size:10pt;" lang="EN">sizeof</span></code><span lang="EN"> <em>array</em>), the name of an array is automatically converted to a pointer to the array&#8217;s first element; this implies that an array is never copied as a whole when named as an argument to a function, but rather only the address of its first element is passed. Therefore, although C&#8217;s function calls use <a title="Call-by-value" href="http://en.wikipedia.org/wiki/Call-by-value"><span style="color:windowtext;text-decoration:none;">pass-by-value</span></a> semantics, arrays are <em>in effect</em> passed by <a title="Reference (computer science)" href="http://en.wikipedia.org/wiki/Reference_(computer_science)"><span style="color:windowtext;text-decoration:none;">reference</span></a>.</span></p>
<p><span lang="EN">The number of elements in a declared array </span><code><span style="font-size:10pt;" lang="EN">a</span></code><span lang="EN"> can be determined as </span><code><span style="font-size:10pt;" lang="EN">sizeof a / sizeof a[0]</span></code><span lang="EN">.</span></p>
<p><span lang="EN">An interesting demonstration of the interchangeability of pointers and arrays is shown below. The four assignments are equivalent and each is valid C code. Note how the last line contains the strange code </span><code><span style="font-size:10pt;" lang="EN">i[x] = 1;</span></code><span lang="EN">, which has the index variable </span><code><span style="font-size:10pt;" lang="EN">i</span></code><span lang="EN"> apparently interchanged with the array variable </span><code><span style="font-size:10pt;" lang="EN">x</span></code><span lang="EN">. This last line might be found in <a title="International Obfuscated C Code Contest" href="http://en.wikipedia.org/wiki/International_Obfuscated_C_Code_Contest"><span style="color:windowtext;text-decoration:none;">obfuscated C</span></a> code.</span></p>
<pre><span lang="EN"><span style="font-size:x-small;">/* x designates an array */</span></span>
<span lang="EN"><span style="font-size:x-small;">x[i] = 1;</span></span>
<span lang="EN"><span style="font-size:x-small;">*(x + i) = 1;</span></span>
<span lang="EN"><span style="font-size:x-small;">*(i + x) = 1;</span></span>
<span lang="EN"><span style="font-size:x-small;">i[x] = 1; /* strange, but correct: i[x] is equivalent to *(i + x) */</span></span></pre>
<p><span lang="EN">However, there is a distinction to be made between arrays and pointer variables. Even though the name of an array is in most expression contexts converted to a pointer (to its first element), this pointer does not itself occupy any storage. Consequently, you cannot change what an array &#8220;points to&#8221;, and it is impossible to assign to an array. (Arrays may however be copied using the </span><code><span style="font-size:10pt;" lang="EN">memcpy</span></code><span lang="EN"> function, for example.)</span></p>
<h2 style="margin:auto 0;"><a id="Memory_management" name="Memory_management"></a><span class="mw-headline"><span lang="EN">Memory management</span></span><span lang="EN"></span></h2>
<p style="text-indent:.25in;"><span lang="EN">One of the most important functions of a programming language is to provide facilities for managing <a title="Computer memory" href="http://en.wikipedia.org/wiki/Computer_memory"><span style="color:windowtext;text-decoration:none;">memory</span></a> and the objects that are stored in memory. C provides three distinct ways to allocate memory for objects:</span></p>
<ul type="disc">
<li class="MsoNormal"><span lang="EN"><a title="Static memory allocation" href="http://en.wikipedia.org/wiki/Static_memory_allocation"><span style="color:windowtext;text-decoration:none;">Static memory allocation</span></a>: space for the object is provided in the binary at compile-time; these objects have an <a title="Variable" href="http://en.wikipedia.org/wiki/Variable#Scope_and_extent"><span style="color:windowtext;text-decoration:none;">extent</span></a> (or lifetime) as long as the binary which contains them is loaded into memory </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Automatic memory allocation" href="http://en.wikipedia.org/wiki/Automatic_memory_allocation"><span style="color:windowtext;text-decoration:none;">Automatic memory allocation</span></a>: temporary objects can be stored on the <a title="Call stack" href="http://en.wikipedia.org/wiki/Call_stack"><span style="color:windowtext;text-decoration:none;">stack</span></a>, and this space is automatically freed and reusable after the block in which they are declared is exited </span></li>
<li class="MsoNormal"><span lang="EN"><a title="Dynamic memory allocation" href="http://en.wikipedia.org/wiki/Dynamic_memory_allocation"><span style="color:windowtext;text-decoration:none;">Dynamic memory allocation</span></a>: blocks of memory of arbitrary size can be requested at run-time using library functions such as </span><code><span style="font-size:10pt;" lang="EN"><a title="Malloc" href="http://en.wikipedia.org/wiki/Malloc"><span style="color:windowtext;text-decoration:none;">malloc</span></a></span></code><span lang="EN"> from a region of memory called the <a title="Dynamic memory allocation" href="http://en.wikipedia.org/wiki/Dynamic_memory_allocation"><span style="color:windowtext;text-decoration:none;">heap</span></a>; these blocks persist until subsequently freed for reuse by calling the library function </span><code><span style="font-size:10pt;" lang="EN"><a title="Malloc" href="http://en.wikipedia.org/wiki/Malloc"><span style="color:windowtext;text-decoration:none;">free</span></a></span></code><span lang="EN"> </span></li>
</ul>
<p><span lang="EN">These three approaches are appropriate in different situations and have various tradeoffs. For example, static memory allocation has no allocation overhead, automatic allocation may involve a small amount of overhead, and dynamic memory allocation can potentially have a great deal of overhead for both allocation and deallocation. On the other hand, stack space is typically much more limited and transient than either static memory or heap space, and dynamic memory allocation allows allocation of objects whose size is known only at run-time. Most C programs make extensive use of all three.</span></p>
<p><span lang="EN">Where possible, automatic or static allocation is usually preferred because the storage is managed by the compiler, freeing the programmer of the potentially error-prone chore of manually allocating and releasing storage. However, many data structures can grow in size at runtime, and since static allocations (and automatic allocations in C89 and C90) must have a fixed size at compile-time, there are many situations in which dynamic allocation must be used. Prior to the C99 standard, variable-sized arrays were a common example of this (see &#8220;<a title="Malloc" href="http://en.wikipedia.org/wiki/Malloc"><span style="color:windowtext;text-decoration:none;">malloc</span></a>&#8221; for an example of dynamically allocated arrays).</span></p>
<p><span lang="EN">Automatically and dynamically allocated objects are only initialized if an initialized is explicitly specified; otherwise they initially have indeterminate values (typically, whatever <a title="Bit" href="http://en.wikipedia.org/wiki/Bit"><span style="color:windowtext;text-decoration:none;">bit pattern</span></a> happens to be present in the <a title="Computer storage" href="http://en.wikipedia.org/wiki/Computer_storage"><span style="color:windowtext;text-decoration:none;">storage</span></a>, which might not even represent a valid value for that type). If the program attempts to access an uninitialized value, the results are undefined. Many modern compilers try to detect and warn about this problem, but both <a title="Type I and type II errors" href="http://en.wikipedia.org/wiki/Type_I_and_type_II_errors"><span style="color:windowtext;text-decoration:none;">false positives and false negatives</span></a> occur.</span></p>
<p><span lang="EN">Another issue is that heap memory allocation has to be manually synchronized with its actual usage in any program in order for it to be reused as much as possible. For example, if the only pointer to a heap memory allocation goes out of scope or has its value overwritten before </span><code><span style="font-size:10pt;" lang="EN"><a title="Malloc" href="http://en.wikipedia.org/wiki/Malloc"><span style="color:windowtext;text-decoration:none;">free()</span></a></span></code><span lang="EN"> has been called, then that memory cannot be recovered for later reuse and is essentially lost to the program, a phenomenon known as a <em><a title="Memory leak" href="http://en.wikipedia.org/wiki/Memory_leak"><span style="color:windowtext;text-decoration:none;">memory leak</span></a>.</em> Conversely, it is possible to release memory too soon and continue to access it; however, since the allocation system can re-allocate or itself use the freed memory, unpredictable behavior is likely to occur when the multiple users corrupt each other&#8217;s data. Typically, the symptoms will appear in a portion of the program far removed from the actual error. Such issues are ameliorated in languages with <a title="Garbage collection (computer science)" href="http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)"><span style="color:windowtext;text-decoration:none;">automatic garbage collection</span></a> or <a title="Resource acquisition is initialization" href="http://en.wikipedia.org/wiki/Resource_acquisition_is_initialization"><span style="color:windowtext;text-decoration:none;">RAII</span></a>.</span></p>
<h2 style="margin:auto 0;"><a id="Libraries" name="Libraries"></a><span class="mw-headline"><span lang="EN">Libraries</span></span><span lang="EN"></span></h2>
<p style="text-indent:.5in;"><span lang="EN">The C programming language uses <a title="Library (software)" href="http://en.wikipedia.org/wiki/Library_(software)"><span style="color:windowtext;text-decoration:none;">libraries</span></a> as its primary method of extension. In C, a library is a set of functions contained within a single &#8220;archive&#8221; file. Each library typically has a <a title="Header files" href="http://en.wikipedia.org/wiki/Header_files"><span style="color:windowtext;text-decoration:none;">header file</span></a>, which contains the prototypes of the functions contained within the library that may be used by a program, and declarations of special data types and macro symbols used with these functions. In order for a program to use a library, it must include the library&#8217;s header file, and the library must be linked with the program, which in many cases requires <a title="Compiler flag" href="http://en.wikipedia.org/wiki/Compiler_flag"><span style="color:windowtext;text-decoration:none;">compiler flags</span></a> (e.g., </span><code><span style="font-size:10pt;" lang="EN">-lm</span></code><span lang="EN">, shorthand for &#8220;math library&#8221;).</span></p>
<p><span lang="EN">The most common C library is the <a title="C standard library" href="http://en.wikipedia.org/wiki/C_standard_library"><span style="color:windowtext;text-decoration:none;">C standard library</span></a>, which is specified by the <a title="ISO standard" href="http://en.wikipedia.org/wiki/ISO_standard"><span style="color:windowtext;text-decoration:none;">ISO</span></a> and <a title="ANSI C" href="http://en.wikipedia.org/wiki/ANSI_C"><span style="color:windowtext;text-decoration:none;">ANSI C</span></a> standards and comes with every C implementation. (&#8220;Freestanding&#8221; [embedded] C implementations may provide only a subset of the standard library.) This library supports stream input and output, memory allocation, mathematics, character strings, and time values.</span></p>
<p><span lang="EN">Another common set of C library functions are those used by applications specifically targeted for <a title="Unix" href="http://en.wikipedia.org/wiki/Unix"><span style="color:windowtext;text-decoration:none;">Unix</span></a> and <a title="Unix-like" href="http://en.wikipedia.org/wiki/Unix-like"><span style="color:windowtext;text-decoration:none;">Unix-like</span></a> systems, especially functions which provide an interface to the <a title="Kernel (computer science)" href="http://en.wikipedia.org/wiki/Kernel_(computer_science)"><span style="color:windowtext;text-decoration:none;">kernel</span></a>. These functions are detailed in various standards such as <a title="POSIX" href="http://en.wikipedia.org/wiki/POSIX"><span style="color:windowtext;text-decoration:none;">POSIX</span></a> and the <a title="Single UNIX Specification" href="http://en.wikipedia.org/wiki/Single_UNIX_Specification"><span style="color:windowtext;text-decoration:none;">Single UNIX Specification</span></a>.</span></p>
<p><span lang="EN">Since many programs have been written in C, there are a wide variety of other libraries available. Libraries are often written in C because C compilers generate efficient <a title="Object code" href="http://en.wikipedia.org/wiki/Object_code"><span style="color:windowtext;text-decoration:none;">object code</span></a>; programmers then create interfaces to the library so that the routines can be used from higher-level languages like <a title="Java (programming language)" href="http://en.wikipedia.org/wiki/Java_(programming_language)"><span style="color:windowtext;text-decoration:none;">Java</span></a>, <a title="Perl" href="http://en.wikipedia.org/wiki/Perl"><span style="color:windowtext;text-decoration:none;">Perl</span></a>, and <a title="Python (programming language)" href="http://en.wikipedia.org/wiki/Python_(programming_language)"><span style="color:windowtext;text-decoration:none;">Python</span></a>.</span></p>
<h2 style="margin:auto 0;"><a id="Deficiencies" name="Deficiencies"></a><span class="mw-headline"><span lang="EN">Deficiencies</span></span><span lang="EN"></span></h2>
<p style="text-indent:.5in;"><span lang="EN">Although the C language is extremely concise, C is subtle, and expert competency in C is not common—taking more than ten years to achieve.<sup><a href="http://en.wikipedia.org/wiki/C_(programming_language)#cite_note-10#cite_note-10"><span style="color:windowtext;text-decoration:none;">[11]</span></a></sup> C programs are also notorious for security vulnerabilities due to the unconstrained direct access to memory of many of the standard C library function calls.</span></p>
<p><span lang="EN">In spite of its popularity and elegance, real-world C programs commonly suffer from instability and <a title="Memory leaks" href="http://en.wikipedia.org/wiki/Memory_leaks"><span style="color:windowtext;text-decoration:none;">memory leaks</span></a>, to the extent that any appreciable C programming project will have to adopt specialized practices and tools to mitigate spiraling damage. Indeed, an entire industry has been born merely out of the need to stabilize large source-code bases.</span></p>
<p><span lang="EN">Although C was developed for Unix, <a title="Microsoft" href="http://en.wikipedia.org/wiki/Microsoft"><span style="color:windowtext;text-decoration:none;">Microsoft</span></a> adopted C as the core language of its operating systems. Although all standard C library calls are supported by <a title="Microsoft Windows" href="http://en.wikipedia.org/wiki/Microsoft_Windows"><span style="color:windowtext;text-decoration:none;">Windows</span></a>, there is only ad-hoc support for Unix functionality side-by-side with an inordinate number of inconstant Windows-specific <a title="Application programming interface" href="http://en.wikipedia.org/wiki/Application_programming_interface"><span style="color:windowtext;text-decoration:none;">API</span></a> calls.</span></p>
<p><span lang="EN">It is inevitable that C did not choose limit the size or <a title="Endianness" href="http://en.wikipedia.org/wiki/Endianness"><span style="color:windowtext;text-decoration:none;">endianness</span></a> of its types—for example, each compiler is free to choose the size of an </span><code><span style="font-size:10pt;" lang="EN">int</span></code><span lang="EN"> type as any anything over 16 bits according to what is efficient on the current platform. Many programmers work based on size and endianness assumptions, leading to code that is not <a title="Software portability" href="http://en.wikipedia.org/wiki/Software_portability"><span style="color:windowtext;text-decoration:none;">portable</span></a>.</span></p>
<p><span lang="EN">Also inevitable is that the C standard defines only a very limited gamut of functionality, excluding anything related to network communications, user interaction, or process/thread creation. Its parent document, the POSIX standard, includes such a wide array of functionality that no operating system appears to support it exactly, and only Unix systems have even attempted to support substantial parts of it.</span></p>
<p><span lang="EN">Therefore the kinds of programs that can be portably written are extremely restricted, unless specialized programming practices are adopted.</span></p>
<h2 style="margin:auto 0;"><a id="Language_tools" name="Language_tools"></a><span class="mw-headline"><span lang="EN">Language tools</span></span><span lang="EN"></span></h2>
<p style="text-indent:.5in;"><span lang="EN">Tools have been created to help C programmers avoid some of the problems inherent in the language, such as statements with undefined behavior or statements that are not a good practice because they are more likely to result in unintended behavior or run-time errors.</span></p>
<p><span lang="EN">Automated source code checking and auditing are beneficial in any language, and for C many such tools exist, such as <a title="Lint programming tool" href="http://en.wikipedia.org/wiki/Lint_programming_tool"><span style="color:windowtext;text-decoration:none;">Lint</span></a>. A common practice is to use Lint to detect questionable code when a program is first written. Once a program passes Lint, it is then compiled using the C compiler. Also, many compilers can optionally warn about syntactically valid constructs that are likely to actually be errors. <a title="MISRA C" href="http://en.wikipedia.org/wiki/MISRA_C"><span style="color:windowtext;text-decoration:none;">MISRA C</span></a> is a proprietary set of guidelines to avoid such questionable code, developed for embedded systems.</span></p>
<p><span lang="EN">There are also compilers, libraries and operating system level mechanisms for performing array bounds checking, <a title="Buffer overflow" href="http://en.wikipedia.org/wiki/Buffer_overflow"><span style="color:windowtext;text-decoration:none;">buffer overflow</span></a> detection, <a title="Serialization" href="http://en.wikipedia.org/wiki/Serialization"><span style="color:windowtext;text-decoration:none;">serialization</span></a> and <a title="Garbage collection (computer science)" href="http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)"><span style="color:windowtext;text-decoration:none;">automatic garbage collection</span></a>, that are not a standard part of C.</span></p>
<p><span lang="EN">Tools such as <a title="IBM Rational Purify" href="http://en.wikipedia.org/wiki/IBM_Rational_Purify"><span style="color:windowtext;text-decoration:none;">Purify</span></a>, <a title="Valgrind" href="http://en.wikipedia.org/wiki/Valgrind"><span style="color:windowtext;text-decoration:none;">Valgrind</span></a>, and linking with libraries containing special versions of the <a title="Malloc" href="http://en.wikipedia.org/wiki/Malloc"><span style="color:windowtext;text-decoration:none;">memory allocation functions</span></a> can help uncover runtime memory errors.</span></p>
<h2 style="margin:auto 0;"><a id="Related_languages" name="Related_languages"></a><span class="mw-headline"><span lang="EN">Related languages</span></span><span lang="EN"></span></h2>
<p style="text-indent:.5in;"><span lang="EN">C has directly or indirectly influenced many later languages such as <a title="Java (programming language)" href="http://en.wikipedia.org/wiki/Java_(programming_language)"><span style="color:windowtext;text-decoration:none;">Java</span></a>, <a title="C Sharp (programming language)" href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)"><span style="color:windowtext;text-decoration:none;">C#</span></a>, <a title="Perl" href="http://en.wikipedia.org/wiki/Perl"><span style="color:windowtext;text-decoration:none;">Perl</span></a>, <a title="PHP" href="http://en.wikipedia.org/wiki/PHP"><span style="color:windowtext;text-decoration:none;">PHP</span></a>, <a title="JavaScript" href="http://en.wikipedia.org/wiki/JavaScript"><span style="color:windowtext;text-decoration:none;">JavaScript</span></a>, <a title="LPC (programming language)" href="http://en.wikipedia.org/wiki/LPC_(programming_language)"><span style="color:windowtext;text-decoration:none;">LPC</span></a>, and Unix&#8217;s <a title="C Shell" href="http://en.wikipedia.org/wiki/C_Shell"><span style="color:windowtext;text-decoration:none;">C Shell</span></a>. The most pervasive influence has been syntactical: all of the languages mentioned combine the statement and (more or less recognizably) expression syntax of C with type systems, data models and/or large-scale program structures that differ from those of C, sometimes radically.</span></p>
<p><span lang="EN">When object-oriented languages became popular, <a title="C++" href="http://en.wikipedia.org/wiki/C%2B%2B"><span style="color:windowtext;text-decoration:none;">C++</span></a> and <a title="Objective-C" href="http://en.wikipedia.org/wiki/Objective-C"><span style="color:windowtext;text-decoration:none;">Objective-C</span></a> were two different extensions of C that provided object-oriented capabilities. Both languages were originally implemented as <a title="Source-to-source compiler" href="http://en.wikipedia.org/wiki/Source-to-source_compiler"><span style="color:windowtext;text-decoration:none;">source-to-source compilers</span></a> &#8212; source code was translated into C, and then compiled with a C compiler.</span></p>
<p><span lang="EN"><a title="Bjarne Stroustrup" href="http://en.wikipedia.org/wiki/Bjarne_Stroustrup"><span style="color:windowtext;text-decoration:none;">Bjarne Stroustrup</span></a> devised the C++ programming language as one approach to providing object-oriented functionality with C-like syntax. C++ adds greater typing strength, scoping and other tools useful in object-oriented programming and permits <a title="Generic programming" href="http://en.wikipedia.org/wiki/Generic_programming"><span style="color:windowtext;text-decoration:none;">generic programming</span></a> via templates. Nearly a superset of C, C++ now supports most of C, with a few exceptions (see <a title="Compatibility of C and C++" href="http://en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B%2B"><span style="color:windowtext;text-decoration:none;">Compatibility of C and C++</span></a> for an exhaustive list of differences).</span></p>
<p><span lang="EN">Unlike C++, which maintains nearly complete backwards compatibility with C, the <a title="D (programming language)" href="http://en.wikipedia.org/wiki/D_(programming_language)"><span style="color:windowtext;text-decoration:none;">D language</span></a> makes a clean break with C while maintaining the same general syntax. It abandons a number of features of C which <a title="Walter Bright" href="http://en.wikipedia.org/wiki/Walter_Bright"><span style="color:windowtext;text-decoration:none;">Walter Bright</span></a> (the designer of D) considered undesirable, including the <a title="C preprocessor" href="http://en.wikipedia.org/wiki/C_preprocessor"><span style="color:windowtext;text-decoration:none;">C preprocessor</span></a> and <a title="C trigraph" href="http://en.wikipedia.org/wiki/C_trigraph"><span style="color:windowtext;text-decoration:none;">trigraphs</span></a>. Some, but not all, of D&#8217;s extensions to C overlap with those of C++.</span></p>
<p><span lang="EN"><a title="Objective-C" href="http://en.wikipedia.org/wiki/Objective-C"><span style="color:windowtext;text-decoration:none;">Objective-C</span></a> was originally a very &#8220;thin&#8221; layer on top of, and remains a strict superset of, C that permits object-oriented programming using a hybrid dynamic/static typing paradigm. Objective-C derives its syntax from both C and <a title="Smalltalk" href="http://en.wikipedia.org/wiki/Smalltalk"><span style="color:windowtext;text-decoration:none;">Smalltalk</span></a>: syntax that involves preprocessing, expressions, function declarations and function calls is inherited from C, while the syntax for object-oriented features was originally taken from Smalltalk.</span></p>
<p><span lang="EN"><a title="Limbo (programming language)" href="http://en.wikipedia.org/wiki/Limbo_(programming_language)"><span style="color:windowtext;text-decoration:none;">Limbo</span></a> is a language developed by the same team at Bell Labs that was responsible for C and Unix, and while retaining some of the syntax and the general style, introduced garbage collection, <a title="Communicating sequential processes" href="http://en.wikipedia.org/wiki/Communicating_sequential_processes"><span style="color:windowtext;text-decoration:none;">CSP</span></a> based concurrency and other major innovations.</span></p>
<p><span title="This claim needs references to reliable sources since September 2008"></p>
<p class="MsoNormal" style="margin:0;"> </p>
<p></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lhen24.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lhen24.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lhen24.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lhen24.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lhen24.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lhen24.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lhen24.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lhen24.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lhen24.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lhen24.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lhen24.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lhen24.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lhen24.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lhen24.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lhen24.wordpress.com&amp;blog=6790546&amp;post=3&amp;subd=lhen24&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lhen24.wordpress.com/2009/03/02/3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/80defc718e511753b8b12475b73dbdc4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">vluee</media:title>
		</media:content>
	</item>
	</channel>
</rss>
