[COFF] [TUHS] The most surprising Unix programs

Dave Horsfall dave at horsfall.org
Sat Mar 21 13:53:02 AEST 2020


On Fri, 20 Mar 2020, Grant Taylor via COFF wrote:

> However, I have to stop and think about how to enter this on an RPN 
> calculator.  I'll take a swing at this, but I might get it wrong, and I 
> don't have anything handy to test at the moment.
>
> [a] [enter]
> [a] [enter]
> [multiply]
> [b] [enter]
> [b] [enter]
> [multiply]
> [add]
> [square root]   # to solve for c

[a] [square] [enter] [b] [square] [+] [sqrt] (You don't need those extra 
"enter" keys, as the display is implicitly the top of the stack.)

> (12 keys)

7.  Well, "square" also needs the orange "shift" key, so that's really 9, 
but the number of keystrokes ain't exactly the point; it's not a race, but 
a method of thinking.

> Conversely infix notation for comparison.
>
> [a]
> [square]
> [plus]
> [b]
> [square]
> [square root]
>
> (6 keys)

[...]

Well, it really comes down to the calculation that you are trying to 
perform.  Trivial example:

1 + 1 = -> 4 keys.
1 enter 1 add -> 4 keys.

I don't have an algebraic calculator right to hand, but I'd imagine that 
solving a second-order polynomial (without a built-in program!) would 
involve fewer keys when using RPN because of the stack for intermediate 
results; a quick estimate is around 30 keys (with single-digit numbers) to 
get one of the roots, and you could probably save the result of most of it 
on the stack for re-use to get the other root (and the 42S groks complex 
numbers as a bonus[*], but that's hardly as a result of RPN).  The 42S 
also has a handy "swap x/y" if the operands are the wrong way around, 
another one to rotate the stack, etc.

You don't do Computer Science without being exposed to RPN, and I had to 
wait for a salary-in-lieu payout (long story) before I could afford the 
42S that I'd been drooling over (and forget the overpriced IR printer[#]).

[*]
1 +/- SQRT => "0.00 i1.00" (I have the display precision set to 2 because 
I use it for monetary stuff a lot; the internal precision is 15 digits).

[#]
A dream of mine is to reverse-engineer the printer protocol, then grab it 
using a laptop camera.

Here endeth today's HP-42S lesson...

-- Dave


More information about the COFF mailing list