117 comments

[ 3.7 ms ] story [ 174 ms ] thread
I like to repeat everywhere that HP48 series had code block syntax with arrow notation.

    << a -> a a + >> (double function)
Those machines were well before their time.. I hope the makers had fun, it's really sad it's gone from the market although one could say that ES6 in your smartphone browser is your modern day HP48 reincarnation.
My grandfather was a civil engineer and he had a number of different RPN HP calculators. He gave them to me when I was becoming interested in programming - a really exciting gift to explore.
Do you still have them? Back in the 90’s when HP was discontinuing them, I bought 4x 32sii. I still have them un-opened. I still have my dads LED one from the 70’s. They are collectors items now.
And the LED ones had relatively short battery life; they were rechargeable. When I started college, HP calculators were still very expensive so I started with a TI. Within a year or two, you could get an HP LED model (HP-55 in my case) for a reasonable price. Through college I still took a slide rule to exams as a backup in case the battery died for some reason though I never had to use it. During the latter part of the 70s, calculators were dropping in price extremely rapidly.
Here's my take on the Forth equivalent.

Defining a DOUBLE word, the usual way, rather than anonymously. (Tricky to pick a good identifier that doesn't sound like it's doing something with double-precision floats.)

    ( num -- num_doubled )
    : DOUBLE DUP + ;
Next up, we push 7 to the stack, define our 'function' (not a Forth term) anonymously using :NONAME which pushes an execution token value to the stack, then we immediately invoke it. This has the effect of printing 14.

    7   :NONAME DUP + ;   EXECUTE .
Too late to edit: the second example leaks memory, as the execution token is not destroyed before becoming inaccessible. As far as I know, ANS Forth doesn't offer a friendly interface for destroying execution tokens.
Every time I end up on a non-rpn calculator I struggle to convert the calculation I have in my head to use infix operators.
Same here. I can’t really tell if it’s bias because I am very comfortable with RPN, but another of the benefits of RPN is that it seems much easier to build up a complex computation on the fly without having to backtrack and add parentheses, which on most calculators means you have to start over. With an infix calculator, I have to plan the whole thing out precisely before I even begin entering it, whereas RPN feels like a “streaming” translation that is very easy.
I can hardly use a non-RPN calculator. Wonderfully efficient for both simple and complex calculations.
It's simpler to implement RPN than algebraic notation with precedence. The latter requires an operation stack where operations are stacked until they encounter a lower precedence operator or the user presses =.

The user types less, the computer does a lot less.

I find it fun to think in RPN.

Yeah, it feels like the whole "why" is that RPN reflects how the machine works, so it's easier to build it that way.
Well, it’s easier to build because it has a terse syntax that requires fewer symbols, doesn’t need precedence and associativity rules, and has no ambiguous instructions. It’s easier to use for the same reasons.
> has no ambiguous instructions

Really? What do you call an operator applied to an empty stack? A sequence of commands that leaves the stack non-empty? I don't see why that's any less ambiguous than mismatched parentheses.

Why would any person or machine care that the stack wasn't empty?
And there is actually no such thing as an empty stack on an RPN calculator. A four register stack, as is common, always holds four numbers.
> A sequence of commands that leaves the stack non-empty?

That’s actually a feature. It’s even fundamental in concatenative programming languages such as FORTH and Factor.

> What do you call an operator applied to an empty stack?

[Pi] for example is an operator which can push the value of Pi onto an empty stack.

It may be easier to build, but that difference is quite small and not likely something that would have influenced the design of a scientific calculator. Many people have found RPN to be a superior user interface, and that’s likely the “why”.
Yes, the user types less but they have to think more.

Don't get me wrong, I love RPN and I've had a stream of HP calculators through my college years (synthetic programming on the HP41!), but... they come at a cognitive price. When you see an expression, you have to process the precedence in your mind to find out the most nested expression and start entering from there.

Basically, the calculator is cheating by forcing you to do some of its job.

That’s the point. This precedence processing should be intuitive if you’ve learned to do calculations by hand, and it helps you understand the expression as you enter it which makes for easier error detection. It’s also nicer for building up an expression on the fly as opposed to the Answer key on standard calculators.

If you’re just copying existing expressions, you might as well use one of those OCR calculators.

The point is not really whether it's intuitive or not (and for very nested expression, it's really not always intuitive to find the most nested one, especially if you have to remember precedence laws).

The point is that it takes time.

