4 ms·
Can you elaborate on this? What kinds of one-off calculations is RPN better for and why?
by mediocrejoker 9y ago
Can you elaborate on this? What kinds of one-off calculations is RPN better for and why?
- mohaine 9y agoIt isn't about about one off calcs but really about how the stack works over multiple operations. So you enter number 1, verify it, enter number 2, verify it, then do the operation. If you mess up, fix it now and go on. You can even go back and fix things on the stack if you notice a typo later. Multi step complex operations is where RPN really shines. Do multi step operation 1, then 2, then 3 as independent operations. When it comes time to combine the results of the 3 operations, they are just there on the stack waiting to be used. Without RPN you had to think about saving them to memory at the end of each operation, then remember were you saved them at the end. I had to switch from a std graph calc to RPN half way through collage and the first test I took with the 48G was a bit of a struggle. After the first 4 part question where the 4th step ended up being just combining the results from parts 1-3 that I had absentmindedly left on the stack I was sold. Just pressing + and * was SO much better then typing everything back in and verifying 3 numbers and hoping I didn't mess up a number.
- hajile 9y agoFor 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.