Skip to content

[RFC]: add airy to compute Airy functions #6962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
rreusser opened this issue May 9, 2025 · 11 comments · May be fixed by #6969
Open
3 tasks done

[RFC]: add airy to compute Airy functions #6962

rreusser opened this issue May 9, 2025 · 11 comments · May be fixed by #6969
Labels
Accepted RFC feature request which has been accepted. difficulty: 3 Likely to be challenging but manageable. Feature Issue or pull request for adding a new feature. Math Issue or pull request specific to math functionality. priority: Normal Normal priority concern or feature request. RFC Request for comments. Feature requests and proposed changes.

Comments

@rreusser
Copy link
Member

rreusser commented May 9, 2025

Description

Airy functions are a common special function in scientific applications, particularly wave phenomena. This RFC proposes to add a single package to compute for real-valued inputs the Airy function of the first kind, Ai(x), the second kind, Bi(x), and respective derivatives, Ai'(x) and Bi'(x).

The four outputs share a lot of computation, so for similar reasons and in the style of @stdlib/math/base/special/ellipj, perhaps the structure that makes sense is a single package, airy with exports:

airy(x)           // [ Ai(x), Ai'(x), Bi(x), Bi'(x) ]
airy.ai( x )      // Ai(x)
airy.aip( x )     // Ai'(x)
airy.bi( x )      // Bi(x)
airy.bip( x )     // Bi'(x)
airy.assign( x, out, stride, offset )

Exports ai, aip, bi, and bip would be convenience functions that compute all four values and throw away three.

Related Issues

No response

Questions

No.

Other

See also:

scipy.special.airy
cephes airy

Checklist

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with RFC:.
@kgryte
Copy link
Member

kgryte commented May 9, 2025

@rreusser Yes, this makes sense to me and would be a welcome addition!

@kgryte kgryte added RFC Request for comments. Feature requests and proposed changes. difficulty: 3 Likely to be challenging but manageable. Math Issue or pull request specific to math functionality. Accepted RFC feature request which has been accepted. Feature Issue or pull request for adding a new feature. priority: Normal Normal priority concern or feature request. labels May 9, 2025
@kgryte
Copy link
Member

kgryte commented May 9, 2025

@rreusser Are you thinking to follow the SciPy implementation or is there some other reference implementation (e.g., Boost) which serves as the gold standard?

@kgryte
Copy link
Member

kgryte commented May 9, 2025

SciPy's implementation in xsf: https://github.com/scipy/xsf/blob/main/include/xsf/airy.h

@rreusser
Copy link
Member Author

rreusser commented May 9, 2025

It looks to me like:

  • cephes: relies heavily on rational polynomial approximations. Simple to port. (full disclosure: poked around and already ported it, though that shouldn't preclude making the best choice)
  • xsf: relies on slightly more involved iteration, but looks similarly highly straightforward to port.
  • boost: farms out to cylindrical bessel functions. Maybe alright to port and plus then you get some other functions, but more involved dependencies to implement and trace.

I don't have a strong opinion myself. My preference would be for cephes or xsf, then boost, mainly just since boost seems very, very well done, but in a way that requires a lot more untangling of dependencies and logic and probably a couple/few precursor packages. (I think it was for bessel where functions keep calling themselves with differently-typed arguments until templating sifts through it and selects the proper implementation. C++ certainly is certainly a higher-effort candidate for translation.)

Just one note, am I missing something that it looks to me like scipy depends on cephes and not xsf? See scipy.airy notes:

For real z in [-10, 10], the computation is carried out by calling the Cephes [1] airy routine, which uses power series summation for small z and rational minimax approximations for large z.

Outside this range, the AMOS [2] zairy and zbiry routines are employed.

Perhaps the notes are outdated?

@kgryte
Copy link
Member

kgryte commented May 9, 2025

xsf is what SciPy is moving toward. They want a header-only implementation of scalar kernels to allow for GPU compilation via nvcc. Looking at xsf, it seems they do use both the Cephes and the Amos implementations based on value range. Both look straightforward to port.

@rreusser
Copy link
Member Author

rreusser commented May 9, 2025

Ah, that makes sense. How about xsf then?

@kgryte
Copy link
Member

kgryte commented May 9, 2025

I am fine with using the xsf implementation, which is ultimately derived (and occasionally improved) from Cephes.

@rreusser
Copy link
Member Author

rreusser commented May 9, 2025

Well porting xsf took… ten minutes. 👍

Image

@kgryte
Copy link
Member

kgryte commented May 9, 2025

@rreusser Well, you are a pro.

@rreusser
Copy link
Member Author

rreusser commented May 9, 2025

It's criminally easy to just s/double/var/g and ship ported code. 🙈

@kgryte
Copy link
Member

kgryte commented May 9, 2025

We'll see how well that withstands code review. 😅

rreusser added a commit to rreusser/stdlib that referenced this issue May 10, 2025
close stdlib-js#6962

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: passed
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: passed
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: passed
  - task: lint_c_tests_fixtures
    status: passed
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@rreusser rreusser linked a pull request May 10, 2025 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted RFC feature request which has been accepted. difficulty: 3 Likely to be challenging but manageable. Feature Issue or pull request for adding a new feature. Math Issue or pull request specific to math functionality. priority: Normal Normal priority concern or feature request. RFC Request for comments. Feature requests and proposed changes.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants