Did you ever see one of those trivial sums on Facebook, which looked so easy and yet you knew there must be some trick going on? Something like:

3 + 2 × 6 = ???

Well, you’re right.

Because we, in English, read from left to right. But in math, you don’t. In math, you work certain sums out before others, and not necessarily in the same order that they appear on the page. This is a standard mathematical idea, usually called the *order of precedence*, Wikipedia talks about it here. So, something like a × happens before a +, and so on. Working in computing I’ve come across this a lot, and the rules in full are pretty verbose, but the basic thing is that you perform some operations before others. Left or right matters less. It matters for some things, like ÷, but mostly, no.

So, if somebody presented me with a line of computer code which said,

3 + 2 × 6

the first thing, I would probably fail its review, because it is ambiguous. In fact, it should be written as

3 + (2 × 6)

which gives the exact same result, but by introducing the brackets, you make it obvious. It’s easier for the reader to see what is going on, and that has always been my #1 aim when reviewing computer code.

The bracket says *perform me first*, so you can see we are no longer in the realm of left-to-right.

Once you realise that, the answer is trivial.

3 + 2 × 6 = 3 + (2 × 6) = 15

Easy, huh? But not so easy as you might think. Even Microsoft’s own calculator (on my PC) gets the sum wrong, unless I help it out by adding the brackets.

### Like this:

Like Loading...

*Related*

## Author: Mister Bump UK

Designed/developed IT systems for banks, but had a stroke in 2016, aged 48. Returned to developing from home, plus do some voluntary work. Married, with a grown-up, left-home daughter.
View all posts by Mister Bump UK

Right: just because you don’t technically need the parentheses, if adding them clarifies the equation, put them in.

LikeLiked by 1 person

Why wouldn’t it be (3+2) x 6? That would equal 30: 3+2=5; 5×6=30.

I was never good at math.

LikeLiked by 1 person

Yup, (3+2) x 6 would be 30, you’re absolutely right. But the order of precedence comes into play, so 3 + 2 x 6 actually means 3 + (2 x 6) – that is basically by definition because x outranks +. 30 is actually the answer given by Microsoft, but it isn’t right.. The calculator on Android is correct.

LikeLiked by 1 person

Who said math is an exact science?

LikeLiked by 1 person

Indeed there are people who advocate that the “rules” of math should fit in with what people think, not the other war round.

LikeLiked by 1 person

Good old BODMAS!

LikeLiked by 1 person

Absolutely. I saw a post only yesterday, though, which purported to be a bit of simple math, but was actually a test of this. I guess people don’t know (which is why they get the sum wrong).

LikeLiked by 1 person

Nice work!!!

Follow https://heatmath415345277.wordpress.com/

For more blogs

LikeLiked by 1 person