As much of an RPN fan I am, I am not convinced that the time it takes my brain to identify nested expressions is smaller than the time it would take me to just type the expression left to right on a regular calculator.

This is an odd explanation. II mean I t may be factually correct but has nothing to do with why people choose to use RPN calculators.

When calculating with an RPN calculator you do the calculation the same way you would by hand: “ok, figugpre out the numerator, now calculate the denominator, ok, do the division, ok now there’s a product, so do the multiplication, now add it to that fraction I just calculated...” except you don’t need to write down the partial results.

Not only is it fewer keystrokes and parentheses and such, but as you’re doing it as you naturally would anyway you’re less likely to get lost.

It took awhile to learn RPN in undergrad in electrical engineering. But, once you learn it, it is so much easier to solve problems and it is much more efficient. You never go back, and you are less likely to make errors entering in equations compared to your peers. This is important on timed exams.

I prefer to always use RPN. MacOS has an RPN mode on their calculator, which one can activate by pressing command + R. On my iPhone I have an app called i41CX+, which is an HP-41CX emulator. I highly recommend the app, as the developer is constantly updating it. It probably is the most updated app I have of all of my apps.

Also apparently there are some companies that recreate old HP RPN scientific calculators: https://www.swissmicros.com/products

yep, rpn is great!

And since you're solving part by part, it's easier to spot mistakes in calculations.

Going back to algebraic is pretty much impossible... luckily, there are many rpn calculator apps for phones.

Emacs calc-mode is RPN by default as well.
calc-mode is wholly responsible for my HP49G+ not having had its batteries replaced in a few years. :D
My daughter is at the learning algebra stage. I note that the way they teach kids to parse algebraic notation is by building an infix operation tree. If they’d just take the natural next step of discussing postfix (and prefix) traversal, everyone would think rpn natural.
>On my iPhone I have an app called i41CX+

The dev sent me the upgraded one after I reviewed the free(?) one in CNET years ago. I used an HP-41CV with various expansion packs for years. It doesn't have the same feel as the sadly broken physical calculator of course but I still like it. I basically don't anything these days more than simple arithmetic these days though--and if I did I'd use a computer. (I have been tempted by the Swiss Micro models but that would be a pure nostalgia-fueled buy on my part.)

RPN is so nice and efficient, can't imagine using anything else. I like that the OSX calculator does RPN.

But mostly I use my old 28S which is next to my keyboard always. Also have a 50g on the desk, but I prefer the 28S.

After using a 41CV for years, I bought a used 28S off someone. I just never cared for it. Probably just too accustomed to the more traditional RPN calcs.
I get annoyed by the ways the OS X calculator deviates from HP RPN.

The main one is that the pi and e keys act as if they are invoking constant functions that return pi and e, respectively. On an HP calculator, the pi key enters pi.

That may sound like the same thing, but it is not. Consider this sequence:

  2 ln  pi x
On my HP 15C the result is to multiply the natural log of 2 and pi. Same thing with PCalc on my iPhone. With OS X calculator the result is either pi with an error beep if you started with an empty stack or pi times whatever was on the top of the stack if you started with a non-empty stack.

The "2 ln" part leaves ln(2) on the stack. On the HP and other sensible calculators the pi key pushes pi. On the MacOS calculator, it replaces the top of the stack with pi.

They also had some problems where if you did a function and then started entering digits it would overwrite the function result, but I think they fixed those. I've seen what I thought was that problem recently, but when I finished entering the number and hit enter or invoked a function on the number, the previous function result appeared second on the stack, so it apparently is just a bug in displaying the stack.

That sounds like a bug. Why would any value replace the top of the stack?
Interesting, that's certainly broken of the OSX calc.

Admittedly I only use the OSX calc for very basic +-*/ operations. Anything more than that and I grab the 28S!

I went through all of high school and college with an HP48 calculator. I can't express how much more natural RPN felt than the more traditional alternative (and fast!).

It also made for very confused expressions whenever anyone borrowed my calculator...

I have an original HP-11C on my desk. It's about 30 years old, works perfectly, and I've had to replace the batteries about once a decade.
I also keep my HP32S RPN from 25 years ago on my desk still.

The combination of HP quality build and RPN.

Not a chance that I would have allowed anything less waste my desk space

