Re: Bug in calculating -3^49999.0
- To: mathgroup at smc.vnet.net
- Subject: [mg66034] Re: [mg65989] Bug in calculating -3^49999.0
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Thu, 27 Apr 2006 02:26:38 -0400 (EDT)
- References: <200604260837.EAA02684@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
kowald at molgen.mpg.de wrote:
> Hello everybody,
>
> I'm using Mathematica 5.1 under Win2k and I found a bug when I try to compute
> -3^49999. I get:
>
> -3^49999 //N => -3.85 * 10^23855 okay
> -3^49999. => -3.85 * 10^23855 okay
> (-3)^49999. => -3.85 * 10^23855 + 4.56*10^23844 i wrong
> (-3)^49999 => -3.85 * 10^23855 okay
>
> Is this a known problem?
> Is there a work around ?
> Obviously this is part of a more complicated calculation and so I
> cannot simply leave out the brackets.
>
> Many thanks,
>
> Axel
It is known behavior. I would not regard it as a problem insofar as it
is also expected behavior (that is, not a bug).
Raising a number to a power in approximate arithmetic will be done more
or less as follows.
(1) Find the (approximate) log of the base. Call this logb.
(2) Compute the exponential of logb*power.
Given that you use N without requesting specific precision, these
computations will be performed using machine arithmetic if possible.
Otherwise they will sue bignum (software) arithmetic but at
$MachinePrecision. That is what happens in this case due to the sizes of
exponents required.
We can do this "by hand" as below.
In[18]:= InputForm[lb = Log[-3.]]
Out[18]//InputForm= 1.0986122886681098 + 3.141592653589793*I
In[20]:= InputForm[Exp[lb*49999]]
Out[20]//InputForm=
-3.8513654349963041533518106689182`15.954589770191005*^23855 +
4.5651915515655449441209549063423`15.954589770191005*^23844*I
The factor of 49999 has the effect of amplifying error in that exponent
by about 5 orders of magnitude. As machine precision handles about 16
decimal places, we see that a result good to only 11 or so places is a
quite plausible outcome. Notice (e.g. by comparison with N[3^49999,50])
that the real part of the above is only "correct" to 11 places. As the
imaginary part is about 11 orders of magnitude smaller than the real
part, it's contribution to the relative error is also in line with
expectations.
If you want higher precision results your options are to request higher
precision (the hammer approach) or to try to rearrange the computations
in such a way as to reduce effects of truncation and other error when
doing approximate numerical evaluations. A beneficial effect of using
higher precision is that significance arithmetic will be utilized, and
this will let you know that some "digits" are not to be trusted. For
example, below we learn that the imaginary part has NO significant
digits, and is at least 19 orders of magnitude smaller than the real part.
In[23]:= Exp[N[lb*49999,25]]
23855 23836
Out[23]= -3.8513654349686329705 10 + 0. 10 I
Daniel Lichtblau
Wolfram Research
- References:
- Bug in calculating -3^49999.0
- From: kowald@molgen.mpg.de
- Bug in calculating -3^49999.0