From d9587127d59627924871e740675fe4245b3637e2 Mon Sep 17 00:00:00 2001 From: Ferrangelo <85937147+Ferrangelo@users.noreply.github.com> Date: Sun, 17 Aug 2025 12:11:22 +0200 Subject: [PATCH] Correct implementation of spherical bessel functions (#992) Closes #991 --- mpmath/functions/bessel.py | 4 ++-- mpmath/tests/test_functions2.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mpmath/functions/bessel.py b/mpmath/functions/bessel.py index 42b7f208..d8fe37ca 100644 --- a/mpmath/functions/bessel.py +++ b/mpmath/functions/bessel.py @@ -218,7 +218,7 @@ def spherical_jn(ctx, n, z): mpf('0.84147098480789639') """ - return ctx.besselj(n + ctx.one/2, z) * ctx.sqrt(ctx.pi/2*z) + return ctx.besselj(n + ctx.one/2, z) * ctx.sqrt(ctx.pi/(2*z)) @defun def spherical_yn(ctx, n, z): @@ -240,7 +240,7 @@ def spherical_yn(ctx, n, z): mpf('-0.54030230586813965') """ - return ctx.bessely(n + ctx.one/2, z) * ctx.sqrt(ctx.pi/2*z) + return ctx.bessely(n + ctx.one/2, z) * ctx.sqrt(ctx.pi/(2*z)) @defun_wrapped def whitm(ctx,k,m,z,**kwargs): diff --git a/mpmath/tests/test_functions2.py b/mpmath/tests/test_functions2.py index 0392ecba..cd925c8a 100644 --- a/mpmath/tests/test_functions2.py +++ b/mpmath/tests/test_functions2.py @@ -2454,3 +2454,7 @@ def test_issue_908(): def test_issue_637(): assert hankel1(1, 1 + 30j).ae(-7.25495e-15 - 1.17346e-14j) assert hankel2(1, 1 - 30j).ae(-7.25495e-15 + 1.17346e-14j) + +def test_issue_991(): + assert spherical_jn(0, 1.3).ae(0.74119860416707) + assert spherical_yn(0, 1.3).ae(-0.20576832971122)