<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
   <channel>
      <title>Sundry Miscellanea</title>
      <link>http://blog.lib.umn.edu/sturt001/sturtivant/</link>
      <description></description>
      <language>en</language>
      <copyright>Copyright 2008</copyright>
      <lastBuildDate>Thu, 03 Apr 2008 13:54:50 -0600</lastBuildDate>
      <generator>http://www.sixapart.com/movabletype/?v=3.33.uthink</generator>
      <docs>http://blogs.law.harvard.edu/tech/rss</docs> 

            <item>
	
         <title>Programming with Generators</title>
         <description><![CDATA[<p>I gave a talk about programming with generators in the remarkable programming language Icon courtesy of the local ACM chapter. Here are the <a href="http://www-users.cs.umn.edu/~carl/icontalk/">small programs</a> I used to illustrate Icon's expression evaluation mechanism. Here is the <a href="#Title">flyer!</a> As you can see at the bottom of the flyer, I have written a dynamic 'glue' library for the Icon virtual machine in C++. This library makes writing dynamic libraries for Icon in C++ very simple. The current documentation for the glue is <a href="http://members.bitstream.net/carl/">here</a>. which I am currently writing it as of 2008/4/1. The glue is complete and being tested and cleaned up as I do this.</p>

<p>=================</p>

<p><a name="Title">Title</a>:		Paradigm Lost?<br />
Subtitle: 	Programming without Booleans: using Generators in Icon<br />
Author:		Carl Sturtivant, Dept. of CS & E, U of M<br />
When & Where: 5:30pm Thursday April 17, EE/CSci 3-115</p>

<p>Abstract</p>

<p>The otherwise conventional programming language Icon is designed around a powerful control mechanism called generators. Instead of testing whether something can be done, and if so attempting to do it, generators enable a much more natural programming style: simply attempt to do it, and the success or failure of the attempt will automatically be propagated to the surrounding context. There may be more than one way to succeed, and if the first way found leads to the failure of something else, then control can automatically backtrack to get a second way to succeed and then go forward with a second attempt to do the something else, and so forth. For this reason expressions in Icon may implicitly produce a sequence of results: an empty result sequence is interpreted as failure, and a non-empty one as success.</p>

<p>A small, mature and powerful language, Icon is implemented through a 300K virtual machine, iconx, implemented in C. The source has been placed overtly in the public domain. An Icon program is compiled into an icode file with an executable header, that when run will automatically invoke iconx. Benchmarks indicate that Icon runs at a similar speed to Perl or Python, and about twice as fast as Ruby. Icon was developed at the University of Arizona over a period of two decades, and the implementation is both robust and available for a wide variety of platforms. Designed for the purpose of manipulating text effectively, Icon has sufficient expressive power that regular expressions are unecessary. In this talk I will demonstrate programming with generators in Icon with applications, as well as giving a survey of the features of the language.</p>

<p>Those who wish to try out some of the ideas in his talk may pick up <a href="http://www.cs.arizona.edu/icon/">Icon 9.4.3 </a> The <a href="http://www.cs.arizona.edu/icon/v95x/readme.htm">Icon 9.5x</a> binary distribution is currently only available for cygwin, macintosh and linux, though source is available with builds for many platforms. MSWindows users will need to install <a href="http://www.cygwin.com/">cygwin</a> and will need to get <a href="http://www.cs.arizona.edu/icon/v95x/readme.htm">Icon 9.5x</a> which has vital bug fixes. </p>

<p>Icon related bio: Dr. Sturtivant has built an experimental dynamic 'glue' library for Icon in C++ that enables additions to Icon to be written cleanly in C++. Such an addition can then be compiled into its own dynamic library and loaded by an Icon program at runtime, without any modification to iconx or the icode compiler. The glue library enables further C++ to routinely do esoteric things such as call an Icon procedure, or when called by Icon act as an Icon generator that suspends a sequence of results. He also inspired and co-wrote the new external value datatype for Icon, that will be a part of the standard distribution of version 9.5.</p>]]></description>
         <link>http://blog.lib.umn.edu/sturt001/sturtivant/2008/04/programming_with_generators_1.html</link>
         <guid>http://blog.lib.umn.edu/sturt001/sturtivant/2008/04/programming_with_generators_1.html</guid>
         <category>Comment</category>
         <pubDate>Thu, 03 Apr 2008 13:54:50 -0600</pubDate>
      </item>
            <item>
	<enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/math.jpg" length="3448" type="image/jpeg" />
         <title>Innumeracy. Why the blog is it tolerated?!</title>
         <description><![CDATA[<p>If you don't have a little mathematics or coding up your sleeve or more conveniently placed in your head, then you won't like the overhead necessary to understand this blog. Sorry --- for some reason liberal arts ignorance (illiteracy being the ultimate form) is socially and culturally unacceptable, but scientific ignorance (of which the inability to read and understand simple mathematics or code is the ultimate form) is considered the norm. The latter is called <a href="http://wordnet.princeton.edu/perl/webwn?o2=&o0=1&o7=&o5=&o1=1&o6=&o4=&o3=&s=innumerate&h=0&j=0#c">innumeracy </a>by the very literate, and given that the root of this word gives a completely misleading impression that it's all about numbers, I am convinced that it was coined by an innumerate. So I say sorry to apologize for your ignorance for you, if you're one of those people, since for cultural reasons you're unlikely to endeavor to fix the problem for yourself, or perhaps even to realize there <strong>is</strong> a problem. Don't take this personally --- the educational apparatus around the world strongly supports this strange situation, especially primary and secondary education.</p>

<p>Mathematics is an international language evolved to talk of the world with far greater intellectual economy than the best so-called natural languages. The syntax and semantics of mathematics have been much more consciously honed than those of natural languages. A person who does not speak at least a basic core of mathematics is ignorant indeed, unable to grasp simple attributes of artifacts or nature, or communicate without immense difficulty about such. It's like going through life with a paper bag over your head. And just like any other language it's best learned when you're young. Eradicating illiteracy in adults is difficult. Eradicating innumeracy in adults is likewise difficult. So a better path would be to eliminate it at source during primary and secondary education. And given that innumeracy is the default, we have a catch-22 roadblock to doing that: innumerate parents, teachers and peers.</p>

<p>If you do have some active calculus and some mathematical maturity, then you speak a second language and I hope you proclaim "I speak mathematics", and use it wherever possible with others. Like any minority language only use and a cultural perception that speaking it is important will have an effect on its spread. Add your vote to the widespread occurrence of mathematical speech by speaking mathematics. It occupies a unique position among natural languages, making it the most important second language.<br />
<img alt="math.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/math.jpg" width="156" height="53" /><br />
</p>]]></description>
         <link>http://blog.lib.umn.edu/sturt001/sturtivant/2007/01/what_the_blog.html</link>
         <guid>http://blog.lib.umn.edu/sturt001/sturtivant/2007/01/what_the_blog.html</guid>
         <category>Comment</category>
         <pubDate>Fri, 05 Jan 2007 10:10:04 -0600</pubDate>
      </item>
            <item>
	<enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative1.jpg" length="3660" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative10.jpg" length="3362" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative11.jpg" length="13572" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative12.jpg" length="2821" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative13.jpg" length="12266" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative14.jpg" length="2821" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative15.jpg" length="6903" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative16.jpg" length="2821" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative17.jpg" length="6915" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative18.jpg" length="2821" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative19.jpg" length="2821" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative2.jpg" length="2187" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative20.jpg" length="4619" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative21.jpg" length="1517" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative22.jpg" length="11256" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative23.jpg" length="2778" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative24.jpg" length="7884" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative25.jpg" length="4915" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative26.jpg" length="11111" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative27.jpg" length="3037" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative28.jpg" length="11167" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative29.jpg" length="3139" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative3.jpg" length="3424" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative30.jpg" length="17860" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative31.jpg" length="14961" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative32.jpg" length="6277" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative33.jpg" length="9011" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative34.jpg" length="5099" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative35.jpg" length="2334" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative4.jpg" length="3390" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative5.jpg" length="1772" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative6.jpg" length="5749" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative7.jpg" length="7425" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative8.jpg" length="2431" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative9.jpg" length="11167" type="image/jpeg" />
         <title>Add so as to multiply (part 2)</title>
         <description><![CDATA[<p>    <a href="http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/add_so_as_to_multiply_1.html">Add so as to multiply</a> looked at differentiable solutions to the functional equation<br />
<img alt="multiplicative1.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative1.jpg" width="167" height="44" /><br />
and showed that they were all of the form<br />
<img alt="multiplicative2.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative2.jpg" width="110" height="44" /><br />
i.e. they are all logarithms in some base. But now what if we drop differentiability and just look for a function of the positive real numbers, and proceed from first principles? (We stick to positive numbers for now because <em><strong>g</strong></em> has a problem at <strong><em>0</em></strong>. If we set <em><strong>y</strong></em> to <strong><em>0</em></strong> in the functional equation, we get<br />
<img alt="multiplicative3.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative3.jpg" width="160" height="44" /><br />
so if <em><strong>g</strong></em> ever takes on a non-zero value we have a contradiction, unless <em><strong>g</strong></em> is undefined at <strong><em>0</em></strong>.) We pursue an exploratory argument that could be made a lot more compact, but I won't do that for exploration's sake. Perhaps I will write a very compact version as a later blog article.<br />
    <br />
    First consider the functional equation when we set <strong><em>x</em></strong> and <em><strong>y</strong></em> to <strong><em>1</em></strong>.<br />
<img alt="multiplicative4.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative4.jpg" width="160" height="44" /><br />
So<br />
<img alt="multiplicative5.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative5.jpg" width="85" height="44" /><br />
Now what if we set <strong><em></em>y</strong> to be <strong><em>x</em></strong> to the power <strong><em>n-1</em></strong> where <strong><em>n</em></strong> is a positive integer. Then<br />
<img alt="multiplicative6.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative6.jpg" width="192" height="74" /><br />
so we may decrement the exponent of <strong><em>x</em></strong> by adding <strong><em>g(x)</em></strong>. Decrementing it by <strong><em>n</em></strong> gives<br />
<img alt="multiplicative7.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative7.jpg" width="187" height="103" /><br />
Note that this also works when <strong><em>n</em></strong> is <strong><em>0</em></strong> because <strong><em>g(1)</em></strong> is <strong><em>0</em></strong>. Call this the natural exponent rule. So if <strong><em>x</em></strong> is a positive natural number and we factor it into a product of distinct prime powers<br />
<img alt="multiplicative8.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative8.jpg" width="121" height="44" /><br />
then we may use the original functional equation and the natural exponent rule to find that<br />
<img alt="multiplicative9.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative9.jpg" width="260" height="106" /><br />
So the value of <strong><em>g</em></strong> at each positive natural number <strong><em>x</em></strong> depends upon its values at all of the prime numbers. In fact as we will see, we may define <em><strong>g(2), g(3), g(5), g(7), g(11)</strong></em> and so forth quite arbitrarily. So unless we impose some constraint upon <strong><em>g</em></strong>, it can be quite nasty. However, we will now show that if we insist that <strong><em>g</em></strong> is a continuous function, then fixing one value of <strong><em>g</em></strong> fixes all others ... ok, back to the details. Suppose we set <strong><em></em>y</strong> to be the reciprocal of <strong><em>x</em></strong> in the original functional equation. This gives<br />
<img alt="multiplicative10.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative10.jpg" width="167" height="48" /><br />
and since <strong><em>g(1)</em></strong> is zero we have<br />
<img alt="multiplicative11.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative11.jpg" width="385" height="110" /><br />
Call the last rule the quotient rule. So now we have the rule<br />
<img alt="multiplicative12.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative12.jpg" width="133" height="44" /><br />
for any integer <strong><em>a</em></strong>. Now what about rational exponents? Let's start with an exponent of <strong><em>1/n</em></strong>, where <strong><em>n</em></strong> is a natural number.<br />
<img alt="multiplicative13.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative13.jpg" width="186" height="170" /><br />
So now we know that the rule<br />
<img alt="multiplicative14.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative14.jpg" width="133" height="44" /><br />
works when <strong><em>a</em></strong> is the reciprocal of a positive natural number. What about any positive rational exponent, <strong><em>m/n</em></strong> ? Applying the rules we know so far, we get<br />
<img alt="multiplicative15.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative15.jpg" width="177" height="106" /><br />
So now we know that the rule<br />
<img alt="multiplicative16.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative16.jpg" width="133" height="44" /><br />
works for any positive rational exponent. What about any negative rational exponent <strong><em>-m/n</em></strong> ?<br />
<img alt="multiplicative17.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative17.jpg" width="191" height="106" /><br />
Putting all these together we know that the rule<br />
<img alt="multiplicative18.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative18.jpg" width="133" height="44" /><br />
applies whenever <strong><em>a</em></strong> is rational. Call this the rational exponent rule, and note that there's nothing here forcing <strong><em>x</em></strong> to be rational, just positive by our current convention. </p>

<p>What about <strong><em>g(2), g(3), g(5), g(7), g(11)</em></strong> and so forth? Roughly speaking these are independent in general, because the primes <strong><em>2,3,5,7,11</em></strong> etcetera are not mutually related by rational exponents, only by real ones. And unless <strong><em>g</em></strong> is required to be continuous, we do not know that the rule<br />
<img alt="multiplicative19.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative19.jpg" width="133" height="44" /><br />
applies for all real exponents. If we knew this, then we could conclude for example that<br />
<img alt="multiplicative20.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative20.jpg" width="159" height="74" /><br />
where (<strong>lg</strong> denotes the base <strong><em>2</em></strong> logarithm as usual) and so only one <strong><em>g</em></strong> value would be arbitrary, say <strong><em>g(2)</em></strong> and then the rules would determine <strong><em>g</em></strong> on any rational argument (you might like to check this). So suppose we fix <strong><em>g(2)</em></strong> and assert that <strong><em>g</em></strong> must be continuous. Let <strong><em>p</em></strong> be an even prime (i.e. not <strong><em>2</em></strong>). We know that<br />
<img alt="multiplicative21.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative21.jpg" width="83" height="44" /><br />
but we need to approximate this arbitrarily closely with rational exponents, so we can use the rational exponent rule. Here's how we may play that game! Let <strong><em>n</em></strong> be an arbitrarily large natural number, then<br />
<img alt="multiplicative22.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative22.jpg" width="216" height="115" /><br />
Notice that the two exponents have numerators that differ by <strong><em>1</em></strong>, as we can definitely use <strong><em>&lt;</em></strong> because the log of <strong><em>p</em></strong> is irrational. But the denominators of the exponents are both <strong><em>n</em></strong>, so the error in each exponent is at most <strong><em>1/n</em></strong>. So by choosing sufficiently large <strong><em>n</em></strong> we may approximate the genuine but irrational exponent as closely as we please. That is to say<br />
<img alt="multiplicative23.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative23.jpg" width="144" height="48" /><br />
If <strong><em>g</em></strong> is continuous (which informally means approximable i.e. <strong><em>g</em></strong> of an approximation to <strong><em>p</em></strong> is approximately <strong><em>g</em></strong> of <strong><em>p</em></strong>, and this can be made as accurate as you like by choosing better and better approximations of <strong><em>p</em></strong>), then applying <strong><em>g</em></strong> to both sides gives<br />
<img alt="multiplicative24.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative24.jpg" width="190" height="83" /><br />
where continuity allows us to move the limit. (Notice how this is just a limit of approximations as in the parenthesised statement above.) Now using rational exponent rule for <strong><em>g</em></strong> gives<br />
<img alt="multiplicative25.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative25.jpg" width="197" height="55" /><br />
and as we take the limit the floor makes a vanishing difference, so<br />
<img alt="multiplicative26.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative26.jpg" width="266" height="122" /><br />
So we may conclude that<br />
<img alt="multiplicative27.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative27.jpg" width="138" height="44" /><br />
if <strong><em>g</em></strong> is continuous, for any odd prime <strong><em>p</em></strong>. So now if <strong><em>x</em></strong> is any natural number, <strong><em>g(x)</em></strong> is determined from its factorization as before<br />
<img alt="multiplicative28.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative28.jpg" width="260" height="106" /><br />
but now we know that for each <strong><em>i</em></strong><br />
<img alt="multiplicative29.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative29.jpg" width="149" height="44" /><br />
and so<br />
<img alt="multiplicative30.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative30.jpg" width="285" height="168" /><br />
Now the quotient rule gives <strong><em>g</em></strong> for <strong><em>x</em></strong> any positive rational number <strong><em>m/n</em></strong> because<br />
<img alt="multiplicative31.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative31.jpg" width="224" height="200" /><br />
and because <strong><em>g</em></strong> is continuous, this defines <strong><em>g</em></strong> on all positive real numbers as well (by rational approximation in the spirit of continuity as exemplified above). So we conclude that the functional equation has continuous solutions on the positive reals only of the form<br />
<img alt="multiplicative32.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative32.jpg" width="145" height="115" /><br />
i.e. all solutions are differentiable, and there are no more than before.<br />
    <br />
    What happens for negative <strong><em>x</em></strong> ? Well if we set both <strong><em>x</em></strong> and <strong><em>y</em></strong> to <strong><em>-1</em></strong> in the original functional equation we get<br />
<img alt="multiplicative33.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative33.jpg" width="245" height="103" /><br />
So if we just set <strong><em>y</em></strong> to <strong><em>-1</em></strong> in the original functional equation we get<br />
<img alt="multiplicative34.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative34.jpg" width="181" height="74" /><br />
So the final conclusion is<br />
<img alt="multiplicative35.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/multiplicative35.jpg" width="121" height="44" /></p>]]></description>
         <link>http://blog.lib.umn.edu/sturt001/sturtivant/2007/01/add_so_as_to_multiply_part_2.html</link>
         <guid>http://blog.lib.umn.edu/sturt001/sturtivant/2007/01/add_so_as_to_multiply_part_2.html</guid>
         <category>Real</category>
         <pubDate>Fri, 05 Jan 2007 00:40:19 -0600</pubDate>
      </item>
            <item>
	<enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/array37.jpg" length="4521" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/cyclic.jpg" length="16313" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/dull.jpg" length="1955" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/final37.jpg" length="3307" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/lastone.jpg" length="26378" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/mod37.jpg" length="2759" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/mod7mult.jpg" length="12854" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/negreln.jpg" length="1630" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/rightmost.jpg" length="6198" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/xplusnegx.jpg" length="1620" type="image/jpeg" />
         <title>Finding the right one</title>
         <description><![CDATA[<p>Here's my way to find the position in a 32 bit word of the rightmost 1 bit. Back in late '96 I used this for certain purposes, other portable methods being too slow. The technique works equally well for 64 bit or larger word sizes. It uses the well known trick that given a word <em><strong>x</strong></em>, we can compute a word containing a single 1 bit in the position of the rightmost 1 bit of <em><strong>x</strong></em> by bitwise <em>and</em>ing <em><strong>x</strong></em> with its arithmetic negation. Here's why: if I add a word to its bitwise negation, there are no carries and I get a word of all ones, which is -1 in standard two's complement representation of signed words. Why is this word of all ones the representation of -1? Well just imagine adding 1 onto it --- carries ripple all the way through the word and fall off the end, leaving a word of all zeros, which is 0. Just as 999 behaves like -1 on a three digit decimal counter.<br />
<img alt="xplusnegx.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/xplusnegx.jpg" width="114" height="44" /><br />
Now the arithmetic negation of a word, on the other hand, obeys this obvious rule.<br />
<img alt="dull.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/dull.jpg" width="115" height="44" /><br />
Comparing the two, we see the relation between the two kinds of negation.<br />
<img alt="negreln.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/negreln.jpg" width="123" height="44" /><br />
So here's what happens when you add one onto the bitwise negation to get the arithmetic negation, followed by bitwise <em>and</em>ing that with the original word, illustrated by an example.<br />
<img alt="lastone.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/lastone.jpg" width="401" height="133" /><br />
A non-zero word consists of an arbitrary sequence of bits followed by the last 1 bit, followed by all zeros. (In the example there are two such zeros.) So its bitwise negation consists of the negation of the arbitrary sequence of bits followed by a 0 bit followed by all ones. Note that if we <em>and</em>ed the logical negation with the original word we would get zero, because in each bit position we would be <em>and</em>ing together a 0 bit with a 1 bit giving a 0 bit. However, now we add 1 onto the bitwise negation first, to get the arithmetic negation. This has the effect of causing a carry to ripple through the sequence of ones at the right hand end, putting a 1 bit into the position of the 0 bit to the left of that sequence, which is in the position of the rightmost 1 bit in the original word. So the arithmetic negation consists of the negation of the arbitrary sequence of bits followed by a 1 bit followed by all zeros. Clearly <em>and</em>ing it with the original word causes the arbitrary leading bits to be <em>and</em>ed with their negations, thus making all upper bits of the result be 0, and the zeros on the right hand end lead to zeros in the result. So the only bit position that is 1 in both is that of the last 1 in the original pattern. So we may conclude that<br />
<img alt="rightmost.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/rightmost.jpg" width="244" height="83" /><br />
where <em><strong>k</strong></em> is the position of the rightmost 1 bit in the word <em><strong>x</strong></em>, with position zero defined to be the rightmost position.</p>

<p>Now to the real problem --- how do we find <em><strong>k</strong></em> given this? We could keep shifting it to the right until we get 1, but that looks clumsy and inefficient. Instead we use some mathematics! The integers <a href="http://en.wikipedia.org/wiki/Modular_arithmetic">modulo</a> a prime number <em><strong>p</strong></em> form a <a href="http://en.wikipedia.org/wiki/Finite_field">finite field</a>, and the <a href="http://en.wikipedia.org/wiki/Finite_field#Applications">multiplicative group in any finite field is cyclic</a>. Here is a concrete example where <em><strong>p</strong></em>=7 of what this all means. First the multiplicative group of integers modulo 7 is just the multiplication table of the possible non-zero remainders when dividing by 7. The term "modulo 7" just means "ignoring multiples of 7", so everything is a remainder on dividing by 7. We throw out zero because it behaves badly with multiplication. The result is as follows.<br />
<img alt="mod7mult.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/mod7mult.jpg" width="181" height="218" /><br />
This is the "multiplicative group of the integers modulo 7", and it is cyclic, which means that there is an element that generates all of the others. In this case 3 does the job, as follows.<br />
<img alt="cyclic.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/cyclic.jpg" width="247" height="195" /><br />
The powers of 3 cycle through all values. This does not work for 2 in this case. We say that 3 is a generator and two is not, for modulo 7 multiplication.</p>

<p>Now for my little trick: if we choose a prime <em><strong>p</strong></em> bigger than the word size (32 bits say) where 2 <strong>is </strong>a generator, then modulo <em><strong>p</strong></em> the different powers of 2 that appear when we and a word with its arithmetic negation will all be different modulo <em><strong>p</strong></em>. 37 is such a prime (for 32 bit words). So the value of the following expression has 32 distinct values, all less than 37, for each different position of the last 1 bit. Here "mod 37" just means "take the remainder upon dividing by 37", sometimes written "%&nbsp;37" in some programming languages.<br />
<img alt="mod37.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/mod37.jpg" width="153" height="44" /><br />
So if we create a constant array with a maximum index of 36 that contains a table as follows, we may use it for table lookup of the position of the rightmost 1 bit, given the value of the previous expression. The array should contain the following values, which are <a href="http://en.wikipedia.org/wiki/Discrete_logarithm">discrete logarithms</a> modulo 37.<br />
<img alt="array37.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/array37.jpg" width="260" height="44" /><br />
Note that it is the fact that values are now small (less than 37 in fact) that makes the array practicable. Now we may write the final expression for the position of the rightmost 1 using this array.<br />
<img alt="final37.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/final37.jpg" width="174" height="44" /><br />
If the word size is 64 or 128 or 256 bits, we may use the same method <em>mutatis mutandis</em> with the respective primes 67, 131 and 269.<br />
</p>]]></description>
         <link>http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/finding_the_right_one.html</link>
         <guid>http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/finding_the_right_one.html</guid>
         <category>Binary</category>
         <pubDate>Thu, 28 Dec 2006 08:14:15 -0600</pubDate>
      </item>
            <item>
	<enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/logfunc.jpg" length="3660" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/logfunc2.jpg" length="3015" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/logfunc3.jpg" length="2816" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/logfunc4.jpg" length="3532" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/logfunc5.jpg" length="2187" type="image/jpeg" />
         <title>Add so as to multiply</title>
         <description><![CDATA[<p>In a discussion of <a href="http://en.wikipedia.org/wiki/Entropy">entropy</a> it may be pointed out that when physical systems are paired the total number of <a href="http://en.wikipedia.org/wiki/Microstate_%28statistical_mechanics%29">microstates</a> multiplies, since a microstate of the composite system is a pair of states of the separate systems. And yet the entropy, (which is a measure our ignorance of the exact state of a system) adds under these conditions. <a href="http://en.wikipedia.org/wiki/Boltzmann">Boltzmann</a> took this to mean that the entropy is proportional to the logarithm of the number of microstates, a famous result that endures today. This is because any logarithm satisfies the following functional equation, mapping multiplication of numbers to the addition of their logarithms.<br />
<img alt="logfunc.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/logfunc.jpg" width="167" height="44" /><br />
But now we may ask which functions <em><strong>g</strong></em> actually satisfy this equation! If <em><strong>g</strong></em> is differentiable, then we may proceed as follows. First partial differentiate with respect to <em><strong>y</strong></em>.<br />
<img alt="logfunc2.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/logfunc2.jpg" width="143" height="44" /><br />
Now set <em><strong>y</strong></em> to 1, and divide by <em><strong>x</strong></em>.<br />
<img alt="logfunc3.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/logfunc3.jpg" width="126" height="55" /><br />
Look familiar? Integrating both sides gives a logarithm.<br />
<img alt="logfunc4.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/logfunc4.jpg" width="171" height="44" /><br />
And we may write <strong><em>k</em></strong> for the coefficient of the logarithm, and note that if this is to satisfy the original functional equation, the constant of integration <strong><em>C</em></strong> must be zero. So the general differentiable solution is<br />
<img alt="logfunc5.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/logfunc5.jpg" width="110" height="44" /><br />
But what if we care only about continuous functions: are there  any more solutions? More on this soon!</p>]]></description>
         <link>http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/add_so_as_to_multiply_1.html</link>
         <guid>http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/add_so_as_to_multiply_1.html</guid>
         <category>Real</category>
         <pubDate>Fri, 15 Dec 2006 15:22:33 -0600</pubDate>
      </item>
            <item>
	<enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/precomp.jpg" length="4916" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/threebranch.jpg" length="8024" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/threevals.jpg" length="3032" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/update.jpg" length="3137" type="image/jpeg" />
         <title>Alternating three ways without branching</title>
         <description><![CDATA[<p>Suppose you want a variable to cycle between three different values in a loop, like this.<br />
<img alt="threebranch.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/threebranch.jpg" width="272" height="83" /><br />
If this code is executed in a loop, then <strong><em>x</em></strong> will alternate between the values <strong><em>a</em></strong>, <strong><em>b</em></strong>,  and <strong><em>c</em></strong> repeatedly. But how may we achieve the same effect without any branching? Tricky...here's a little scheme I've cooked up to do just that. It cheats by using <em>two </em> variables <strong><em>x</em></strong> and <strong><em>y</em></strong>. The mysterious "plus-in-a-circle" operation is bitwise <em><a href="http://en.wikipedia.org/wiki/Exclusive_or">exclusive-or</a></em> (exor). </p>

<p>First, before the loop starts, initialize <strong><em>x</em></strong> and <strong><em>y</em></strong>, and precompute the magic constant <strong><em>s</em></strong> as follows.<br />
<img alt="precomp.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/precomp.jpg" width="130" height="103" /><br />
Then inside the loop execute the following non-branching code.<br />
<img alt="update.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/update.jpg" width="155" height="44" /><br />
Note that <strong><em>x</em></strong> cycles between the following three values, because of the self-inverse property of exor (see <a href="http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/alternating_without_a_branch_1.html">Alternating without a branch</a>).<br />
<img alt="threevals.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/threevals.jpg" width="62" height="103" /><br />
So if we exor <strong><em>x</em></strong> with the magic constant <strong><em>s</em></strong> we get a value that cycles between <strong><em>a</em></strong>, <strong><em>b</em></strong>,  and <strong><em>c</em></strong>, because of the self-inverse property of exor, once again.</p>

<p>There's a secret connection between this scheme and the Fibonacci numbers...<br />
</p>]]></description>
         <link>http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/alternating_three_ways_without.html</link>
         <guid>http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/alternating_three_ways_without.html</guid>
         <category>Binary</category>
         <pubDate>Thu, 14 Dec 2006 09:48:24 -0600</pubDate>
      </item>
            <item>
	<enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/algswap.jpg" length="2275" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/branchswap.jpg" length="4125" type="image/jpeg" /><enclosure url="http://blog.lib.umn.edu/sturt001/sturtivant/images/exor.jpg" length="1660" type="image/jpeg" />
         <title>Alternating without a branch</title>
         <description><![CDATA[<p>Suppose you want to achieve the effect of a variable repeatedly alternating between two values<br />
<img alt="branchswap.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/branchswap.jpg" width="251" height="44" /> <br />
(for example inside a loop) without using a branch. If the variables are just bit patterns such as integers or references (pointers) then you may use bitwise <em>exclusive-or</em> (exor) as follows, and eliminate the branch.<br />
<img alt="algswap.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/algswap.jpg" width="131" height="44" /><br />
Of course, the exor of <em><strong>a</strong></em> and <em><strong>b</strong></em> can be precomputed outside the loop. This relies upon exor being not only commutative and associative, but also acting as its own inverse as follows.<br />
<img alt="exor.jpg" src="http://blog.lib.umn.edu/sturt001/sturtivant/images/exor.jpg" width="93" height="44" /><br />
Informally speaking, exor acts as its own inverse; it is both addition and subtraction in its domain.</p>

<p>Soon (after doing some real work) I will say how to alternate cyclically between three different values in a loop, without branching ... this is a little more amusing.</p>]]></description>
         <link>http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/alternating_without_a_branch_1.html</link>
         <guid>http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/alternating_without_a_branch_1.html</guid>
         <category>Binary</category>
         <pubDate>Wed, 13 Dec 2006 14:16:36 -0600</pubDate>
      </item>
            <item>
	
         <title> We blog</title>
         <description><![CDATA[<p>therefore we cyber-exist. This 'blog will contain a rag-bag of fragments of information, useless by default, serendipitously assembled. Examining this 'blog will be less like watching paint dry than like checking the content of an obscure storage closet in a sub-basement. </p>]]></description>
         <link>http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/we_blog.html</link>
         <guid>http://blog.lib.umn.edu/sturt001/sturtivant/2006/12/we_blog.html</guid>
         <category>Comment</category>
         <pubDate>Wed, 13 Dec 2006 13:15:48 -0600</pubDate>
      </item>
      
   </channel>
</rss>
