upiterbarg / mpmath

Automatically exported from code.google.com/p/mpmath
Other
0 stars 0 forks source link

exp(huge) results in infinite recursion #118

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
mp.dps = 15
exp('1e3000')

...
  File "c:\source\mp\trunk\mpmath\libelefun.py", line 614, in exp_newton
    r = mpf_exp(x, 60)
  File "c:\source\mp\trunk\mpmath\libelefun.py", line 709, in mpf_exp
    res = exp_newton(x, wp)
  File "c:\source\mp\trunk\mpmath\libelefun.py", line 614, in exp_newton
    r = mpf_exp(x, 60)
  File "c:\source\mp\trunk\mpmath\libelefun.py", line 709, in mpf_exp
    res = exp_newton(x, wp)
  File "c:\source\mp\trunk\mpmath\libelefun.py", line 614, in exp_newton
    r = mpf_exp(x, 60)
  File "c:\source\mp\trunk\mpmath\libelefun.py", line 703, in mpf_exp
    x = mpf_sub(x, from_int(n, wp), wp)
  File "c:\source\mp\trunk\mpmath\libmpf.py", line 375, in from_int
    return from_man_exp(n, 0, prec, rnd)
RuntimeError: maximum recursion depth exceeded

Original issue reported on code.google.com by fredrik....@gmail.com on 16 Jan 2009 at 8:05

GoogleCodeExporter commented 9 years ago
Also, exp('1e1000') is not accurate. I think it needs about mag/log(2) extra 
prec.

Original comment by fredrik....@gmail.com on 19 Jan 2009 at 2:46

GoogleCodeExporter commented 9 years ago
Committed fix to avoid infinite recursion in exp_newton with large arguments.
I do not think that more precision is needed:
>>> from mpmath import *
>>> a = mpf('1e1000')
>>> r = exp(a)
>>> extra = 10000
>>> mp.dps +=extra
>>> r1 = exp(a)
>>> mp.dps -= extra
>>> assert r == +r1
>>> 
'1e1000' is converted to different mpf's at different precisions, so I think 
that
it cannot be avoided that exp('1e1000') gives incompatible results at different
precisions

Original comment by mario.pe...@gmail.com on 19 Jan 2009 at 12:01

GoogleCodeExporter commented 9 years ago
Thanks for the fix.

> '1e1000' is converted to different mpf's at different precisions, so I think 
that
> it cannot be avoided that exp('1e1000') gives incompatible results at 
different
> precisions

Right, but results should be consistent when one fixes the argument beforehand.

I forgot to say, I'm referring only to the case "prec > 600 and exp >= 0". It 
can be
seen like this:

mp.prec = 600
a = mpf('1e1000')
exp(a)
mp.prec = 800
exp(a)

Easy fix committed in r843.

Original comment by fredrik....@gmail.com on 19 Jan 2009 at 12:28

GoogleCodeExporter commented 9 years ago
What's left to resolve this?

Original comment by Vinzent.Steinberg@gmail.com on 17 Feb 2009 at 12:49

GoogleCodeExporter commented 9 years ago
Nothing.

Original comment by fredrik....@gmail.com on 17 Feb 2009 at 6:41