Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to optimize an expression that involves a number of trigonometric functions and Exp[]. How do I make sure that all my calculations have an accuracy of 120-200 digits after the decimal point? This includes the accuracy of Exp[] and trig functions.

To get my point across, here is part of the equation:

z[x_, y_]:= Exp[Sin[60.0*x]] + Sin[50.0*Exp[y]]

Mathematica lets you control Precision of computations (which is total number of digits in the number) with two global variables: $MinPrecision and $MaxPrecision. However, I am not looking for precision.

share|improve this question
Do you know that keeping expressions in terms of integers and rationals will keep exact values? Try NestList[16 # (1 - #)/3 &, 1/5, 4] ? Though for heavy computations you will lose speed. – Vitaliy Kaurov Jul 1 '12 at 17:53
I am aware that Mathematica will give me exact values for integer & rational calculations, but my calculations are far from exact. – newprint Jul 1 '12 at 18:00
It seems that N[expr, {Infinity, accuracy}] might be the way to go, assuming the inputs are known to sufficient precision. (If the inputs are aren't, then you cannot know the result to the desired accuracy.) – Michael E2 Aug 6 '15 at 21:37

How about something like

z[x_, y_] := Exp[Sin[60*x]] + Sin[50*Exp[y]]
z[SetAccuracy[20., 200], SetAccuracy[20., 200]] // Accuracy

does this not do what you need?

share|improve this answer
In[8]:= z[SetAccuracy[20., 200], SetAccuracy[20., 200]] // Accuracy Out[8]= 13.6508 Don't think it worked. – newprint Jul 1 '12 at 18:25
@newprint Sorry, I forgot to add the modified definition of z I used. Or, is it that you simply don't know the coeffs? Because that's different... – acl Jul 1 '12 at 18:47
Thanks, I understood the SetAccuracy and // Accuracy – newprint Jul 2 '12 at 1:13

If you use inexact constant in your equation it helps if you increase their accuracy as well. You can do that easily using the backtick notation:

z[x_, y_] := Exp[Sin[60.0`200*x]] + Sin[50.0`200*Exp[y]]
z[SetAccuracy[20., 200], SetAccuracy[20., 200]] // Accuracy


share|improve this answer
Initially, I used the backtick for floating point values as well(I read about in Mathematical Cookbook), though it becomes somewhat cumbersome within long equation. – newprint Jul 2 '12 at 1:19

Short answer

If you want Mathematica to return arbitrary-precision calculations with (approximately) a given Accuracy you could ask for it in MantissaExponent form:

MantissaExponent[Exp[150] 123``50][[1]] // Accuracy

Supporting information

Accuracy of input numbers can be set with double backticks:

12345.5678``50   // Accuracy
12345``50        // Accuracy

Single backticks define Precision:

12345.5678`50   // Precision
12345`50        // Precision

A "constant accuracy" doesn't make much sense for floating point calculations. Mathematica tracks and preserves Precision. This is called "arbitrary-precision" after all.

Exp[150] 123`50  // Precision
Exp[150] 123``50 // Accuracy
share|improve this answer
I think in the "Short answer" section you use wrong formulation because MantissaExponent does not alter the accuracy of the result (I know, you know it - just for correctness). The right formulation could be: "If you want Mathematica to give you the accuracy of the result of calculations you could ask for it using MantissaExponent form: ..." – Alexey Popkov Jul 2 '12 at 17:43
@Alexey I wasn't sure how to say what I wanted to. I'll try to rephrase it as you suggest later today. – Mr.Wizard Jul 2 '12 at 18:00
One problem is that Wolfram's understanding of precision and accuracy is significantly misleading and the second one is that you use in this sentence the term "accuracy" with another meaning: the number of precise digits right to the decimal point in ScientificForm. In other words, it is something always approximately equal to Precision minus 1. – Alexey Popkov Jul 2 '12 at 18:14
Discussion on Precision and Accuracy in Mathematica:… – Alexey Popkov Jul 2 '12 at 18:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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