[R] Spreadsheet math problem (exponentiation)
John McKown
john.archie.mckown at gmail.com
Fri Sep 18 16:31:02 CEST 2015
On Fri, Sep 18, 2015 at 8:39 AM, John Kane <jrkrideau at inbox.com> wrote:
> It appears that at least three major spreadsheets, Excel, Apache
> OpenOffice Cal and gnumeric have a problem with the correct order of
> operations when dealing with exponents. The gnumeric result is very strange.
>
> This problem has probably been reported before but just in case it has
> not, it would appear to be one more serious problem with spreadsheets. It
> might be useful in warning people away from using a spreadsheet for serious
> analysis.
>
> Excel
>
> -2^2 = 4
>
> 2^2^3 = 64
>
> Apache OpenOffice
>
> -2^2 = 4
>
> 2^2^3 = 64
>
My opinion: One correct, one error! R agrees with me on this:
> 2^2
[1] 4
> 2^2^3
[1] 256
> 2^(2^3)
[1] 256
> -2^2
[1] -4
> (-2)^2
[1] 4
>
>
> gnumeric # note one correct, one error!
>
My opinion: two correct!
>
> -2^2 = 4
>
> 2^2^3 = 256
>
> John Kane
> Kingston ON Canada
>
>
Seems to be a bit off-topic. Unless your point to is to use R for
important work instead of some spreadsheet. A point with which I completely
agree!
MS-Excel, and Apache OpenOffice, appear to implement the above as
(2^2)^3==64. Whereas gnumeric implements appears to implement this as:
2^(2^3)==256. Which is "correct"? Depends on whom you ask.
ref: https://en.wikipedia.org/wiki/Order_of_operations
<quote>
If exponentiation is indicated by stacked symbols, the usual rule is to
work from the top down, thus:
[image: a^{b^c} = a^{(b^c)}],
which typically is not equal to [image: (a^b)^c]. However, some computer
systems may resolve the ambiguous expression differently. For example,
Microsoft
Office Excel <https://en.wikipedia.org/wiki/Microsoft_Office_Excel>
evaluates *a*^*b*^*c* as (*a*^*b*)^*c*, which is opposite of normally
accepted convention of top-down order of execution for exponentiation. If
a=4, p=3, and q=2, [image: a^{p^q}] is evaluated to 4096 in Microsoft Excel
2013, the same as [image: (a^p)^q]. The expression [image: a^{(p^q)}], on
the other hand, results in 262144 using the same program.
</quote>
Gnumeric abides by the above definition. FWIW. BTW - MS-Excel also has
1900 as a friggin' leap year (due to Lotus 1-2-3 apparently), so I don't
consider MS-Excel (or anything else from MS for that matter) to be a
definitive source of correctness. Personal opinion. FSF associate member.
Penguinista.
--
Schrodinger's backup: The condition of any backup is unknown until a
restore is attempted.
Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be.
He's about as useful as a wax frying pan.
10 to the 12th power microphones = 1 Megaphone
Maranatha! <><
John McKown
[[alternative HTML version deleted]]
More information about the R-help
mailing list