Skip to content

Commit 36365ae

Browse files
committed
doc: update doc and examples for partitions(s::AbstractVector)
1 parent e708971 commit 36365ae

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

src/partitions.jl

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,43 @@ Base.eltype(p::SetPartitions) = Vector{Vector{eltype(p.s)}}
250250
"""
251251
partitions(s::AbstractVector)
252252
253-
Generate all set partitions of the elements of an array `s`, represented as arrays of
254-
arrays. Because the number of partitions can be very large, this function returns an
255-
iterator object. Use `collect(partitions(s))` to get an array of all partitions. The
256-
number of partitions to generate can be efficiently computed using
257-
`length(partitions(s))`.
253+
Generate all set partitions of the elements of an array `s`,
254+
represented as arrays of arrays.
255+
256+
Because the number of partitions can be very large,
257+
this function returns an iterator object.
258+
Use `collect(partitions(s))` to get an array of all partitions.
259+
260+
The number of partitions of an `n`-element set
261+
is given by the n-th Bell number `Bn`:
262+
`length(partitions(s)) == catalannum(legnth(s))`.
263+
264+
# Examples
265+
```jldoctest
266+
julia> collect(partitions([1, 1]))
267+
2-element Vector{Vector{Vector{Int64}}}:
268+
[[1, 1]]
269+
[[1], [1]]
270+
271+
julia> collect(partitions(-1:-1:-2))
272+
2-element Vector{Vector{Vector{Int64}}}:
273+
[[-1, -2]]
274+
[[-1], [-2]]
275+
276+
julia> collect(partitions('a':'c'))
277+
5-element Vector{Vector{Vector{Char}}}:
278+
[['a', 'b', 'c']]
279+
[['a', 'b'], ['c']]
280+
[['a', 'c'], ['b']]
281+
[['a'], ['b', 'c']]
282+
[['a'], ['b'], ['c']]
283+
284+
julia> length(partitions(1:10)) == bellnum(10)
285+
true
286+
```
287+
288+
# References
289+
- [Partition of a set - Wikipedia](https://en.wikipedia.org/wiki/Partition_of_a_set)
258290
"""
259291
partitions(s::AbstractVector) = SetPartitions(s)
260292

0 commit comments

Comments
 (0)