Glen Whitney ecbd877643
fix(combinatorics): Improve precision of stirlingS2 (#2509)
* fix(combinatorics): Improve precision of stirlingS2

  Previously the computation of stirlingS2 used the closed form, which
  suffers numerically by dividing a sum of very large terms by a large
  factorial, causing roundoff errors for unnecessarily small inputs.

  This commit switches to using the recurrence relation for the stirling
  numbers of the second kind, and caching the partial results for future
  calls. This has the advantage that all intermediate results are smaller
  than the final value.

  Also adds tests for much larger values of the stirlingS2 function and of
  bellNumbers, whose computation depends on stirlingS2.

  Resolves #2508.

* fix(stirlingS2): Correct lint errors.
2022-04-01 16:23:53 +02:00
..