File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -349,6 +349,47 @@ function lucasnum(n::Integer)
349349 return z[]
350350end
351351
352+ """
353+ stirlings1(n::Int, k::Int, signed::Bool=false)
354+
355+ Compute the Stirling number of the first kind, ``s(n,k)``.
356+
357+ If `signed` is `true`, return the signed value ``(-1)^{n-k} s(n,k)``.
358+
359+ # Examples
360+ ```jldoctest
361+ julia> stirlings1(5, 5) # s(n, n) = 1
362+ 1
363+
364+ julia> n=9; stirlings1(n, 1) == factorial(n-1)
365+ true
366+
367+ julia> n=233; stirlings1(n, n-1) == binomial(n,2)
368+ true
369+
370+ julia> stirlings1(6, 3, true)
371+ -225
372+
373+ julia> [(k<=n ? stirlings1(n,k,true) : 0) for n in 1:6, k in 1:6]
374+ 6×6 Matrix{Int64}:
375+ 1 0 0 0 0 0
376+ -1 1 0 0 0 0
377+ 2 -3 1 0 0 0
378+ -6 11 -6 1 0 0
379+ 24 -50 35 -10 1 0
380+ -120 274 -225 85 -15 1
381+
382+ julia> stirlings1(-1, 1)
383+ ERROR: DomainError with -1:
384+ n must be nonnegative
385+ Stacktrace:
386+ [...]
387+ ```
388+
389+ # References
390+ - [Stirling numbers of the first kind - Wikipedia](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_first_kind)
391+ - [DLMF: §26.8 Stirling number of the first kind](https://dlmf.nist.gov/26.8#i.p1)
392+ """
352393function stirlings1 (n:: Int , k:: Int , signed:: Bool = false )
353394 if signed == true
354395 return (- 1 )^ (n - k) * stirlings1 (n, k)
You can’t perform that action at this time.
0 commit comments