<?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>nklein software &#187; Articles</title>
	<atom:link href="http://nklein.com/articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://nklein.com</link>
	<description>software development and consulting</description>
	<lastBuildDate>Tue, 22 May 2012 03:48:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Visualizing Galois Fields (Follow-up)</title>
		<link>http://nklein.com/2012/05/visualizing-galois-fields-follow-up/</link>
		<comments>http://nklein.com/2012/05/visualizing-galois-fields-follow-up/#comments</comments>
		<pubDate>Tue, 22 May 2012 03:48:05 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Galois fields]]></category>
		<category><![CDATA[Let Over Lambda]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[zpng]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1872</guid>
		<description><![CDATA[In my previous article, I should have finished by remapping the multiplication and addition tables so that the multiplication table was in cyclic order. In cyclic order, the zeroth column (or row) represents zero and the -th column (or row) (for]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://nklein.com/2012/05/visualizing-galois-fields/">previous article</a>, I should have finished by remapping the multiplication and addition tables so that the multiplication table was in cyclic order.  In cyclic order, the zeroth column (or row) represents zero and the <img src="http://l.wordpress.com/latex.php?latex=%28i%2B1%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="(i+1)" style="vertical-align:-20%;" class="tex" alt="(i+1)" />-th column (or row) (for <img src="http://l.wordpress.com/latex.php?latex=i%20%3E%200&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="i > 0&#8243; style=&#8221;vertical-align:-20%;&#8221; class=&#8221;tex&#8221; alt=&#8221;i > 0&#8243; />) represents <img src="http://l.wordpress.com/latex.php?latex=a%5Ei&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^i" style="vertical-align:-20%;" class="tex" alt="a^i" /> for some generator <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" />.  As such, the multiplication table is simply <img src="http://l.wordpress.com/latex.php?latex=0&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="0" style="vertical-align:-20%;" class="tex" alt="0" /> in the zeroth row and column and <img src="http://l.wordpress.com/latex.php?latex=1%20%2B%20%28%28i%2Bj%29%20%5Cmod%20255%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="1 + ((i+j) \mod 255)" style="vertical-align:-20%;" class="tex" alt="1 + ((i+j) \mod 255)" /> for the spot <img src="http://l.wordpress.com/latex.php?latex=%28i%2B1%2Cj%2B1%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="(i+1,j+1)" style="vertical-align:-20%;" class="tex" alt="(i+1,j+1)" />.</p>
<p><center><a href="http://nklein.com/wp-content/uploads/2012/05/gf256m.png"><img src="http://nklein.com/wp-content/uploads/2012/05/gf256m.png" alt="" title="gf256m" width="256" height="256" class="aligncenter size-full wp-image-1873" /></a></center></p>
<p>Once resorted by the order of the powers of a generator <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" />, the multiplication table look the same regardless of the <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" />.  The addition, however, looks different for different generators.  Below are the addition tables for two of them: <img src="http://l.wordpress.com/latex.php?latex=a%20%3D%20%281%2Bx%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a = (1+x)" style="vertical-align:-20%;" class="tex" alt="a = (1+x)" /> on the right and <img src="http://l.wordpress.com/latex.php?latex=a%20%3D%20x%5E3%20%2B%20x%5E6%20%2B%20x%5E7&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a = x^3 + x^6 + x^7" style="vertical-align:-20%;" class="tex" alt="a = x^3 + x^6 + x^7" /> on the left.  They make as decent a stereo as any of the other pairs so far.</p>
<p><center><a href="http://nklein.com/wp-content/uploads/2012/05/gf256a.png"><img src="http://nklein.com/wp-content/uploads/2012/05/gf256a.png" alt="" title="gf256a-00000011" width="256" height="256" class="aligncenter size-full wp-image-1874" /></a> &nbsp; <a href="http://nklein.com/wp-content/uploads/2012/05/gf256a-200.png"><img src="http://nklein.com/wp-content/uploads/2012/05/gf256a-200.png" alt="" title="gf256a-11001000" width="256" height="256" class="aligncenter size-full wp-image-1875" /></a></center></p>
<p>Here&#8217;s the code that I used to generate the remapping for a given generator.</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> make-cyclic-remapping <span style="color: #66cc66;">&#40;</span>fn generator <span style="color: #66cc66;">&amp;</span>optional <span style="color: #66cc66;">&#40;</span>limit <span style="color: #cc66cc;">256</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>to <span style="color: #66cc66;">&#40;</span>make-<span style="color: #b1b100;">array</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> limit<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">initial-element</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>from <span style="color: #66cc66;">&#40;</span>make-<span style="color: #b1b100;">array</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> limit<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">initial-element</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>used <span style="color: #66cc66;">&#40;</span>make-hash-table <span style="color: #66cc66;">:</span><span style="color: #555;">test</span> #'<span style="color: #b1b100;">equal</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #808080; font-style: italic;">;; fill up the lookup tables</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setf</span> <span style="color: #66cc66;">&#40;</span>gethash <span style="color: #cc66cc;">0</span> used<span style="color: #66cc66;">&#41;</span> t<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>nlet fill-tables <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">exp</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>acc <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span> <span style="color: #b1b100;">exp</span> limit<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setf</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">aref</span> to <span style="color: #b1b100;">exp</span><span style="color: #66cc66;">&#41;</span> acc
              <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">aref</span> from acc<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">exp</span>
              <span style="color: #66cc66;">&#40;</span>gethash acc used<span style="color: #66cc66;">&#41;</span> t<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>fill-tables <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>+ <span style="color: #b1b100;">exp</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">funcall</span> fn acc generator<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #808080; font-style: italic;">;; return a closure around the lookup tables</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span>hash-table-count used<span style="color: #66cc66;">&#41;</span> limit<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>direction n<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>ecase direction
          <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">to</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">aref</span> to n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">from</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">aref</span> from n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>If you&#8217;ve read it, you can probably tell by my code that I&#8217;m still under the influence of <a href="http://letoverlambda.com/">Let Over Lambda</a>.  If you haven&#8217;t read it, it is quite worth the read.</p>
<p>Then, I used a modified version of the <code class="codecolorer lisp default"><span class="lisp">draw-heightmap</span></code> function which also takes in the remapping function.</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> draw-mapped-heightmap <span style="color: #66cc66;">&#40;</span>op map filename <span style="color: #66cc66;">&amp;</span>optional <span style="color: #66cc66;">&#40;</span>limit <span style="color: #cc66cc;">256</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>png <span style="color: #66cc66;">&#40;</span>make-instance 'zpng<span style="color: #66cc66;">:</span><span style="color: #555;">pixel-streamed-png</span>
                            <span style="color: #66cc66;">:</span><span style="color: #555;">color-type</span> <span style="color: #66cc66;">:</span><span style="color: #555;">grayscale</span>
                            <span style="color: #66cc66;">:</span><span style="color: #555;">width</span> limit
                            <span style="color: #66cc66;">:</span><span style="color: #555;">height</span> limit<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>with-open-file <span style="color: #66cc66;">&#40;</span>stream filename
                            <span style="color: #66cc66;">:</span><span style="color: #555;">direction</span> <span style="color: #66cc66;">:</span><span style="color: #555;">output</span>
                            <span style="color: #66cc66;">:</span><span style="color: #555;">if-does-not-exist</span> <span style="color: #66cc66;">:</span><span style="color: #555;">create</span>
                            <span style="color: #66cc66;">:</span><span style="color: #555;">element-type</span> '<span style="color: #66cc66;">&#40;</span>unsigned-byte <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>zpng<span style="color: #66cc66;">:</span><span style="color: #555;">start-png</span> png stream<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">dotimes</span> <span style="color: #66cc66;">&#40;</span>xx limit<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">dotimes</span> <span style="color: #66cc66;">&#40;</span>yy limit<span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span>* <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>a <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">funcall</span> map <span style="color: #66cc66;">:</span><span style="color: #555;">to</span> xx<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                 <span style="color: #66cc66;">&#40;</span>b <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">funcall</span> map <span style="color: #66cc66;">:</span><span style="color: #555;">to</span> yy<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                 <span style="color: #66cc66;">&#40;</span>c <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">funcall</span> map <span style="color: #66cc66;">:</span><span style="color: #555;">from</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">funcall</span> op a b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#40;</span>zpng<span style="color: #66cc66;">:</span><span style="color: #555;">write-pixel</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> c<span style="color: #66cc66;">&#41;</span> png<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>zpng<span style="color: #66cc66;">:</span><span style="color: #555;">finish-png</span> png<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>values<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2012/05/visualizing-galois-fields-follow-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualizing Galois Fields</title>
		<link>http://nklein.com/2012/05/visualizing-galois-fields/</link>
		<comments>http://nklein.com/2012/05/visualizing-galois-fields/#comments</comments>
		<pubDate>Fri, 18 May 2012 03:58:53 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Galois]]></category>
		<category><![CDATA[Galois fields]]></category>
		<category><![CDATA[group theory]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[vecto]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1819</guid>
		<description><![CDATA[Galois fields are used in a number of different ways. For example, the AES encryption standard uses them. Arithmetic in Galois Fields The Galois fields of size for various are convenient in computer applications because of how nicely they fit into bytes or words on the machine. The Galois field has elements. These elements are [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.lipwalklyrics.com/lyrics/728310-thekleinfour-stefanietheballadofgalois.html">Galois</a> fields are used in a number of different ways.  For example, the AES encryption standard uses them.</p>
<h3>Arithmetic in Galois Fields</h3>
<p>The Galois fields of size <img src="http://l.wordpress.com/latex.php?latex=2%5En&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="2^n" style="vertical-align:-20%;" class="tex" alt="2^n" /> for various <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_18a633fc025e2f1a862f7c8de3b31d6c.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" /> are convenient in computer applications because of how nicely they fit into bytes or words on the machine.  The Galois field <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" /> has <img src="http://l.wordpress.com/latex.php?latex=2%5En&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="2^n" style="vertical-align:-20%;" class="tex" alt="2^n" /> elements.  These elements are represented as polynomials of degree less than <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_18a633fc025e2f1a862f7c8de3b31d6c.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" /> with all coefficients either 0 or 1.  So, to encode an element of <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" /> as a number, you need an <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_18a633fc025e2f1a862f7c8de3b31d6c.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" />-bit binary number.</p>
<p>For example, let us consider the Galois field <img src="http://l.wordpress.com/latex.php?latex=GF%282%5E3%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^3)" style="vertical-align:-20%;" class="tex" alt="GF(2^3)" />.  It has <img src="http://l.wordpress.com/latex.php?latex=2%5E3%20%3D%208&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="2^3 = 8" style="vertical-align:-20%;" class="tex" alt="2^3 = 8" /> elements.  They are (as binary integers) <img src="http://l.wordpress.com/latex.php?latex=000&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="000" style="vertical-align:-20%;" class="tex" alt="000" />, <img src="http://l.wordpress.com/latex.php?latex=001&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="001" style="vertical-align:-20%;" class="tex" alt="001" />, <img src="http://l.wordpress.com/latex.php?latex=010&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="010" style="vertical-align:-20%;" class="tex" alt="010" />, <img src="http://l.wordpress.com/latex.php?latex=011&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="011" style="vertical-align:-20%;" class="tex" alt="011" />, <img src="http://l.wordpress.com/latex.php?latex=100&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="100" style="vertical-align:-20%;" class="tex" alt="100" />, <img src="http://l.wordpress.com/latex.php?latex=101&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="101" style="vertical-align:-20%;" class="tex" alt="101" />, <img src="http://l.wordpress.com/latex.php?latex=110&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="110" style="vertical-align:-20%;" class="tex" alt="110" />, and <img src="http://l.wordpress.com/latex.php?latex=111&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="111" style="vertical-align:-20%;" class="tex" alt="111" />.  The element <img src="http://l.wordpress.com/latex.php?latex=110&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="110" style="vertical-align:-20%;" class="tex" alt="110" />, for example, stands for the polynomial <img src="http://l.wordpress.com/latex.php?latex=x%5E2%20%2B%20x&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^2 + x" style="vertical-align:-20%;" class="tex" alt="x^2 + x" />.  The element <img src="http://l.wordpress.com/latex.php?latex=011&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="011" style="vertical-align:-20%;" class="tex" alt="011" /> stands for the polynomial <img src="http://l.wordpress.com/latex.php?latex=x%20%2B%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x + 1" style="vertical-align:-20%;" class="tex" alt="x + 1" />.</p>
<p>The coefficients add together just like the integers-modulo-2 add.  In group theory terms, the coefficients are from <img src="http://l.wordpress.com/latex.php?latex=%5Cmathbb%7BZ%7D%2F2%5Cmathbb%7BZ%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\mathbb{Z}/2\mathbb{Z}" style="vertical-align:-20%;" class="tex" alt="\mathbb{Z}/2\mathbb{Z}" />.  That means that <img src="http://l.wordpress.com/latex.php?latex=0%20%2B%200%20%3D%200&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="0 + 0 = 0" style="vertical-align:-20%;" class="tex" alt="0 + 0 = 0" />, <img src="http://l.wordpress.com/latex.php?latex=0%20%2B%201%20%3D%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="0 + 1 = 1" style="vertical-align:-20%;" class="tex" alt="0 + 1 = 1" />, <img src="http://l.wordpress.com/latex.php?latex=1%20%2B%200%20%3D%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="1 + 0 = 1" style="vertical-align:-20%;" class="tex" alt="1 + 0 = 1" />, and <img src="http://l.wordpress.com/latex.php?latex=1%20%2B%201%20%3D%200&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="1 + 1 = 0" style="vertical-align:-20%;" class="tex" alt="1 + 1 = 0" />.  In computer terms, <img src="http://l.wordpress.com/latex.php?latex=a%20%2B%20b&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a + b" style="vertical-align:-20%;" class="tex" alt="a + b" /> is simply <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> XOR <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_97f4a1ba736119e3cd4de6fca35efd6b.png" title="b" style="vertical-align:-20%;" class="tex" alt="b" />.  That means, to get the integer representation of the sum of two elements, we simply have to do the bitwise-XOR of their integer representations.  Every processor that I&#8217;ve ever seen has built-in instructions to do this.  Most computer languages support bitwise-XOR operations.  In Lisp, the bitwise-XOR of <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_97f4a1ba736119e3cd4de6fca35efd6b.png" title="b" style="vertical-align:-20%;" class="tex" alt="b" /> is <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">logxor</span> a b<span style="color: #66cc66;">&#41;</span></span></code>.</p>
<p>Multiplication is somewhat trickier.  Here, we have to multiply the polynomials together.  For example, <img src="http://l.wordpress.com/latex.php?latex=%28x%20%2B%201%29%20%5Ccdot%20x%20%3D%20x%5E2%20%2B%20x&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="(x + 1) \cdot x = x^2 + x" style="vertical-align:-20%;" class="tex" alt="(x + 1) \cdot x = x^2 + x" />.  But, if we did <img src="http://l.wordpress.com/latex.php?latex=%28x%5E2%20%2B%20x%29%20%5Ccdot%20x&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="(x^2 + x) \cdot x" style="vertical-align:-20%;" class="tex" alt="(x^2 + x) \cdot x" />, we&#8217;d end up with <img src="http://l.wordpress.com/latex.php?latex=x%5E3%20%2B%20x%5E2&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^3 + x^2" style="vertical-align:-20%;" class="tex" alt="x^3 + x^2" />.  We wanted everything to be polynomials of degree less than <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_18a633fc025e2f1a862f7c8de3b31d6c.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" /> and our <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_18a633fc025e2f1a862f7c8de3b31d6c.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" /> is 3.  So, what do we do?</p>
<p>What we do, is we take some polynomial of degree <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_18a633fc025e2f1a862f7c8de3b31d6c.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" /> that cannot be written as the product of two polynomials of less than degree <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_18a633fc025e2f1a862f7c8de3b31d6c.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" />.  For our example, let&#8217;s use <img src="http://l.wordpress.com/latex.php?latex=x%5E3%20%2B%20x%20%2B%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^3 + x + 1" style="vertical-align:-20%;" class="tex" alt="x^3 + x + 1" /> (which is <img src="http://l.wordpress.com/latex.php?latex=1011&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="1011" style="vertical-align:-20%;" class="tex" alt="1011" /> in our binary scheme).  Now, we need to take our products modulo this polynomial.</p>
<p>You may not have divided polynomials by other polynomials before.  It&#8217;s a perfectly possible thing to do.  When we divide a positive integer <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> by another positive integer <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_97f4a1ba736119e3cd4de6fca35efd6b.png" title="b" style="vertical-align:-20%;" class="tex" alt="b" /> (with <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_97f4a1ba736119e3cd4de6fca35efd6b.png" title="b" style="vertical-align:-20%;" class="tex" alt="b" /> bigger than 1), we get some answer strictly smaller than <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> with a remainder strictly smaller than <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_97f4a1ba736119e3cd4de6fca35efd6b.png" title="b" style="vertical-align:-20%;" class="tex" alt="b" />.  When we divide a polynomial of degree <img src="http://l.wordpress.com/latex.php?latex=m&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="m" style="vertical-align:-20%;" class="tex" alt="m" /> by a polynomial of degree <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_18a633fc025e2f1a862f7c8de3b31d6c.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" /> (with <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_18a633fc025e2f1a862f7c8de3b31d6c.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" /> greater than zero), we get an answer that is a polynomial of degree strictly less than <img src="http://l.wordpress.com/latex.php?latex=m&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="m" style="vertical-align:-20%;" class="tex" alt="m" /> and a remainder that is a polynomial of degree strictly less than <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_18a633fc025e2f1a862f7c8de3b31d6c.png" title="n" style="vertical-align:-20%;" class="tex" alt="n" />.</p>
<p>Dividing proceeds much as long division of integers does.  For example, if we take the polynomial (with integer coefficients) <img src="http://l.wordpress.com/latex.php?latex=x%5E3%20%2B%202x%20%2B%205&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^3 + 2x + 5" style="vertical-align:-20%;" class="tex" alt="x^3 + 2x + 5" /> and divide it by the polynomial <img src="http://l.wordpress.com/latex.php?latex=x%20%2B%203&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x + 3" style="vertical-align:-20%;" class="tex" alt="x + 3" />, we start by writing it as:</p>
<p><center><img src="http://l.wordpress.com/latex.php?latex=x%20%2B%203%20%5Coverline%7B%5Cleft%29%20x%5E3%20%2B%200x%5E2%20%2B%202x%20%2B%205%5Cright.%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x + 3 \overline{\left) x^3 + 0x^2 + 2x + 5\right.}" style="vertical-align:-20%;" class="tex" alt="x + 3 \overline{\left) x^3 + 0x^2 + 2x + 5\right.}" /></center></p>
<p>We notice that to get <img src="http://l.wordpress.com/latex.php?latex=%28x%2B3%29%20%5Ccdot%20q%28x%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="(x+3) \cdot q(x)" style="vertical-align:-20%;" class="tex" alt="(x+3) \cdot q(x)" /> to start with <img src="http://l.wordpress.com/latex.php?latex=x%5E3&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^3" style="vertical-align:-20%;" class="tex" alt="x^3" />, we need <img src="http://l.wordpress.com/latex.php?latex=q%28x%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="q(x)" style="vertical-align:-20%;" class="tex" alt="q(x)" /> to start with <img src="http://l.wordpress.com/latex.php?latex=x%5E2&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^2" style="vertical-align:-20%;" class="tex" alt="x^2" />.  We then proceed to subtract <img src="http://l.wordpress.com/latex.php?latex=%28x%2B3%29%20%5Ccdot%20x%5E2&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="(x+3) \cdot x^2" style="vertical-align:-20%;" class="tex" alt="(x+3) \cdot x^2" /> and then figure out that we need a <img src="http://l.wordpress.com/latex.php?latex=-3x&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="-3x" style="vertical-align:-20%;" class="tex" alt="-3x" /> for the next term, and so on.  We end up with <img src="http://l.wordpress.com/latex.php?latex=x%5E2%20-%203x%20%2B%2011&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^2 - 3x + 11" style="vertical-align:-20%;" class="tex" alt="x^2 - 3x + 11" /> with a remainder of <img src="http://l.wordpress.com/latex.php?latex=-28&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="-28" style="vertical-align:-20%;" class="tex" alt="-28" /> (a degree zero polynomial).</p>
<p><center><img src="http://l.wordpress.com/latex.php?latex=%5Cbegin%7Barray%7D%7Bccrcrcrcr%7D%20%26%20%26%20%26%20%26%20x%5E2%20%26%20-%20%26%203x%20%26%20%2B%20%26%2011%20%5C%5C%20%26%20%5Cmulticolumn%7B8%7D%7Bl%7D%7B%5Chrulefill%7D%20%5C%5C%28x%2B3%29%20%26%20%29%20%26%20x%5E3%20%26%20%2B%20%26%200x%5E2%20%26%20%2B%20%26%202x%20%26%20%2B%20%26%205%20%5C%5C%20%26%20%26%20x%5E3%20%26%20%2B%20%26%203x%5E2%20%26%20%26%20%26%20%26%20%5C%5C%20%26%20%26%20%5Cmulticolumn%7B3%7D%7Bl%7D%7B%5Chrulefill%7D%20%26%20%26%20%26%20%26%20%5C%5C%20%26%20%26%20%20%20%20%20%26%20-%20%26%203x%5E2%20%26%20%2B%20%26%202x%20%26%20%26%20%5C%5C%20%26%20%26%20%20%20%20%20%26%20-%20%26%203x%5E2%20%26%20-%20%26%209x%20%26%20%26%20%5C%5C%20%26%20%26%20%20%20%20%20%26%20%5Cmulticolumn%7B4%7D%7Bl%7D%7B%5Chrulefill%7D%20%26%20%26%20%5C%5C%20%26%20%26%20%20%20%20%20%26%20%20%20%26%20%20%20%20%20%20%26%20%20%20%26%2011x%20%26%20%2B%20%26%205%20%5C%5C%20%26%20%26%20%20%20%20%20%26%20%20%20%26%20%20%20%20%20%20%26%20%20%20%26%2011x%20%26%20%2B%20%26%2033%20%5C%5C%20%26%20%26%20%20%20%20%20%26%20%20%20%26%20%20%20%20%20%20%26%20%20%20%26%20%5Cmulticolumn%7B3%7D%7Bl%7D%7B%5Chrulefill%7D%20%5C%5C%20%26%20%26%20%20%20%20%20%26%20%20%20%26%20%20%20%20%20%20%26%20%20%20%26%20%20%20%20%20%26%20-%20%26%2028%5Cend%7Barray%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\begin{array}{ccrcrcrcr} &#038; &#038; &#038; &#038; x^2 &#038; - &#038; 3x &#038; + &#038; 11 \\ &#038; \multicolumn{8}{l}{\hrulefill} \\(x+3) &#038; ) &#038; x^3 &#038; + &#038; 0x^2 &#038; + &#038; 2x &#038; + &#038; 5 \\ &#038; &#038; x^3 &#038; + &#038; 3x^2 &#038; &#038; &#038; &#038; \\ &#038; &#038; \multicolumn{3}{l}{\hrulefill} &#038; &#038; &#038; &#038; \\ &#038; &#038;     &#038; - &#038; 3x^2 &#038; + &#038; 2x &#038; &#038; \\ &#038; &#038;     &#038; - &#038; 3x^2 &#038; - &#038; 9x &#038; &#038; \\ &#038; &#038;     &#038; \multicolumn{4}{l}{\hrulefill} &#038; &#038; \\ &#038; &#038;     &#038;   &#038;      &#038;   &#038; 11x &#038; + &#038; 5 \\ &#038; &#038;     &#038;   &#038;      &#038;   &#038; 11x &#038; + &#038; 33 \\ &#038; &#038;     &#038;   &#038;      &#038;   &#038; \multicolumn{3}{l}{\hrulefill} \\ &#038; &#038;     &#038;   &#038;      &#038;   &#038;     &#038; - &#038; 28\end{array}" style="vertical-align:-20%;" class="tex" alt="\begin{array}{ccrcrcrcr} &#038; &#038; &#038; &#038; x^2 &#038; - &#038; 3x &#038; + &#038; 11 \\ &#038; \multicolumn{8}{l}{\hrulefill} \\(x+3) &#038; ) &#038; x^3 &#038; + &#038; 0x^2 &#038; + &#038; 2x &#038; + &#038; 5 \\ &#038; &#038; x^3 &#038; + &#038; 3x^2 &#038; &#038; &#038; &#038; \\ &#038; &#038; \multicolumn{3}{l}{\hrulefill} &#038; &#038; &#038; &#038; \\ &#038; &#038;     &#038; - &#038; 3x^2 &#038; + &#038; 2x &#038; &#038; \\ &#038; &#038;     &#038; - &#038; 3x^2 &#038; - &#038; 9x &#038; &#038; \\ &#038; &#038;     &#038; \multicolumn{4}{l}{\hrulefill} &#038; &#038; \\ &#038; &#038;     &#038;   &#038;      &#038;   &#038; 11x &#038; + &#038; 5 \\ &#038; &#038;     &#038;   &#038;      &#038;   &#038; 11x &#038; + &#038; 33 \\ &#038; &#038;     &#038;   &#038;      &#038;   &#038; \multicolumn{3}{l}{\hrulefill} \\ &#038; &#038;     &#038;   &#038;      &#038;   &#038;     &#038; - &#038; 28\end{array}" /></center></p>
<p>For the example we cited earlier we had <img src="http://l.wordpress.com/latex.php?latex=x%5E3%20%2B%20x%5E2&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^3 + x^2" style="vertical-align:-20%;" class="tex" alt="x^3 + x^2" /> which we needed to take modulo <img src="http://l.wordpress.com/latex.php?latex=x%5E3%20%2B%20x%20%2B%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^3 + x + 1" style="vertical-align:-20%;" class="tex" alt="x^3 + x + 1" />.  Well, dividing <img src="http://l.wordpress.com/latex.php?latex=x%5E3%20%2B%20x%5E2&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^3 + x^2" style="vertical-align:-20%;" class="tex" alt="x^3 + x^2" /> by <img src="http://l.wordpress.com/latex.php?latex=x%5E3%20%2B%20x%20%2B%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^3 + x + 1" style="vertical-align:-20%;" class="tex" alt="x^3 + x + 1" />, we see that it goes in one time with a remainder of <img src="http://l.wordpress.com/latex.php?latex=x%5E2%20%2B%20x%20%2B%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x^2 + x + 1" style="vertical-align:-20%;" class="tex" alt="x^2 + x + 1" />.  [Note: addition and subtraction are the same in <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" />.]</p>
<p><center><img src="http://l.wordpress.com/latex.php?latex=%5Cbegin%7Barray%7D%7Bccrcrcrcr%7D%20%26%20%26%20%26%20%26%20%26%20%26%20%26%20%26%201%20%5C%5C%20%26%20%5Cmulticolumn%7B8%7D%7Bl%7D%7B%5Chrulefill%7D%20%5C%5C%28x%5E3%2Bx%2B1%29%20%26%20%29%20%26%20x%5E3%20%26%20%2B%20%26%20x%5E2%20%26%20%2B%20%26%200x%20%26%20%2B%20%26%200%20%5C%5C%20%26%20%20%20%20%20%20%20%20%20%20%20%20%26%20x%5E3%20%26%20%2B%20%26%200x%5E2%20%26%20%2B%20%26%20x%20%26%20%2B%20%26%201%20%5C%5C%20%26%20%26%20%5Cmulticolumn%7B7%7D%7Bl%7D%7B%5Chrulefill%7D%20%5C%5C%20%26%20%26%20%20%20%20%20%26%20%20%26%20x%5E2%20%26%20%2B%20%26%20x%20%26%20%2B%20%26%201%5C%5C%5Cend%7Barray%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\begin{array}{ccrcrcrcr} &#038; &#038; &#038; &#038; &#038; &#038; &#038; &#038; 1 \\ &#038; \multicolumn{8}{l}{\hrulefill} \\(x^3+x+1) &#038; ) &#038; x^3 &#038; + &#038; x^2 &#038; + &#038; 0x &#038; + &#038; 0 \\ &#038;            &#038; x^3 &#038; + &#038; 0x^2 &#038; + &#038; x &#038; + &#038; 1 \\ &#038; &#038; \multicolumn{7}{l}{\hrulefill} \\ &#038; &#038;     &#038;  &#038; x^2 &#038; + &#038; x &#038; + &#038; 1\\\end{array}" style="vertical-align:-20%;" class="tex" alt="\begin{array}{ccrcrcrcr} &#038; &#038; &#038; &#038; &#038; &#038; &#038; &#038; 1 \\ &#038; \multicolumn{8}{l}{\hrulefill} \\(x^3+x+1) &#038; ) &#038; x^3 &#038; + &#038; x^2 &#038; + &#038; 0x &#038; + &#038; 0 \\ &#038;            &#038; x^3 &#038; + &#038; 0x^2 &#038; + &#038; x &#038; + &#038; 1 \\ &#038; &#038; \multicolumn{7}{l}{\hrulefill} \\ &#038; &#038;     &#038;  &#038; x^2 &#038; + &#038; x &#038; + &#038; 1\\\end{array}" /></center></p>
<p>For a reasonable way to accomplish this in the special case of our integer representations of polynomials in <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" />, see this article about <a href="http://http://research.swtch.com/field">Finite Field Arithmetic and Reed Solomon Codes</a>.  In (tail-call style) Lisp, that algorithm for <img src="http://l.wordpress.com/latex.php?latex=GF%282%5E8%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^8)" style="vertical-align:-20%;" class="tex" alt="GF(2^8)" /> might look something like this to multiply <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> times <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_97f4a1ba736119e3cd4de6fca35efd6b.png" title="b" style="vertical-align:-20%;" class="tex" alt="b" /> modulo <img src="http://l.wordpress.com/latex.php?latex=m&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="m" style="vertical-align:-20%;" class="tex" alt="m" />:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>flet <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>next-a <span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span>
               <span style="color: #66cc66;">&#40;</span>ash a -<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span>next-b <span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">&#41;</span>
               <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>overflow <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">plusp</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">logand</span> b #x80<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> overflow
                     <span style="color: #66cc66;">&#40;</span>mod <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">logxor</span> <span style="color: #66cc66;">&#40;</span>ash b <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> m<span style="color: #66cc66;">&#41;</span> #x100<span style="color: #66cc66;">&#41;</span>
                   <span style="color: #66cc66;">&#40;</span>ash b <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>labels <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>mult <span style="color: #66cc66;">&#40;</span>a b r<span style="color: #66cc66;">&#41;</span>
             <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
              <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">zerop</span> a<span style="color: #66cc66;">&#41;</span> r<span style="color: #66cc66;">&#41;</span>
              <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">oddp</span> a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>mult <span style="color: #66cc66;">&#40;</span>next-a a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>next-b b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">logxor</span> r b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
              <span style="color: #66cc66;">&#40;</span>t <span style="color: #66cc66;">&#40;</span>mult <span style="color: #66cc66;">&#40;</span>next-a a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>next-b b<span style="color: #66cc66;">&#41;</span> r<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>mult a b <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<h3>How is the Galois field structured?</h3>
<p>The additive structure is simple.  Using our 8-bit representations of elements of <img src="http://l.wordpress.com/latex.php?latex=GF%282%5E8%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^8)" style="vertical-align:-20%;" class="tex" alt="GF(2^8)" />, we can create an image where the pixel in the <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_5477186a84cc2c889974ca6fd01ca96f.png" title="i" style="vertical-align:-20%;" class="tex" alt="i" />-th row and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_33c9ab784156bc3b75c894b91ea4ecf8.png" title="j" style="vertical-align:-20%;" class="tex" alt="j" />-th column is the sum (in the Galois field) of <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_5477186a84cc2c889974ca6fd01ca96f.png" title="i" style="vertical-align:-20%;" class="tex" alt="i" /> and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_33c9ab784156bc3b75c894b91ea4ecf8.png" title="j" style="vertical-align:-20%;" class="tex" alt="j" /> (written as binary numbers).  That looks like this:</p>
<p><center><a href="http://nklein.com/wp-content/uploads/2012/05/gf256.png"><img src="http://nklein.com/wp-content/uploads/2012/05/gf256.png" alt="" title="gf256" width="256" height="256" class="aligncenter size-full wp-image-1851" /></a></center></p>
<p>Just before the <a href="http://http://research.swtch.com/field">above-mentioned article</a> hit <a href="http://research.swtch.com/field">reddit</a>, I got to wondering if the structure of the Galois field was affected at all by the choice of polynomial you used as the modulus.  So, I put together some code to try out all of the polynomials of order 8.</p>
<p>Remember way back at the beginning of multiplication, I said that the modulus polynomial had to be one which couldn&#8217;t be written as the product of two polynomials of smaller degree?  If you allow that, then you have two non-zero polynomials that when multiplied together will equal your modulus polynomial.  Just like with integers, if you&#8217;ve got an exact multiple of the modulus, the remainder is zero.  We don&#8217;t want to be able to multiply together two non-zero elements to get zero.  Such elements would be called zero divisors.</p>
<p>Zero divisors would make these just be Galois rings instead of Galois fields.  Another way of saying this is that in a field, the non-zero elements form a <a href="http://en.wikipedia.org/wiki/Group_(mathematics)">group under multiplication</a>.  If they don&#8217;t, but multiplication is still associative and distributes over addition, we call it a ring instead of a field.</p>
<p>Galois rings might be interesting in their own right, but they&#8217;re not good for AES-type encryption.  In AES-type encryption, we&#8217;re trying to mix around the bits of the message.  If our mixing takes us to zero, we can never undo that mixing&mdash;there is nothing we can multiply or divide by to get back what we mixed in.</p>
<p>So, we need a polynomial that cannot be factored into two smaller polynomials.  Such a polynomial is said to be irreducible.  We can just start building an image for the multiplication for a given modulus and bail out if it has two non-zero elements that multiply together to get zero.  So, I did this for all elements which when written in our binary notation form odd numbers between (and including) 100000001 and 111111111 (shown as binary).  These are the only numbers which could possibly represent irreducible polynomials of degree 8.  The even numbers are easy to throw out because they can be written as <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_1a507c5494969dc6de305770cadc6630.png" title="x" style="vertical-align:-20%;" class="tex" alt="x" /> times a degree 7 polynomial.</p>
<p>The ones that worked were: 100011011, 100011101, 100101011, 100101101, 100111001, 100111111, 101001101, 101011111, 101100011, 101100101, 101101001, 101110001, 101110111, 101111011, 110000111, 110001011, 110001101, 110011111, 110100011, 110101001, 110110001, 110111101, 111000011, 111001111, 111010111, 111011101, 111100111, 111110011, 111110101, and 111111001.  That first one that worked (100011011) is the one used in AES.  Its multiplication table looks like:</p>
<p><center><a href="http://nklein.com/wp-content/uploads/2012/05/gf256-x11B.png"><img src="http://nklein.com/wp-content/uploads/2012/05/gf256-x11B.png" alt="" title="gf256-x11B" width="256" height="256" class="aligncenter size-full wp-image-1853" /></a></center></p>
<p>Here&#8217;s it is again on the left with the multiplication table when 110011111 is the modulus on the right:</p>
<p><center><a href="http://nklein.com/wp-content/uploads/2012/05/gf256-x11B.png"><img src="http://nklein.com/wp-content/uploads/2012/05/gf256-x11B.png" alt="" title="gf256-x11B" width="256" height="256" class="aligncenter size-full wp-image-1853" /></a> &nbsp; <a href="http://nklein.com/wp-content/uploads/2012/05/gf256-x19F.png"><img src="http://nklein.com/wp-content/uploads/2012/05/gf256-x19F.png" alt="" title="gf256-x19F" width="256" height="256" class="aligncenter size-full wp-image-1856" /></a></center></p>
<p>So, the addition image provides some insight into how addition works.  The multiplication tables, at least for me, provide very little insight into anything.  They don&#8217;t even make a good stereo pair.</p>
<p>To say two of the multiplication tables have the same structure, means there is some way to map back and forth between them so that the multiplication still works.  If we have table <img src="http://l.wordpress.com/latex.php?latex=X&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="X" style="vertical-align:-20%;" class="tex" alt="X" /> and table <img src="http://l.wordpress.com/latex.php?latex=Y&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="Y" style="vertical-align:-20%;" class="tex" alt="Y" />, then we need an invertible function <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_349b42d4616c442fb8f2c706a240b394.png" title="f" style="vertical-align:-20%;" class="tex" alt="f" /> such that <img src="http://l.wordpress.com/latex.php?latex=f%28a%20%5Ccdot_X%20b%29%20%3D%20f%28a%29%20%5Ccdot_Y%20f%28b%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="f(a \cdot_X b) = f(a) \cdot_Y f(b)" style="vertical-align:-20%;" class="tex" alt="f(a \cdot_X b) = f(a) \cdot_Y f(b)" /> for all <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_97f4a1ba736119e3cd4de6fca35efd6b.png" title="b" style="vertical-align:-20%;" class="tex" alt="b" /> in the table <img src="http://l.wordpress.com/latex.php?latex=X&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="X" style="vertical-align:-20%;" class="tex" alt="X" />. </p>
<h3>What&#8217;s next?</h3>
<p>If there is an invertible map between two multiplication tables and there is some element <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> in the first table, you can take successive powers of it: <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" />, <img src="http://l.wordpress.com/latex.php?latex=a%5E2&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^2" style="vertical-align:-20%;" class="tex" alt="a^2" />, <img src="http://l.wordpress.com/latex.php?latex=a%5E3&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^3" style="vertical-align:-20%;" class="tex" alt="a^3" />, <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_4b30e31f5d5a5dbe4dcd2e370ee5d1ae.png" title="\ldots" style="vertical-align:-20%;" class="tex" alt="\ldots" />.  There are only <img src="http://l.wordpress.com/latex.php?latex=2%5En&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="2^n" style="vertical-align:-20%;" class="tex" alt="2^n" /> elements in <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" /> no matter which polynomial we pick.  So, somewhere in there, you have to start repeating.  In fact, you have to get back to <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" />.  There is some smallest, positive integer <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_98d86ac06986d02b6e40f483093b61e0.png" title="k" style="vertical-align:-20%;" class="tex" alt="k" /> so that <img src="http://l.wordpress.com/latex.php?latex=a%5E%7Bk%2B1%7D%20%5Cequiv%20a&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^{k+1} \equiv a" style="vertical-align:-20%;" class="tex" alt="a^{k+1} \equiv a" /> in <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" />.  If we pick <img src="http://l.wordpress.com/latex.php?latex=a%20%3D%200&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a = 0" style="vertical-align:-20%;" class="tex" alt="a = 0" />, then we simply have that <img src="http://l.wordpress.com/latex.php?latex=k%20%3D%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="k = 1" style="vertical-align:-20%;" class="tex" alt="k = 1" />.  For non-zero <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" />, we are even better off because <img src="http://l.wordpress.com/latex.php?latex=a%5Ek%20%5Cequiv%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^k \equiv 1" style="vertical-align:-20%;" class="tex" alt="a^k \equiv 1" />.</p>
<p>So, what if I took the powers of each element of <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" /> in turn?  For each number, I would get a sequence of its powers.  If I throw away the order of that sequence and just consider it a set, then I would end up with a subset of <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" /> for each <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> in <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" />.  How many different subsets will I end up with?  Will there be a different subset for each <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" />?</p>
<p>I mentioned earlier that the non-zero elements of <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" /> form what&#8217;s called a group.  The subset created by the powers of any fixed <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> forms what&#8217;s called a subgroup.  A subgroup is a subset of a group such that given any two members of that subset, their product (in the whole group) is also a member of the subset.  As it turns out, for groups with a finite number of elements, the number of items in a subgroup has to divide evenly into the number of elements in the whole group.</p>
<p>The element zero in <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" /> forms the subset containing only zero.  The non-zero elements of <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" /> form a group of <img src="http://l.wordpress.com/latex.php?latex=2%5En%20-%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="2^n - 1" style="vertical-align:-20%;" class="tex" alt="2^n - 1" /> elements.  The number <img src="http://l.wordpress.com/latex.php?latex=2%5En%20-%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="2^n - 1" style="vertical-align:-20%;" class="tex" alt="2^n - 1" /> is odd (for all <img src="http://l.wordpress.com/latex.php?latex=n%20%3E%200&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="n > 0&#8243; style=&#8221;vertical-align:-20%;&#8221; class=&#8221;tex&#8221; alt=&#8221;n > 0&#8243; />).  So, immediately, we know that all of the subsets we generate are going to have an odd number of items in them.  For <img src="http://l.wordpress.com/latex.php?latex=GF%282%5E8%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^8)" style="vertical-align:-20%;" class="tex" alt="GF(2^8)" />, there are 255 non-zero elements.  The numbers that divide 255 are: 1, 3, 5, 15, 17, 51, 85, and 255. </p>
<p>It turns out that the non-zero elements of <img src="http://l.wordpress.com/latex.php?latex=GF%282%5En%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^n)" style="vertical-align:-20%;" class="tex" alt="GF(2^n)" /> form what&#8217;s called a cyclic group.  That means that there is at least one element <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> whose subset is all <img src="http://l.wordpress.com/latex.php?latex=2%5En%20-%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="2^n - 1" style="vertical-align:-20%;" class="tex" alt="2^n - 1" /> of the non-zero elements.  If take one of those <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" />&#8216;s in <img src="http://l.wordpress.com/latex.php?latex=GF%282%5E8%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^8)" style="vertical-align:-20%;" class="tex" alt="GF(2^8)" /> whose subset is all 255 of the elements, we can quickly see that the powers of <img src="http://l.wordpress.com/latex.php?latex=a%5E3&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^3" style="vertical-align:-20%;" class="tex" alt="a^3" /> form a subset containing 85 elements, the powers of <img src="http://l.wordpress.com/latex.php?latex=a%5E5&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^5" style="vertical-align:-20%;" class="tex" alt="a^5" /> form a subset containing 51 elements, &#8230;, the powers of <img src="http://l.wordpress.com/latex.php?latex=a%5E%7B85%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^{85}" style="vertical-align:-20%;" class="tex" alt="a^{85}" /> form a subset containing 3 elements, and the powers of <img src="http://l.wordpress.com/latex.php?latex=a%5E%7B255%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^{255}" style="vertical-align:-20%;" class="tex" alt="a^{255}" /> form a subset containing 1 element.  Further, if both <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_97f4a1ba736119e3cd4de6fca35efd6b.png" title="b" style="vertical-align:-20%;" class="tex" alt="b" /> have all 255 elements in their subset, then <img src="http://l.wordpress.com/latex.php?latex=a%5Ek&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^k" style="vertical-align:-20%;" class="tex" alt="a^k" /> and <img src="http://l.wordpress.com/latex.php?latex=b%5Ek&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="b^k" style="vertical-align:-20%;" class="tex" alt="b^k" /> will have the same number of elements in their subsets for all <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_98d86ac06986d02b6e40f483093b61e0.png" title="k" style="vertical-align:-20%;" class="tex" alt="k" />.  We would still have to check to make sure that if <img src="http://l.wordpress.com/latex.php?latex=a%5Ei%20%2B%20a%5Ej%20%3D%20a%5Ek&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^i + a^j = a^k" style="vertical-align:-20%;" class="tex" alt="a^i + a^j = a^k" /> that <img src="http://l.wordpress.com/latex.php?latex=b%5Ei%20%2B%20b%5Ej%20%3D%20b%5Ek&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="b^i + b^j = b^k" style="vertical-align:-20%;" class="tex" alt="b^i + b^j = b^k" /> to verify the whole field structure is the same.</p>
<p>This means there are only 8 different subset of <img src="http://l.wordpress.com/latex.php?latex=GF%282%5E8%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="GF(2^8)" style="vertical-align:-20%;" class="tex" alt="GF(2^8)" />&#8216;s non-zero elements which form subgroups.  Pictorially, if we placed the powers of <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> around a circle so that <img src="http://l.wordpress.com/latex.php?latex=a%5E0%20%3D%201&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^0 = 1" style="vertical-align:-20%;" class="tex" alt="a^0 = 1" /> was at the top and the powers progressed around the circle and then drew a polygon connecting consecutive points, then consecutive points in the <img src="http://l.wordpress.com/latex.php?latex=a%5E3&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^3" style="vertical-align:-20%;" class="tex" alt="a^3" /> sequence and consecutive points in the <img src="http://l.wordpress.com/latex.php?latex=a%5E5&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a^5" style="vertical-align:-20%;" class="tex" alt="a^5" /> sequence, etc&#8230;. we&#8217;d end up with this:</p>
<p><center><a href="http://nklein.com/wp-content/uploads/2012/05/z255c.png"><img src="http://nklein.com/wp-content/uploads/2012/05/z255c.png" alt="" title="z255c" width="256" height="256" class="aligncenter size-full wp-image-1860" /></a></center></p>
<p>If we don&#8217;t reorder them and just leave them in the numerical order of their binary representation, the result isn&#8217;t as aesthetically pleasing as the previous picture.  Here are the same two we used before 100011011 (on the left) and 110011111 (on the right).  They are easier to look at.  They do not lend much more insight nor make a better stereo pair.</p>
<p><center><a href="http://nklein.com/wp-content/uploads/2012/05/gf256-x11Bc.png"><img src="http://nklein.com/wp-content/uploads/2012/05/gf256-x11Bc.png" alt="" title="gf256-x11Bc" width="256" height="256" class="aligncenter size-full wp-image-1862" /></a> &nbsp; <a href="http://nklein.com/wp-content/uploads/2012/05/gf256-x19Fc.png"><img src="http://nklein.com/wp-content/uploads/2012/05/gf256-x19Fc.png" alt="" title="gf256-x19Fc" width="256" height="256" class="aligncenter size-full wp-image-1863" /></a></center></p>
<p>*shrug* Here&#8217;s the source file that I used to generate all of these images with <a href="http://www.xach.com/lisp/vecto/">Vecto</a> and <a href="http://www.xach.com/lisp/zpng/">ZPNG</a>:  <a href="http://nklein.com/wp-content/uploads/2012/05/group.lisp">group.lisp</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2012/05/visualizing-galois-fields/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>HTML + JS + LISP.  Oh My.</title>
		<link>http://nklein.com/2012/03/html-js-lisp-oh-my/</link>
		<comments>http://nklein.com/2012/03/html-js-lisp-oh-my/#comments</comments>
		<pubDate>Wed, 21 Mar 2012 03:37:49 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[cl-who]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[hunchentoot]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[parenscript]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1812</guid>
		<description><![CDATA[I started a Javascript + HTML application some time back. I decided that I wanted to get some Lisp on. So, it was time to pull out Hunchentoot, CL-WHO, and Parenscript. It&#8217;s been awkward slogging so far. I still don&#8217;t have a good user-model of when exactly I need to wrap something in a &#40;cl-who:str [...]]]></description>
			<content:encoded><![CDATA[<p>I started a Javascript + HTML application some time back.  I decided that I wanted to get some Lisp on.  So, it was time to pull out Hunchentoot, CL-WHO, and Parenscript.</p>
<p>It&#8217;s been awkward slogging so far.  I still don&#8217;t have a good user-model of when exactly I need to wrap something in a <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&#40;</span>cl-who<span style="color: #66cc66;">:</span><span style="color: #555;">str</span> <span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span></span></code> or when Parenscript will expand my macro rather than convert it into a function call or how I managed to get the <code class="codecolorer lisp default"><span class="lisp">cl-who<span style="color: #66cc66;">:</span>*attribute-quote-char*</span></code> to finally stick for a few REPLs.</p>
<p>The other half of the awkwardness is that I started writing the application in idiomatic javascript with prototype-based objects.</p>
<div class="codecolorer-container javascript blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> MyClass <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myfirst</span> <span style="color: #339933;">=</span> undefined<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myarray</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
MyClass.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">mymethod</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>arg1<span style="color: #339933;">,</span> arg2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myfirst</span> <span style="color: #339933;">=</span> arg1<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myarray</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>arg2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div>
<p>This makes for some awkward javascript when converted directly into Parenscript because:</p>
<ul>
<li>The method <code class="codecolorer javascript default"><span class="javascript">mymethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> will try to return the result of <code class="codecolorer javascript default"><span class="javascript">Array.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> (which, technically, is fine, but not really the intent of the method).</li>
<li>Almost every statement on the Lisp side ends up wrapping just about everything in <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&#40;</span>parenscript<span style="color: #66cc66;">:</span><span style="color: #555;">chain</span> <span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span></span></code>. (<b>Edit:</b> Of course, I discovered right after posting this that the dot is left untouched in the Parenscript symbol conversion, so I can do <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&#40;</span>this<span style="color: #66cc66;">.</span>myarray<span style="color: #66cc66;">.</span>push arg2<span style="color: #66cc66;">&#41;</span></span></code> instead of <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&#40;</span>parenscript<span style="color: #66cc66;">:</span><span style="color: #555;">chain</span> this my <span style="color: #b1b100;">array</span> <span style="color: #66cc66;">&#40;</span>push arg2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></span></code>.  I&#8217;m certainly pleased with the brevity, but it pegs my <q>something&#8217;s fishy here, Batman</q> meter.)</li>
<li>I have an aversion to using any package other than <code class="codecolorer lisp default"><span class="lisp">COMMON-LISP</span></code>, so everything is way clunkier than all of the tutorials and examples online.</li>
</ul>
<p>I think that I&#8217;m going to scratch all of the Javascript and Parenscript code that I have right now and start over with a mindset of <q>How would I do this if it were just in Lisp?  Now, what extra hoops do I need to get Parenscript to make usable Javascript?</q> rather than <q>How would I do this in Javascript? Oh, and then, how can I make Parenscript say exactly that?</q>  And, I may bite the bullet and <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&#40;</span>use-package <span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span></span></code> both CL-WHO and Parenscript.</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2012/03/html-js-lisp-oh-my/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The Anti-Cons</title>
		<link>http://nklein.com/2012/02/the-anti-cons/</link>
		<comments>http://nklein.com/2012/02/the-anti-cons/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 03:51:44 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[anti-cons]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[polynomials]]></category>
		<category><![CDATA[recursion]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1801</guid>
		<description><![CDATA[Motivation I no longer remember what led me to this page of synthetic division implemented in various languages. The author provides a common lisp implementation for taking a list representing the coefficients of a polynomial in one variable and a number and returning the result of dividing the polynomial by . The author states: I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<h3>Motivation</h3>
<p>I no longer remember what led me to this page of <a href="http://kourge.net/node/98">synthetic division</a> implemented in various languages.  The author provides a common lisp implementation for taking a list representing the coefficients of a polynomial in one variable <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_1a507c5494969dc6de305770cadc6630.png" title="x" style="vertical-align:-20%;" class="tex" alt="x" /> and a number <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_a7175a60e504c64ad51e7119b44ee9aa.png" title="\alpha" style="vertical-align:-20%;" class="tex" alt="\alpha" /> and returning the result of dividing the polynomial by <img src="http://l.wordpress.com/latex.php?latex=%28x-%5Calpha%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="(x-\alpha)" style="vertical-align:-20%;" class="tex" alt="(x-\alpha)" />. </p>
<p>The author states: <q>I&#8217;m very sure this isn&#8217;t considered <em>Lispy</em> and would surely seem like an awkward port from an extremely Algol-like mindset in the eyes of a seasoned Lisper.</q>  In the mood for the exercise, I reworked his code snippet into slightly more canonical lisp while leaving the basic structure the same:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> synthetic-division <span style="color: #66cc66;">&#40;</span>polynomial divisor<span style="color: #66cc66;">&#41;</span>                                  
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span>* <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>result <span style="color: #66cc66;">&#40;</span>first polynomial<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>                                            
         <span style="color: #66cc66;">&#40;</span>quotient <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> result<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>                                              
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">dolist</span> <span style="color: #66cc66;">&#40;</span>coefficient <span style="color: #66cc66;">&#40;</span>rest polynomial<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>                                     
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setf</span> result <span style="color: #66cc66;">&#40;</span>* result divisor<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>                                          
      <span style="color: #66cc66;">&#40;</span>incf result coefficient<span style="color: #66cc66;">&#41;</span>                                                 
      <span style="color: #66cc66;">&#40;</span>push result quotient<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>                                                   
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>remainder <span style="color: #66cc66;">&#40;</span>pop quotient<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>                                           
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">:</span><span style="color: #555;">quotient</span> <span style="color: #66cc66;">&#40;</span>nreverse quotient<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">remainder</span> remainder<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>From there, I went on to implement it using tail recursion to get rid of the <code class="codecolorer lisp default"><span class="lisp">#'<span style="color: #b1b100;">setf</span></span></code> and <code class="codecolorer lisp default"><span class="lisp">#'incf</span></code> and <code class="codecolorer lisp default"><span class="lisp">#'push</span></code>:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> synthetic-division-<span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#40;</span>polynomial divisor<span style="color: #66cc66;">&#41;</span>                                
  <span style="color: #66cc66;">&#40;</span>labels <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>divide <span style="color: #66cc66;">&#40;</span>coefficients remainder quotient<span style="color: #66cc66;">&#41;</span>                            
             <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> coefficients                                                   
                 <span style="color: #66cc66;">&#40;</span>divide <span style="color: #66cc66;">&#40;</span>rest coefficients<span style="color: #66cc66;">&#41;</span>                                    
                         <span style="color: #66cc66;">&#40;</span>+ <span style="color: #66cc66;">&#40;</span>* divisor remainder<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>first coefficients<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>         
                         <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>* remainder quotient<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>                            
               <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">:</span><span style="color: #555;">quotient</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">reverse</span> quotient<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">remainder</span> remainder<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>      
    <span style="color: #66cc66;">&#40;</span>divide <span style="color: #66cc66;">&#40;</span>rest polynomial<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>first polynomial<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>What I didn&#8217;t like about this was the complexity of calling the tail-recursive portion.  If I just called it like I wished to  <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&#40;</span>divide polynomial <span style="color: #cc66cc;">0</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span></span></code> then I ended up with one extra coefficient in the answer.  This wouldn&#8217;t do.</p>
<h3>The Joke</h3>
<p>There&#8217;s an old joke about a physicist, a biologist, and a mathematician who were having lunch at an outdoor café.  Just as their food was served, they noticed a couple walk into the house across the street.  As they were finishing up their meal, they saw three people walk out of that very same house.</p>
<p>The physicist said, <q>We must have miscounted.  Three must have entered before.</q></p>
<p>The biologist said, <q>They must have pro-created.</q></p>
<p>The mathematician said, <q>If one more person enters that house, it will again be empty.</q></p>
<h3>The Anti-Cons</h3>
<p>What I needed was a more-than-empty list.  I needed a negative cons-cell.  I needed something to put in place of the <code class="codecolorer lisp default"><span class="lisp"><span style="color: #b1b100;">nil</span></span></code> in <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&#40;</span>divide polynomial <span style="color: #cc66cc;">0</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span></span></code> that would annihilate the first thing it was cons-ed to.</p>
<p>I haven&#8217;t come up with the right notation to make this clear.  It is somewhat like a <a href="http://en.wikipedia.org/wiki/Quasigroup">quasigroup</a> except that there is only one inverse element for all other elements.  Let&#8217;s denote this annihilator: <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_0824a1fdf135170467671326d5780e2b.png" title="\omega" style="vertical-align:-20%;" class="tex" alt="\omega" />.  Let&#8217;s denote list concatenation with <img src="http://l.wordpress.com/latex.php?latex=%5Coplus&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\oplus" style="vertical-align:-20%;" class="tex" alt="\oplus" />.</p>
<p>Only having one inverse-ish element means we have to give up associativity.  For lists <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" /> and <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_97f4a1ba736119e3cd4de6fca35efd6b.png" title="b" style="vertical-align:-20%;" class="tex" alt="b" />, evaluating <img src="http://l.wordpress.com/latex.php?latex=%28a%20%5Coplus%20%5Comega%29%20%5Coplus%20b&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="(a \oplus \omega) \oplus b" style="vertical-align:-20%;" class="tex" alt="(a \oplus \omega) \oplus b" /> equals <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_97f4a1ba736119e3cd4de6fca35efd6b.png" title="b" style="vertical-align:-20%;" class="tex" alt="b" />, but <img src="http://l.wordpress.com/latex.php?latex=a%20%5Coplus%20%28%5Comega%20%5Coplus%20b%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a \oplus (\omega \oplus b)" style="vertical-align:-20%;" class="tex" alt="a \oplus (\omega \oplus b)" /> equals <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_3cad95c81df4676e1b14e93cbb0b18ae.png" title="a" style="vertical-align:-20%;" class="tex" alt="a" />.</p>
<p>Associativity is a small price to pay though for a prettier call to my tail-recursive function, right?</p>
<h3>The Basic Operations</h3>
<p>For basic operations, I&#8217;m going to need the anti-cons itself and a lazy list of an arbitrary number of anti-conses.</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>defconstant anti-<span style="color: #b1b100;">cons</span> 'anti-<span style="color: #b1b100;">cons</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defclass anti-cons-<span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> <span style="color: #66cc66;">:</span><span style="color: #555;">initarg</span> <span style="color: #66cc66;">:</span><span style="color: #b1b100;">length</span> <span style="color: #66cc66;">:</span><span style="color: #555;">reader</span> anti-cons-list-<span style="color: #b1b100;">length</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">default-initargs</span> <span style="color: #66cc66;">:</span><span style="color: #b1b100;">length</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defmethod print-object <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>obj anti-cons-<span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> stream<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>print-unreadable-object <span style="color: #66cc66;">&#40;</span>obj stream<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>prin1 <span style="color: #66cc66;">&#40;</span>loop <span style="color: #66cc66;">:</span><span style="color: #555;">for</span> ii <span style="color: #66cc66;">:</span><span style="color: #555;">from</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">:</span><span style="color: #555;">to</span> <span style="color: #66cc66;">&#40;</span>anti-cons-list-<span style="color: #b1b100;">length</span> obj<span style="color: #66cc66;">&#41;</span>
              <span style="color: #66cc66;">:</span><span style="color: #555;">collecting</span> 'anti-<span style="color: #b1b100;">cons</span><span style="color: #66cc66;">&#41;</span>
           stream<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>Then, I&#8217;m going to make some macros to define generic functions named by adding a minus-sign to the end of a Common Lisp function.  The default implementation will simply be the common-lisp function.</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> defun- <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">name</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>rest args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;</span>body methods<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>name- <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">intern</span> <span style="color: #66cc66;">&#40;</span>concatenate 'string <span style="color: #66cc66;">&#40;</span>symbol-<span style="color: #b1b100;">name</span> <span style="color: #b1b100;">name</span><span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot;-&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    `<span style="color: #66cc66;">&#40;</span>defgeneric <span style="color: #66cc66;">,</span>name- <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">,</span>@args<span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">method</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">,</span>@args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">,</span><span style="color: #b1b100;">name</span> <span style="color: #66cc66;">,</span>@args<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
       <span style="color: #66cc66;">,</span>@methods<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>I&#8217;m even going to go one step further for single-argument functions where I want to override the body for my lazy list of anti-conses using a single form for the body:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defmacro</span> defun1- <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">name</span> <span style="color: #66cc66;">&#40;</span>arg<span style="color: #66cc66;">&#41;</span> a-list-form <span style="color: #66cc66;">&amp;</span>body body<span style="color: #66cc66;">&#41;</span>
  `<span style="color: #66cc66;">&#40;</span>defun- <span style="color: #66cc66;">,</span><span style="color: #b1b100;">name</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">,</span>arg<span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">method</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">,</span>arg anti-cons-<span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">,</span>a-list-form<span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">,</span>@body<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>I need <code class="codecolorer lisp default"><span class="lisp">#'cons-</span></code> to set the stage.  I need to be able to cons an anti-cons with a normal list.  I need to be able to cons an anti-cons with a list of anti-conses.  And, I need to be able to cons something other than an anti-cons with a list of anti-conses.</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>defun- <span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span>a b<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">method</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>a <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eql</span> 'anti-<span style="color: #b1b100;">cons</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>b <span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">null</span> b<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>make-instance 'anti-cons-<span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">method</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>a <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eql</span> 'anti-<span style="color: #b1b100;">cons</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>b anti-cons-<span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>make-instance 'anti-cons-<span style="color: #b1b100;">list</span> <span style="color: #66cc66;">:</span><span style="color: #b1b100;">length</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>+ <span style="color: #66cc66;">&#40;</span>anti-cons-list-<span style="color: #b1b100;">length</span> b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">method</span> <span style="color: #66cc66;">&#40;</span>a <span style="color: #66cc66;">&#40;</span>b anti-cons-<span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>b-len <span style="color: #66cc66;">&#40;</span>anti-cons-list-<span style="color: #b1b100;">length</span> b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> b-len <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span>make-instance 'anti-cons-<span style="color: #b1b100;">list</span> <span style="color: #66cc66;">:</span><span style="color: #b1b100;">length</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>- b-len<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>Now, I can go on to define some simple functions that can take either anti-cons lists or regular Common Lisp lists.</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>defun1- <span style="color: #b1b100;">length</span> <span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>- <span style="color: #66cc66;">&#40;</span>anti-cons-list-<span style="color: #b1b100;">length</span> a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defun1- <span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">anti-</span><span style="color: #b1b100;">cons</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defun1- <span style="color: #b1b100;">cdr</span> <span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>a-len <span style="color: #66cc66;">&#40;</span>anti-cons-list-<span style="color: #b1b100;">length</span> a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> a-len <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>make-instance 'anti-cons-<span style="color: #b1b100;">list</span> <span style="color: #66cc66;">:</span><span style="color: #b1b100;">length</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>- a-len<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defun1- <span style="color: #b1b100;">cadr</span> <span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>anti-cons-list-<span style="color: #b1b100;">length</span> a<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">anti-</span><span style="color: #b1b100;">cons</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defun1- <span style="color: #b1b100;">caddr</span> <span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>anti-cons-list-<span style="color: #b1b100;">length</span> a<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">:</span><span style="color: #555;">anti-</span><span style="color: #b1b100;">cons</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>To give a feel for how this all fits together, here&#8217;s a little interactive session:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ANTI-CONS<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>cons- anti-<span style="color: #b1b100;">cons</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span>
#<span style="color: #66cc66;">&lt;</span><span style="color: #66cc66;">&#40;</span>ANTI-<span style="color: #b1b100;">CONS</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
ANTI-CONS<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>cons- anti-<span style="color: #b1b100;">cons</span> *<span style="color: #66cc66;">&#41;</span>
#<span style="color: #66cc66;">&lt;</span><span style="color: #66cc66;">&#40;</span>ANTI-<span style="color: #b1b100;">CONS</span> ANTI-<span style="color: #b1b100;">CONS</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
ANTI-CONS<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>cons- <span style="color: #66cc66;">:</span><span style="color: #555;">a</span> *<span style="color: #66cc66;">&#41;</span>
#<span style="color: #66cc66;">&lt;</span><span style="color: #66cc66;">&#40;</span>ANTI-<span style="color: #b1b100;">CONS</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
ANTI-CONS<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>length- *<span style="color: #66cc66;">&#41;</span>
-<span style="color: #cc66cc;">1</span></pre></div>
<h3>Denouement</h3>
<p>Only forty or fifty lines of code to go from:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>divide <span style="color: #66cc66;">&#40;</span>rest polynomial<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>first polynomial<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>To this:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span>divide polynomial <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> anti-<span style="color: #b1b100;">cons</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>Definitely worth it.</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2012/02/the-anti-cons/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>My Favorite Macro Patterns</title>
		<link>http://nklein.com/2012/02/my-favorite-macro-patterns</link>
		<comments>http://nklein.com/2012/02/my-favorite-macro-patterns#comments</comments>
		<pubDate>Sat, 18 Feb 2012 02:00:00 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[cl-who]]></category>
		<category><![CDATA[css-lite]]></category>
		<category><![CDATA[hunchentoot]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[macros]]></category>
		<category><![CDATA[parenscript]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1789</guid>
		<description><![CDATA[I read Jorge Tavares&#8217;s article on Macro Patterns a few days ago.  I was thinking about replying to mention a few of my favorites: The with- pattern which makes sure a special variable is bound for the body and makes sure the tied resources are released at the end of the block. Macros which collect [...]]]></description>
			<content:encoded><![CDATA[<p>I read <a href="http://jorgetavares.com/2012/02/13/macros-design-patterns/">Jorge Tavares&#8217;s article on Macro Patterns</a> a few days ago.  I was thinking about replying to mention a few of my favorites:</p>
<ul>
<li>The <code class="codecolorer lisp default"><span class="lisp">with-</span></code> pattern which makes sure a special variable is bound for the body and makes sure the tied resources are released at the end of the block.</li>
<li>Macros which collect content (usually into a special variable) so they can do something with the content at the end of the close of the macro.</li>
</ul>
<p>Then, I was working on something tonight when I re-discovered a favorite pattern that I&#8217;d forgotten about:  Putting multiple wrappers on the same body.</p>
<p>I am working on an HTML+JavaScript+CSS project.  In the end, I need static files.  But, I thought I would use the opportunity to really experience <a href="http://weitz.de/cl-who/">CL-Who</a>, <a href="http://common-lisp.net/project/parenscript/">Parenscript</a>, and <a href="https://github.com/paddymul/css-lite">CSS-Lite</a>.</p>
<p>I have now made a macro called <code class="codecolorer lisp default"><span class="lisp">define-web-file</span></code> which takes a CL-Who or Parenscript body and wraps it up as both a <a href="http://weitz.de/hunchentoot/">Hunchentoot</a> handler and a <code class="codecolorer text default"><span class="text">write-to-file</span></code> wrapper.  Now, I can test interactively with Hunchentoot and generate the whole web application when I&#8217;m ready.</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2012/02/my-favorite-macro-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dusting off my Growl Library</title>
		<link>http://nklein.com/2011/12/dusting-off-my-growl-library/</link>
		<comments>http://nklein.com/2011/12/dusting-off-my-growl-library/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 04:42:24 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[cl-growl]]></category>
		<category><![CDATA[iolib]]></category>
		<category><![CDATA[ironclad]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[usocket]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1782</guid>
		<description><![CDATA[I&#8217;ve spent the last few hours dusting off my Common Lisp Growl client library. The last time I worked on it was before the Mac Growl Application supported GNTP (Growl Notification Transport Protocol). Today, working on it, I&#8217;m not quite sure what&#8217;s up, but I am not succeeding in communicating with the server using encryption. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the last few hours dusting off my <a href="http://nklein.com/software/cl-growl/">Common Lisp Growl client library</a>.  The last time I worked on it was before the Mac Growl Application supported GNTP (Growl Notification Transport Protocol).</p>
<p>Today, working on it, I&#8217;m not quite sure what&#8217;s up, but I am not succeeding in communicating with the server using encryption.  I&#8217;ll have to look more closely.  Last time that I worked on it, I extended <a href="http://method-combination.net/lisp/ironclad/">Ironclad</a>, but I never got those changes pushed fully into Ironclad&#8217;s main line.  But, I think I&#8217;m using the same version of Ironclad that I was using when I tested against the Windows Growl Application.  *shrug*</p>
<p>I&#8217;ve also run into a snag with the Callbacks.  Essentially, your Lisp program could get a callback when the user has clicked on your Growl notification.  This actually works except for the fact that I am calling <code class="codecolorer lisp default"><span class="lisp">READ-SEQUENCE</span></code> into a buffer that is longer than the message.  The server, I believe, is supposed to close the socket after the callback.  But, it does not.  So, I am stuck waiting for more bytes that will never come.</p>
<p>Now, I either have to do one of the following:</p>
<ul>
<li>refactor it to use <code class="codecolorer lisp default"><span class="lisp">READ-LINE</span></code> instead</li>
<li>switch from using <a href="http://common-lisp.net/project/usocket/">USocket</a> to using <a href="http://common-lisp.net/project/iolib/">IOLib</a> (and hope that <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">:</span><span style="color: #555;">dont-wait</span></span></code> works as expected)</li>
<li>extend USocket to support <code class="codecolorer lisp default"><span class="lisp">SOCKET-RECEIVE</span></code> even on TCP sockets</li>
</ul>
<p>Anyone have a preference?</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2011/12/dusting-off-my-growl-library/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>If it quacks like a parabola&#8230;</title>
		<link>http://nklein.com/2011/09/if-it-quacks-like-a-parabola/</link>
		<comments>http://nklein.com/2011/09/if-it-quacks-like-a-parabola/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 00:20:06 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[classical mechanics]]></category>
		<category><![CDATA[differential equations]]></category>
		<category><![CDATA[intuition]]></category>
		<category><![CDATA[special relativity]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1765</guid>
		<description><![CDATA[I am working on a game idea that involves (special) relativistic mechanics instead of classical mechanics. Working out the details that I needed was easy enough if I assumed that: ships had a maximum speed at which they could move relative to my base frame ships could instantly go from stopped to maximum speed or [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a game idea that involves <a href="http://en.wikipedia.org/wiki/Special_relativity#Relativistic_mechanics">(special) relativistic mechanics</a> instead of <a href="http://en.wikipedia.org/wiki/Classical_mechanics">classical mechanics</a>.  Working out the details that I needed was easy enough if I assumed that:</p>
<ul>
<li>ships had a maximum speed at which they could move relative to my base frame</li>
<li>ships could instantly go from stopped to maximum speed or vice-versa</li>
</ul>
<p>I didn&#8217;t like those assumptions at all.  So, I started playing with the equations for relativity.  In classical mechanics, the rate-of-change of velocity equals the force you&#8217;re applying divided by your mass: <img src="http://l.wordpress.com/latex.php?latex=%5Cfrac%7Bdv%7D%7Bdt%7D%20%3D%20%5Cfrac%7BF%7D%7Bm%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\frac{dv}{dt} = \frac{F}{m}" style="vertical-align:-20%;" class="tex" alt="\frac{dv}{dt} = \frac{F}{m}" />.</p>
<p>In special relativity, your mass increases with velocity.  So, that equation becomes: <img src="http://l.wordpress.com/latex.php?latex=%5Cfrac%7Bd%5Cleft%28%5Cfrac%7Bv%7D%7B%5Csqrt%7B1-v%5E2%7D%7D%5Cright%29%7D%7Bdt%7D%20%3D%20%5Cfrac%7BF%7D%7Bm_0%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\frac{d\left(\frac{v}{\sqrt{1-v^2}}\right)}{dt} = \frac{F}{m_0}" style="vertical-align:-20%;" class="tex" alt="\frac{d\left(\frac{v}{\sqrt{1-v^2}}\right)}{dt} = \frac{F}{m_0}" /> (assuming units where the speed of light is 1 unit of distance per 1 unit of time and <img src="http://l.wordpress.com/latex.php?latex=m_0&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="m_0" style="vertical-align:-20%;" class="tex" alt="m_0" /> is your rest-mass).</p>
<p>For the purposes of this post, I&#8217;m going to assume the simplest initial conditions:  you start motionless and at the origin.  For ease of notation, let <img src="http://l.wordpress.com/latex.php?latex=a%20%3D%20%5Cfrac%7BF%7D%7Bm_0%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="a = \frac{F}{m_0}" style="vertical-align:-20%;" class="tex" alt="a = \frac{F}{m_0}" />.  Solving the above differential equation to get a formula for velocity and solving the resulting differential equation to get the distance <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_1a507c5494969dc6de305770cadc6630.png" title="x" style="vertical-align:-20%;" class="tex" alt="x" /> you&#8217;ve travelled in my base frame by time <img src="http://nklein.com/wp-content/plugins/easy-latex/cache/tex_4e156c4dfd6f5bd0adffc493c64bc7ca.png" title="t" style="vertical-align:-20%;" class="tex" alt="t" />, the answer comes out to:  <img src="http://l.wordpress.com/latex.php?latex=x%28t%29%20%3D%20%5Cfrac%7B1%7D%7Ba%7D%5Cleft%28-1%20%2B%20%5Csqrt%7B1%2Ba%5E2t%5E2%7D%5Cright%29&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x(t) = \frac{1}{a}\left(-1 + \sqrt{1+a^2t^2}\right)" style="vertical-align:-20%;" class="tex" alt="x(t) = \frac{1}{a}\left(-1 + \sqrt{1+a^2t^2}\right)" />.</p>
<p>I have solved this problem at least thirty times in the past two months.  Sometimes I used the simple initial conditions as above.  Sometimes I did it in all of its gory details (including the messy case where the applied force is not aligned with the current velocity).</p>
<p>I got the same answer (well, plus the extra mess when I did the full-on problem) every way that I tried it.</p>
<p>So, why did I do it over and over again?</p>
<p>If this were classical mechanics, the end equation would have been <img src="http://l.wordpress.com/latex.php?latex=x%28t%29%20%3D%20%5Cfrac%7B1%7D%7B2%7Dat%5E2&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x(t) = \frac{1}{2}at^2" style="vertical-align:-20%;" class="tex" alt="x(t) = \frac{1}{2}at^2" />.  And, I know that for low velocities, the classical mechanics answer should be almost identical to the special relativity answer.  And, there was no way that I thought <img src="http://l.wordpress.com/latex.php?latex=%5Cfrac%7B1%7D%7Ba%7D%5Cleft%28-1%20%2B%20%5Csqrt%7B1%2Ba%5E2t%5E2%7D%5Cright%29%20%5Capprox%20%5Cfrac%7B1%7D%7B2%7Dat%5E2&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="\frac{1}{a}\left(-1 + \sqrt{1+a^2t^2}\right) \approx \frac{1}{2}at^2" style="vertical-align:-20%;" class="tex" alt="\frac{1}{a}\left(-1 + \sqrt{1+a^2t^2}\right) \approx \frac{1}{2}at^2" />.</p>
<p>I knew what the graph <img src="http://l.wordpress.com/latex.php?latex=x%20%3D%20%5Csqrt%7Ba%5E2t%5E2%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x = \sqrt{a^2t^2}" style="vertical-align:-20%;" class="tex" alt="x = \sqrt{a^2t^2}" /> looked like when <img src="http://l.wordpress.com/latex.php?latex=t%20%5Cge%200&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="t \ge 0" style="vertical-align:-20%;" class="tex" alt="t \ge 0" />.  It is a straight line.  It doesn&#8217;t look much like the parabola <img src="http://l.wordpress.com/latex.php?latex=x%20%3D%20%5Cfrac%7B1%7D%7B2%7Da%20t%5E2&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x = \frac{1}{2}a t^2" style="vertical-align:-20%;" class="tex" alt="x = \frac{1}{2}a t^2" /> at all.  </p>
<p>My assumption was that since <img src="http://l.wordpress.com/latex.php?latex=x%20%3D%20%5Csqrt%7Ba%5E2t%5E2%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x = \sqrt{a^2t^2}" style="vertical-align:-20%;" class="tex" alt="x = \sqrt{a^2t^2}" /> was a straight line for <img src="http://l.wordpress.com/latex.php?latex=t%20%5Cge%200&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="t \ge 0" style="vertical-align:-20%;" class="tex" alt="t \ge 0" />, then <img src="http://l.wordpress.com/latex.php?latex=x%20%3D%20%5Csqrt%7B1%20%2B%20a%5E2t%5E2%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x = \sqrt{1 + a^2t^2}" style="vertical-align:-20%;" class="tex" alt="x = \sqrt{1 + a^2t^2}" /> would be a straight line shifted up one unit and bent (concave-down) a little bit like the graph of <img src="http://l.wordpress.com/latex.php?latex=x%20%3D%20%5Csqrt%7Bat%7D&#038;bg=FFFFCC&#038;fg=000000&#038;s=0" title="x = \sqrt{at}" style="vertical-align:-20%;" class="tex" alt="x = \sqrt{at}" /> is bent.</p>
<p>Boy was I wrong.  Here is a plot of the two together (created with <a href="http://fooplot.com/index.php?&#038;type0=0&#038;type1=0&#038;type2=0&#038;type3=0&#038;type4=0&#038;y0=%28-1%2Bsqrt%281%2B%28x%29%5E2%29%29&#038;y1=0.5%20*%20x%5E2&#038;y2=&#038;y3=&#038;y4=&#038;r0=&#038;r1=&#038;r2=&#038;r3=&#038;r4=&#038;px0=&#038;px1=&#038;px2=&#038;px3=&#038;px4=&#038;py0=&#038;py1=&#038;py2=&#038;py3=&#038;py4=&#038;smin0=0&#038;smin1=0&#038;smin2=0&#038;smin3=0&#038;smin4=0&#038;smax0=2pi&#038;smax1=2pi&#038;smax2=2pi&#038;smax3=2pi&#038;smax4=2pi&#038;thetamin0=0&#038;thetamin1=0&#038;thetamin2=0&#038;thetamin3=0&#038;thetamin4=0&#038;thetamax0=2pi&#038;thetamax1=2pi&#038;thetamax2=2pi&#038;thetamax3=2pi&#038;thetamax4=2pi&#038;ipw=1&#038;ixmin=0&#038;ixmax=0.3&#038;iymin=0&#038;iymax=0.05&#038;igx=0.1&#038;igy=0.01&#038;igl=1&#038;igs=0&#038;iax=1&#038;ila=1&#038;xmin=0&#038;xmax=0.3&#038;ymin=0&#038;ymax=0.05">fooplot</a>).  The red line is the classical mechanics version.  The black line is the relativistic version.  Here, the force is such that the body is accelerating at a rate of <q>the speed of light per second</q> so they&#8217;ve already gotten up to around 28,000 miles per second before you can see any separation in the graphs here.</p>
<p><a href="http://nklein.com/wp-content/uploads/2011/09/special-acceleration.png"><img src="http://nklein.com/wp-content/uploads/2011/09/special-acceleration.png" alt="distance (in light-seconds) vs. time (in seconds)" title="special-acceleration" width="500" height="300" class="aligncenter size-full wp-image-1766" /></a></p>
<p>Definitely, I can see the resemblance.  Now, to fix my intuition about square-roots.</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2011/09/if-it-quacks-like-a-parabola/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Keeping Server and Client Separate</title>
		<link>http://nklein.com/keeping-server-and-client-separate</link>
		<comments>http://nklein.com/keeping-server-and-client-separate#comments</comments>
		<pubDate>Thu, 08 Sep 2011 19:51:33 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[client-server]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[literate programming]]></category>
		<category><![CDATA[userial]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1758</guid>
		<description><![CDATA[The problem Whenever I write client-server applications, I run into the same problem trying to separate the code. To send a message from the server to the client, the server has to serialize that message and the client has to unserialize that message. The server doesn&#8217;t need to unserialize that message. The client doesn&#8217;t need [...]]]></description>
			<content:encoded><![CDATA[<h3>The problem</h3>
<p>Whenever I write client-server applications, I run into the same problem trying to separate the code.  To send a message from the server to the client, the server has to serialize that message and the client has to unserialize that message.  The server doesn&#8217;t need to unserialize that message.  The client doesn&#8217;t need to serialize that message.</p>
<p>It seems wrong to include both the serialization code and the unserialization code in both client and server when each side will only be using 1/2 of that code.  On the other hand, it seems bad to keep the serialization and unserialization code in separate places.  You don&#8217;t want one side serializing A+B+C and the other side trying to unserialize A+C+D+B.</p>
<h3>One approach: data classes</h3>
<p>Some projects deal with this situation by making every message have its own data class.  You take all of the information that you want to be in the message and plop it into a data class.  You then serialize the data class and send the resulting bytes.  The other side unserializes the bytes into a data class and plucks the data out of the data class.</p>
<p>The advantage here is that you can have some metaprogram read the data class definition and generate a serializer or unserializer as needed.  You&#8217;re only out-of-sync if one side hasn&#8217;t regenerated since the data class definition changed.</p>
<p>The disadvantage here is that I loathe data classes.  If my top-level interface is going to be <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&#40;</span>send-login username password<span style="color: #66cc66;">&#41;</span></span></code>, then why can&#8217;t I just serialize straight from there without having to create a dippy data structure to hold my opcode and two strings?</p>
<h3>Another approach: suck it up</h3>
<p>Who cares if the client contains both the serialization and unserialization code?  Heck, if you&#8217;re really all that concerned, then <code class="codecolorer lisp default"><span class="lisp">fmakunbound</span></code> half the universe before you <code class="codecolorer lisp default"><span class="lisp">save-lisp-and-die</span></code>.</p>
<p>Of course, unless you&#8217;re using data classes, you&#8217;re either going to have code in your client that references a bunch of functions and variables that only exist in your server or your client and server will be identical except for:</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> main <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  #+server <span style="color: #66cc66;">&#40;</span>server-main<span style="color: #66cc66;">&#41;</span>
  #-server <span style="color: #66cc66;">&#40;</span>client-main<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>Now, of course, your server is going to accidentally depend on OpenGL and OpenAL and SDL and a whole bunch of other -L&#8217;s it never actually calls.  Meanwhile, your client is going to accidentally depend on Postmodern and Portable-Threads and a whole bunch of other Po-&#8217;s it never actually calls.</p>
<h3>Another approach: tangle and weave, baby</h3>
<p>Another way that I&#8217;ve got around this is to use literate programming tools to let me write the serialiization and unserialization right next to each other in my document.  Then, anyone going to change the serialize code would be immediately confronted with the unserialize code that goes with it.</p>
<p>The advantage here is that you can tangle the client code through an entirely separate path than the server code keeping only what you need in each.</p>
<p>The disadvantage here is that now both your client code and your server code have to be in the same document or both include the same sizable chunk of document.  And, while there aren&#8217;t precisely name-capturing problems, trying to include the &#8220;serialize-and-send&#8221; chunk in your function in the client code still requires that you use the same variable names that were in that chunk.</p>
<h3>How can Lisp make this better?</h3>
<p>In Lisp, we can get the benefits of a data-definition language and data classes without needing the data classes.  Here&#8217;s a snippet of the data definition for a simple client-server protocol.</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">;;;; protocol.lisp</span>
<span style="color: #66cc66;">&#40;</span>userial<span style="color: #66cc66;">:</span><span style="color: #555;">make-enum-serializer</span> <span style="color: #66cc66;">:</span><span style="color: #555;">opcode</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">:</span><span style="color: #555;">ping</span> <span style="color: #66cc66;">:</span><span style="color: #555;">ping-ack</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defmessage <span style="color: #66cc66;">:</span><span style="color: #555;">ping</span>     <span style="color: #66cc66;">:</span><span style="color: #555;">uint32</span> ping-payload<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defmessage <span style="color: #66cc66;">:</span><span style="color: #555;">ping-ack</span> <span style="color: #66cc66;">:</span><span style="color: #555;">uint32</span> ping-payload<span style="color: #66cc66;">&#41;</span></pre></div>
<p>I&#8217;ve declared there are two different types of messages, each with their own opcode.  Now, I have macros for <code class="codecolorer lisp default"><span class="lisp">define-sender</span></code> and <code class="codecolorer lisp default"><span class="lisp">define-handler</span></code> that allow me to create functions which have no control over the actual serialization and unserialization.  My functions can only manipulate the named message parameters (the value of <code class="codecolorer lisp default"><span class="lisp">ping-payload</span></code> in this case) before serialization or after unserialization but cannot change the serialization or unserialization itself.</p>
<p>With this protocol, the client side has to handle ping messages by sending ping-ack messages.  The <code class="codecolorer lisp default"><span class="lisp">define-sender</span></code> macro takes the opcode of the message (used to identify the message fields), the name of the function to create, the argument list for the function (which may include declarations for some or all of the fields in the message), the form to use for the address to send the resulting message to, and any body needed to set fields in the packet based on the function arguments before the serialization.  The <code class="codecolorer lisp default"><span class="lisp">define-handler</span></code> macro takes the opcode of the message (again, used to identify the message fields), the name of the function to create, the argument list for the function, the form to use for the buffer to unserialize, and any body needed to act on the unserialized message fields.</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">;;;; client.lisp</span>
<span style="color: #66cc66;">&#40;</span>define-sender  <span style="color: #66cc66;">:</span><span style="color: #555;">ping-ack</span> send-ping-ack <span style="color: #66cc66;">&#40;</span>ping-payload<span style="color: #66cc66;">&#41;</span> *server-address*<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>define-handler <span style="color: #66cc66;">:</span><span style="color: #555;">ping</span>     handle-ping   <span style="color: #66cc66;">&#40;</span>buffer<span style="color: #66cc66;">&#41;</span> buffer
  <span style="color: #66cc66;">&#40;</span>send-ping-ack ping-payload<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<p>The server side has a bit more work to do because it&#8217;s going to generate the sequence numbers and track the round-trip ping times.</p>
<div class="codecolorer-container lisp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><pre class="lisp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">;;;; server.lisp</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defvar *last-ping-payload* <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>defvar *last-ping-time*    <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>define-sender <span style="color: #66cc66;">:</span><span style="color: #555;">ping</span> send-ping <span style="color: #66cc66;">&#40;</span>who<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>get-address-of who<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>incf *last-ping-payload*<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setf</span> *last-ping-time*    <span style="color: #66cc66;">&#40;</span>get-internal-real-time<span style="color: #66cc66;">&#41;</span>
        ping-payload        *last-ping-payload*<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>define-handler <span style="color: #66cc66;">:</span><span style="color: #555;">ping-ack</span> handle-ping-ack <span style="color: #66cc66;">&#40;</span>who buffer<span style="color: #66cc66;">&#41;</span> buffer
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> ping-payload *last-ping-payload*<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>update-ping-time who <span style="color: #66cc66;">&#40;</span>- <span style="color: #66cc66;">&#40;</span>get-internal-real-time<span style="color: #66cc66;">&#41;</span> *last-ping-time*<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div>
<h3>Problems with the above</h3>
<p>It feels strange to leave compile-time artifacts like the names and types of the message fields in the code after I&#8217;ve generated the functions that I&#8217;m actually going to use.  But, I guess that&#8217;s just part of Lisp development.  You can&#8217;t (easily) unload a package.  I can <code class="codecolorer lisp default"><span class="lisp">makunbound</span></code> a bunch of stuff after I&#8217;m loaded if I don&#8217;t want it to be convenient to modify senders or handlers at run-time.</p>
<p>There is intentional name-capture going on.  The names of the message fields become names in the handlers.  The biggest problem with this is that the <code class="codecolorer lisp default"><span class="lisp">defmessage</span></code> calls really have to be in the same namespace as the <code class="codecolorer lisp default"><span class="lisp">define-sender</span></code> and <code class="codecolorer lisp default"><span class="lisp">define-handler</span></code> calls.</p>
<p>I still have some work to do on my macros to support <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&amp;</span>key</span></code> and <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&amp;</span>optional</span></code> and <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&amp;</span>aux</span></code> and <code class="codecolorer lisp default"><span class="lisp"><span style="color: #66cc66;">&amp;</span>rest</span></code> arguments properly.  I will post those macros once I&#8217;ve worked out those kinks.</p>
<p>Anyone care to share how they&#8217;ve tackled client-server separation before?</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/keeping-server-and-client-separate/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Blackthorn 3D &#8212; Lisp game engine using USerial</title>
		<link>http://nklein.com/2011/06/blackthorn-3d-lisp-game-engine-using-userial/</link>
		<comments>http://nklein.com/2011/06/blackthorn-3d-lisp-game-engine-using-userial/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 23:35:00 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[userial]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1751</guid>
		<description><![CDATA[Elliott Slaughter announced Blackthorn 3D, yesterday. Blackthorn 3D is a game engine crafted in Lisp using LispbuilderSDL and cl-opengl for graphics and usocket and userial for network play.]]></description>
			<content:encoded><![CDATA[<p>Elliott Slaughter announced <a href="http://elliottslaughter.com/2011/06/blackthorn-3d">Blackthorn 3D</a>, yesterday.  Blackthorn 3D is a game engine crafted in Lisp using <a href="http://code.google.com/p/lispbuilder/wiki/LispbuilderSDL">LispbuilderSDL</a> and <a href="http://common-lisp.net/project/cl-opengl/">cl-opengl</a> for graphics and <a href="http://common-lisp.net/project/usocket/">usocket</a> and <a href="http://nklein.com/software/unet/userial/">userial</a> for network play.</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2011/06/blackthorn-3d-lisp-game-engine-using-userial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C- in MacOSX&#8217;s Terminal.app</title>
		<link>http://nklein.com/2011/06/c-in-macosxs-terminal-app/</link>
		<comments>http://nklein.com/2011/06/c-in-macosxs-terminal-app/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 06:25:24 +0000</pubDate>
		<dc:creator>pat</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://nklein.com/?p=1747</guid>
		<description><![CDATA[After tonight&#8217;s TC Lispers Meeting, I had a renewed interest in figuring out why C-&#60;right arrow&#62; didn&#8217;t work for me in Org-Mode or Paredit. After a whole bunch of running in circles, I have discovered a combination that works (with these clues). I have my TERM variable set to xterm-color. I configured the Terminal.app using [...]]]></description>
			<content:encoded><![CDATA[<p>After tonight&#8217;s <a href="http://tclispers.org/events/june-meeting-emacs-theme">TC Lispers Meeting</a>, I had a renewed interest in figuring out why C-&lt;right arrow&gt; didn&#8217;t work for me in Org-Mode or Paredit.</p>
<p>After a whole bunch of running in circles, I have discovered a combination that works (with <a href="http://marc-abramowitz.com/archives/2006/10/05/ctrl-left-and-ctrl-right-in-bash-and-emacs/">these clues</a>).  I have my <code class="codecolorer text default"><span class="text">TERM</span></code> variable set to <code class="codecolorer text default"><span class="text">xterm-color</span></code>.  I configured the Terminal.app using its Keyboard settings to have it send the string &#8220;\033[1;5C&#8221; for C-&lt;right arrow&gt; and &#8220;\033[1;5D&#8221; for C-&lt;left arrow&gt;.  (The &#8220;\033&#8243; is the escape key.)</p>
<p>This works for me even through <code class="codecolorer text default"><span class="text">screen</span></code>.</p>
<p>Bonus.</p>
]]></content:encoded>
			<wfw:commentRss>http://nklein.com/2011/06/c-in-macosxs-terminal-app/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

