Saturday, September 24, 2011

Operator precedence

At the back of the box of a popular brand of hot chocolate mix are several activities for children and one of them is to determine the average number of mini marshmallows in a serving of hot cocoa by solving the equation 3+2x4÷2-3x7-4+47.  My son happily evaluates this equation from left to right and came up with the answer 92 which is the same as the answer given at the bottom of the box.  My wife took a look at what he was doing and said: "Wait a minute, that is not the way we were taught in school. There is a precedence of operators, multiplication and division before addition and subtraction."  Furthermore, when the part of the equation contains both multiplication and division, the evaluation proceeds from left to right.  Similarly for addition and subtraction.  Using this rule, the correct answer is 3+(2x4÷2)-(3x7)-4+47 = 29 (which coincidentally is 92 reversed), a much smaller number of marshmallows.  It is not clear how the rule of operator precedence evolved, but the development of computer programming languages such as FORTRAN necessitates this disambiguation of the syntax of mathematical equations (see the webpost here).

Sunday, January 30, 2011

How do you say 293?

Everyone time I learned a new language, sometimes I feel like I have to learn a new number system as well. Consider the number 293. In my mother tongue, Chinese, 293 is written as 二百九十三, which literally means "two-hundred-nine-ten-three". Thus the positions of the digits 2 and 9 are denoted by the words for "hundred (百)" and "ten (十)" respectively. Then when I learned Dutch, 293 is written as "twee honderd drieënnegentig" which literally means "two-hundred-three-and-ninety". Instead of reading the number from left to right, I have to mentally insert the unit digit (3) before the decade digit (9). This took me a while to master. Then when I learned French, 293 is written as "deux cents et quatre-vingt-treize", which literally means "two-hundreds-and-four-twenty-thirteen". I mainly use English these days, which luckily write the number similar to Chinese syntactically.