Look ma, no brackets!

Sometimes it is futile to plan even a day ahead. Sometimes, you just have to go with the flow, and do much more exciting and useful things than you could possibly have foreseen. Yesterday was such a day.

New Laconi.ca release

I was barely awake after a long night sleeping away most of my head cold, when Evan announced identi.ca was going down for a server update. When it came back, he mentioned people tagging and I immediately went to explore: just last week I had been wishing I could apply labels to my contacts to sort them into groups — and now I could?

I found it soon enough and immediately started going through my contact list applying my mental labels for real: now all my Habari contacts have a "habari" tag, and all my Wakoopa contacts of Team identi.ca have a "wakoopa" tag, and so on. Apparently I was one of the first to explore this new feature, and while I was tagging away, I found myself also explaining to others how to use it. And once people had prodded Evan enough for him to write a blog post about the new features I became even more excited: you can actually send a dent all at once to contacts you have tagged with a particular tag, using the format @#tag. Wonderful! (And then of course I was explaining that to some others as well.) You can tag both your subscriptions and your subscribers, and these "contact-tags" are "private": they are only for your own contacts (but others can explore them as you can see in the links above). But you can also tag yourself, and these "self-tags" become globally browsable: so you can find all people who have tagged themselves with "wiki", for instance.

I was exceedingly happy with this new tagging, and told Evan he'd made my day with that. The icing on the cake came late at night when I saw someone mention he'd been featured: the "Featured" page is another new feature. So I went to have a look... and found myself there, too. *blush*. But the cake is delicious without the icing, too! (And the content of the "Featured" page will change, of course.)

RPN

In-between all that someone mentioned he didn't like his new calculator with so many extra functions: he'd rather use his PC for the more complicated calculations. Which sent me right down memory lane, and I remarked:

I remember when a good calculator *was* a "PC". … I was referring to the HP scientific calculators I worked with before PCs even existed. ;) I loved RPN.

I was really surprised to find my contact, who's a scientist, had not known what "RPN" was, and had to look it up. So let me explain: it's interesting, fun, and easy to learn.

part of Adler 81S keyboard with a single brackets button
Original: NJR ZA

In the 1970s, electronics miniaturization was in full swing, with integrated circuits with ever smaller and more numerous transistors making such things as pocket calculators and, since 1977, the first consumer desktop computers like the Commodore PET a reality. Although in 1971 Mostek was the first to produce a "calculator on a chip", closely followed by Texas Instruments, the two big players in the scientific calculator market were Texas Instruments (TI) and Hewlett-Packard (HP). In this market, the two were major competitors, with HP's first scientific pocket calculator, the HP-35, appearing in 1972, and TI's first, the SR-10, in 1973.

There was a fundamental difference between the two: The SR-10 used algebraic entry which means you could enter a whole calculation, using brackets to enforce precendence where needed, and then get the result at the end; this means the calculator must store the whole formula, parse it for precedence, and store intermediate results. This parsing was built into the chip, and a discerning feature between calculators (even non-scientific calculators) was how many levels of brackets it could handle.

part of Casio FX-77 keyboard with two brackets buttons and the number '6' between them
Original: Sergei Frolov

All calculators using algebraic entry have buttons on their keyboard to enter parentheses (or a single button if only one level is supported), as can be seen on the photos (click through for the full image): the first has only a single button, suggesting only one level, while the second has two buttons, and the number '6' between them, suggesting it may support up to six levels.

keyboard of the first HP-35 with a big enter button, and no brackets
Original: David G. Hicks

Now have a look at this keyboard of the first production model of the HP-35: lots of buttons, but no brackets! And a big button labeled "Enter". So how can you do scientific calculations using no brackets at all? The technology behind that is Reverse Polish Notation (RPN). The Reverse Polish scheme was proposed by F. L. Bauer and E. W. Dijkstra in the early 1960s to reduce computer memory access and utilize the stack to evaluate expressions. Hewlett Packard introduced its first scientific (desktop) calculator in 1968, which employed this RPN technology, though the implementation was a little different than that in later models. But they stuck to using RPN in most of their later calculators, and made RPN popular in the scientific and financial world.

