4
$\begingroup$

I'm getting the same answer "1" for Exp[x] with x less than "1.1*10^-16", and I really need to calculate much smaller numbers (in order of 10^-40).

I tried using SetPrecision[Exp[x],1000].

Obviously I'm doing something wrong. #_-

I've searched about increasing the precision but I couldn't find helpful answers. Would you please kindly guide me?

Edit:

Maybe this screenshot could make it easier to understand what I'm talking about.

enter image description here

$\endgroup$
4
  • $\begingroup$ Try N[Exp[11/10000000000000000000000], 4000]. In other words, use rational numbers and not numbers with decimal points when you need lots of precision. $\endgroup$
    – JimB
    Commented Nov 26, 2016 at 20:16
  • $\begingroup$ By default only 6 digits are displayed, see Preferences -> Appearance -> Numbers -> Displayed precision. Edit the output cell to see all. In your last examples first you compute something ridiculously close to 1 using machine precision (15 digits), and only after you get the result you increase the precision ... $\endgroup$
    – Szabolcs
    Commented Nov 26, 2016 at 20:22
  • $\begingroup$ Thank you guys for your quick replies. I've tried them. @JimBaldwin I have other calculations that results to "x" which is not rational. Like divisions and stuff. I think I'm going to lose accuracy If I Rationalize my "x" right? $\endgroup$
    – Pedram
    Commented Nov 26, 2016 at 20:28
  • 2
    $\begingroup$ Most languages' standard libraries provide an expm1 function for this purpose, which returns $\exp(x)-1$ to high precision even when $\exp(x)$ would return exactly $1$. Mathematica unfortunately doesn't, but if that's your goal, you could implement something similar along the lines of log1p. $\endgroup$
    – user484
    Commented Nov 27, 2016 at 3:19

1 Answer 1

6
$\begingroup$

You're setting the precision too late.

Exp[1.`200*^-40]

and

Exp[SetPrecision[1*^-40, 200]]

yield

Mathematica graphics

On the other hand,

SetPrecision[Exp[1.*^-40], 200]

yields

Mathematica graphics

because Exp[1.*^-40] evaluates to 1. (exactly, in machine precision), before it is passed to SetPrecision.

$\endgroup$
4
  • $\begingroup$ Woah Thanks! You made my day! $\endgroup$
    – Pedram
    Commented Nov 26, 2016 at 20:30
  • $\begingroup$ @PedramAshofteArdakani You're welcome. $\endgroup$
    – Michael E2
    Commented Nov 26, 2016 at 20:31
  • $\begingroup$ Hi again! I noticed something strange here, Exp[SetPrecision [1.1^-40, 200]] , Exp[(1.1`200)^-40] and Exp[(SetPrecision[1.1, 200])^-40] Hold different answers, aren't these supposed to be identical? $\endgroup$
    – Pedram
    Commented Dec 2, 2016 at 18:06
  • 1
    $\begingroup$ @PedramAshofteArdakani I don't think they supposed to be identical. 1.1^40 is first computed in 16-digit machine precision and will have significant differences when compared to the other 200-digit precision results. For the difference in the other two, examine 1.1`200 // FullForm and SetPrecision[1.1, 200] // FullForm. Here the difference arises because 1.1`200 is parsed to have 200-digit precision, whereas with SetPrecision, the 1.1 is first evaluated at 16-digit machine precision, then converted to 200-digit precision. $\endgroup$
    – Michael E2
    Commented Dec 2, 2016 at 23:19

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