Skip to content

Problems with Stirling numbers #104

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
scheinerman opened this issue Jun 9, 2021 · 1 comment · May be fixed by #193
Open

Problems with Stirling numbers #104

scheinerman opened this issue Jun 9, 2021 · 1 comment · May be fixed by #193

Comments

@scheinerman
Copy link

Stirling numbers of the second kind are always nonnegative and yet:

julia> stirlings2(26,10)
-5247188700862703611

The same issue plagues stirlings1. We have

julia> stirlings1(26,10)
9107464261356742080

but the correct value is 196928100451110820242880.

FedericoStra added a commit to FedericoStra/Combinatorics.jl that referenced this issue May 11, 2025
This allows to call them with `BigInt` arguments to avoid overflow.

Closes JuliaMath#104.
@FedericoStra
Copy link
Contributor

Both errors are caused by overflow. stirlings1 and stirlings2 take arguments of type Int, which is usually Int64, but

  • $s(26, 10) \simeq 2^{77} > 2^{63}-1 =$ typemax(Int64),
  • $S(26, 10) \simeq 2^{63.5} > 2^{63}-1 =$ typemax(Int64).

#193 addresses this by allowing stirlings1 and stirlings2 to be called with arguments of any subtype of Integer:

julia> stirlings1(big(26), 10)
196928100451110820242880

julia> stirlings2(big(26), 10)
13199555372846848005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants