Skip to content

Commit 70ebc52

Browse files
committed
doc: add doc and examples for stirlings2
1 parent f33bf3a commit 70ebc52

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

src/numbers.jl

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,54 @@ end
419419
"""
420420
stirlings2(n::Int, k::Int)
421421
422-
Compute the Stirling number of the second kind, `S(n,k)`.
422+
Compute the Stirling number of the second kind, ``S(n,k)``.
423+
424+
# Examples
425+
```jldoctest
426+
julia> stirlings2(0, 0)
427+
1
428+
429+
julia> n=233; stirlings2(n, 0) == 0 # n > 0
430+
true
431+
432+
julia> stirlings2(0, 1)
433+
0
434+
435+
julia> n=13; stirlings2(n, 1) == stirlings2(n, n) == 1 # n > 0
436+
true
437+
438+
julia> n=6; [stirlings2(6, k) for k in 0:6]
439+
7-element Vector{Int64}:
440+
0
441+
1
442+
31
443+
90
444+
65
445+
15
446+
1
447+
448+
julia> n=6; sum(stirlings2(6, k) for k in 0:6) == bellnum(n)
449+
true
450+
451+
julia> [stirlings2(n,k) for n in 1:6, k in 1:6]
452+
6×6 Matrix{Int64}:
453+
1 0 0 0 0 0
454+
1 1 0 0 0 0
455+
1 3 1 0 0 0
456+
1 7 6 1 0 0
457+
1 15 25 10 1 0
458+
1 31 90 65 15 1
459+
460+
julia> stirlings2(-1, 1)
461+
ERROR: DomainError with -1:
462+
n must be nonnegative
463+
Stacktrace:
464+
[...]
465+
```
466+
467+
# References
468+
- [Stirling numbers of the second kind - Wikipedia](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind)
469+
- [DLMF: §26.8 Stirling number of the second kind](https://dlmf.nist.gov/26.8#i.p3)
423470
"""
424471
function stirlings2(n::Int, k::Int)
425472
if n < 0

0 commit comments

Comments
 (0)