I was forced to use an HP12C as part of my university degree. Once you get used to RPN it’s quite uncomfortable to switch back. It’s a much more intuitive way to do math once you get over the small hurdle. 15 years later and I’m still using the same calculator!
Yep, had my Radio Shack calculator stolen from a college lab in 1990. Replaced it with a 32sii. After 30 years of RPN, I can never use a normal calculator. They are horrible.
We had plug-and-chug competitions at school: big equations with some inputs, ready, go. The HP RPN folks would always beat the algebraic (casio, TI, etc) ones.
I bought an HP48 in 1990 junior year in college when it came out. A calculator WAS required for engineering school, but this one made everything way easier. I think it was almost $200. Anyway, once you go RPN, you don't go back. It makes way more sense. It finally died 5 years ago: the keys stopped working. I read about how to repair the keypad but finally had to let go. I had all my crib sheets from engineering school stuffed into the pouch. That calculator was epic. I can't imagine trying to do complex math with a slide rule, even though that's how engineers had done it for ages.
Similar story. Got a 48GX in high school. Everyone had TI89, maybe TI-92. I was the only one with HP.

Even with its lowly Saturn CPU and perceptually slower, it was trouncing the TIs at basically every task, especially when you customised it.

I learned RPN and RPL alright, but also got to dive into System RPL: the low level, faster, much more rich RPL, but where every argument was basically unchecked as it was more like HP-provided ASM routines in disguise.

And then learned to bit-bang stuff on the screen in assembly with all the timing tricks to produce 4 grayscale instead of just black/white. Great for coding small games.

Got the the third party CAS algebra extension card that also replaced the original UI for the same thing, only faster and better, and with a much more potent symbolic solver, whose UI was absolutely glorious to write, select, navigate, and perform advanced stuff.

Also got a maxed out storage expansion for the second slot. Such storage was not solid state so it required a continuously operating CR2032 battery to persist over time.

Unfortunately, as robust as it was, some time after engineering school it took a hard fall too much and was irreparably broken.

Later got my hand on a HP49G+, ARM powered but surprisingly the default was to run an emulation of the Saturn CPU, and CAS was bundled. You could still code for the ARM one though. By that time I lost interest so it currently sits in a drawer. Also preferred the 48 boxy design, especially the mushy keys of the new one were way worse.

For whatever reason my high school had HP48s for my junior year math class, which got replaced the following year for TIs since “that’s what you’ll be using in college”. I much preferred the RPN and ended up convincing my parents my life would be easier with a new HP49g (which wasn’t a lie, it was). That thing helped get me through my math major and I’ll always remember my old school professor who taught my complex analysis course amazed that it could even solve those equations (which I’m sure the TIs could do as well).
The HP48s has a much nicer keyboard than the HP49g though! HP48gx may have been a suitable upgrade instead :)
I used a CASIO FX-880P during university, but my dream one would be HP-48GX, unfortunately a bit too out of budget for my former self.
With the GX (which I got, and it still works) you could run metakernel [0], which itself was one heck of an upgrade over the base system and really an unbelievably impressive effort in its own right. It pushed the hardware so much farther it's still stunning. The HP48 remains one of my favorite calculation devices ever, with a great ratio of utility for both the most simple brainstorming calculations and going right into great depth. I'm still bummed my favorite emulator for iOS devices (m48+) stopped getting updates and faded away, and also that HP let its calculator division languish. What a tool.

----

0: https://www.hpcalc.org/hp48/apps/mk/mk.php

I agree with this and definitely would tell 17 year old me to go for the 48gx instead!
I never used an HP, but I did have a TI-89, and used a program for it that added RPN input.
I took an exam many years ago that required a non-programmable calculator; I told the instructor I literally had no idea how to use a non-RPN calculator any more and she was fine with me using my HP-15.

Sadly my collection of HP and other RPN calculators (there are a few) was stolen two years ago.

I don’t think it’s more intuitive. It’s just that you’re used to it.
With RPN you can just type facts in as you think of them, and figure out how to combine them later. With conventional entry, you have to have the entire equation in mind from the beginning, or backtrack to add brackets.

RPN has no use for brackets, because there is never any ambiguity.

Everybody thinks that RPN is about the inverted order when it's really about having an explicit stack instead of an implicit one.

If you're using "algebraic", you sometimes have to put a "(" into your expression a long way ahead of when you need it. Think of how many times you have to go and fix up your left parens when writing C code conditionals. On a calculator, if you screw up, go back to start. Also, old calculators had parentheses limits.

"Modern" algebraic calculators mitigate this somewhat because they can enter the expression in text form on a dot matrix LCD so you can go back and add/delete parentheses as required.

