There periodically appears on the Internet an arithmetic type of puzzle. Typically it will be a string of small natural numbers and a few arithmetic operations, such as “3 + 7 x 2 – 4” and the task is to work out the result.

The trick here is that people tend to perform such a series of calculations strictly from left to right, so the sequence goes:

3 + 7 = 10, 10 x 2 = 20, 20 – 4 = 16. Bingo!

Most mathematicians, and people who remember maths from school would disagree however. They would calculate as follows:

7 x 2 = 14, 3 + 14 = 17, 17 – 4 = 13. QED!

Why the difference? Well, mathematicians have a rule that states how such calculations are to be performed. Briefly the calculations is performed from left to right, but if a multiplication or division is found between two numbers, that calculation is performed **before** any additions or subtractions. In fact the rule is more complex than that, and a mnemonic often used to remember it is “BODMAS” or “BEDMAS” (which I’m not going to explain in detail here. See the link above).

```
```

This rule is only a convention and so is not followed everywhere, so there are various “correct” answers to the problem. Also, there are still ambiguities if the conventions are applied which could cause confusion. However, most people with some mathematical training would claim that 13 is the correct answer.

Interestingly, computer programming languages, which are much stricter about such things, codify the precedence of operations in a calculation exactly, so that there can be no ambiguity. It is the programmers task to understand the precedence rules that apply for a particular language.

In most cases the rules are very, very similar, but it is the documentation of the language which describes the rules of precedence, and wise programmers study the section on operator precedence very closely.

There are ways of specifying an arithmetic problem uniquely, and one of those (which is sometimes of interest to programmers) is “Reverse Polish Notation“. Using this my original puzzle becomes “3 7 2 x + 4 -” which looks odd until you understand what is going on here.

Imagine that you are traversing the above list from left to right. First you find the number “3”. This is not something you have to do, like “+”, “-“, “x” or “/”, so you just start a pile and put it on the bottom. The same goes for “7” and “2”, so the pile now has “3” on the bottom and “2” at the top and “7” in the middle.

Next we come across “x”. This tells us to do something, so we pull the last two things off the pile and multiply them (7 x 2 = 14) and stick the result, “14” back on the stack which now contains “3” and “14”. The next thing we find is “+” so we pluck the last two things off the pile “3” and “14” and add them, putting the result “17” back on the (empty) pile.

```
```

Next up is “4” which we put on the pile, and finally, we have “-“, so we pull the two last elements from the pile (“17” and “4”) and subtract the second from the first, giving “13” (Yay!) and that is the answer which we put back on the stack. The stack now contains nothing but the answer.

This looks confusing, but that may be because we are used to the conventional left to right way of doing things. It is actually easier for a computer to understand the RPN version of the puzzle and there are no ambiguities in it at all. Technically, it’s a lot simpler to parse than the conventional version.

Parsing is what happens when you type a command into a computer, or you type something complex, such as a credit card number into the checkout section of a web site. The computer running the web site takes your input and breaks it up if necessary and checks it against rules that the programmer has set up.

So, if you type 15 numbers or 17 numbers into the field for the credit card number, or you type a letter into the field by mistake, the computer will inform you that something is wrong. Infuriatingly, it may be not be specific about what the trouble is!

Anyway, back to the arithmetic. It grates with me when people make simple arithmetical errors and then excuse themselves with the phrase “I never was much good at maths at school”! That may well be true, but to blame their problems with arithmetic of the whole diverse field of mathematics.

It’s like saying “I can’t add up a few numbers in my head or on paper because I missed the class on elliptic functions“! It’s way over the top. For some reason people (especially those who can’t get their head around algebra) equate the whole of mathematics with the bit that they do, which is the stuff about numbers, which is arithmetic.

As we evolved, we started counting things. It’s important to know if someone has got more beans than you or that you have enough beans to give everyone one of them. We invented names for numbers and names for the things (operations) we did on them.

We did this without much thought about what numbers actually are. We as a species have only relatively thought deeply about numbers fairly recently, and we only discovered such things as real numbers and geometry in the last couple of thousand years so it is not surprising that the average brain has yet to expand to cope with the more advanced mathematical concepts.

This could be why so many people these days equate fairly simple arithmetic with mathematics as a whole – our brains are only now coming to grips with the concept that there is more to maths than simply manipulating numbers with a very few simply operations.

It may be that the average human brain never will get to grips with more advanced maths. After all, people can survive and thrive in the modern world with on a rudimentary grasp of mathematics, the arithmetic part.

Some human brains however do proceed further and much of modern society is the result of mathematics in its wider sense applied to the things that we see around us. For instance, we could not have sent men to the moon without advanced mathematics, and technology relies heavily on mathematics to produce all sorts of things. It’s a good things that some brains can tell the difference between the field of arithmetic and mathematics as a whole.