Thursday, February 14, 2013

Cybernetics is a Thing

There is a basic fundamental result in Cybernetics that holds that any self-regulating system must contain a model of itself.  We can examine this in the operation of so simple a self-regulating system as the common household thermostat.

A common design for thermostats is to have a mercury switch attached to a bi-metal ribbon coil.  The two different metals expand and contract with temperature changes to close and open the switch, which then activates or deactivates the heating system.  The coil is adjusted by turning the dial to set the desired temperature.

Now it should be obvious that the coil "measures" the ambient temperature, and can thus be considered an "internal" analog model of the "external" temperature.  (I put "external" in quotes because the entire thermostat is always at that temperature so it is not exactly external, is it?)

It should also be obvious that the angle of adjustment of the dial and the way that that affects the "set point" of the mercury switch is an analog model of the user's desired temperature.

So where is the internal model that Cybernetic theory predicts must exist? The thermostat must contain a model of itself in order to operate, so where is it?

There's a model of the current temperature, that's the current expansion/contraction ratio of the coil.

There's a model of the desired output temperature, that's the angle that the user sets on the dial. That modifies the relationship between the current temperature and the mercury switch which controls the heating system.

Where's the model of the thermostat itself? Switch plus dial plus coil, so simple, how can this system be modelling itself?

I'll give you a hint: I left out the heating system in the above.  The system is properly:
Room + Air + Heater + Thermostat
Here's another hint: Other than the temperature, the only aspect of the system that the thermostat really needs to model to model itself properly is how long it takes to heat up the room.

Figure it out yet?  Once the temperature of the room reaches the desired temperature the thermostat does not cut off immediately.  The heater runs a little while longer and heats the room a little bit past the desired temperature. You can easily adjust the amount of the delay (and in fact there is a little screw in there just for that purpose) but if it's set correctly you generally don't have to.

But how do you know what the "correct" setting for that delay is?  Well, it depends on how long it takes to heat up the room.

That delay is the self-model in the self-regulating system of "Room + Air + Heater + Thermostat"!

That delay prevents the heater from switching on and off too often, which prevents wasting energy and keeps the room at the desired temperature more efficiently.  If the system changes, say between summer and winter, you can adjust that delay (internal model) to re-optimize the efficiency of the heating system.

Isn't Cybernetics cool?

I surrender.

Well, that's it.  I surrender.  I've had enough and I'm throwing in the towel.

To be specific, I've been "working" freelance since quitting my job a few months ago, and it hasn't worked out.

I don't want a job. I've tried that and it's not for me. (In fact I was contacted by a recruiter a few weeks back who had my dream job if there was one and I realized I didn't want it.)  I also don't want to try to manage a freelance practice, I lack the social and organizational skills.  I thought about hiring a manager, like a musician or other performer, and that seemed like a good idea.  Unfortunately it is unlikely that such a person exists or that I could find them if they did.

I do still want to help people with programming, both by teaching it and, to a limited extent, writing software.  I just don't think I'm in a position to make anything happen.  I'm not apathetic just content.

I don't need anything. I have no children, and no wife or girlfriend. I'm capable of living in any major city with a clement climate without using money. (Go on and ask me how, I dare you. Warning: the answer is "I'm fucking magic.")

Really I can't tell you how tempted I am to go sit by the CalTrain Philz Coffee with a sign that says something like, "Any computer question answered, FREE!" and see what happens.

Sadly, I expect nothing would happen.  Mostly I'd be ignored, some people might venture quizzical or bewildered looks, and eventually the police would politely ask me to knock it off, or not. The officers I see frequenting that cafĂ© seem pretty chill.

If you have a question about computers, post-Singularity life, or "Spiritual Matters" ("WhoooOOOOooooOO!") go ahead and ask me.

Other than that, live long and prosper!

Eternal Life is Living Love.
~Simon Peter Forman

@SimonForman on Twitter
Google+ Profile
 

Saturday, February 2, 2013

How to teach anyone to program using Xerblin

I have long maintained that anybody who can solve a sudoku puzzle is more than capable of learning to program.  The Xerblin system provides a programmable metaphor for normal people to enable them to use their computers to greatest effect.

If you go step-by-step, in the right order, it is very easy to teach the Xerblin metaphor to anyone in about a half an hour.  This gives them the ability to program the various versions (firmware, server, web page) as well as a solid foundation to learn more.

Stack of Plates

Everyone already knows what a stack is: you put down a plate, and then put another one on top of it, then another, and so on. When you need a plate you take one off the top of the stack ("TOS").

Dictionary of Words

