classification
Title: Add the Bessel functions of the first and second kind to the math module
Type: enhancement Stage: resolved
Components: Extension Modules Versions: Python 3.9
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, mark.dickinson, pablogsal, rhettinger, steven.daprano, tim.peters
Priority: normal Keywords: patch

Created on 2019-08-26 02:29 by pablogsal, last changed 2019-08-26 13:58 by pablogsal. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 15497 closed pablogsal, 2019-08-26 02:34
Messages (8)
msg350477 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-08-26 02:29
After repeatedly having to add 3rd party libraries only for the these functions or having to implement them myself quick and dirty based on numerical integration, I suggest add the Bessel functions of the first and second kind to the math module. These functions tend to appear a lot (but not restricted to) when evaluating systems that are defined on cylindrical geometries, restrictions or approximations (like the proximate solution to Kepler's equation as a truncated Fourier sine series) and many other special functions can be described as series involving them.

Based on the fact that many libc implementations include them I think the cost-benefit of exposing them when available is acceptable.
msg350479 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-08-26 03:16
If they are provided by the C lib, I would love to see them exposed by Python.

If they aren't, I don't know if they should be treated as optional/platform dependent, or if we should provide an independent implementation. I guess the easy way is to just make it optional.
msg350480 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-08-26 03:23
> If they are provided by the C lib, I would love to see them exposed by Python.

Check PR 15497 for an initial version of exposing the libm functions if they are available.

> I don't know if they should be treated as optional/platform dependent, or if we should provide an independent implementation.

Even if we want to provide an independent implementation, I would suggest to separate the two steps and starting to expose the underliying ones if they are available.
msg350489 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2019-08-26 06:29
They're not part of the C standard and they're not provided by all C libraries; we'd have to code our own and add thorough tests for the implementations (as we have for lgamma, gamma, erf, and other functions that may or may not exist in the platform libm). Making them optional is a no-go - you'd end up with code that works on some platforms but not on others. We've always provided fallback implementations in the past.

IMO this is the province of things like scipy.special. The Bessel functions (and many others) are already easily available to users of the scientific Python stack. I don't really see a need to have them in core Python.
msg350498 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2019-08-26 07:15
I'd also say that SciPy does this much better than the Python math library could ever hope to (without that math library effectively becoming a copy of scipy.special). It probably wouldn't be long before a user of the new Bessel functions also wanted Bessel functions of half-integer order (which turn up in statistics and in spherical harmonics problems), or of arbitrary complex order, or modified Bessel functions, or Airy functions and elliptic integrals, or ... For all those cases, SciPy has you covered, but extending the math module to cover all these things would be a lot of work and an unnecessary (IMO) duplication of effort.
msg350499 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2019-08-26 07:16
Tim, Raymond: thoughts? I'm inclined to close this as rejected.
msg350521 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2019-08-26 10:40
> IMO this is the province of things like scipy.special. The Bessel functions (and many others) are already easily available to users of the scientific Python stack. I don't really see a need to have them in core Python.

I agree.
msg350530 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-08-26 13:58
Thanks for your detailed opinion, Mark. After reflecting on your arguments I agree that we should close this issue as rejected.

Thanks to everyone!
History
Date User Action Args
2019-08-26 13:58:05pablogsalsetstatus: open -> closed
resolution: rejected
messages: + msg350530

stage: patch review -> resolved
2019-08-26 10:40:25ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg350521
2019-08-26 07:16:42mark.dickinsonsetmessages: + msg350499
2019-08-26 07:16:21mark.dickinsonsetnosy: + tim.peters
2019-08-26 07:15:58mark.dickinsonsetmessages: + msg350498
2019-08-26 06:29:13mark.dickinsonsetmessages: + msg350489
2019-08-26 03:23:54pablogsalsetmessages: + msg350480
2019-08-26 03:16:34steven.dapranosetnosy: + steven.daprano
messages: + msg350479
2019-08-26 02:34:30pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request15187
2019-08-26 02:29:39pablogsalcreate