MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: why extending numbers by zeros instead of dropping precision is a good idea / iterating sqrt

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117855] Re: why extending numbers by zeros instead of dropping precision is a good idea / iterating sqrt
  • From: Richard Fateman <fateman at eecs.berkeley.edu>
  • Date: Sat, 2 Apr 2011 02:39:50 -0500 (EST)

On 3/31/2011 10:07 AM, Daniel Lichtblau wrote:

... (summarizing) iterating square root of 2, in fixed precision, 
eventually gets to 1....
... iterating square root of 2;  call it 1+epsilon,  with increasing 
precision, gets you to  1+epsilon/(2^n) + ...
>
> The problematic aspect to the computation, in this case, is fixed 
> precision arithmetic. Not because Mathematica's significance 
> arithmetic does error tracking but rather simply because it allows for 
> precision to go up, when justified. I'll show using bigfloats but in 
> fixed precision. I use more iterations to make quite clear that the 
> result is bad. One can check that in default mathematica arithmetic 
> this would still ahve worked just fine.
>
> In[398]:= iters = 70;
> Block[{$MinPrecision = 20, $MaxPrecision = 20},
>   res = NestList[s[#, 1/2] &, two, iters]];
> Last[res]
> Last[res]^(2^iters)
>
> Out[400]= 1.0000000000000000000
>
> Out[401]= 0``-1.6531076715578628
>
>
> Daniel Lichtblau
> Wolfram Research
>

The problem (which occurs in other contexts too), is that you are 
computing a function  which differs from 1 by a small amount.  Let's 
call it p=1+f(x).
What you can do is compute f(x).    Sometimes you don't really need p to 
high precision if all you are going to do is compute p-1.

This happens enough  in computing Exp[x] that some scientific subroutine 
libraries will have functions to compute expm1(x) defined as Exp[x]-1,  
for small x.  Otherwise, computing Exp[x] using the regular 
approximations  needs lots of bits.
Also, log1p for computing log(1+x) accurately for small x, for the same 
reason.


Similarly, if you want to compute  q(eps,n) :=  (1+eps)^(1/(2^n), 
consider instead computing r(eps,n):= q(eps,n)-1.  This can be computed 
without using additional costly precision.  You can then add the 1 back, 
later, if you want.  Of course if you are just doing it one-off, who cares.

RJF






  • Prev by Date: Re: Wolfram, meet Stefan and Boltzmann
  • Next by Date: Re: Combinatorica
  • Previous by thread: Re: Using Nearest on a group of points
  • Next by thread: Re: Combinatorica