MathGroup Archive 2011

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

Search the Archive

Re: Why Mathematica does not issue a warning when the calculations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117682] Re: Why Mathematica does not issue a warning when the calculations
  • From: Richard Fateman <fateman at eecs.berkeley.edu>
  • Date: Tue, 29 Mar 2011 06:59:46 -0500 (EST)

Anyway...
....
>
> (DL) Specifically if you take the symbolic input, evaluate exactly, 
> and then numericized, you get the situation I described. In detail:
>
> e1 = FractionalPart[(6 + Sqrt[2])^20];
>
> Now evaluate in fixed precision. In Mathematica this can be done (to 
> close approximation) as below.
>
> In[28]:= a1 = Block[{$MinPrecision=10,$MaxPrecision=10},
>   e1 /. n_Integer:>SetPrecision[n,10]]
> Out[28]= 0.7149336997
>
> In[29]:= a2 = Block[{$MinPrecision,$MaxPrecision},
>   e1 /. n_Integer:>SetPrecision[n,20]]
> Out[29]= 0.68777819382990998756
>
> In[30]:= a1==a2
> Out[30]= False
Yes, this is just fine.  You are taking an expression e1 and applying 
two different functions, call them f10 and f20, and getting two 
different answers.  There is no special reason to think that a1= f10(e1) 
and a2= f20(e1) should be the same, and they are in fact different.
>
> Recall that all we are doing, in effect, is numericizing the numbers 
> and evaluating in fixed precision. If this is not deemed to qualify as 
> the type of situation you describe
no, because f10 and f20 are two different functions. This is not the 
situation I described, which is that a single function f when applied to 
e1 and e2 where e1==e2, should result in f(e1) - f(e2) == 0
> , then the more direct variant below will certainly suffice.
>
> In[36]:= b1 = With[{prec=10}, 
> Block[{$MinPrecision=prec,$MaxPrecision=prec},
>   SetPrecision[-251942729309018542,prec] + (6 + Sqrt[2])^20]]
> Out[36]= 0.6619679453
>
> In[37]:= b2 = With[{prec}, 
> Block[{$MinPrecision=prec,$MaxPrecision=prec},
>   SetPrecision[-251942729309018542,prec] + (6 + Sqrt[2])^20]]
> Out[37]= 0.68777820337396297032
>
> In[38]:= b1 == b2
> Out[38]= False
>
> This is truncation at work, behind the scenes.
Again, these are two different functions, and there is no reason for 
them to result in the same answer.
Fortran 77 has two (maybe more?) sine functions for different 
precisions. Starting with an exact integer 2, you presumably get 
different results for  sin(1.0 * 2)   and sin(1.0d0 * 2). The intrinsic 
functions for different precisions are different. Perhaps this is what 
you are getting at.  If you call two different functions "the same" then 
it would seem that you might get different answers on inputs that are 
the same value (in Fortran or any other system).

though the situation in Mathematica is kind of the reverse.  That is, 
you have a function, say s[x_,y_]:=x-y.  It is not really a single 
function of two arguments. Really it is a function of 4 arguments,

s(x,y, Precision(x), Precision(y),

  and the result is computed by something like

  SetPrecision(RawSubtract(x,y),Min(prec1,prec2))

Calling a function like this requires you to distinguish x and y if they 
have different values or different precisions.
Mathematica hides the precision of numbers from the user during ordinary 
arithmetic.



  • Prev by Date: Re: Why Mathematica does not issue a warning when the calculations
  • Next by Date: Re: Writing images from manipulate
  • Previous by thread: Re: Why Mathematica does not issue a warning when the calculations
  • Next by thread: Re: Why Mathematica does not issue a warning when the calculations