# Reverse Polish Notation

Reverse Polish Notation is a method of creating unambiguous mathematical calculations without the need for parentheses. It operates by means of a stack with values being pushed onto the stack, then an operation popping the right number of arguments off the stack, working on them, then pushing the result back.

For example a simple addition might look like:

```
Push 1
Push 5
Operation +
```

Here the values 1 and 5 are pushed onto the stack in that order, then the addition operation is requested. The last two values are popped from the stack (1 and 5) and the addition operation is performed on them. The result is then pushed back to the stack.

To see that in more detail if we look at the stack at the same time as doing the operations we see this:

```
Operation | Stack
---------------------
Push 1 | 1
Push 5 | 1 5
+ | 1 5
[pop] | 1
[pop] | [empty]
1 + 5 = 6 | [empty]
Push 6 | 6
```

Reverse Polish Notation is incredibly easy to implement programatically and also removes any ambiguity regarding operator precedence. Every operation always works on the required number of values that are at the end of the stack.

For example the equation `5 + 3 * 7 / 4`

is ambiguous. Tradition dictates that it should be calculated as `5 + ((3 * 7) / 4)`

but without knowing that tradition and those existing rules it's impossible to calculate reliably. RPN removes that ambiguity and the same equation would be written as: `3, 7, *, 4, /, 5, +`

which can be read as *take 3 and 7 then multiply them. Take 4 and divide that with the previous answer. Take 5 and add it to the previous answer*. There is no other way of doing the calculation. All ambiguity is gone.

UECIDE uses RPN in the `math`

Variable Command not only because it is simple to implement but also because it removes the need to parse parentheses and work out the right order to calculate.

### Support Us

Running this server costs money. This server not only hosts this website, but is also the main build platform for creating the download files for UECIDE. Just a couple of pounds (or Dollars, Yen, Mongolian tögrög... we're not fussy) can help to offset the costs.

Alternatively, if you want to be more personal, you could buy me something on Amazon. I have a small wish-list of low-cost items that I'd quite like to receive. Make it a surprise.