An explicit stack means that I can start and stop subexpression calculations at various points and cache the results. It also means that I can rearrange precedence at my convenience--of course, the flip side is that precedence is my problem instead of the calculator's.

> It’s a much more intuitive way to do math

Is it? It's easier to code an evaluator, but I'm not convinced it's necessarily more intuitive. In practice, only addition/subtraction and multiplication/division are ambiguous. I'll also play devil's advocate and admit order of precedence is somewhat arbitrary, and precedence of bitwise and and equality is wrong in most languages. Not sure why I'd want this: (flags & (4 == 4)), but that's what flags & 4 == 4 does.

Yes. It is.

One difference is you see all intermediate results. That's huge for avoiding mistakes. In-fix, if you type (5+5)*(9+9), you only see the end result. Post-fix 5 5 + 9 9 + *, you see 10 and 18 along the way.

Another is the stack lets you easily reuse subresults. If you've computed the total energy and want to use it three places, you pick it off of the stack. All your work is there. It's very common that this happens.

It's an incredible productivity boost once you get used to it.

Seeing intermediate values can’t be overstated. It’s a huge sanity check that catches many mistakes way earlier in the process.
It gets even better when you tag numbers with the correct units. The calculator does type checking and automatic unit conversions. So if you key in the wrong operations, you'll either get an error somewhere along the way (from eg. trying to add something in m/s to something in m/2^2) or you'll notice the units at the end of the calculation don't match what you're supposed to end up with.
> if you type (5+5)*(9+9), you only see the end result.

Only if in see-full-expression-before-action mode. Otherwise you would see 10 after the first ), and see 18 after the second ).

> Not sure why I'd want this: (flags & (4 == 4)), but that's what flags & 4 == 4 does.

