3 ms·
For anything more complex than a + b, I find RPN to be superior. I'll speak specifically about a calculator like the HP50g. Pardon my rambling. The first advan
by hajile 9y ago
For anything more complex than a + b, I find RPN to be superior. I'll speak specifically about a calculator like the HP50g. Pardon my rambling.
The first advantage is that you calculate in the same order you'd do it by hand. Not only is that more natural, but it also encourages understanding the problem because you don't just blindly copy/paste some convoluted formula.
Saving intermediate results is not only incredibly easy, but can be very organic and spontaneous. As I'm solving the problem, I can recognize an interesting sub-problem and simply run off a copy (pick or dup then rotate the stack).
The infix issue is that you generally don't know what parts are interesting until you're mid-calculation. By that point, you'll be scrolling side-to-side to strip the outer parts and then doing a bunch of paren balancing. Even worse, because there's the temptation to just write everything and mash enter, you may not even recognize that it's of interest.
Integrating new functions is also seamless. Functions are just small forth programs that manipulate the stack. Once I add a function to my function row, it's a single button press to execute it.
For a simple example, let's say that I'm doing parallel/series resistor calculations. I would add a rule (lets call it para) for calculating parallel resistors that would be something like `inv swap inv + inv` assuming I just entered the two resistors (swap flips the position of the bottom two stack items and inv is inverse).
Now, to calculate a circuit with two sets of parallel resistors in series with each other and in parallel to another resistor, we do `r1 ent r2 para r3 ent r4 para + r5 para` (ent is the enter key). That reads "enter the first two resistors and find the parallel. Enter the second two and find the parallel. Add those results. Enter the last resistor and find the parallel." That is exactly how you'd think through the problem if you didn't have a calculator.
In infix that would be `para(r1, r2) = 1 / ((1 / r1) + (1 / r2))` and then `para((para(r1, r2) + para(r3, r4)), r5)`
From a mechanical perspective though, the RPN version has 5 keypresses to program the function and is very short while the infix version is much more complex. For the final calculation, only 6 non-number keypresses are needed in RPN. For infix, if you had the complete foresight to predict every single paren, you'd need 20 keypresses, 25 if you want sane spacing, and many more if you missed something. As this illustrates, RPN is generally faster and easier.
I'd finally note that RPN and forth tend to become confusing for complex reusable functions, but I'm generally going to do those on my desktop and input/output from a file anyway.
tl;dr RPN calculates in the order your brain does. It's faster and less error prone than infix (due to fewer keypresses). It encourages comprehension of the material and makes recognizing/saving partial solutions organic and easy.
- mediocrejoker 9y agoThanks for writing this. It sounds like something I would like to learn. I'm not calculating parallel resistances much these days but I'm a sucker for efficiency, even if it's just a few keystrokes on a calculator.