Again, everybody knows what a dictionary is: it's a bunch of words and their definitions. In Xerblin the words are all commands that work on the stack at first, but the user can "inscribe" anything they like in the dictionary.

Put Numbers on the Stack, Be a Calculator

So put some numbers onto the stack and use the four math commands to do some simple math.  Everybody knows how a calculator works, so you explain this as "just another kind of calculator." If you're doing it right they'll be getting impatient with you for explaining such obvious stuff.

Put "Strings" of Text on the Stack

Most people won't have encountered the term "string" for a sequence of characters yet, so be careful to explain that before you use it.  I've hit that whirlpool a couple of times.
"What's a string?"

"You know what a turtle is?"

"Yeah?"

"Same thing."

I'm not the best and most highly focused teacher sometimes.

Anyhow, put some strings on the stack. Show how they are just data like the numbers.  Add a couple of strings together.  Multiply a string by an integer. Go nuts.

Now that you have established that you can have a string on the stack...

Lookup & Inscribe

Show how the strings-as-data become strings-as-names. This is the power of names and is the single fundamental phenomenon underlying all computation and, indeed, all thought. The fact that one piece of the universe can serve as a "name" for another piece of the universe is completely incontrovertible and yet totally inexplicable.

This sentence does not describe itself.

Naming enables programming.  When the folks can put named things into the dictionary and get them back out again the key is in the lock.

Put a Command on the Stack

Turn the key, unlock the door. By putting a command word (function) onto the stack using a string as the name, it becomes data and can be subjected to manipulation just like numbers and strings.

This is the very essence of programming: verb becomes noun, action becomes recipe, and we can reason about the static pattern we see.

Programming is the alphabet of thought.

sqr() = (dup(), mul())

There is no one-true-computer-language (except Lisp, heh) in the same way that there is no one-true-circle, or one-true-triangle. But this metaphor is both useful and as simple as I could make it, and I have already taught several people how it works.

Now that I have a proper format I am teaching people how to use it in earnest. I have a client who is producing SVG animations using it.  (I'll add links when he's ready to publicly show it off.)

I see a great potential for programmability to become commonplace. It would make developers' lives easier and free users from the tyranny of crappy interface design.

Thursday, January 31, 2013

Legos are my Poison

Legos are my poison of choice.  That LEGO Deathstar? Yeah, they've got my number.

For some it's model trains.

We tend to discount these activities because they are economically non-viable.  "Grown men playing with toys."

Well, are you in the manufacturing sector and not doing 3D printing and/or nanotech?  Go home, you are playing with toys. How about energy? Are you building a molten salt nuclear reactor? If not, you're just playing with toys. Are you in the health sector? Paying attention to Reiki? If you are not doing far out "energy healing" then you are just playing with toys.  Whatever those (as my mom calls them) "woo-woo" folks are doing there is something there. Let us do Science to It!

We are in that part of the S-curve that goes pretty much straight up and down and if you are not on the way up, brother you're going down.

If you are not preparing for a world of infinite energy and infinite malleability then you are, in effect, like a child playing with toys and refusing to deal with reality.  You should be feeling giddy or you're not doing it right.

Wednesday, January 16, 2013

new_group 2500 300 45 "x" make_effect trans

Every once in a while I write some code that is so cool it makes me ecstatic.
new_group 2500 300 45 "x" make_effect trans
I'm working on a single-page HTML document that implements a kind of theatrical stage using SVG and D3.js with my Xerblin user interface metaphor.

Last night I got it to a stable point where my task shifted from creating the internal structure to "sculpting" a set of commands that will make it easy to create animations.

I started with a simple command word new_group that creates a new SVG "group" element (this is a kind of invisible container, like a HTML div element) inside a D3 selection and puts it on the stack.  In order to see it I made it also automatically create a green rectangle in the group.

The idea is that you create a new group and add visible SVG elements to it to create "characters" or "props" for animation.

I'll write some words to do that later, but for now I have created a command word set_attr that takes three things from the stack: a D3 selection, an attribute name, and a value, and it sets the attribute on the selection.

This lets you directly and immediately modify all the SVG attributes of an element (or set of elements) including position and transforms!

I also created a make_effect command word that takes just an attribute name and value from the stack and returns a function that can be used to modify attributes as part of a D3 transition.

To provide D3 transitions (awesome animations!) I made a trans command word that takes a D3 selection, a delay value, duration value, and an effect function (as created by the make_effect command word) and applies the effect to the selection with the given delay and duration.

So, breaking it down:

new_group
This creates a new group with a green rectangle in it to make it visible. It will be put on the stack.

