Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

but that integral seems to be computed symbolically.

Nope. It's just that :

  1. it can't be expressed in terms of "elementary" functions, but that

  2. it occurs frequently enough to warrant the creation of a "special function" (the curse of engineering maths...).

Try :

sage: (e*exp(-1/x)/x).integrate(x)
-Ei(-1/x)*e

And read Ei?...

This integral can be checked :

sage: bool((-Ei(-1/x)*e).diff(x)==(e*exp(-1/x)/x))
True

Therefore, one can trust :

sage: (e*exp(-1/x)/x).integrate(x, 0, 1).n(digits=200)

0.5963473623231940743410784993692793760741778601525487815734849104823272191148744174704304970936
127603442370347484286236898120782995290571966173692226658940243185135143682937632962547711879740
2524323021

as far as one trusts the mutliprécision arithmetic used by Sage.

Now, if you want high precision on a numerical integral, numerical_integralhas parameterseps_absandeps_rel` allowing you to set the desired precision, as long as this precision can be achieved with (machine) double precision arithmetic. Therefore, this routine cannot give you 200-digit precision.

mpmath being part of Sagemath, you may try to use mpmath's quad routine after setting the relevant precision parameters (mp.prec and mp.dps), but I am not familiar with this direct use of mpmath and can't possibly comment...

Final note of caution : there is no "magic bullet" in numerical analysis. Analyse your problem and try to find "reasonable" algorithms. For example, compute a small quantity as the difference of two large quantities is probably not a good idea...