View Single Post
  #22   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove Harlan Grove is offline
external usenet poster
 
Posts: 733
Default Excel 2003 SP2 computes the power of a negative number wrong.

Giovanni Ciriani wrote...
Then let me ask you a question. Why should -A1^4-1 evaluate to a different
number than 1-A4^4 ? (-255 vs 257 for A1 equal to -4).

....

Your error here comes from confusing the unary minus operator with the
dyadic subtraction operator. In bodmas texts, unary minus is treated
implicitly as multiplication by -1, so -x^4 could be expanded as
(-1)*x^4, and bodmas would evaluate this as (-1)*(x^4). This is just a
convention. Unfortunately, Excel adopts a different but internally
self-consistent convention of treating -x implicitly as (0-x), and the
parentheses are *INTENDED*.

Also, your first expression has 3 operators while your second has only
2. It's not immediately obvious why changing the number of operators
shouldn't change the values. Perhaps you should have written the second
as 1--x^4, in which case -x^4-1 = 255 and 1--x^4 = -255, which is
EXPECTED since subtraction is anticommutative: a - b = -(b - a). Or you
could have written the first as -x^4+-1 and the second as -1+-x^4, and
in that case both would equal 255. Commutivity and anticommutivity are
preserved as long as you use APPROPRIATE arithmetic rephrasing, and
that REQUIRES distinguishing between - as unary minus and as
subtraction. IOW, Excel's convention, PROPERLY UNDERSTOOD, is
self-consistent. Your mistake is assuming a--b^c = a+b^c as it would in
bodmas.

In some programming languages there's a different token for the
arithmetic sign of negative numeric literals. APL and its offspring are
prime examples. In those languages the sign token is part of the
numeric literal, so if I were to use underscore, _, as such a token,
0-3 = _3, and _3^4 would always be interpretted as (0-3)^4. This
probably wasn't Excel's original developers' explicit rationale, but I
suspect they believed that users would expect -3^2 to be evaluated as
(-3)^2 when the base was a negative numeric literal, so they chose to
have unary minus behave the same way: -x^2 = (-x)^2. Their convention
is equivalent to translating all instances of -x (unary -) as (0-x).

Mathematicians back in the 17th century were lazy in this regard, and
used the same symbol to represent numeric sign, sign change and
subtraction. In order to resolve the ambiguity that this produces,
mathematicians and other writers who use mathematics adopted the bodmas
convention. Excel adopted a different convention. Unfortunate, but as
likely to be resolved as the UK, Ireland, Japan, Australia and New
Zeeland are to switching to driving on the right side of the road.