<?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/"
	>

<channel>
	<title>Nathaniel Johnston &#187; Integer Sequences</title>
	<atom:link href="http://www.njohnston.ca/tag/integer-sequences/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.njohnston.ca</link>
	<description>A blog of recreational math and quantum information theory</description>
	<lastBuildDate>Thu, 15 Dec 2011 16:11:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>The Q-Toothpick Cellular Automaton</title>
		<link>http://www.njohnston.ca/2011/03/the-q-toothpick-cellular-automaton/</link>
		<comments>http://www.njohnston.ca/2011/03/the-q-toothpick-cellular-automaton/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 13:48:46 +0000</pubDate>
		<dc:creator>Nathaniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Cellular automata]]></category>
		<category><![CDATA[Integer Sequences]]></category>
		<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.nathanieljohnston.com/?p=1437</guid>
		<description><![CDATA[The Q-toothpick cellular automaton (defined earlier this month by Omar E. Pol) is described by the following simple rules: On an infinite square grid, draw a quarter circle from one corner of a square to the opposite corner of that square: Call an endpoint of a quarter circle (or a &#8220;Q-toothpick&#8221;) exposed if it does [...]]]></description>
			<content:encoded><![CDATA[<p>The Q-toothpick cellular automaton (<a href="https://oeis.org/A187210">defined earlier this month</a> by Omar E. Pol) is described by the following simple rules:</p>
<ol>
<li>On an infinite square grid, draw a quarter circle from one corner of a square to the opposite corner of that square:<img class="aligncenter size-full wp-image-1439" title="Step 1" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/q1.png" alt="" width="52" height="52" /></li>
<li>Call an endpoint of a quarter circle (or a &#8220;Q-toothpick&#8221;) <em>exposed</em> if it does not touch the endpoint of any other quarter circle.</li>
<li>From each exposed endpoint, draw two more quarter circles, each of the same size as the first quarter circle you drew. Furthermore, the two quarter circles that you draw are the ones that can be drawn &#8220;smoothly&#8221; (without creating a 90° or 180° corner). Thus the next two generations of the automaton are (already-placed quarter circles are green, newly-added quarter circles are red):<br />
<table style="margin-left: auto; margin-right: auto; border-width: 0px;" border="0" cellspacing="0" cellpadding="6">
<tbody>
<tr>
<td style="border-width: 0px;" valign="top"><img class="aligncenter size-full wp-image-1440" title="Step 2" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/q2.png" alt="" width="86" height="86" /></td>
<td style="border-width: 0px;"><img class="aligncenter size-full wp-image-1441" title="Step 3" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/q3.png" alt="" width="120" height="120" /></td>
</tr>
</tbody>
</table>
</li>
</ol>
<p>The name &#8220;Q-toothpick&#8221; comes from its analogy to the more well-studied <em>toothpick automaton</em> (see Sloane&#8217;s <a href="https://oeis.org/A139250">A139250</a> and <a href="http://arxiv.org/abs/1004.3036">this paper</a>), in which toothpicks (rather than quarter circles) are repeatedly placed on a grid where exposed ends of other toothpicks lie. In this post, we will examine how this automaton evolves over time, and in particular we will investigate the types of shapes that it produces.</p>
<h3>Counting Q-Toothpicks</h3>
<p>While the Q-toothpick automaton appears quite random and unpredictable for the first few generations, evolving past generation 6 or so reveals several patterns. The following image depicts the evolution of the automaton for its first 19 generations.</p>
<div id="attachment_1438" class="wp-caption aligncenter" style="width: 640px"><a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/Qtooth.gif"><img class="size-full wp-image-1438" title="Q-Toothpick Animation" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/Qtooth.gif" alt="" width="630" height="630" /></a><p class="wp-caption-text">The first 19 generations of the Q-toothpick cellular automaton (red segments are pieces that are newly added in the current generation)</p></div>
<p>Perhaps the most notable pattern is that the grid is more or less filled up in an expanding square starting from the initial Q-toothpick. In fact, by inspecting generations <a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/q4.png">4</a>, <a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/q6.png">6</a>, <a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/q10.png">10</a>, <a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/q18.png">18</a>, we see that at generation 2<sup>n</sup> + 2 (n = 1, 2, 3, &#8230;) the automaton has roughly filled in a square of side length 2<sup>n+1</sup> + 1, and then evolution continues from there on out of the corners of that square. Also, the number of cells added (<a href="https://oeis.org/A187211">A187211</a>) at these generations can now easily be computed:</p>
<p>A187211(2<sup>n</sup> + 2) = 16 + 8(2<sup>n-1</sup> &#8211; 1) for n ≥ 3.</p>
<p>Furthermore, the growth in the following generations repeats itself. In particular, we have:</p>
<p>A187211(2<sup>n</sup> + 3) = 22 for n ≥ 1,<br />
A187211(2<sup>n</sup> + 4) = 40 for n ≥ 2,<br />
A187211(2<sup>n</sup> + 5) = 54 for n ≥ 2.</p>
<p>Similarly, for n ≥ 3, the four values of A187211(2<sup>n</sup> + 6) through A187211(2<sup>n</sup> + 9) are similarly constant (their values are 56, 70, 120, and 134). In general, for n ≥ k the 2<sup>k-1</sup> values of A187211(2<sup>n</sup> + 2<sup>k-1</sup> + 2) through A187211(2<sup>n</sup> + 2<sup>k</sup> + 1) are constant in n, though I am not aware of a general formula for what these constants are. If we ignore the first four generations and arrange the number of Q-toothpicks added in each generation in rows of length 2<sup>n</sup>, we obtain a table that begins as follows:</p>
<p>22, 20<br />
22, 40, 54, 40<br />
22, 40, 54, 56, 70, 120, 134, 72<br />
22, 40, 54, 56, 70, 120, 134, 88, 70, 120, 150, 168, 246, 360, 326, 136</p>
<p>C scripts are provided at the end of this post for computing the values of A187210 and A187211 (and hence the values in the above table).</p>
<h3>Shapes Traced Out by Q-Toothpicks</h3>
<div>In the graphic above that depicts the initial 19 generations of the Q-toothpick automaton, several shapes are traced out, including circles, diamonds, hearts, and several nameless blobs:</div>
<table style="margin-left: auto; margin-right: auto; border-width: 0px;" border="0" cellspacing="0" cellpadding="6">
<tbody>
<tr>
<td style="border-width: 0px;" valign="top"><img class="aligncenter size-full wp-image-1456" title="Circle" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/s1.png" alt="" width="69" height="69" /></td>
<td style="border-width: 0px;" valign="top"><img class="aligncenter size-full wp-image-1461" title="Diamond" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/s6.png" alt="" width="69" height="69" /></td>
<td style="border-width: 0px;" valign="top"><img class="aligncenter size-full wp-image-1457" title="Heart" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/s2.png" alt="" width="103" height="86" /></td>
<td style="border-width: 0px;" valign="top"><img class="aligncenter size-full wp-image-1458" title="Fishbulb" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/s3.png" alt="" width="86" height="86" /></td>
</tr>
</tbody>
</table>
<table style="margin-left: auto; margin-right: auto; border-width: 0px;" border="0" cellspacing="0" cellpadding="6">
<tbody>
<tr>
<td style="border-width: 0px;" valign="top"><img class="aligncenter size-full wp-image-1459" title="Unnamed Shape" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/s4.png" alt="" width="103" height="103" /></td>
<td style="border-width: 0px;" valign="top"><img class="aligncenter size-full wp-image-1460" title="Unnamed Shape" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/s5.png" alt="" width="171" height="103" /></td>
</tr>
</tbody>
</table>
<p>By far the most common of these shapes are circles, diamonds and hearts. The fourth shape appears only on the diagonal and it&#8217;s not difficult to see that it forever will make up the entirety of the diagonal (with the exception of the circle in the center). The fifth and sixth objects are the first two members of an infinite family of objects that appear as the automaton evolves. The fifth object first appears in generation <a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/g9.png">9</a>, and sixth object (which is basically two copies of the fifth object) first appears in generation <a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/g17.png">17</a>. The following object, which is basically made up of two copies of the sixth object (i.e., four copies of the fifth object) first appears in generation 33:</p>
<p><img class="aligncenter size-full wp-image-1462" title="Unnamed Object" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/s7.png" alt="" width="307" height="103" /></p>
<p>In general, a new object of this type (made of 2<sup>n</sup> copies of the fifth object above) first appears in generation 2<sup>n+3</sup> + 1. In fact, these objects are the only ones that are traced out by this automaton. [<span style="color: #ff0000;">Edit:</span> this final claim is not true! See ebcube's <a href="http://www.conwaylife.com/forums/viewtopic.php?f=11&amp;t=663">great post</a> that shows a double-heart shape in generation 31.]</p>
<p><span style="color: #800000;"><strong>Update [March 28, 2011]:</strong></span> I have added a script that counts the number of circles, diamonds, and hearts in the nth generation of the Q-toothpick automaton, and another script that computes Sloane&#8217;s <a href="http://www.oeis.org/A187212">A187212</a>.</p>
<p><strong>Download:</strong></p>
<ul>
<li><a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/A187210.c">A187210.c</a> – computes the total number of Q-toothpicks present in the nth generation</li>
<li><a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/A187211.c">A187211.c</a> – computes the number of Q-toothpicks added in the nth generation</li>
<li><a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/A187212.c">A187212.c</a> – computes the number of Q-toothpicks if we restrict them to the positive quadrant</li>
<li><a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/03/count_shapes.c">count_shapes.c</a> – computes the number of circles, diamonds, and hearts in the nth generation</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.njohnston.ca/2011/03/the-q-toothpick-cellular-automaton/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Maximum Score in the Game &#8220;Entanglement&#8221; is 9080</title>
		<link>http://www.njohnston.ca/2011/01/the-maximum-score-in-the-game-entanglement-is-9080/</link>
		<comments>http://www.njohnston.ca/2011/01/the-maximum-score-in-the-game-entanglement-is-9080/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 23:05:33 +0000</pubDate>
		<dc:creator>Nathaniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Integer Sequences]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Popular Culture]]></category>

		<guid isPermaLink="false">http://www.nathanieljohnston.com/?p=1381</guid>
		<description><![CDATA[Entanglement is a browser-based game that has gained a fair bit of popularity lately due to its recent inclusion in Google&#8217;s Chrome Web Store and Chrome 9. The way the game works is probably best understood by actually playing it, but here is my brief attempt: You are given a hexagonal tile with six paths [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;"><a href="http://entanglement.gopherwoodstudios.com">Entanglement</a> is a browser-based game that has gained a fair bit of popularity lately due to its recent inclusion in Google&#8217;s <a href="https://chrome.google.com/webstore/detail/aciahcmjmecflokailenpkdchphgkefd?hl=en-US">Chrome Web Store</a> and <a href="http://blog.gopherwoodstudios.com/2010/12/entanglement-to-be-pre-installed-on.html">Chrome 9</a>. The way the game works is probably best understood by actually playing it, but here is my brief attempt:</p>
<ul>
<li>You are given a hexagonal tile with six paths printed on it, with two path ends touching each side of the hexagon. One such tile is as follows:</li>
</ul>
<p><img class="aligncenter size-full wp-image-1384" title="Entanglement Tile" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/01/egtile.png" alt="" width="135" height="120" /></p>
<ul>
<li>You may rotate, but not move the hexagon that has been provided to you.</li>
<li>Once you have selected an orientation of the hexagon, a path is traced along that hexagon, and you are provided a new hexagon that you may rotate at the end of your current path.</li>
<li>The goal of the game is to create the longest path possible without running into either the centre hexagon or the outer edge of the game board.</li>
</ul>
<p>To make things a bit more interesting, <a href="http://blog.gopherwoodstudios.com/2010/11/were-happy-to-introduce-latest-version.html">the game was updated in November 2010</a> to include a new scoring system that gives you 1 + 2 + 3 + &#8230; + n (the nth <a href="http://en.wikipedia.org/wiki/Triangular_number">triangular number</a>) points on a turn if you extend the length of your path by n on that turn. This encourages clever moves that significantly extend the length of the path all at once. The question that I am going to answer today is what the maximum score in Entanglement is under this scoring system (inspired by <a href="http://www.reddit.com/r/math/comments/f6i98/whats_the_best_possible_entanglement_game_score">this reddit thread</a>).</p>
<h3>On a Standard-Size Game Board</h3>
<p>The standard Entanglement game board is made up of a hexagonal ring of 6 hexagons, surrounded by a hexagonal ring of 12 hexagons, surrounded by a hexagonal ring of 18 hexagons, for a total of 36 hexagons. In order to maximize our score, we want to maximize how much we increase the length of our path on our final move. Thus, we want to just extend our path by a length of one on each of our first 35 moves, and then score big on the 36th move.</p>
<p>Well, each hexagon that we lay has six paths on it, for a total of 6*36 = 216 paths on the board. 35 of those paths will be used up by our first 35 moves. It is not possible to use all of the remaining 181 paths, however, because many of them lead into the edge of the game board or the central hexagon, and connecting to such a path immediately ends the game. Because there are 12 path ends that touch the central hexagon and 84 path ends that touch the outer border, there must be at least (12+84)/2 &#8211; 1 = 47 unused paths on the game board (we divided by 2 because each unused path takes up two path ends and we subtracted 1 because one of the paths will be used by us).</p>
<p>Thus we can add a length of at most 181 &#8211; 47 = 134 to our path on the 36th and final move of the game, giving a total score of at most 35 (from the first 35 moves of the game) + 1 + 2 + 3 + &#8230; + 134 = 35 + 9045 = 9080. Not only is this an upper bound of the possible scores, but it is actually attainable, as demonstrated by the following optimal game board:</p>
<p style="text-align: center;"><a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/01/board.png"><img class="aligncenter size-full wp-image-1382" title="Optimal Entanglement Board" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/01/board.png" alt="" width="544" height="608" /></a></p>
<p style="text-align: left;">Paths in red are unused, the green line depicts the portion of the path laid by the first 35 moves of the game, and the blue line depicts the portion of the path (of length 134) gained on the 36th move. One fun property of the above game board is that it is actually completely &#8220;unentangled&#8221; – no paths cross over any other paths.</p>
<h3>On a Larger or Smaller Game Board</h3>
<p style="text-align: left;">Other than being a good size for playability purposes, there is no reason why we couldn&#8217;t play Entanglement on a game board of larger or smaller radius (by radius I mean the number of rings of hexagons around the central hexagon – the standard game board has a radius of 3). We will compute the maximum score simply by mimicking our previous analysis for the standard game board. If the board has radius n, then there are 6 + 12 + 18 + &#8230; + 6n = 3n(n+1) hexagons, each of which contains 6 paths. Thus there are 18n(n+1) lengths of path, 3n(n+1)-1 of which are used in the first 3n(n+1)-1 moves of the game, and we want to add as many as possible of the remaining 15n(n+1)+1 lengths of path in the final move of the game. There are 12 path ends that touch the central hexagon and 12 + 24n path ends that touch the outer edge of the game board. Thus there are at least (12 + 12 + 24n)/2 &#8211; 1 = 11 + 12n unused paths on the game board.</p>
<p style="text-align: left;">Tallying the numbers up, we see that on the final move, we can add at most 15n(n+1)+1 &#8211; (11 + 12n) = 15n<sup>2</sup> + 3n &#8211; 10 length of path. If T(n) = n(n+1)/2 is the nth triangular number, then we see that it&#8217;s not possible to obtain more than 3n(n+1)-1 + T(15n<sup>2</sup> + 3n &#8211; 10) = (225/2)n<sup>4</sup> + 45n<sup>3</sup> &#8211; 135n<sup>2</sup> &#8211; (51/2)n + 44 points. In fact, this score is obtainable via the exact same construction as the optimal board in the n = 3 case – just extend the (counter)clockwise rotation of the path in the obvious way. Thus, the maximum score for a game of Entanglement on a board of radius n for n = 1, 2, 3, &#8230; is given by the sequence 41, 1613, 9080, 29462, 72479, &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.njohnston.ca/2011/01/the-maximum-score-in-the-game-entanglement-is-9080/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Further Variants of the &#8220;Look-and-Say&#8221; Sequence</title>
		<link>http://www.njohnston.ca/2011/01/further-variants-of-the-look-and-say-sequence/</link>
		<comments>http://www.njohnston.ca/2011/01/further-variants-of-the-look-and-say-sequence/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 09:52:42 +0000</pubDate>
		<dc:creator>Nathaniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Integer Sequences]]></category>
		<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.nathanieljohnston.com/?p=1347</guid>
		<description><![CDATA[In two previous posts, I explored Conway&#8217;s famous &#8220;look-and-say&#8221; sequence 1, 11, 21, 1211, 111221, 312211, &#8230;, obtained by repeatedly describing the sequence&#8217;s previous term, as well as a simple binary variant of the sequence. In this post I will use similar techniques to explore some further variations of the sequence – a version where [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.nathanieljohnston.com/2010/10/a-derivation-of-conways-degree-71-look-and-say-polynomial/">two</a> previous <a href="http://www.nathanieljohnston.com/2010/11/the-binary-look-and-say-sequence/">posts</a>, I explored Conway&#8217;s famous &#8220;look-and-say&#8221; sequence 1, 11, 21, 1211, 111221, 312211, &#8230;, obtained by repeatedly describing the sequence&#8217;s previous term, as well as a simple binary variant of the sequence. In this post I will use similar techniques to explore some further variations of the sequence – a version where each term in the sequence is read in ternary, and a related sequence where no digit larger than 2 may be used when describing its terms.</p>
<p>As with the regular look-and-say sequence, the way we will attack these sequences is by constructing a &#8220;periodic table&#8221; of elementary non-interacting subsequences that all terms in the sequence are made up of. Then standard recurrence relation techniques will allow us to determine the rate of growth of the length of the terms in the sequences as well as the limiting distribution of the different digits in the sequence.</p>
<h3>The Ternary Look-and-Say Sequence</h3>
<p>Since we have already looked at the regular (i.e., decimal) look-and-say sequence, which is equivalent to the base-4 version of the sequence since it never contains a digit of 4 or larger, and we have also looked at the binary version of the sequence, it makes sense to ask what happens in the intermediate case of the ternary (base-3) version of the sequence: 1, 11, 21, 1211, 111221, 1012211, &#8230; (see <a href="http://oeis.org/A001388">A001388</a>).</p>
<p>As always, we begin by listing the noninteracting subsequences that make this version of the sequence tick. Not surprisingly, it is more complicated than the corresponding table (of 10 subsequences) in the binary case, but not as complicated as the corresponding table (of 92 subsequences) in the decimal case.</p>
<table style="margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<th>#</th>
<th>Subsequence</th>
<th>Evolves Into</th>
</tr>
<tr>
<td><strong>1</strong></td>
<td>1</td>
<td>(3)</td>
</tr>
<tr>
<td><strong>2</strong></td>
<td>10</td>
<td>(5)</td>
</tr>
<tr>
<td><strong>3</strong></td>
<td>11</td>
<td>(19)</td>
</tr>
<tr>
<td><strong>4</strong></td>
<td>110</td>
<td>(21)</td>
</tr>
<tr>
<td><strong>5</strong></td>
<td>1110</td>
<td>(2)(4)</td>
</tr>
<tr>
<td><strong>6</strong></td>
<td>111210</td>
<td>(2)(8)</td>
</tr>
<tr>
<td><strong>7</strong></td>
<td>111221</td>
<td>(2)(16)</td>
</tr>
<tr>
<td><strong>8</strong></td>
<td>1121110</td>
<td>(22)(4)</td>
</tr>
<tr>
<td><strong>9</strong></td>
<td>112211</td>
<td>(23)</td>
</tr>
<tr>
<td><strong>10</strong></td>
<td>112221</td>
<td>(21)(20)</td>
</tr>
<tr>
<td><strong>11</strong></td>
<td>11222110</td>
<td>(21)(24)</td>
</tr>
<tr>
<td><strong>12</strong></td>
<td>1122211210</td>
<td>(21)(25)</td>
</tr>
<tr>
<td><strong>13</strong></td>
<td>1211</td>
<td>(7)</td>
</tr>
<tr>
<td><strong>14</strong></td>
<td>121110</td>
<td>(6)(4)</td>
</tr>
<tr>
<td><strong>15</strong></td>
<td>1221</td>
<td>(9)</td>
</tr>
<tr>
<td><strong>16</strong></td>
<td>12211</td>
<td>(10)</td>
</tr>
<tr>
<td><strong>17</strong></td>
<td>122110</td>
<td>(11)</td>
</tr>
<tr>
<td><strong>18</strong></td>
<td>1221121110</td>
<td>(12)(4)</td>
</tr>
<tr>
<td><strong>19</strong></td>
<td>21</td>
<td>(13)</td>
</tr>
<tr>
<td><strong>20</strong></td>
<td>211</td>
<td>(15)</td>
</tr>
<tr>
<td><strong>21</strong></td>
<td>2110</td>
<td>(17)</td>
</tr>
<tr>
<td><strong>22</strong></td>
<td>211210</td>
<td>(18)</td>
</tr>
<tr>
<td><strong>23</strong></td>
<td>212221</td>
<td>(14)(20)</td>
</tr>
<tr>
<td><strong>24</strong></td>
<td>22110</td>
<td>(26)</td>
</tr>
<tr>
<td><strong>25</strong></td>
<td>221121110</td>
<td>(27)(4)</td>
</tr>
<tr>
<td><strong>26</strong></td>
<td>222110</td>
<td>(2)(24)</td>
</tr>
<tr>
<td><strong>27</strong></td>
<td>22211210</td>
<td>(2)(25)</td>
</tr>
</tbody>
</table>
<p>The (27×27) transition matrix for this evolution rule is included in the text file at the end of this post. Its characteristic polynomial is</p>
<p><img class="aligncenter size-full wp-image-1363" title="Ternary Characteristic Polynomial" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/01/char.gif" alt="" width="412" height="20" /></p>
<p>The maximal eigenvalue of the transition matrix is thus the largest root of x<sup>3</sup> &#8211; x &#8211; 1, which is approximately 1.324718. It follows that the number of digits in the terms of this sequence grows on average by about 32.5% from one term to the next.</p>
<h3>The Look-and-Say Sequence with Digits 1 and 2</h3>
<p>Closely related to the ternary version of the sequence is the sequence obtained by reading the previous term in the sequence, but with the restriction that you can never use a number larger than 2 (see <a href="http://oeis.org/A110393">A110393</a>). This sequence begins 1, 11, 21, 1211, 111221, 21112211, &#8230;, and the sixth term is obtained by reading the fifth term as &#8220;two ones, one one, two twos, one one&#8221;. Because only two different digits appear in this sequence, it is perhaps not surprising that its table of noninteracting subsequences is quite simple:</p>
<table style="margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<th>#</th>
<th>Subsequence</th>
<th>Evolves Into</th>
</tr>
<tr>
<td><strong>1</strong></td>
<td>1</td>
<td>(2)</td>
</tr>
<tr>
<td><strong>2</strong></td>
<td>11</td>
<td>(5)</td>
</tr>
<tr>
<td><strong>3</strong></td>
<td>111</td>
<td>(7)</td>
</tr>
<tr>
<td><strong>4</strong></td>
<td>1211</td>
<td>(3)(6)(1)</td>
</tr>
<tr>
<td><strong>5</strong></td>
<td>21</td>
<td>(4)</td>
</tr>
<tr>
<td><strong>6</strong></td>
<td>22</td>
<td>(6)</td>
</tr>
<tr>
<td><strong>7</strong></td>
<td>2111</td>
<td>(1)(6)(3)</td>
</tr>
</tbody>
</table>
<p>The transition matrix associated with this evolution rule is</p>
<p><img class="aligncenter size-full wp-image-1349" title="One Two Transition Matrix" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/01/onetwo.gif" alt="" width="262" height="154" /></p>
<p>As before, the average rate of growth of the number of digits in the terms of this sequence is determined by the magnitude of the largest eigenvalue of this matrix. A simple calculation reveals that this eigenvalue is √φ = 1.272&#8230;, where φ = (1 + √5)/2 is the <a href="http://en.wikipedia.org/wiki/Golden_ratio">golden ratio</a>. Furthermore, we can answer the question of how many 1s there are in the terms of this sequence compared to 2s by looking at the eigenvector corresponding to the maximal eigenvalue:</p>
<p><img class="aligncenter size-full wp-image-1352" title="OneTwo Eigenvector" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/01/eig.gif" alt="" width="187" height="155" /></p>
<p>What this means is, for example, that the second elementary subsequence (11) occurs φ times as frequently as the fourth elementary subsequence (1211). By weighting the subsequences by the entries in this vector appropriately, we can calculate the limiting ratio of the number of ones to the number of twos as</p>
<p><img class="aligncenter size-full wp-image-1374" title="OneTwo Ratio" src="http://www.nathanieljohnston.com/wp-content/uploads/2011/01/ratio2.gif" alt="" width="277" height="47" /></p>
<p><strong>Download:</strong> <a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/01/TransitionMatrices.txt"></a><a href="http://www.nathanieljohnston.com/wp-content/uploads/2011/01/TransitionMatrices1.txt">Transition matrices</a> [plaintext file]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.njohnston.ca/2011/01/further-variants-of-the-look-and-say-sequence/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Binary &#8220;Look-and-Say&#8221; Sequence</title>
		<link>http://www.njohnston.ca/2010/11/the-binary-look-and-say-sequence/</link>
		<comments>http://www.njohnston.ca/2010/11/the-binary-look-and-say-sequence/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 22:00:10 +0000</pubDate>
		<dc:creator>Nathaniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Integer Sequences]]></category>
		<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.nathanieljohnston.com/?p=1278</guid>
		<description><![CDATA[The look-and-say sequence (which I talked about here) is the sequence that you get by starting with the number 1 and constructing the next term in the sequence by &#8220;reading&#8221; the previous term. So 1 becomes &#8220;one one&#8221;, or 11. That becomes &#8220;two ones&#8221;, or 21. That becomes &#8220;one two, one one&#8221;, or 1211, and [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/Look-and-say_sequence">look-and-say sequence</a> (which I talked about <a href="http://www.nathanieljohnston.com/2010/10/a-derivation-of-conways-degree-71-look-and-say-polynomial/">here</a>) is the sequence that you get by starting with the number 1 and constructing the next term in the sequence by &#8220;reading&#8221; the previous term. So 1 becomes &#8220;one one&#8221;, or 11. That becomes &#8220;two ones&#8221;, or 21. That becomes &#8220;one two, one one&#8221;, or 1211, and so on.</p>
<p>In this post, I am going to investigate the related <a href="http://www.research.att.com/~njas/sequences/A001387">binary version of the sequence</a>, which starts off 1, 11 much like the regular sequence. But then when reading 11, we read it as &#8220;two ones&#8221;. Since two in binary is 10, the next term in the sequence is 101. When reading that term, we read it as &#8220;one one, one zero, one one&#8221;, so the next term is 111011. That term is read as &#8220;three ones, one zero, two ones&#8221;, and since three is 11 in binary and two is 10 in binary, the next term is 11110101, and so on. In this post we will answer two questions in particular about this sequence:</p>
<p>1) On average, how much longer is the (n+1)<sup>th</sup> term in the sequence than the n<sup>th</sup> term in the sequence?</p>
<p>2) On average, what is the ratio of the number of ones to the number of zeroes in the sequence?</p>
<h3>Non-Interacting Subsequences</h3>
<p>Much like the regular look-and-say sequence, we are able to study this sequence by constructing a &#8220;basis&#8221; of non-interacting subsequences that every term in the binary look-and-say sequence is made up of. Fortunately, constructing such a family of subsequences for the binary version of the look-and-say sequence is much simpler than it is for the decimal version of the sequence – here we only need ten different basic subsequences (whereas we needed <a href="http://mathworld.wolfram.com/CosmologicalTheorem.html">92 different subsequences</a> for the regular look-and-say sequence!). These ten subsequences, and the subsequences they evolve into, are summarized in the following table.</p>
<table style="margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<th>#</th>
<th>Subsequence</th>
<th>Evolves Into</th>
</tr>
<tr>
<td><strong>1</strong></td>
<td>1</td>
<td>(2)</td>
</tr>
<tr>
<td><strong>2</strong></td>
<td>11</td>
<td>(3)(1)</td>
</tr>
<tr>
<td><strong>3</strong></td>
<td>10</td>
<td>(5)</td>
</tr>
<tr>
<td><strong>4</strong></td>
<td>110</td>
<td>(3)(4)</td>
</tr>
<tr>
<td><strong>5</strong></td>
<td>1110</td>
<td>(6)</td>
</tr>
<tr>
<td><strong>6</strong></td>
<td>11110</td>
<td>(7)(4)</td>
</tr>
<tr>
<td><strong>7</strong></td>
<td>100</td>
<td>(9)</td>
</tr>
<tr>
<td><strong>8</strong></td>
<td>1100</td>
<td>(3)(8)</td>
</tr>
<tr>
<td><strong>9</strong></td>
<td>11100</td>
<td>(10)</td>
</tr>
<tr>
<td><strong>10</strong></td>
<td>111100</td>
<td>(7)(8)</td>
</tr>
</tbody>
</table>
<p>So for example, the first term in the sequence, 1, evolves into the subsequence (2), which is 11. That term then evolves into subsequence (3) followed by subsequence (1), or 101. That term then evolves into the subsequence (5) followed by the subsequence (2), or 111011, and so on. The reason that this representation of the sequence is useful is we can use it to describe the evolution of the binary look-and-say sequence entirely within a matrix T. In particular, we let T be the matrix with 1 in its (i,j) entry if the subsequence (i) appears in the evolution rule for subsequence (j), and 0 in its (i,j) entry otherwise:</p>
<p><img class="aligncenter size-full wp-image-1282" title="Transition Matrix" src="http://www.nathanieljohnston.com/wp-content/uploads/2010/11/1.gif" alt="" width="285" height="222" /></p>
<p>Now if <strong>v</strong> is a 10-dimensional vector whose ith entry indicates how many times the subsequence (i) appears in a particular term of the binary look-and-say sequence, it follows that the entries of T<strong>v</strong> tell us how many times each subsequence appears in the <em>next </em>term of the binary look-and-say sequence. So it follows from standard theory of linear homogeneous <a href="http://en.wikipedia.org/wiki/Recurrence_relation">recurrence relations</a> that we can now read off all of the long-term behaviour of the binary look-and-say sequence from the eigenvalues and eigenvectors of T.</p>
<h3>Rate of Growth of the Sequence</h3>
<p>The asymptotic rate of growth of the number of digits in the terms of the binary look-and-say sequence is simply the magnitude of the largest eigenvalue of the transition matrix T above. Using Maple it is simple to derive this value. If L<sub>n</sub> is the number of digits in the n<sup>th</sup> term of the binary look-and-say sequence, then</p>
<p><img class="aligncenter size-full wp-image-1294" title="Asymptotic Growth Rate" src="http://www.nathanieljohnston.com/wp-content/uploads/2010/11/dfsfdssdfsdf.gif" alt="" width="428" height="43" /></p>
<p>This limit is approximately 1.465571, which means that the binary version of this sequence grows much faster than the decimal version of the sequence (recall that the growth rate of the number of digits of the regular look and say sequence is approximately 1.303577). This limit is also the unique real root of the cubic x<sup>3</sup> &#8211; x<sup>2</sup> &#8211; 1, which follows from the fact that the <a href="http://en.wikipedia.org/wiki/Characteristic_polynomial">characteristic polynomial</a> of T is</p>
<p><img class="aligncenter size-full wp-image-1284" title="Characteristic Polynomial" src="http://www.nathanieljohnston.com/wp-content/uploads/2010/11/3.gif" alt="" width="258" height="25" /></p>
<h3>Ratio of Number of Ones to Zeroes</h3>
<p>If we let N<sub>n</sub> denote the number of ones in the n<sup>th</sup> term of the binary look-and-say sequence, and if we let Z<sub>n</sub> denote the number of zeroes in the n<sup>th</sup> term of the sequence, what is</p>
<p><sub><img class="aligncenter size-full wp-image-1285" title="Limiting Ratio" src="http://www.nathanieljohnston.com/wp-content/uploads/2010/11/11.gif" alt="" width="74" height="41" /></sub></p>
<p>In other words, what is the average ratio of ones to zeroes in this sequence? The following table shows the value of N<sub>n</sub>/Z<sub>n</sub> for n = 3, 4, &#8230;, 25, which might give some intuition to the problem:</p>
<table style="margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<th>n</th>
<th>N<sub>n</sub>/Z<sub>n</sub></th>
</tr>
<tr>
<td><strong>3</strong></td>
<td>2.000</td>
</tr>
<tr>
<td><strong>4</strong></td>
<td>5.000</td>
</tr>
<tr>
<td><strong>5</strong></td>
<td>3.000</td>
</tr>
<tr>
<td><strong>6</strong></td>
<td>2.000</td>
</tr>
<tr>
<td><strong>7</strong></td>
<td>2.000</td>
</tr>
<tr>
<td><strong>8</strong></td>
<td>2.000</td>
</tr>
<tr>
<td><strong>9</strong></td>
<td>1.786</td>
</tr>
<tr>
<td><strong>10</strong></td>
<td>1.762</td>
</tr>
<tr>
<td><strong>11</strong></td>
<td>1.742</td>
</tr>
<tr>
<td><strong>12</strong></td>
<td>1.717</td>
</tr>
<tr>
<td><strong>13</strong></td>
<td>1.691</td>
</tr>
<tr>
<td><strong>14</strong></td>
<td>1.690</td>
</tr>
<tr>
<td><strong>15</strong></td>
<td>1.680</td>
</tr>
<tr>
<td><strong>16</strong></td>
<td>1.676</td>
</tr>
<tr>
<td><strong>17</strong></td>
<td>1.672</td>
</tr>
<tr>
<td><strong>18</strong></td>
<td>1.671</td>
</tr>
<tr>
<td><strong>19</strong></td>
<td>1.669</td>
</tr>
<tr>
<td><strong>20</strong></td>
<td>1.668</td>
</tr>
<tr>
<td><strong>21</strong></td>
<td>1.667</td>
</tr>
<tr>
<td><strong>22</strong></td>
<td>1.667</td>
</tr>
<tr>
<td><strong>23</strong></td>
<td>1.666</td>
</tr>
<tr>
<td><strong>24</strong></td>
<td>1.666</td>
</tr>
<tr>
<td><strong>25</strong></td>
<td>1.666</td>
</tr>
</tbody>
</table>
<p>Based on numerical estimates like those given in the table above, <a href="http://numeratus.net/enlightened/bls.html">it has been conjectured</a> that the limiting ratio is 5/3 (or some nearby value). We will now show that the limit does indeed exist, but its value is <em>not</em> 5/3 &#8212; it just happens to be really close to 5/3.</p>
<p>Much like the maximal eigenvalue of T tells us the overall growth rate of the sequence, the corresponding eigenvector tells us the distribution of the different subsequences that are present in the limit. Once we know the distribution of the individual subsequences, it is not difficult to find out the overall ratio of ones to zeroes by weighing the different subsequences appropriately. So our first step is to find the eigenvector corresponding to the maximal eigenvalue. To this end, it will be convenient to let</p>
<p><img class="aligncenter size-full wp-image-1289" title="Alpha Beta" src="http://www.nathanieljohnston.com/wp-content/uploads/2010/11/fred.png" alt="" width="163" height="80" /></p>
<p>α is the same as in the previous section, and β is exactly the growth rate limit that we computed. Then the eigenvector corresponding to the maximal eigenvalue of T is:</p>
<p><img class="aligncenter size-full wp-image-1290" title="Maximal Eigenvector" src="http://www.nathanieljohnston.com/wp-content/uploads/2010/11/eig.gif" alt="" width="80" height="222" /></p>
<p>What this means is that, in the limit, the fifth subsequence, 1110, is β times as frequently-occurring as the sixth subsequence, 11110 (for example). Now we just weigh each subsequence according to how many zeros and ones they contain, and we find the limiting ratio of ones to zeroes is</p>
<p><img class="aligncenter size-full wp-image-1293" title="Ones to Zeroes Ratio" src="http://www.nathanieljohnston.com/wp-content/uploads/2010/11/goog.gif" alt="" width="392" height="39" /></p>
<p>In particular, this ratio does <em>not </em>equal 5/3, but rather its decimal expansion begins 1.6657272222676&#8230; (which is less than 1/1000 away from 5/3).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.njohnston.ca/2010/11/the-binary-look-and-say-sequence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Derivation of Conway&#8217;s Degree-71 &#8220;Look-and-Say&#8221; Polynomial</title>
		<link>http://www.njohnston.ca/2010/10/a-derivation-of-conways-degree-71-look-and-say-polynomial/</link>
		<comments>http://www.njohnston.ca/2010/10/a-derivation-of-conways-degree-71-look-and-say-polynomial/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 02:05:49 +0000</pubDate>
		<dc:creator>Nathaniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Integer Sequences]]></category>
		<category><![CDATA[Math]]></category>

		<guid isPermaLink="false">http://www.nathanieljohnston.com/?p=1230</guid>
		<description><![CDATA[The look-and-say sequence is the sequence of numbers 1, 11, 21, 1211, 111221, 312211, &#8230;, in which each term is constructed by &#8220;reading&#8221; the previous term in the sequence. For example, the term 1 is read as &#8220;one 1&#8243;, which becomes the next term: 11. Then 11 is read as &#8220;two ones&#8221;, which becomes the [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/Look-and-say_sequence">look-and-say sequence</a> is the sequence of numbers 1, 11, 21, 1211, 111221, 312211, &#8230;, in which each term is constructed by &#8220;reading&#8221; the previous term in the sequence. For example, the term 1 is read as &#8220;one 1&#8243;, which becomes the next term: 11. Then 11 is read as &#8220;two ones&#8221;, which becomes the next term: 21, and so on.</p>
<p>The remarkable thing about this sequence is that even though it seems at first glance to be quite arbitrary and non-mathematical, it has some interesting properties that were unearthed by John Conway. Most notably, he showed that the number of digits in each term of the sequence on average grows by about 30% from one term to the next. A bit more specifically, he showed that if L<sub>n</sub> is the number of digits in the n<sup>th</sup> term in the sequence, then</p>
<p><img class="aligncenter size-full wp-image-1232" title="30% growth" src="http://www.nathanieljohnston.com/wp-content/uploads/2010/10/lambda.gif" alt="" width="269" height="41" /></p>
<p>where λ is the unique positive real root of the following degree-71 polynomial:</p>
<p><img class="aligncenter size-full wp-image-1234" title="Degree-71 Polynomial" src="http://www.nathanieljohnston.com/wp-content/uploads/2010/10/poly1.gif" alt="" width="595" height="129" /></p>
<p>In order to demystify this seemingly bizarre fact, in this post we will show where this polynomial comes from and prove that the above limit does indeed equal its largest root (which happens to be its one and only positive real root).</p>
<h3>The Cosmological Theorem</h3>
<p>What lets us formally study the look-and-say sequence is a rather ominous-sounding result known as the <a href="http://mathworld.wolfram.com/CosmologicalTheorem.html">cosmological theorem</a>, which says that the eighth term and every term after it in the sequence is made up of one or more of 92 &#8220;basic&#8221; non-interacting subsequences. These 92 basic subsequences are summarized in lexicographical order in the following table. The fourth column in the table says what other subsequence(s) the given subsequence evolves into. For example, the first subsequence, 1112, evolves into the 63rd subsequence: 3112. Similarly, the second subsequence, 1112133, evolves into the 64th subsequence followed by the 62nd subsequence: 31121123.</p>
<table style="margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<th>#</th>
<th>Subsequence</th>
<th>Length</th>
<th>Evolves Into</th>
</tr>
<tr>
<td><strong>1</strong></td>
<td>1112</td>
<td>4</td>
<td>(63)</td>
</tr>
<tr>
<td><strong>2</strong></td>
<td>1112133</td>
<td>7</td>
<td>(64)(62)</td>
</tr>
<tr>
<td><strong>3</strong></td>
<td>111213322112</td>
<td>12</td>
<td>(65)</td>
</tr>
<tr>
<td><strong>4</strong></td>
<td>111213322113</td>
<td>12</td>
<td>(66)</td>
</tr>
<tr>
<td><strong>5</strong></td>
<td>1113</td>
<td>4</td>
<td>(68)</td>
</tr>
<tr>
<td><strong>6</strong></td>
<td>11131</td>
<td>5</td>
<td>(69)</td>
</tr>
<tr>
<td><strong>7</strong></td>
<td>111311222112</td>
<td>12</td>
<td>(84)(55)</td>
</tr>
<tr>
<td><strong>8</strong></td>
<td>111312</td>
<td>6</td>
<td>(70)</td>
</tr>
<tr>
<td><strong>9</strong></td>
<td>11131221</td>
<td>8</td>
<td>(71)</td>
</tr>
<tr>
<td><strong>10</strong></td>
<td>1113122112</td>
<td>10</td>
<td>(76)</td>
</tr>
<tr>
<td><strong>11</strong></td>
<td>1113122113</td>
<td>10</td>
<td>(77)</td>
</tr>
<tr>
<td><strong>12</strong></td>
<td>11131221131112</td>
<td>14</td>
<td>(82)</td>
</tr>
<tr>
<td><strong>13</strong></td>
<td>111312211312</td>
<td>12</td>
<td>(78)</td>
</tr>
<tr>
<td><strong>14</strong></td>
<td>11131221131211</td>
<td>14</td>
<td>(79)</td>
</tr>
<tr>
<td><strong>15</strong></td>
<td>111312211312113211</td>
<td>18</td>
<td>(80)</td>
</tr>
<tr>
<td><strong>16</strong></td>
<td>111312211312113221133211322112211213322112</td>
<td>42</td>
<td>(81)(29)(91)</td>
</tr>
<tr>
<td><strong>17</strong></td>
<td>111312211312113221133211322112211213322113</td>
<td>42</td>
<td>(81)(29)(90)</td>
</tr>
<tr>
<td><strong>18</strong></td>
<td>11131221131211322113322112</td>
<td>26</td>
<td>(81)(30)</td>
</tr>
<tr>
<td><strong>19</strong></td>
<td>11131221133112</td>
<td>14</td>
<td>(75)(29)(92)</td>
</tr>
<tr>
<td><strong>20</strong></td>
<td>1113122113322113111221131221</td>
<td>28</td>
<td>(75)(32)</td>
</tr>
<tr>
<td><strong>21</strong></td>
<td>11131221222112</td>
<td>14</td>
<td>(72)</td>
</tr>
<tr>
<td><strong>22</strong></td>
<td>111312212221121123222112</td>
<td>24</td>
<td>(73)</td>
</tr>
<tr>
<td><strong>23</strong></td>
<td>111312212221121123222113</td>
<td>24</td>
<td>(74)</td>
</tr>
<tr>
<td><strong>24</strong></td>
<td>11132</td>
<td>5</td>
<td>(83)</td>
</tr>
<tr>
<td><strong>25</strong></td>
<td>1113222</td>
<td>7</td>
<td>(86)</td>
</tr>
<tr>
<td><strong>26</strong></td>
<td>1113222112</td>
<td>10</td>
<td>(87)</td>
</tr>
<tr>
<td><strong>27</strong></td>
<td>1113222113</td>
<td>10</td>
<td>(88)</td>
</tr>
<tr>
<td><strong>28</strong></td>
<td>11133112</td>
<td>8</td>
<td>(89)(92)</td>
</tr>
<tr>
<td><strong>29</strong></td>
<td>12</td>
<td>2</td>
<td>(1)</td>
</tr>
<tr>
<td><strong>30</strong></td>
<td>123222112</td>
<td>9</td>
<td>(3)</td>
</tr>
<tr>
<td><strong>31</strong></td>
<td>123222113</td>
<td>9</td>
<td>(4)</td>
</tr>
<tr>
<td><strong>32</strong></td>
<td>12322211331222113112211</td>
<td>23</td>
<td>(2)(61)(29)(85)</td>
</tr>
<tr>
<td><strong>33</strong></td>
<td>13</td>
<td>2</td>
<td>(5)</td>
</tr>
<tr>
<td><strong>34</strong></td>
<td>131112</td>
<td>6</td>
<td>(28)</td>
</tr>
<tr>
<td><strong>35</strong></td>
<td>13112221133211322112211213322112</td>
<td>32</td>
<td>(24)(33)(61)(29)(91)</td>
</tr>
<tr>
<td><strong>36</strong></td>
<td>13112221133211322112211213322113</td>
<td>32</td>
<td>(24)(33)(61)(29)(90)</td>
</tr>
<tr>
<td><strong>37</strong></td>
<td>13122112</td>
<td>8</td>
<td>(7)</td>
</tr>
<tr>
<td><strong>38</strong></td>
<td>132</td>
<td>3</td>
<td>(8)</td>
</tr>
<tr>
<td><strong>39</strong></td>
<td>13211</td>
<td>5</td>
<td>(9)</td>
</tr>
<tr>
<td><strong>40</strong></td>
<td>132112</td>
<td>6</td>
<td>(10)</td>
</tr>
<tr>
<td><strong>41</strong></td>
<td>1321122112</td>
<td>10</td>
<td>(21)</td>
</tr>
<tr>
<td><strong>42</strong></td>
<td>132112211213322112</td>
<td>18</td>
<td>(22)</td>
</tr>
<tr>
<td><strong>43</strong></td>
<td>132112211213322113</td>
<td>18</td>
<td>(23)</td>
</tr>
<tr>
<td><strong>44</strong></td>
<td>132113</td>
<td>6</td>
<td>(11)</td>
</tr>
<tr>
<td><strong>45</strong></td>
<td>1321131112</td>
<td>10</td>
<td>(19)</td>
</tr>
<tr>
<td><strong>46</strong></td>
<td>13211312</td>
<td>8</td>
<td>(12)</td>
</tr>
<tr>
<td><strong>47</strong></td>
<td>1321132</td>
<td>7</td>
<td>(13)</td>
</tr>
<tr>
<td><strong>48</strong></td>
<td>13211321</td>
<td>8</td>
<td>(14)</td>
</tr>
<tr>
<td><strong>49</strong></td>
<td>132113212221</td>
<td>12</td>
<td>(15)</td>
</tr>
<tr>
<td><strong>50</strong></td>
<td>13211321222113222112</td>
<td>20</td>
<td>(18)</td>
</tr>
<tr>
<td><strong>51</strong></td>
<td>1321132122211322212221121123222112</td>
<td>34</td>
<td>(16)</td>
</tr>
<tr>
<td><strong>52</strong></td>
<td>1321132122211322212221121123222113</td>
<td>34</td>
<td>(17)</td>
</tr>
<tr>
<td><strong>53</strong></td>
<td>13211322211312113211</td>
<td>20</td>
<td>(20)</td>
</tr>
<tr>
<td><strong>54</strong></td>
<td>1321133112</td>
<td>10</td>
<td>(6)(61)(29)(92)</td>
</tr>
<tr>
<td><strong>55</strong></td>
<td>1322112</td>
<td>7</td>
<td>(26)</td>
</tr>
<tr>
<td><strong>56</strong></td>
<td>1322113</td>
<td>7</td>
<td>(27)</td>
</tr>
<tr>
<td><strong>57</strong></td>
<td>13221133112</td>
<td>11</td>
<td>(25)(29)(92)</td>
</tr>
<tr>
<td><strong>58</strong></td>
<td>1322113312211</td>
<td>13</td>
<td>(25)(29)(67)</td>
</tr>
<tr>
<td><strong>59</strong></td>
<td>132211331222113112211</td>
<td>21</td>
<td>(25)(29)(85)</td>
</tr>
<tr>
<td><strong>60</strong></td>
<td>13221133122211332</td>
<td>17</td>
<td>(25)(29)(68)(61)(29)(89)</td>
</tr>
<tr>
<td><strong>61</strong></td>
<td>22</td>
<td>2</td>
<td>(61)</td>
</tr>
<tr>
<td><strong>62</strong></td>
<td>3</td>
<td>1</td>
<td>(33)</td>
</tr>
<tr>
<td><strong>63</strong></td>
<td>3112</td>
<td>4</td>
<td>(40)</td>
</tr>
<tr>
<td><strong>64</strong></td>
<td>3112112</td>
<td>7</td>
<td>(41)</td>
</tr>
<tr>
<td><strong>65</strong></td>
<td>31121123222112</td>
<td>14</td>
<td>(42)</td>
</tr>
<tr>
<td><strong>66</strong></td>
<td>31121123222113</td>
<td>14</td>
<td>(43)</td>
</tr>
<tr>
<td><strong>67</strong></td>
<td>3112221</td>
<td>7</td>
<td>(38)(39)</td>
</tr>
<tr>
<td><strong>68</strong></td>
<td>3113</td>
<td>4</td>
<td>(44)</td>
</tr>
<tr>
<td><strong>69</strong></td>
<td>311311</td>
<td>6</td>
<td>(48)</td>
</tr>
<tr>
<td><strong>70</strong></td>
<td>31131112</td>
<td>8</td>
<td>(54)</td>
</tr>
<tr>
<td><strong>71</strong></td>
<td>3113112211</td>
<td>10</td>
<td>(49)</td>
</tr>
<tr>
<td><strong>72</strong></td>
<td>3113112211322112</td>
<td>16</td>
<td>(50)</td>
</tr>
<tr>
<td><strong>73</strong></td>
<td>3113112211322112211213322112</td>
<td>28</td>
<td>(51)</td>
</tr>
<tr>
<td><strong>74</strong></td>
<td>3113112211322112211213322113</td>
<td>28</td>
<td>(52)</td>
</tr>
<tr>
<td><strong>75</strong></td>
<td>311311222</td>
<td>9</td>
<td>(47)(38)</td>
</tr>
<tr>
<td><strong>76</strong></td>
<td>311311222112</td>
<td>12</td>
<td>(47)(55)</td>
</tr>
<tr>
<td><strong>77</strong></td>
<td>311311222113</td>
<td>12</td>
<td>(47)(56)</td>
</tr>
<tr>
<td><strong>78</strong></td>
<td>3113112221131112</td>
<td>16</td>
<td>(47)(57)</td>
</tr>
<tr>
<td><strong>79</strong></td>
<td>311311222113111221</td>
<td>18</td>
<td>(47)(58)</td>
</tr>
<tr>
<td><strong>80</strong></td>
<td>311311222113111221131221</td>
<td>24</td>
<td>(47)(59)</td>
</tr>
<tr>
<td><strong>81</strong></td>
<td>31131122211311122113222</td>
<td>23</td>
<td>(47)(60)</td>
</tr>
<tr>
<td><strong>82</strong></td>
<td>3113112221133112</td>
<td>16</td>
<td>(47)(33)(61)(29)(92)</td>
</tr>
<tr>
<td><strong>83</strong></td>
<td>311312</td>
<td>6</td>
<td>(45)</td>
</tr>
<tr>
<td><strong>84</strong></td>
<td>31132</td>
<td>5</td>
<td>(46)</td>
</tr>
<tr>
<td><strong>85</strong></td>
<td>311322113212221</td>
<td>15</td>
<td>(53)</td>
</tr>
<tr>
<td><strong>86</strong></td>
<td>311332</td>
<td>6</td>
<td>(38)(29)(89)</td>
</tr>
<tr>
<td><strong>87</strong></td>
<td>3113322112</td>
<td>10</td>
<td>(38)(30)</td>
</tr>
<tr>
<td><strong>88</strong></td>
<td>3113322113</td>
<td>10</td>
<td>(38)(31)</td>
</tr>
<tr>
<td><strong>89</strong></td>
<td>312</td>
<td>3</td>
<td>(34)</td>
</tr>
<tr>
<td><strong>90</strong></td>
<td>312211322212221121123222113</td>
<td>27</td>
<td>(36)</td>
</tr>
<tr>
<td><strong>91</strong></td>
<td>312211322212221121123222122</td>
<td>27</td>
<td>(35)</td>
</tr>
<tr>
<td><strong>92</strong></td>
<td>32112</td>
<td>5</td>
<td>(37)</td>
</tr>
</tbody>
</table>
<p>The important thing about this particular basis of subsequences is that the evolution of any sequence made up of these subsequences is determined entirely by the evolution rule for the subsequences given in the final column of the above table. For example, the eighth term in the look-and-say sequence is 1113213211 = (24)(39). The subsequence (24) evolves into (83) and the subsequence (39) evolves into (9), so the ninth term in the look-and-say sequence is (83)(9), which is 31131211131221.</p>
<h3>Computing the Number of Digits in Sequences</h3>
<p>Since the evolution of every term in the look-and-say sequence after the eighth can be computed using the table above, we can easily compute the length of every term after the eighth as well. For example, the eighth term in the sequence evolves into (83)(9), so the number of digits of the ninth term in the sequence is 6 + 8 = 14. The subsequence (83) evolves into a subsequence with 10 digits, and (9) evolves into a subsequence with 10 digits, so the tenth term in the look-and-say sequence has 10 + 10 = 20 digits.</p>
<p>All of the information about how the lengths of the 92 subsequences change can be represented in a 92&#215;92 matrix T. In particular, the matrix T has its (i,j) entry equal to C<sub>ij</sub> × ℓ<sub>i</sub>/ℓ<sub>j</sub>, where C<sub>ij</sub> is the number of times subsequence (i) appears in the evolution rule for subsequence (j) and ℓ<sub>i</sub> is the length of subsequence (i). This matrix is represented in the following image – white squares represent zero entries in the matrix, and black squares represent the number 2, which is the largest value present in the matrix. Shades of grey represent non-zero numbers, with larger numbers being darker.</p>
<p><img class="aligncenter size-full wp-image-1242" title="Transition matrix" src="http://www.nathanieljohnston.com/wp-content/uploads/2010/10/matrix.png" alt="" width="365" height="365" /></p>
<p>Then if we represent a term in the look-and-say sequence as a vector <strong>v</strong> with its i<sup>th</sup> entry being c<sub>i</sub> × ℓ<sub>i</sub>, where c<sub>i</sub> is the number of times the subsequence (i) appears in that term, we find that the sum of the entries in <strong>v</strong> is the total length of that term of the look-and-say sequence. More important, however, is the fact that the sum of the entries in T<strong>v</strong> is the length of the next term in the look-and-say sequence. The sum of the entries in T<sup>2</sup><strong>v</strong> is the length of the <em>next</em> term in the look-and-say sequence, and so on. So we have found a degree-92 recurrence relation for the length of terms in the look-and-say sequence, and the corresponding transition matrix is T.</p>
<h3>Computing the Limit</h3>
<p>It is a basic fact of linear homogeneous <a href="http://en.wikipedia.org/wiki/Recurrence_relation">recurrence relations</a> that a closed-form solution to the recurrence relation can be written down in terms of the eigenvalues of the transition matrix (see the linked Wikipedia page for specifics). As a corollary of this, the limiting ratio of terms in the sequence is equal to the <a href="http://en.wikipedia.org/wiki/Spectral_radius">spectral radius</a> of the transition matrix. Fortunately, the transition matrix in this case is quite sparse, so its characteristic polynomial isn&#8217;t <em>too</em> difficult to compute:</p>
<p><img class="aligncenter size-full wp-image-1248" title="Characteristic Polynomial" src="http://www.nathanieljohnston.com/wp-content/uploads/2010/10/91poly.png" alt="" width="595" height="155" /></p>
<p>Indeed, the degree-71 polynomial that λ is a root of is one of the factors of the characteristic polynomial of the transition matrix T. All that remains to do is to get MATLAB to compute the largest root of that polynomial (i.e., the spectral radius of T):</p>
<pre>&gt;&gt; max(abs(eig(T)))

ans =
    1.303577269034287</pre>
<p>The matrix T is attached below for those who would like to play with it. Something fun to think about: what do the rational eigenvalues (-1, 0, and 1) of T represent?</p>
<p><strong>Download:</strong> <a href="http://www.nathanieljohnston.com/wp-content/uploads/2010/10/transition.txt">Transition matrix</a> [plaintext file]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.njohnston.ca/2010/10/a-derivation-of-conways-degree-71-look-and-say-polynomial/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Generating Sequences of Primes in Conway&#039;s Game of Life</title>
		<link>http://www.njohnston.ca/2009/08/generating-sequences-of-primes-in-conways-game-of-life/</link>
		<comments>http://www.njohnston.ca/2009/08/generating-sequences-of-primes-in-conways-game-of-life/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 12:00:11 +0000</pubDate>
		<dc:creator>Nathaniel</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Conway's Game of Life]]></category>
		<category><![CDATA[Integer Sequences]]></category>

		<guid isPermaLink="false">http://www.nathanieljohnston.com/?p=598</guid>
		<description><![CDATA[One of the most interesting patterns that has ever been constructed in Conway&#8217;s Game of Life is primer, a gun that fires lightweight spaceships that represent exactly the prime numbers. It was constructed by Dean Hickerson way back in 1991, yet arguably no pattern since then has been constructed that&#8217;s as interesting. It seems somewhat [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most interesting patterns that has ever been constructed in <a href="http://www.conwaylife.com/wiki/index.php?title=Conway's_Game_of_Life">Conway&#8217;s Game of Life</a> is <a href="http://www.conwaylife.com/wiki/index.php?title=Primer">primer</a>, a gun that fires <a href="http://www.conwaylife.com/wiki/index.php?title=Lightweight_spaceship">lightweight spaceships</a> that represent exactly the prime numbers. It was constructed by Dean Hickerson way back in 1991, yet arguably no pattern since then has been constructed that&#8217;s as interesting. It seems somewhat counter-intuitive at first that the prime numbers, which seem somehow &#8220;random&#8221; or &#8220;unpredictable&#8221;, can be generated by this (relatively simple) pattern in the completely deterministic Game of Life.</p>
<div id="attachment_632" class="wp-caption aligncenter" style="width: 479px"><a href="http://www.conwaylife.com/wiki/index.php?title=Primer"><img class="size-full wp-image-632    " title="Primer" src="http://njohns01home.webfactional.com/wp-content/uploads/2009/08/primer.png" alt="Primer, the prime-generating gun" width="469" height="324" /></a><p class="wp-caption-text">Primer, the prime-generating gun</p></div>
<p>The gun works by firing lightweight spaceships westward, and destroying them via glider guns that emulate the <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes">Sieve of Eratosthenes</a>. A lightweight spaceship makes it past the left edge of the gun at generation 120N if and only if N is a prime number (though for technical reasons, 2 and 3 are not outputted).</p>
<div id="attachment_633" class="wp-caption aligncenter" style="width: 539px"><a href="http://njohns01home.webfactional.com/wp-content/uploads/2009/08/output.png"><img class="size-full wp-image-633   " title="Primer output" src="http://njohns01home.webfactional.com/wp-content/uploads/2009/08/output.png" alt="The first six lightweight spaceships output by primer and the numbers they represent" width="529" height="27" /></a><p class="wp-caption-text">The first six lightweight spaceships output by primer</p></div>
<p>It wasn&#8217;t too long after making primer that Hickerson realized that he could attach a gun to the bottom-left corner of it to turn it into a <a href="http://en.wikipedia.org/wiki/Twin_prime">twin prime</a> calculator by allowing each lightweight spaceship through only if another lightweight spaceship passed through 240 generations earlier. Similarly, Jason Summers constructed a <a href="http://en.wikipedia.org/wiki/Fermat_number#Primality_of_Fermat_numbers">Fermat prime</a> calculator in 2000 by shooting a glider at the lightweight spaceship stream every generation of the form 120(2<sup>N</sup> + 1), which ends up detecting exactly the Fermat primes.</p>
<p>So what other families of primes can we compute in Life by altering the output of the original prime-generating gun?</p>
<h3>Mersenne Primes</h3>
<p><a href="http://en.wikipedia.org/wiki/Mersenne_prime">Mersenne primes</a> can easily be computed using the exact same method as was used in the Fermat prime calculator &#8212; use a <a href="http://www.conwaylife.com/wiki/index.php?title=7-engine_Cordership">7-engine Cordership</a> (in <span style="color: #0000ff;">blue</span> below) to bounce a <a href="http://www.conwaylife.com/wiki/index.php?title=Glider">glider</a> back at the stream of lightweight spaceships, with the time required for the glider to reach the stream doubling each time. An inverter (in <span style="color: #008000;">green</span> below) eliminates all lightweight spaceships that try to get past it <em>unless</em> it just received a glider from the Cordership. By fiddling around with timing a tiny bit, we then have a Mersenne prime calculator:</p>
<div id="attachment_636" class="wp-caption aligncenter" style="width: 600px"><img class="size-full wp-image-636  " title="Mersenne Prime Calculator" src="http://njohns01home.webfactional.com/wp-content/uploads/2009/08/mersenne.png" alt="Mersenne Prime Calculator" width="590" height="402" /><p class="wp-caption-text">Mersenne Prime Calculator</p></div>
<ul>
<li>Java link: <a href="http://www.conwaylife.com/?p=mersenneprimecalculator">here</a></li>
<li>RLE file: <a href="http://www.conwaylife.com/pattern.asp?p=mersenneprimecalculator.rle">here</a></li>
</ul>
<h3>Prime Quadruplets</h3>
<p>Four prime numbers are said to form a <a href="http://en.wikipedia.org/wiki/Prime_quadruplet">prime quadruplet</a> if they are of the form (p, p+2, p+6, p+8) for some prime number p, which is the closest that four prime numbers can be together (except for the degenerate cases of (2,3,5,7) and (3,5,7,11)). Prime quadruplets are easy to compute because they can be thought of as consecutive pairs of twin primes. Since we already have a twin prime calculator, we can just repeat its reaction.</p>
<p>The twin prime calculator works by attaching a period 240 gun (in <span style="color: #008000;">green</span> below) to the bottom-left corner of primer. If it is timed correctly, it has the effect of allowing a lightweight spaceship through at generation 240N if and only if a lightweight spaceship tried to pass through at generation 240(N-1). Thus, it will only allow a lightweight spaceship through if it represents a prime number of the form p+2, where p is another prime number. Well, simply attaching a period 720 gun (in <span style="color: #0000ff;">blue</span> below) then allows a spaceship through at generation 720N if and only if a lightweight spaceship tried to pass through at generation 720(N-1). This has the effect of allowing a lightweight spaceship to pass through only if it represents a twin prime pair (p,p+2), and there is another twin prime pair of the form (p-6,p-4). That is, the only lightweight spaceships allowed through are those representing the upper members of prime quadruplets.</p>
<div id="attachment_640" class="wp-caption aligncenter" style="width: 555px"><img class="size-full wp-image-640" title="Prime quadruplet calculator" src="http://njohns01home.webfactional.com/wp-content/uploads/2009/08/quad.png" alt="Prime quadruplet calculator" width="545" height="353" /><p class="wp-caption-text">Prime quadruplet calculator</p></div>
<ul>
<li>Java link: <a href="http://www.conwaylife.com/?p=primequadrupletcalculator">here</a></li>
<li>RLE file: <a href="http://www.conwaylife.com/pattern.asp?p=primequadrupletcalculator.rle">here</a></li>
</ul>
<h3>Prime Pairs of the Form (p, p+2k)</h3>
<p>The twin prime calculator mentioned earlier gives a way of computing prime pairs of the form (p,p+2), but what about pairs where the gap is larger than 2? For example, the k=2 case gives what are known as <a href="http://en.wikipedia.org/wiki/Cousin_prime">cousin primes</a>, and the k=3 case gives <a href="http://en.wikipedia.org/wiki/Sexy_primes">sexy primes</a> (yes, really).</p>
<p>For the case of cousin primes, the thing to notice is that every pair of cousin primes (except for the first pair, (3,7)) must be of the form (6n+1, 6n+5) for some natural number n. Thus, we can use two period 720 guns (in <span style="color: #0000ff;">blue</span> below) to allow only the upper prime in a cousin prime pair to pass through. This is achieved by having the top gun fire at the lightweight spaceships representing primes of the form 6n+1 &#8212; if a lightweight spaceship is hit, then a block is created in the path of the other gun, which is fired at lightweight spaceships representing primes of the form 6n+5. If a prime was present at 6n+1, then the lightweight spaceship makes it through unharmed at 6n+5. If there was no prime present at 6n+1, then the bottom gun destroys the lightweight spaceship representing 6n+5.</p>
<div id="attachment_643" class="wp-caption aligncenter" style="width: 493px"><img class="size-full wp-image-643" title="Cousin prime calculator" src="http://njohns01home.webfactional.com/wp-content/uploads/2009/08/cousin.png" alt="Cousin prime calculator" width="483" height="383" /><p class="wp-caption-text">Cousin prime calculator</p></div>
<ul>
<li>Java link: <a href="http://www.conwaylife.com/?p=cousinprimecalculator">here</a></li>
<li>RLE file: <a href="http://www.conwaylife.com/pattern.asp?p=cousinprimecalculator.rle">here</a></li>
</ul>
<p>Extending this idea to prime pairs of the form (p,p+2k) for k ≥ 3 is a bit more challenging, however, because it is possible for pairs to overlap. For example, (37,43) is a sexy prime pair, as is (41,47). Up until now we have only been able to detect single pairs at a time, since the block that acts as our &#8220;counter&#8221; that keeps track of whether a prime was detected earlier is placed in the stream of incoming lightweight spaceships. Thus, if it&#8217;s possible for two pairs to overlap, we will get lightweight spaceships colliding with the block, causing a mess.</p>
<p>To get around this problem, we use a device (known as a fanout, in <span style="color: #008000;">green</span> below) that duplicates the stream of lightweight spaceships. We then check for certain pairs on one stream, and the rest of the pairs on the other stream (these devices are outlined in <span style="color: #0000ff;">blue</span> below). Once we&#8217;re done, we merge the resulting streams of lightweight spaceships back together (using the devices in <span style="color: #800080;">purple</span> below).</p>
<p>To make this process a bit more explicit, I present a gun that computes prime pairs of the form (p,p+8). In particular, a lightweight spaceship will make it past the left edge of this pattern at about generation 1620+120N if and only if both N and N+8 are prime.</p>
<div id="attachment_645" class="wp-caption aligncenter" style="width: 600px"><a href="http://njohns01home.webfactional.com/wp-content/uploads/2009/08/pp8.png"><img class="size-full wp-image-645   " title="(p, p+8) prime calculator" src="http://njohns01home.webfactional.com/wp-content/uploads/2009/08/pp8.png" alt="(p, p+8) prime calculator" width="590" height="377" /></a><p class="wp-caption-text">(p, p+8) prime calculator</p></div>
<ul>
<li>Java link: <a href="http://www.conwaylife.com/?p=pp8primecalculator">here</a></li>
<li>RLE file: <a href="http://www.conwaylife.com/pattern.asp?p=pp8primecalculator.rle">here</a></li>
</ul>
<p>We now have all of the tools needed to build any pattern that computes prime pairs of the form (p, p+2k) as long as k = 1 or 2 (mod 3), though we may need to use the fanout device multiple times if it&#8217;s possible for more than one pair to overlap. If k = 0 (mod 3), however, it&#8217;s much more difficult to construct the desired pattern, because not only can you have overlapping prime pairs like (5, 11) and (7, 13), but you can have prime pairs in sequence such as (5, 11) and (11, 17). This problem can be remedied using the same tools as used in the (p,p+8) prime calculator, though you may need to use a <em>lot </em>of fanout devices to make things work. For example, computing the sexy primes using these tools would require at least four fanouts, and some clever elimination logic on each of the resulting five lightweight spaceship streams. I don&#8217;t feel up to that task myself, but it&#8217;s nice to know that we have a method for constructing a sexy prime calculator.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.njohnston.ca/2009/08/generating-sequences-of-primes-in-conways-game-of-life/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

