Skip to content

Commit f33bf3a

Browse files
committed
doc: add doc and examples for stirlings1
1 parent 8446b08 commit f33bf3a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/numbers.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,47 @@ function lucasnum(n::Integer)
349349
return z[]
350350
end
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+
"""
352393
function stirlings1(n::Int, k::Int, signed::Bool=false)
353394
if signed == true
354395
return (-1)^(n - k) * stirlings1(n, k)

0 commit comments

Comments
 (0)