Hypatia — Hypatia’s RPN |
Why RPN?Hypatia uses RPN for three reasons: The first one: I like RPN. Many decades ago, when I got my first scientific pocket calculator, it happened to use RPN, which I had never heard of before, and it was love at first sight. When, many years later, I had the idea of writing my own calcuator for Windows because I couldn’t find one I liked well enough, I immediately thought it should use RPN. The second one: the simplicity of RPN’s syntax makes it easy to implement, and esay to enrich it with a variety of functions and features — and Hypatia makes ample use of that. And finally, because it is different. Everybody knows and uses infix notation, but RPN offers a different approach, and it is fun to explore its possibilities and advantages. Whether you are interested in Hypatia because of RPN or despite of RPN, I hope you will find it useful and easy enough to use. |
RPN (Reverse Polish Notation)Hypatia uses an enhanced version of RPN. RPN is a form to write mathematical expressions that is an alternative to the much better known algebaic notation. Admittedly it’s a matter of taste, but while it can seem a bit confusing at first sight it follows a more concise logic, and it does have advantages for simple as well as for complex calculations. Unlike the commonly used infix notation, RPN has no hierarchy of operations, and does not use parentheses. An RPN expression consists of arguments and operators, with ell elements being separated by spaces. It is strictly written and processed from left to right, operators are written after their arguments. An operator performs a calculation upon one or more argument(s) which it finds to its left, and returns a single value. The operator “knows” how many arguments it has to process (usually either one or two). After the operator has performed its calculation, it replaces the entire expression (arguments and itself) with the result, which can then become an argument for the next operator to the right. This sounds more complicated than it really is — take this example:
From left to right, the first operator is + + has two arguments, so it adds 2 and 3, which makes 5 The next operator is again +, which has 5 and 7 to its left, which makes 12 Operators replace themselves and their arguments with the result, so we are now left with 5 12 * * again takes two arguments, 5 and 12, and replaces them and itself with their product, 60 Because no more operators follow, this is the final result. In algabraic notation, this would be written (2 + 3) * (5 + 7) = You can find more about RPN in the Wikipedia article: en.wikipedia.org/wiki/Reverse_Polish_notation. And here is an online tool that converts infix notation to RPN, which can help to understand the principle: www.dcode.fr/reverse-polish-notation To find more about RPN, just use your favorite search engine to search for "reverse polish notation". With a little practice, you will find RPN as easy to use as infix notation, and in many cases easier. |
Hypatia’s Enhanced RPNHypatia offers a large number of functions that are not part of any standard definition of RPN, for instance unit conversion (:MI converts kilometers to miles, :F converts degrees Celsius to Fahrenheit, and many more), six different percentage functions, two types of rounding, three kinds of random numbers, etc. But Hypatia also has operators that do not use one or two arguments (like 2 SQRT or 3 4 *), but a sequence of arguments of any length — sum, mean, median, but also square sum, sum of reciprocals, and more. (By the way, you can type everything in lower case.) You can use Hypatia’s “n-argument operators” with just a few numbers (7 5 8 13 SUM is a quick way to add these numbers, and 3 4 SQSUM SQRT is a quick way to say “add the squares of 3 and 4 and draw the square root”), but you can also use them with data that you let Hypatia read from a file. And then there is WHISK that allows you to define your own 2-argument operators, and DONE that helps with calculating generalized Fibonacci sequences, and … But for all this, please have a look at the user manual hypatia-doc.pdf. And if you have questions, feel free to ask! |