Skip to content

clsin(s, z) causing a hang #459

Description

@jacksonvanover

Calculating the "classical" clausen function (ie with s = 2) when z is positive infinity, negative infinity, or a nan results in a hang. I believe the execution is getting stuck in the while loop at line 416 in zeta.py.

Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mpmath
>>> mpmath.clsin(1,mpmath.inf)
mpf('nan')
>>> mpmath.clsin(2,mpmath.inf)
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/mpmath/ctx_mp_python.py", line 1035, in f_wrapped
    retval = f(ctx, *args, **kwargs)
  File "[...]/mpmath/functions/zeta.py", line 496, in clsin
    return ctx.im(ctx.polylog(s,a))
  File "[...]/mpmath/ctx_mp_python.py", line 1035, in f_wrapped
    retval = f(ctx, *args, **kwargs)
  File "[...]/mpmath/functions/zeta.py", line 484, in polylog
    return polylog_unitcircle(ctx, int(s), z)
  File "[...]/mpmath/functions/zeta.py", line 418, in polylog_unitcircle
    term = ctx.zeta(n-m) * logmz / ctx.fac(m)
  File "[...]/mpmath/functions/zeta.py", line 531, in zeta
    return ctx._zeta(s, **kwargs)
  File "[...]/mpmath/ctx_mp_python.py", line 1012, in f
    return ctx.make_mpf(mpf_f(x._mpf_, prec, rounding))
  File "[...]/mpmath/libmp/gammazeta.py", line 1206, in mpf_zeta
    return mpf_zeta_int(to_int(s), prec, rnd)
  File "[...]/mpmath/libmp/gammazeta.py", line 1142, in mpf_zeta_int
    return mpf_div(mpf_bernoulli(-s+1, wp), from_int(s-1), prec, rnd)
  File "[...]/mpmath/libmp/gammazeta.py", line 422, in mpf_bernoulli
    return mpf_bernoulli_huge(n, prec, rnd)
  File "[...]/mpmath/libmp/gammazeta.py", line 482, in mpf_bernoulli_huge
    v = mpf_mul(v, mpf_pow_int(mpf_pi(piprec), -n, wp))
  File "[...]/mpmath/libmp/libmpf.py", line 1072, in mpf_pow_int
    inverse = mpf_pow_int(s, -n, prec+5, reciprocal_rnd[rnd])
  File "[...]/mpmath/libmp/libmpf.py", line 1095, in mpf_pow_int
    if n & 1:
KeyboardInterrupt
>>> mpmath.clsin(2,mpmath.nan)
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/mpmath/ctx_mp_python.py", line 1035, in f_wrapped
    retval = f(ctx, *args, **kwargs)
  File "[...]/mpmath/functions/zeta.py", line 496, in clsin
    return ctx.im(ctx.polylog(s,a))
  File "[...]/mpmath/ctx_mp_python.py", line 1035, in f_wrapped
    retval = f(ctx, *args, **kwargs)
  File "[...]/mpmath/functions/zeta.py", line 484, in polylog
    return polylog_unitcircle(ctx, int(s), z)
  File "[...]/mpmath/functions/zeta.py", line 418, in polylog_unitcircle
    term = ctx.zeta(n-m) * logmz / ctx.fac(m)
  File "[...]/mpmath/functions/zeta.py", line 531, in zeta
    return ctx._zeta(s, **kwargs)
  File "[...]/mpmath/ctx_mp_python.py", line 1012, in f
    return ctx.make_mpf(mpf_f(x._mpf_, prec, rounding))
  File "[...]/mpmath/libmp/gammazeta.py", line 1206, in mpf_zeta
    return mpf_zeta_int(to_int(s), prec, rnd)
  File "[...]/mpmath/libmp/gammazeta.py", line 1142, in mpf_zeta_int
    return mpf_div(mpf_bernoulli(-s+1, wp), from_int(s-1), prec, rnd)
  File "[...]/mpmath/libmp/gammazeta.py", line 422, in mpf_bernoulli
    return mpf_bernoulli_huge(n, prec, rnd)
  File "[...]/mpmath/libmp/gammazeta.py", line 480, in mpf_bernoulli_huge
    v = mpf_gamma_int(n+1, wp)
  File "[...]/mpmath/libmp/gammazeta.py", line 2388, in mpf_gamma_int
    return mpf_gamma(from_int(n), prec, rnd)
  File "[...]/mpmath/libmp/gammazeta.py", line 2081, in mpf_gamma
    y = real_stirling_series(absxman, wp)
  File "[...]/mpmath/libmp/gammazeta.py", line 1800, in real_stirling_series
    s = ln_sqrt2pi_fixed(prec) - x
  File "[...]/mpmath/libmp/libelefun.py", line 97, in g
    return f.memo_val >> (memo_prec-prec)
KeyboardInterrupt

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions