ENH: integrate.tanhsinh: make _tanhsinh public

Hi Team,

scipy.integrate._tanhsinh has existed as a private function for elementwise quadrature in SciPy since summer 2023; it is the workhorse behind scipy.integrate.nsum and the new continuous distribution infrastructure’s quadrature. At the time, the plan was to make it public after the quadrature deprecation cycle was completed.

Shortly before quadrature was removed, gh-20252 proposed a more ambitious goal of adding a cubature function with univariate quadrature as a special case. The function cubature was added over the summer, and besides working for N-d integration domains, it matches (and sometimes exceeds) tanhsinh in several respects, e.g. support for non-NumPy backends, vector-valued integration, improved performance relative to quad_vec, etc.

However, there are still several features unique to _tanhsinh that users may appreciate.

  • _tanhsinh supports N-d arrays as limits of integration for elementwise integral evaluation.
  • _tanhsinh is organized for nested, order-adaptive (rather than partition-adaptive) quadrature rules, which may be more efficient for some problems.
  • The tanh-sinh rule performs well for functions with endpoint singularities.
  • _tanhsinh supports “log-integration” - evaluation of the log of an integral given the log of the integrand - which is useful to avoid underflow and overflow.
  • _tanhsinh converges and reports integration status elementwise, avoiding unnecessary function evaluations when some elements of the output take longer to converge than others.
  • _tanhsinh has a callback interface that supports early termination.

cubature (or a 1-D variant) has the potential to add these features. However, it is unfortunate that these features have already waiting through three SciPy releases. If cubature or a follow-up function add them later, great; in the meantime, gh-21977 would make scipy.integrate.tanhsinh public. Please join the discussion there if you’re interested!

Matt