I am reading Mathematica Cookbook, chapter 1.

Author gives two examples, with the following explanation

You can control precision within a complex calculation (without using N[] on every intermediate result) by changing these values; however, you should only do so within a Block (a local context). For example, compare the difference between a calculation with automatic precision for intermediate results to the same calculation with fixed precision (obtained by making $MinPrecision == $MaxPrecision ).

In[1]:= SetPrecision[(1 + Exp[Sqrt[2] + Sqrt[3]])/2^25, 32]

Out[1]= 7.226780742612584668840452114476*10^-7

   Block[{$MinPrecision = 32, $MaxPrecision = 32}, 
     SetPrecision[(1 + Exp[Sqrt[2] + Sqrt[3]])/2^25, 32]]

Out[2]= 7.2267807426125846688404521144759*10^-7

Why two results are different, despite the fact that precision was set to 32 digits in both expression ? And what is "automatic precision" ?
Edit: user "rcollyer" points out that

running Precision on the two results gives 31.5935 and 32..


1 Answer 1


I don't think that SetPrecision[x,p] simply returns a version of x with precision p. Rather, it sets all numeric types in x to precison p and then evaluates x. This is important, if we want SetPrecision to work on symbolic arguments. For example,

SetPrecision[2 x, 4]

2.000 x

Thus, the following computation need not yield 4:

Precision[SetPrecision[Sqrt[2], 4]]


In fact, this is equivalent to

Precision[Sqrt[SetPrecision[2, 4]]]


Of course, Sqrt[SetPrecision[2, 4]] is subject to precision tracking using significance arithmetic. Thus, we don't expect it's precision to be 4.

On the other hand, setting $MaxPrecision==$MinPrecision forces all results to have this common value.

  • $\begingroup$ why is Precision[SetPrecision[Sqrt[2], 4]] results in precision different than 4 ??? $\endgroup$
    – newprint
    Jun 25, 2012 at 5:54
  • $\begingroup$ @newprint I added one line. Does that help? $\endgroup$ Jun 25, 2012 at 10:38
  • 4
    $\begingroup$ SetPrecision does just as you claim (so you can remove the "I don't think that" part if you like). $\endgroup$ Jun 25, 2012 at 16:33
  • $\begingroup$ @DanielLichtblau and Mark, what about Precision[Sqrt[SetPrecision[100, 10]]] not returning the same result as Precision[SetPrecision[Sqrt[100], 10]]? $\endgroup$
    – Rojo
    Jun 28, 2012 at 13:24
  • $\begingroup$ @Rojo It would be easier to answer if you stated why you beleive they should be equal (or whatever expectation they did not meet). The second is clearly going to be 10 up to machine epsilon or so. That's because you set it and immediately evaluated it. The first sets the precision of the argument of Sqrt. The precision of the result will then depend on first order estimates of error of Sqrt, evaluated at 10. $\endgroup$ Jun 28, 2012 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.