<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY % HTMLlat1 PUBLIC
 "-//W3C//ENTITIES Latin 1 for XHTML//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">
]>
<rdf:RDF
 xmlns="http://purl.org/rss/1.0/"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:content="http://purl.org/rss/1.0/modules/content/"
 xmlns:admin="http://webns.net/mvcb/"
>
<channel rdf:about="http://jfet.net/~bryce/nb">
<title>iGurgitate</title>
<link>http://jfet.net/~bryce/nb</link>
<description>Consuming and Producing</description>
<dc:language>en-us</dc:language>
<dc:creator>Bryce</dc:creator>
<dc:date>2010-04-13T18:13:29-07:00</dc:date>
<admin:generatorAgent rdf:resource="http://nanoblogger.sourceforge.net" />
<items>
<rdf:Seq>
<rdf:li rdf:resource="http://jfet.net/~bryce/nb/archives/2010/04/11/T18_20_44/index.html" />
<rdf:li rdf:resource="http://jfet.net/~bryce/nb/archives/2009/04/02/T00_50_34/index.html" />
<rdf:li rdf:resource="http://jfet.net/~bryce/nb/archives/2009/02/18/T23_47_48/index.html" />
<rdf:li rdf:resource="http://jfet.net/~bryce/nb/archives/2008/12/08/T00_11_49/index.html" />
<rdf:li rdf:resource="http://jfet.net/~bryce/nb/archives/2008/12/07/T23_50_52/index.html" />
<rdf:li rdf:resource="http://jfet.net/~bryce/nb/archives/2005/12/10/T22_50_21/index.html" />
</rdf:Seq>
</items>
</channel>
<item rdf:about="http://jfet.net/~bryce/nb/archives/2010/04/11/T18_20_44/index.html">
<link>http://jfet.net/~bryce/nb/archives/2010/04/11/T18_20_44/index.html</link>
<title>C on the PDP10</title>
<dc:date>2010-04-11T18:20:44-07:00</dc:date>
<dc:creator>Bryce</dc:creator>

<description><![CDATA[
<p>
It's been news recently that C is more widely used than Java again, and that
seems to have caused folks to think more about C than usual.  Over, at
<a href="http://james-iry.blogspot.com/">One Div Zero</a>, James wrote
a <a
href="http://james-iry.blogspot.com/2010/04/good-math-bad-pointer-math.html">nice
post</a> about some of the ugly details of C related to portability.
He pointed out that some patterns commonly used in "portable"
C code would not be portable to certain implementations of the
language, but those implementations are not in wide use.  
</p>

<p> Having had experience with C on one of these rare architectures
 (PDP10)
 which makes portability much harder than others, <a
 href="http://james-iry.blogspot.com/2010/04/good-math-bad-pointer-math.html?showComment=1270932636304#c2915560217266921751">I
 left my 2 cents on the topic.</a>
</p>

<p>
My perspective has become that it may be that those architectures
became less desirable to use because of the fact that porting code
(including all that sweet open source goodness) to them was more
difficult than other architectures, adding delays to projects which
were simply not there on architectures for which C programs were more
portable.
</p>]]></description>
</item>
<item rdf:about="http://jfet.net/~bryce/nb/archives/2009/04/02/T00_50_34/index.html">
<link>http://jfet.net/~bryce/nb/archives/2009/04/02/T00_50_34/index.html</link>
<title>Gosper's Display Hack in Processing.js</title>
<dc:date>2009-04-02T00:50:34-07:00</dc:date>
<dc:creator>Bryce</dc:creator>

