From 63e6e24accfaa4e4b05bf4fd00ac3a6ff98e72b2 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Thu, 5 Dec 2024 08:37:19 +0300 Subject: [PATCH] Use parity formula for besseli See https://functions.wolfram.com/Bessel-TypeFunctions/BesselI/04/02/01/0002/ Closes #877 --- mpmath/functions/bessel.py | 2 ++ mpmath/tests/test_functions2.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/mpmath/functions/bessel.py b/mpmath/functions/bessel.py index 4bda960d..6b7dbb7c 100644 --- a/mpmath/functions/bessel.py +++ b/mpmath/functions/bessel.py @@ -82,6 +82,8 @@ def besselj(ctx, n, z, derivative=0, **kwargs): def besseli(ctx, n, z, derivative=0, **kwargs): n = ctx.convert(n) z = ctx.convert(z) + if ctx.nint(n) and n < 0: + return ctx.besseli(-n, z, derivative, **kwargs) if not z: if derivative: raise ValueError diff --git a/mpmath/tests/test_functions2.py b/mpmath/tests/test_functions2.py index d971e24c..c57ec95b 100644 --- a/mpmath/tests/test_functions2.py +++ b/mpmath/tests/test_functions2.py @@ -91,6 +91,12 @@ def test_bessel(): mp.dps = n assert besseli(91.5,24.7708).ae("4.00830632138673963619656140653537080438462342928377020695738635559218797348548092636896796324190271316137982810144874264e-41") +def test_issue_877(): + mp.dps = 64 + r = besseli(-127, 2) + assert besseli(127, 2) == r + assert r.ae("3.345358761443415013354345973251886375421555647081543375756063117036e-214") + def test_bessel_zeros(): assert besseljzero(0,1).ae(2.40482555769577276869) assert besseljzero(2,1).ae(5.1356223018406825563)