Why RPN
The main difference between Algebraic Mode and the Reverse Polish Notation (RPN), is the absence of the = ( ) keys and the addition of an Enter (8 ) Key. RPN looks like this:
5 | + | 4 | = | 9 | Algebraic Mode (5 keystrokes) |
5 | Ent | 4 | + | 9 | Reverse Polish Notation (5 keystrokes) |
Characteristic for RPN is that the operator (red) is always entered after the operands (black). This is called postfix notation. And that is done very consistently. In the next example Algebraic mode switches from infix notation (the operator is placed between the operands) to postfix notation. RPN keeps using postfix notation.
5 | 1/x | 0.2 | Algebraic Mode (3 keystrokes) |
5 | 1/x | 0.2 | Reverse Polish Notation (3 keystrokes) |
The real power of RPN becomes visible when the formula’s gets more complicated. Algebraic mode needs brackets to be effective. RPN does not, it keeps using postfix notation. For instance:
4 | * | ( | 2 | + | 3 | ) | = | 20 | Algebraic Mode (8 keystrokes) |
2 | Ent | 3 | + | 4 | * | 20 | Reverse Polish Notation (6 keystrokes) |
RPN is made possible by the use of a stack. This can be compared with a stack of dinner plates: you can only place and take plates from the top. When a number is entered it is put on the top of the stack. The next entered number, is placed on top of that. An operator always works on the top of stack (unary operator or operator with one operand) or on the top two stack levels (binary operator or operator with two operands). Then the upper two values are replaced with the calculated value and the stack is shifted up. The example above uses a stack as follows:
Keys pressed | 4 | 2 | 3 | + | * | |
Stack level 1 | 4 | 2 | 3 | 5 | 20 | Top of stack |
Stack level 2 | 4 | 2 | 4 | Used for binary operations | ||
Stack level 3 | 4 |
And when the formular gets longer, RPN becomes increasingly more efficient:
( | 1 | + | 2 | ) | * | ( | 3 | + | 4 | ) | = | 21 | Algebraic (12) |
1 | En | 2 | + | 3 | 8 | 4 | + | * | 21 | RPN (9 ) |
So RPN is often shorter (less key strokes), more consistent (uses always postfix notation) and therefore simpler to use. The only disadvantage is that one has to become familiar with RPN, but that appears to go surprisingly fast.
Finally a nerd!
A very good starting point of building your own RPN calculator with a mechanical keyboard, would be to find a suitable key-caps set. An ortholinear key-caps set, has all the key caps made in the same shape. A single sized enter key, would solve the problem of making a large key with two mounting points. Finding suitable keycaps, is very difficult. Since every row of keys has another shape, so keys cannot be placed everywhere. The keys for a keypad also have cursor arrows on it, and that’s not what we want. Finally, the larger enter key often has three mounting points, where two are needed.
I wanted a very rigid calculator, so I made it entirely of aluminum. But a 3d printed case would have been an option too. I wanted a nice retro-look. Therefore, I used a mechanical keyboard with two seven segment displays and not an LCD display. I am very rarely making scientific calculations and need only basic calculation functions And, if I need scientific calculations, I can always use my smartphone app. For most of my calculations, 6 digits are enough. The calculator shows the two top-level stack values. If more digits are used, both displays are automatically combined to one virtual 12-digit display.
At an early stage, I decided that I needed an Arduino Nano, because of its compact size. And I am familiar with C++. Just because I could, I also wanted a real-time clock (RTC). That offers me a date/time display and a count-down clock to my wife’s birthday (or any other very important date).
Writing the software was very hard. It is not difficult to write software, but it is difficult to write excellent and user-friendly software. For instance,...
Read more »
Lovely!