<description><![CDATA[  <script src="http://jfet.net/~bryce/pjs/processing.js"></script>
  <script src="http://jfet.net/~bryce/pjs/init.js"></script>

<p> I've recently been reading through Knuth's new "Art of Computer
Programming" <a
href="http://books.google.com/books?id=2acdOAAACAAJ&dq=Art+of+Computer+Programming+bitwise+tricks&ei=jh3VSa2nLoGulATaoMnrAg">fascicle
on bitwise tricks</a>, and thoroughly enjoying myself.  Especially in
trying to hunt down information on the many side topics which Knuth
alludes to in the text.  For instance, the fact that really the only
bitwise operator that had any historical interest to mathematicians
was XOR; also known as the "nim sum", because of it's ability to give
a winning solution to <a href="http://en.wikipedia.org/wiki/Nim">the game of nim</a>.  Nim is great, and I highly
recommend the Wikipedia article about it, but in this post I'm going
to talk about something else, related to something Knuth
says about our understanding of the power of bitwise operations to
generate complexity.  </p>

<p>
"A famous chain of operations known as 'Gosper's hack,' first
published in 1972, opened people's eyes to the fact that a large
number of useful nontrivial functions can be computed rapidly."
</p>

<p> I've heard of Bill Gosper a few times before, mostly because he is
responsible for writing the majority of the short articles that make
up the body of work known as HAKMEM. A collection of hacks, tricks,
and mathematical curiosities discovered by folks at MIT in late
60s/early 70s.  I also have it on pretty good authority that many in
that time and place jocularly referred to Gosper as the best 19th
century mathematician living today. Most of the examples published in
HAKMEM were coded in PDP10 assembly, but I can read a little of that
so I set out to find the original source on the subject, Gosper's
Display Hack, aka HAKMEM item 145.
</p>

<p>
Item 145 is one of the shorter items in HAKMEM so I will produce it
here in it's entirety. Though the article in the context of other
hacks can be found <a
href="http://www.inwap.com/pdp10/hbaker/hakmem/hacks.html">here</a>.

<h3>ITEM 145 (Gosper):</h3>

Proving that short programs are neither trivial nor exhausted yet,
there is the following:

<tt><pre>
0/      TLCA 1,1(1)
1/      see below
2/      ROT 1,9
3/      JRST 0
</pre></tt>

This is a display hack (that is, it makes pretty patterns) with the
low 9 bits = Y and the 9 next higher = X; also, it makes interesting,
related noises with a stereo amplifier hooked to the X and Y signals.
Recommended variations include:

<tt><pre>
      CHANGE:         GOOD INITIAL CONTENTS OF 1:
        none            377767,,377767; 757777,,757757; etc.
        TLC 1,2(1)      373777,,0; 300000,,0
        TLC 1,3(1)      -2,,-2; -5,,-1; -6,,-1
        ROT 1,1         7,,7; A0000B,,A0000B
        ROTC 1,11       ;Can't use TLCA over data.
        AOJA 1,0
</pre></tt>

<h3> The Hack Deconstructed </h3> <p> Okay, this is about as simple as
you can get. One key thing you need to be aware of is the PDP10 is a
36-bit architecture. That is, registers and words are 36-bits long. So
when he's talking about using The rightmost pair of 9-bits as x and y
coordinates for display he's talking about quarter words.  So, if we
attempt to do this on a standard architecture without any emulation it
makes sense to use 8-bits of the word to represent our coordinates.
This also means that our screen will be 256x256 instead of 512x512 as
in the original hack, but this is actually a pretty good size for a
little processing app.  </p>

<p>
With that in mind lets break down what each line does:
</p>

<tt><pre>
0/      TLCA 1,1(1)
1/      see below
</pre></tt>

The TLCA pneumonic stands for Test Left Compliment and Always skip, which
takes the immediate value on the right side of the comma, and bitwise-XORs it
with the left-half of accumulator 1, storing the result in AC1.  Note that the
program itself is written in the accumlators 0-3.  There's no rule against this
on the 10. Thus, accumulator 1 is actually one of the lines of the
program which this instruction is always skipping over as it
manipulates it.  The immediate value of this instruction is actually
the contents of the right half of accumulator 1 incremented by one,
because we are using 1 as an index register to do the
calculation. Fun stuff! The instruction can be reduced to
something semantically similar, but written in a C-style for
converstion to the Processing Language:

<tt><pre>
 int i = INITIAL_VALUE; // Different values make different pictures
 i = i ^ ((i + 1) << 16);
</pre></tt>

The "see below" from Gosper's code is what I've called INITIAL_VALUE.
Okay that's a start. What about?

<tt><pre>
2/      ROT 1,9
3/      JRST 0
</pre></tt>

Well, that ROT instruction just rotates accumulator 1 9 bits to the
left (we'll rotate by 8), and JRST is just the prefered jump
instruction causing us to do all this in a loop. So putting all 4
PDP10 assembly instructions together and turning them into something
C-like again we get:

<tt><pre>
loop:
 int i = INITIAL_VALUE;      // Different values make differnet pictures
 i = i ^ ((i + 1) << 16);
 i = (i<<8) | (i>>>(32-8));  // Sadly this is how we must rotate
 point(i&0xff, (i>>8)&0xff); // We want to plot this on the screen!
 goto loop;
</pre></tt>

<p>
That's it. This is basically the inner loop of our processing app. In
reality since the draw() function is polled by the processing
environment we dont need the loop explicitely we just put the code in
the draw function. You can do a view source on this page to see the
whole thing, there's a lot more there but most of it is to allow for
the slide bar controls which reset the initial conditions of the loop.
</p>

<p>
As Gosper originally noted a great deal of complexity is generated
from such a simple program. It's very reminiscent of 1-d cellular
atomata. Since the PDP10 is a 36-bit machine the recommended initial
conditions above don't map directly to the 32-bit case, so experiment
with the scrollbars to control the initial values for the left and
right half of our initial 32-bit word.  The simplest interesting case I've
found is 0 0 (Drag both sliders all the way to the left).  That
one creates some patterns reminiscent of <a
href="http://mathworld.wolfram.com/Rule90.html">rule 90</a>, and if
you let it run long enough it takes on some interesting fractal like
properties. A friend of mine, <a
href="http://twitter.com/hallsa">@hallsa</a> also noticed that 
7fff 4797 makes some interesting patterns with totally different characteristics. The slider bars may not be as fine grained as one might like, so
I may add some keyboard input controls to allow for tweaking of the
initial conditions by increments as fine as 1.  Have fun!
</p>

<p>
<script type="application/processing">
int acc;
int leftPos;
int rightPos;
HScrollbar hs1;
HScrollbar hs2;
PFont fontA = loadFont("Arial");

void setup()
{
    size(256, 256+20);
    hs1 = new HScrollbar(0, height-10, width/2, 10, 1);
    hs2 = new HScrollbar(width/2, height-10, width/2, 10, 1);

    
    // Set the font and its size (in units of pixels)
    textFont(fontA, 32);
}

void draw() {
    int tmpPos = hs1.getPos();
    string myString;
    if (tmpPos != leftPos){
	background();
	leftPos = tmpPos;
	acc = (int((tmpPos/(width/2))*0xffff) << 16) | int((rightPos/(width/2))*0xffff) ;
	text(hex(acc >>> 16), 30, 60);
 	text(hex(acc & 0xffff), 150, 60);
    }
    tmpPos = hs2.getPos(); 
    if (tmpPos != rightPos){
	background();
	rightPos = tmpPos;
	acc = (int((leftPos/(width/2))*0xffff) << 16) | int((tmpPos/(width/2))*0xffff) ;
	text(hex(acc >>> 16), 30, 60);
 	text(hex(acc & 0xffff), 150, 60);
    }
    
    acc = (acc ^ ((acc+1)<<16));
    acc = (acc << 8) | (acc >>> (32-8));
    point(acc&255, (acc>>>8)&255);

    hs1.update();
    hs1.display();

    hs2.update();
    hs2.display();
}

String hex(int i)
{
    boolean sawFirstNonZero = false;
    int digits, tmp;
    String retString = new String("");
    
    for ( digits = 8; digits > 0; digits--) {
	tmp = (i & (0xf0000000))>>>(32-4);
	if (tmp > 0)
	    sawFirstNonZero = true;
	if (sawFirstNonZero) {
	    if (tmp <= 9) {
		retString += tmp;
	    }
	    else {
	    
		switch (tmp)
		    {
		    case 0xa:
			retString += "a"; break;
		    case 0xb:
			retString += "b"; break;
		    case 0xc:
			retString += "c"; break;
		    case 0xd:
			retString += "d"; break;
		    case 0xe:
			retString += "e"; break;
		    case 0xf:
			retString += "f"; break;
		    }
	    }
	}
	i <<= 4;
    }

    if (sawFirstNonZero == false)
	retString += "0";
    return retString;
}

class HScrollbar
{
    int swidth, sheight;    // width and height of bar
    int xpos, ypos;         // x and y position of bar
    float spos, newspos;    // x position of slider
    int sposMin, sposMax;   // max and min values of slider
    int loose;              // how loose/heavy
    boolean over;           // is the mouse over the slider?
    boolean locked;
    float ratio;

    HScrollbar (int xp, int yp, int sw, int sh, int l) {
	swidth = sw;
	sheight = sh;
	int widthtoheight = sw - sh;
	ratio = (float)sw / (float)widthtoheight;
	xpos = xp;
	ypos = yp-sheight/2;
	spos = xpos + swidth/2 - sheight/2;
	newspos = spos;
	sposMin = xpos;
	sposMax = xpos + swidth - sheight;
	loose = l;
    }

    boolean myover() {
	if((mouseX > xpos) && (mouseX < xpos+swidth) &&
	   (mouseY > ypos) && (mouseY < ypos+sheight)) {
	    return true;
	} else {
	    return false;
	}
    }
    void update() {
 	if(myover()) {
	    over = true;
	} else {
	    over = false;
	}
	if(mousePressed && over) {
	    locked = true;
	}
	if(!mousePressed) {
	    locked = false;
	}
	if(locked) {
	    newspos = constrain(mouseX-sheight/2, sposMin, sposMax);
	}
	if(abs(newspos - spos) > 1) {
	    spos = spos + (newspos-spos)/loose;
	}
    }

    int constrain(int val, int minv, int maxv) {
	return min(max(val, minv), maxv);
    }



    void display() {
	fill(255);
	rect(xpos, ypos, swidth, sheight);
	if(over || locked) {
	    fill(153, 102, 0);
	} else {
	    fill(102, 102, 102);
	}
	rect(spos, ypos, sheight, sheight);
    }

    float getPos() {
	// Convert spos to be values between
	// 0 and the total width of the scrollbar
	return spos * ratio - (xpos * ratio);
    }
}  
</script><canvas width="512" height="512"></canvas></p>]]></description>
</item>
<item rdf:about="http://jfet.net/~bryce/nb/archives/2009/02/18/T23_47_48/index.html">
<link>http://jfet.net/~bryce/nb/archives/2009/02/18/T23_47_48/index.html</link>
<title>Processing The Tipping Point Segregation Models</title>
<dc:date>2009-02-18T23:47:48-07:00</dc:date>
<dc:creator>Bryce</dc:creator>

<description><![CDATA[<p>
So I checked out some of the references at the end of <a
href="http://www.gladwell.com/bio.html">Malcom Gladwell's</a> <a 
href="http://www.amazon.com/exec/obidos/ASIN/0316346624/bookstorenow104-20">The 
Tipping Point</a>. Mostly because Gladwell's books always 
leave me feeling enthusiastic about their ideas, but with the desire
to put my hands on something concrete. I became interested in work by Schelling
on peoples <a
href="http://www.gemas.msh-paris.fr/dphan/complexe/schelling.html">self
segregation</a>. It wasn't so much that the model was
surprising from a sociological or mathematical standpoint, but because it
represented a pretty simple idea which could be applied to
<a href="http://processing.org">Processing</a>. :-)
</p>

<p> 
So, <a href="/~bryce/Processing/SelfSegregation/">here it is</a>:
more art than science, my processing app which represents a world of
households who are just looking for a place to land. They definitely
prefer living near each other rather than in isolation.  However, if
the neighbors are too different from them they will definitely be
looking for a better place to live.  You can adjust the tolerance of
the people that live in the world.  See what happens if they become
very tolerant quickly vs. slowly, or what the effect of slowly
reducing tolerance for a very stable world is.  Can you find the
tipping point at which order starts to form from chaos?  
</p>]]></description>
</item>
<item rdf:about="http://jfet.net/~bryce/nb/archives/2008/12/08/T00_11_49/index.html">
<link>http://jfet.net/~bryce/nb/archives/2008/12/08/T00_11_49/index.html</link>
<title>Processing: Fun With Visualization</title>
<dc:date>2008-12-08T00:11:49-07:00</dc:date>
<dc:creator>Bryce</dc:creator>

