File tree Expand file tree Collapse file tree 1 file changed +48
-1
lines changed Expand file tree Collapse file tree 1 file changed +48
-1
lines changed Original file line number Diff line number Diff line change 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"""
424471function stirlings2 (n:: Int , k:: Int )
425472 if n < 0
You can’t perform that action at this time.
0 commit comments