I also found the machines I actually used in the late 1970s: they were fully programmable with multiple levels of subroutines, tracing and single-step operation for development and debugging, external storage of programs and data on magnetic strips, and a large library of available software, including games: all even before the Commodore PET appeared in 1977. (Here's a good picture.) And the first actual "PC" was not introduced until 1981. Hence my remark "I remember when a good calculator *was* a "PC"."

Learn RPN!

So how do you use RPN? It's easy and fast to learn. In principle, you enter the operand(s) first, followed by the operator. So to calculate

3 + 5

you first enter the 3, then the 5, and then press the plus button. On a calculator:

3 [Enter] 5 [+]

Another example:

(5 + 7) * (36 - 24)

on a algebraic entry calculator you need brackets for precedence, but on an RPN calculator you do:

5 [enter] 7 [+] 36 [enter] 24 [-] [*]

Not only do you not need brackets using this method, you can also see all intermediate results which helps in preventing errors (and developing programs). The The Museum of HP Calculators has a little course, and a much better explanation of RPN and why HP decided to use it in their calculators.

By the mid-1970s one could witness "religious wars" between proponents of TI's AOS™ algebraic operating system and those of HP's RPN much like the Windows and Mac camps of today.

Of course it's no fun doing this on paper - you need an actual calculator! Of course HP still makes and sells scientific calculators, much more powerful and much cheaper today, while "Select models offer RPN, algebraic, and textbook data entry". If you don't want to buy a calculator, there are other options: for instance there is a nice online (JavaScript-based) mouseless RPN calculator online: operated entirely with the keyboard, like a real calculator; press 'h' for help on how to operate it. There is also rpnjcalc, another RPN calculator implemented in JavaScript and HTML, which you can download for local use in any JavaScript-capable browser. Also, the Mac Calculator program (bundled with OS X) is capable of operating in RPN mode. If you know of any other applications, please leave a comment!

Habari

And with all that, my original plan to get started seriously developing my own theme for Habari came to almost nothing. I think I wrote some 30 lines of code in all. And today I wanted to write this blog post first of all! Back to development, then.


3 Responses to Look ma, no brackets!

  1. 2 bavatar November 26, 2008 5:57pm

    Is it my fault that all the calculators that crossed my way till now use infix notation only? Perhaps I'll do an investigation around my fellow students and check their knowledge about RPN...

    Anyway you're right RPN is fun and intresting, still puzzles me a bit, but that's ok - thanks for fill this hole in my knowledge :)

    I've written a little program (see the website link) to understand RPN better. Hope you enjoy it as I did writing it *g*

  2. 3 bavatar November 27, 2008 7:17pm

    As I'm doing double postings of stories in a german and english languaged Blog of mine, this comment links to the german blog ;)

    I'm thinking about extending the program further and polishing out the quirks I've found so far *g* you really got me with the RPN notation :D

  3. 4 marjolein November 27, 2008 7:41pm

    bavatar,

    Thanks for your comments!

    I'm really glad to know that apparently I caused one little spark to fly there. :)

    Please do keep us posted on developments of your RPN calculator program. What would be really nice is if the operator keys ( + - * / ) would actually perform the operation directly, as is usual on RPN calculators. But of course that would not be directly possible for the more advanced scientific functions. Still, I tried your program and it works!

Leave a Reply


Some HTML allowed (like a, em, strong, pre). If you want to embed a code fragment, its syntax will be highlighted if you surround it in pseudo-tags like this:
[geshi lang="php"]echo 'highlighted code!';[/geshi] (instead of using pre); specify language in the lang attribute. Do not enclose your code in tags like <?php … ?> as that will make it disappear.