Issue 228 in mpmath: Divide by Zero Error in ellippi

1 view
Skip to first unread message

mpm...@googlecode.com

unread,
Aug 6, 2012, 8:43:57 AM8/6/12
to mpmath...@googlegroups.com
Status: New
Owner: ----

New issue 228 by JohnBey...@gmail.com: Divide by Zero Error in ellippi
http://code.google.com/p/mpmath/issues/detail?id=228

What steps will reproduce the problem?
1. ellippi(1,1)
2. ellippi(1,0)
3. ellippi(1,>pi/2,0 or 1)

What is the expected output? What do you see instead?
Divide by Zero Error and nan

What version of the product are you using? On what operating system?
Python 3.2.3, mpmath 0.17, win7pro 64bit

Please provide any additional information below.

I have not used either Python or mpmath before, so my code fix may not be
correct or optimal. The code seems to work and is at the end of the
elliptic.py module.

if complete:
#if m == 0: return ctx.pi/(2*ctx.sqrt(1-n)) #removed by JCB,
div/0 error
if m == 0: #added by JCB
if n == 1: return ctx.inf #added by JCB
return ctx.pi/(2*ctx.sqrt(1-n)) #added by JCB
if n == 0: return ctx.ellipk(m)
if ctx.isinf(n) or ctx.isinf(m): return ctx.zero
else:
if z == 0: return z
if ctx.isinf(n): return ctx.zero
if ctx.isinf(m): return ctx.zero
if ctx.isinf(n) or ctx.isinf(z) or ctx.isinf(m):
raise ValueError
if complete:
#if m == 1: return -ctx.inf/ctx.sign(n-1) #removed by JCB, div/0
error
if m == 1: #added by JCB
if n > 1: return -ctx.inf #added by JCB
return ctx.inf #added by JCB
away = False
else:
x = z.real
ctx.prec += max(0, ctx.mag(x))
pi = +ctx.pi
away = abs(x) > pi/2
if away:
d = ctx.nint(x/pi)
z = z-pi*d
P = 2*d*ctx.ellippi(n,m)
if ctx.isinf(P): return P #added by JCB, return "(+/-)inf"
instead of "nan"
else:


mpm...@googlecode.com

unread,
Aug 9, 2012, 5:56:23 AM8/9/12
to mpmath...@googlegroups.com

mpm...@googlecode.com

unread,
Aug 12, 2012, 11:29:19 AM8/12/12
to mpmath...@googlegroups.com

Comment #2 on issue 228 by JohnBey...@gmail.com: Divide by Zero Error in
ellippi
http://code.google.com/p/mpmath/issues/detail?id=228

Fredrik,
I downloaded and installed your fix. There might still be some issues.
ellippi(1,-2,1) probably should return -inf.
Also, test_linalg.py fails for the print statements and the xrange
references.
I have only installed the minimum modules required for mpmath.
Here is an alternate ending for the ellippi function returning either 2 or
3 terms.
if away:
d = ctx.nint(x/pi)
z = z-pi*d
#P = 2*d*ctx.ellippi(n,m)
#if ctx.isinf(P):
#return ctx.inf
#else:
#P = 0
def terms():
if complete:
c, s = ctx.zero, ctx.one
else:
c, s = ctx.cos_sin(z)
x = c**2
y = 1-m*s**2
RF = ctx.elliprf(x, y, 1)
RJ = ctx.elliprj(x, y, 1, 1-n*s**2)
if away: return s*RF, n*s**3*RJ/3, 2*d*ctx.ellippi(n,m)
return s*RF, n*s**3*RJ/3
return ctx.sum_accurately(terms)


Reply all
Reply to author
Forward
0 new messages