[ANN] Bessels.jl - Bessel, Hankel, and Airy functions

heltonmc
Wed, 28 Sep 2022 16:41:07 +0000
Package Announcements

We are excited to announce Bessels.jl which is a special function library written in Julia to compute Bessel and Modified Bessel functions, Spherical Bessel functions, Airy functions, and Hankel functions. Currently the library supports single and double precision results for real arguments of any order.

There are several advantages of this library as it is written entirely in Julia, generally high performant, and does not allocate. Bessels.jl provides a lot of overlapping functionality with SpecialFunctions.jl and tries to match or exceed the accuracy of SpecialFunctions.jl in most domains. The available functions can be found in the API.

Benchmarks

Some speed comparisons to SpecialFunctions.jl can be found in the Readme. Here are a few comparisons though note that different algorithms are used for different domains in both libraries.

# Bessel functions of the first kind
julia> @benchmark SpecialFunctions.besselj(v, x) setup=(v=rand()*100; x = rand()*100)
BenchmarkTools.Trial: 4681 samples with 803 evaluations.
 Range (min … max):  162.007 ns … 11.076 μs  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):       1.121 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):     1.329 μs ±  1.505 μs  ┊ GC (mean ± σ):  0.01% ± 0.53%

  █▃▂ ▃▇██▂             ▁▁                                     ▂
  ███▇██████▆▅███▆▆▅▁▃▄███▅▁▃▁▇█▆▅▁▁▁▇▇██▆▅▁▁▁▁▁▁▁▃▇█▆▁▁▁▁▁▁▄█ █
  162 ns        Histogram: log(frequency) by time      9.45 μs <

 Memory estimate: 16 bytes, allocs estimate: 1.

julia> @benchmark Bessels.besselj(v, x) setup=(v=rand()*100; x = rand()*100)
BenchmarkTools.Trial: 10000 samples with 983 evaluations.
 Range (min … max):   58.547 ns … 356.359 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):      99.869 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   144.048 ns ±  80.418 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █
  █▃▂▂▂▂▂█▄▂▂█▂▂▂▂▂▂▂▂▂▂▅▂▂▂▂▁▁▂▁▁▁▁▂▁▁▂▁▁▁▁▁▂▃▃▃▃▄▄▄▃▄▃▃▃▃▃▃▂▂ ▃
  58.5 ns          Histogram: frequency by time          278 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

# Modified Bessel function of second kind and zero order
julia> @benchmark SpecialFunctions.besselk(0, x) setup=(x = rand()*100)
BenchmarkTools.Trial: 10000 samples with 807 evaluations.
 Range (min … max):  121.483 ns …  1.209 μs  ┊ GC (min … max): 0.00% … 70.69%
 Time  (median):     197.039 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   213.963 ns ± 49.302 ns  ┊ GC (mean ± σ):  0.08% ±  1.08%

            ▃ ██
  ▂▁▂▂▂▂▂▂▂▂████▆█▇▆▅▅▄▄▄▃▃▃▃▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ ▃
  121 ns          Histogram: frequency by time          449 ns <

 Memory estimate: 16 bytes, allocs estimate: 1.

julia> @benchmark Bessels.besselk(0, x) setup=(x = rand()*100)
BenchmarkTools.Trial: 10000 samples with 998 evaluations.
 Range (min … max):  16.096 ns … 25.895 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     18.430 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   18.425 ns ±  0.270 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

                                                   ▁███▂▃▃▃▂▃ ▂
  ▇█▇▄▅▄▁▃▁▁▁▁▄▅▃▁▁▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄██████████ █
  16.1 ns      Histogram: log(frequency) by time      18.8 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

Limitations

1. No support for complex arguments. This is actively being developed and support for Airy functions in the entire complex plane will be available in the next few days.

2. Does not yet work with automatic differentiation libraries. Though, differentiation wrt to argument are mostly covered by AD rules. For derivatives wrt to order please see BesselK.jl.

3. Only support single and double precision. In the future we plan to support the Double64 type provided by DoubleFloats.jl.

Our current development is focused on tackling these limitations as well as supporting other functions such as inhomogenous Airy functions. There is a current discussion on the scope of this project in this issue. Please leave any comments on what type of special functions you would like to see supported or any other feature requests. That would be most helpful in focusing development effort.

And of course I would like to particularly acknowledge @Oscar_Smith for reviewing every single PR, contributing, and being a big motivation to further develop this project. I would also like to thank @cgeoga for providing very valuable additions to the code and helpful discussions.

Please feel free to ask any questions or provide any requests!

13 posts - 8 participants