2500 300
This puts two integers onto the stack. These will be our duration and delay values in milliseconds.

45 "x" make_effect
These three commands first put 45 and the string "x" onto the stack, and then the make_effect word turns them into an "effect function".  At this point the stack has the group/selection on it, followed by the duration and delay, then the effect function.

trans
Then the call to trans applies the effect to the group with the given duration and delay.

If you go to the demo page and put that command into the text entry and press "run" you should see a green rectangle appear and move to the left. Wow, right?  I know!

update

I forgot to include information on the command system "Xerblin" itself.

This is an old project of mine that defines a really simple but complete programmable command system.

The original project page has some basic description: https://code.google.com/p/xerblin/

I've merged the Xerblin user interface into my educational Pigeon Computer project, and the manual for that has more info:
http://phoenixbureau.github.com/PigeonComputer/user_interface.html

On the live page http://calroc.github.com/aum-gravity/xerblin-stand-alone.html you'll see:

  • "Hi There!"
  • The SVG window, about 3X wider than high.
  • Buttons for each of the command words in the dictionary.  (If you "inscribe" new words in the dictionary they automatically get a button here.)
  • A long text entry for "command line" interaction. (Don't hit enter, there's a bug that I'm about to fix that makes the page reload! D'oh!)
  • Two sets of three buttons that provide "meta" commands, interface commands that aren't in the dictionary.

I should write up the meta-controls but for now just put this in the text entry and click "run" button:

new_group 2500 300 45 "x" make_effect trans

You should see a green rectangle appear and immediately animate moving to the left.

Yay!


Just as a hint:  already with this interface and these controls you can create as many of these "groups" (visually represented by the green rectangle outlines) and animate them (including scale and rotation!!) and attach the animations to new buttons/words in the dictionary.

Not bad, eh?

Tuesday, January 15, 2013

Single-page Xerblin with D3.js

I spent a few hours today porting my "xerblin" user interface metaphor to Javascript.

I've been developing a d3.js-powered page to experiment with dynamic visualizations.  Once I had a fun demo going it seemed obvious to use it to wrap the xerblin system (I'd been planning to do something like this for years and years.  I created a 3D system in Tkinter to support it but never got enough traction with it until now.)

At first I had a simple Flask server that responded to commands, updated a xerblin interpreter, and sent back a representation which was then rendered client-side with SVG.

I spent a bunch of time playing with different ideas for permitting the server-side xerblin interpreter to specify client-side dynamic visualizations.  At some point it just seemed like it would be simpler and much cooler to port the xerblin core to JS and just have a self-contained page.

This means that you can go to the demo and "save page as..." to your desktop and play with it locally! You don't even have to check out a copy from github or anything.

This is inspired by the TiddlyWiki project which is a self-contained single-page HTML and JS wiki document.  I love it.

TiddlyWiki has the ability to save copies of itself to your file system (if you permit it) and it will automatically save backup copies.  It should be fairly easy to let the stand-alone D3+Xerblin demo save itself (with your current state aptly serialized!)  It might also be interesting to save state in a cookie.

Does it Do Anything?


So really you should read the source (and modify it!) but I'll write up a simple tour soon!

Keep in mind that there aren't really any commands for anything other than the xerblin "not-quite-language" itself yet, as this is very much a work in progress and fresh out of the oven.

Monday, January 14, 2013

Riches and Roses

I'm at the point now with the user interface I'm working on (playing with!) where I am confronted with an embarrassment of riches in terms of wonderful design choices.

I'm finding the separation of (graphical, dynamic) user interface from the underlying virtual machine (the xerblin not-quite-language runtime) to be extremely useful and gratifying.

Because the Flask server does not reload the Python interpreter state when I change a template file I can adjust the SVG rendering code and refresh the browser to see the same state rendered with the new code!

Right now I have come to the point where I am creating dictionaries (in xerblin these are sorted binary trees made of tuples, too much to get into here, persistent data structures) to represent SVG elements, as one possibility for "internal" authoring.

Because the dictionaries arrive from the server as JSON arrays, and because the display code is already written to recursively display array contents, the  contents of the dictionaries are already automatically rendered.

Only it doesn't look great.

The array code was written (last night, at 2am) to display linear stacks, but the dictionaries are binary trees, so they sort of pile onto themselves when rendered.

It makes for lovely fractal patterns that are really beautiful to look at, but they could be more useful...

Now I can leave a dictionary on the stack and edit the rendering code to try out different tweaks for displaying arrays, and when I refresh the page I'll see the same dictionary rendered with the new code I just tweaked.

"Roses, just roses..."