Originally there was no && operator. You had to use & for Boolean conjunction too. The precedence makes sense under that condition. (And later couldn't be changed without breaking existing code.)

For general purpose programming, I want to write expressions in algebraic format but for interacting with a calculator RPN is easier. It removes a whole layer of abstraction wondering what the machine is doing.

I would imagine if I were young today and started with a modern multi line calculator with textbook display then that is what I would be comfortable with but for folks born before 1980 or so the algebraic calculators of our time were error prone.

I have an HP 27S that is algebraic and breaks the mold of being error prone because it shows the whole expression up until the point where a part can be evaluated. Then it evaluates the inner part while still showing the rest of the expression.

Reading these comments, I'm surprised that people think in RPN. (I mean I shouldn't be, I just didn't think of it)

I wonder if teaching it early on, instead of parenthesis, would have made math lessons different?

Could there have been different notations used for things like factoring out a quadratic equation?

I learned RPN as a college freshman studying engineering in the late 1980's. Almost all of my fellow students had HP RPN calculators. Once we where doing more advanced math RPN -- with the accompanying stack -- became so much easier to enter. We all quickly learned it and I think most of us came to hate standard calculators.
Even algebraic has different also-possibles. APL and Smalltalk don't bother with precedence, for example.
> Could there have been different notations used for things like factoring out a quadratic equation?

well, you're talking about high school algebra, but just adjacent to that is the lisp programming language which uses polish notation. It also uses parentheses because parsing the parentheses-less polish notation requires that the operators have a fixed number of operands

Sussman, co author of SICP and co creator of lisp-like Scheme, has a current idea/book/project he's advocating which is to teach physics using scheme instead of algebraic-calculus because the notation is more precise: rather than differential equations which you need to be skilled at reading, you use polish notation computer programs that can be executed and studied.

Well. just. wow.

I was just thinking of notation, but making math parsable, or teaching a regular math notation, that should be a thing.

I remember hearing generalizations like "chess is pattern matching", and "math is just symbol manipulation", but latter really comes to life if we make math notation regular enough to be funamentally machine readable.

Just think what it could do with ai (or for ai)

Is there a good RPN calculator currently? The HP Prime is lacking apparently, and the 50G is no longer available (and a bit old)
A 35s and 50g got me through my engineering degree, I'm sure they'll still work fine.
I don't own one, but I've heard great things about SwissMicros calculators (https://www.swissmicros.com/products) from users of HP calculators. The SwissMicros lineup is very similar to HP's 1980s calculator lineup.

Also, the HP 12c financial calculator and the HP 35S scientific calculator are still being sold by HP.

oh shoot, I missed this comment elsewhere in the thread -- just want to say I got their HP15C equivalent years ago and it's high quality.
The HP Prime does have an RPN mode. I bought it recently, for that very feature, when my HP48 died. The keyboard of the HP Prime isn't really optimized for it (some trivial operations on the stack require key combinations, while on the HP48 there were physical keys for them), but it's acceptable.
I have the Droid48 app on my android phone. Pretty nice but I actually never use it.
Love my HP50G. I rode a motorcycle during college, so consequentially I always had my HP50G on me wherever I went since I never took it out of my backpack.
RPN is just so much better. An interesting note, the HP 50g can be programmed in RPL, but you can also use the equation editor and mix and match code and equations.
When I was starting my degree (around 96) I went to the US for a week and bought a HP48Gx since they were cheaper there. This happened a few weeks after a Swiss jet crashed departing NY and the reasons were not known at the time so the airport staff was very suspicious. When they saw the calculator and tried to do a simple test calculation and failed, I struggled to explain how use it, since it was also so new to me. Luckily I got 2 out of 1 1 + and I was let go... still have and love it.
Reminds me of the story of someone who took a Linux laptop through security; they wanted to see it boot, but didn't recognize the command line and were suspicious.

The owner set PS1 to resemble a DOS shell prompt and they were satisfied.

I remember flying with a bunch of hard drives out of SFO in 2002. I was a little worried security would get 9/11 worried about them. Maybe because it was SFO are are used to seeing tech people flying with odd stuff, they didn't care.
I worked in Mountain View and lived in Palm Springs for a while and used to commute back and forth through SFO/PSP.

Im convinced you could take damn near anything through SFO tech wise, cause they've seen it all. Meanwhile explaining to the TSA people in Palm Springs why I've got 3 laptops, let alone 4 dozen cell phones was always a hassle and a half.

I flew into SFO in approx 1990 with some 3.5 inch floppy disks. The customs guy had to ask me what they were.
HP48GX was the best calculator ever. I used one throughout my middle/high school.

The best features, IMO, were (0) the IR emitter and (1) the ability to program it to switch ON at a specified time and run code.

This means I could hide my calculator somewhere in a room before class started and program it to turn on halfway through class, turn the classroom TV on, turn the volume to max, and start wildly flipping to random channels.

One teacher had all of us students put our hands up and walked around the room looking for who had a remote at their desk, and I remember watching that teacher's face of horror when the TV continued flipping channels as everyone had their hands up.

I bought mine in 96, when I was still in high school, and sold it around 2008 for more than I bought it for. But I miss it.
Droid48 to the rescue.
There's also Emu48.
I bought an HP41C in 1979, and I have been a fan of RPN ever since. I tossed the 41C back when I got my first Palm HPC and installed the "RealCalc" app. I'm glad that some of the modern calculator apps still support this mode.
RPN is a lot like vim, the first time you are like DUH! I can't add 2 and 2. But if you take the learning curve, it becomes very efficient and you cannot move back.
I did so much programming on the HP 28S and the HP 48Gx. Really an awesome mobile programming platform at the time.
There's an open-source Android app called Droid48 that gives you a virtual HP48, if you're into that sort of thing.

I know when I'm out with coworkers and they whip out Droid48 to calculate the tip, I picked a good place to work.

For ios, I've used Free42 and i48 (Daniel Parnell).
I own an actual 42S and I prefer Free42.
I prefer the iOS app called 42s. Better user interface in my opinion.
I've had a decent experience using RealCalc Plus, although it's just my backup when I don't have my 32SII handy.
No mention of Forth?

Back in the early 80's Forth was the first language available on the original Macintosh. I loved Forth, but it completely ruins you for every other non-RPN language. I remember writing an ASCII terminal (dial-up modem) application in Forth to learn the language, and afterwards every other language that I was using at the time just looked... weird.

I had to perform a massive mental shift to get back into all of the other languages I was being paid to work with at the time, and it was so difficult (for me, anway) that I never went back to it.

Do you have an example of what you'd consider typical, boring Forth code? I was trying to compare programming styles in different languages the other day by looking at different pieces of randomly selected code, on the theory that most code is probably pretty typical. So, for example, for JS I used the bisect_by function from Crossfilter2, and for Perl I used Net::DBus::Binding::Message::Error::new.

Unfortunately, all the Forth I had on hand or could easily find was one of ⓐ something I'd written myself, ⓑ something written for didactic purposes or as an example of the ideal way to do things, or ⓒ by the author of the Forth implementation it runs on. I'd argue that all of these are likely to be atypical examples of Forth style.