<description><![CDATA[
Thanks to a number of Tim Oreilly's <a href="http://twitter.com/timoreilly/statuses/915565469">tweets</a> a few months ago, I've
recently become interested in MIT's <a href="http://processing.org/">Processing</a> language.  The language
itself is really easy to pickup for anyone who codes in a C style
syntax on a regular basis. But one thing that's really exciting about
it to me is the ease with which one can generate visualizations that
will run on a number of platforms or as a Java applet within a browser for
distribution on the web.

I've always had an interest in standard data visualization methods
(mostly standard graphing techniques) for monitoring various things:
network data sources like traffic flow, computer system state, code
project metrics, sensor networks, etc.. It looks to me like the
processing approach to visualization can be concurrently more precise,
abstract, and artistic.

Anyway, just started playing with some of the <a href="http://www.jfet.net/~bryce/Processing/">exercises</a>. Nothing
particularly interesting yet, but I'll be adding more as time goes on.]]></description>
</item>
<item rdf:about="http://jfet.net/~bryce/nb/archives/2008/12/07/T23_50_52/index.html">
<link>http://jfet.net/~bryce/nb/archives/2008/12/07/T23_50_52/index.html</link>
<title>Review: Feynman's Rainbow</title>
<dc:date>2008-12-07T23:50:52-07:00</dc:date>
<dc:creator>Bryce</dc:creator>

<description><![CDATA[
Feynman's Rainbow is a short paperback you can find nestled somewhere in the Math and Physics section of your local bookstore chain. However, its thesis aims far from many of the popular science or hard science offerings surrounding it. The book provides unique inside information into what it's like to be a part of one of the top research environments in the world, the Cal Tech. Physics department in the late 80s, which will satisfy many popular science mythology/history fans. However, the question central in Mlodinow's mind is not about the process of science, but the process of living.

Leanard Mlodinow himself is a character in his own book. He's a young post doc whose graduate work has merited a fellowship in this elite environment. His office is next door to Murray Gell-Mann's and just down the hall from Richard Feynman's. It's an environment that many young physicists would dream of, but Mlodinow finds himself unworthy of the opportunity. He feels lost both in life and in his research career, and this state of affairs spurs him to seek collaboration from many in the department. It is in this manner that he first comes too start up a discussion with Richard Feynman which leads to a number of such encounters which Mlodinow is scolded and mentored in a Zen like fashion by Feynman. Many of the encounters themselves were recorded and large passages of direct Feynman quote are one of the unique and valuable aspects of this book.

Overall the book is an easy and entertaining read. Mlodinow balances well descriptions of the technical aspects of work by himself, Feynmann, Gell-Mann, and Schwartz on a number of topics at a popular level, with stories of long nights smoking weed with his neighbor and close friend the garbage man. He just as freely discusses Gell-Mann's fractional partical attributes as his balls... Yes, his balls. This freedom of narrative leads to a read that is humorous, interesting, and not lacking in depth. I recommend the book for anyone open to something a little softer and soul searching than the average popular science book]]></description>
</item>
<item rdf:about="http://jfet.net/~bryce/nb/archives/2005/12/10/T22_50_21/index.html">
<link>http://jfet.net/~bryce/nb/archives/2005/12/10/T22_50_21/index.html</link>
<title>Guy Steele Jr. On Language Design</title>
<dc:date>2005-12-10T22:50:21-07:00</dc:date>
<dc:creator>Bryce</dc:creator>

<description><![CDATA[<p>
In the latest version of Dr. Dobbs (January 2006) Guy Steele Jr. has
an <a
href="http://www.ddj.com/documents/s=9938/ddj0601c/0601c.html">article
</a> named, "Thoughts on Language Design." In summary he seems 
to be saying, that language design is driven by context more than we
realize.  That is, for all the ideals that exist in the language
design community, the things that are held as most important often are
quashed in the face of the facts of the environments in which we
program.
<br>
<p>
In the early paragraphs he gives the example of how the '*' character
has come to represent multiply mostly because on the early IBM
punchcard machines, lacked standard mathematical symbols other than
'+' and '-'.  This statement early in the article then set's up the
question , "What if a numerical programming language actually looked
like the stuff that mathematicians and physicists use on their
blackboards?" Yes, what if?  Does unicode present a context in which
programming can gain productivity?  From Steeles own examples
I think we can glean the hint of an answer.  Until, there is a
dramatic shift in the way we enter text into our computers, No.  While
a special user interface designed for scientists and engineers may
provide gains in productivity and expressivness for a few scientists
and engineers, how can we overcome the cultural fixed point that is
the qwerty keyboard?  Unicode alone does not provide the context for
the leap to unicode editing of our programming languages.
<br>
<p>
Some of the more interesting parts of the short article are the
personal tidbits that Steele discloses about how his early exposure to
the GOTO debate (at age 17!) lead to the first lambda paper ("Lambda
the Ultimate Goto"). He even gives us a passage from his public
comments at debate whose existence alone is intersting.  Also are his
comments that he still mostly agrees with his 17 year old self, and
his admittance that he now feels the titles of his papers slightly
pretentious.  Outside of its historical worth, steele uses the ideas
of the goto debate and the lambda papers to back up his argument of
the importance of context in choosing language features.  He argues
that his work on turning function calls into branches was important,
as was the introduction of structured programming (if-else, do-while)
over the use of goto,
but architectures have changed and what we have to do now is to
find the ideas that are important to add to programming languages <it>now</it>;
not just the step of adding multithreading support to a language, but
what about a language who does not think in a single threaded way by
default, whose structured components are not <it>for</it> loops (which force a
single threadedness on us) but something else.  Yes, maybe its
parallel counterpart can be called the semi-for :-). ]]></description>
</item>
</rdf:RDF>
