Sponsored links: Algebra eBooks

### Related

##### set_partitions

ts: {a, b, c, d};

set_partitions(ts,2);

Calculate

##### set_partitions

set_partitions({1,2,3});

Calculate

##### set_partitions

? set_partitions;

Calculate

##### set_partitions

ts: {a, b, c, d};

set_partitions(ts,2);

Calculate

##### set_partitions

set_partitions({1,2,3});

Calculate

##### set_partitions

? set_partitions;

Calculate

### set_partitions

Run Example
```(%i1)? set_partitions;

-- Function: set_partitions (<a>)
-- Function: set_partitions (<a>, <n>)
Returns the set of all partitions of <a>, or a subset of that set.

`set_partitions(<a>, <n>)' returns a set of all decompositions of
<a> into <n> nonempty disjoint subsets.

`set_partitions(<a>)' returns the set of all partitions.

`stirling2' returns the cardinality of the set of partitions of a
set.

A set of sets P is a partition of a set S when

1. each member of P is a nonempty set,

2. distinct members of P are disjoint,

3. the union of the members of P equals S.

Examples:

The empty set is a partition of itself, the conditions 1 and 2
being vacuously true.

(%i1) set_partitions ({});
(%o1)                         {{}}

The cardinality of the set of partitions of a set can be found
using `stirling2'.

(%i1) s: {0, 1, 2, 3, 4, 5}\$
(%i2) p: set_partitions (s, 3)\$
(%i3) cardinality(p) = stirling2 (6, 3);
(%o3)                        90 = 90

Each member of `p' should have <n> = 3 members; let's check.

(%i1) s: {0, 1, 2, 3, 4, 5}\$
(%i2) p: set_partitions (s, 3)\$
(%i3) map (cardinality, p);
(%o3)                          {3}

Finally, for each member of `p', the union of its members should
equal `s'; again let's check.

(%i1) s: {0, 1, 2, 3, 4, 5}\$
(%i2) p: set_partitions (s, 3)\$
(%i3) map (lambda ([x], apply (union, listify (x))), p);
(%o3)                 {{0, 1, 2, 3, 4, 5}}

(%o1)                                true
(%i2) ```
Run Example
```p:sublist(makelist(k,k,2,100),lambda([x],primep(x)));
(%o1) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
71, 73, 79, 83, 89, 97]
(%i2) s:makelist([(k-mod(k,10))/10,mod(k,10)],k,p);
(%o2) [[0, 2], [0, 3], [0, 5], [0, 7], [1, 1], [1, 3], [1, 7], [1, 9], [2, 3],
[2, 9], [3, 1], [3, 7], [4, 1], [4, 3], [4, 7], [5, 3], [5, 9], [6, 1],
[6, 7], [7, 1], [7, 3], [7, 9], [8, 3], [8, 9], [9, 7]]
(%i3) s:map(lambda([x],delete(0,x)),s);
(%o3) [[2], [3], [5], [7], [1, 1], [1, 3], [1, 7], [1, 9], [2, 3], [2, 9],
[3, 1], [3, 7], [4, 1], [4, 3], [4, 7], [5, 3], [5, 9], [6, 1], [6, 7],
[7, 1], [7, 3], [7, 9], [8, 3], [8, 9], [9, 7]]
(%i4) s:map(lambda([x],sort(x)),s);
(%o4) [[2], [3], [5], [7], [1, 1], [1, 3], [1, 7], [1, 9], [2, 3], [2, 9],
[1, 3], [3, 7], [1, 4], [3, 4], [4, 7], [3, 5], [5, 9], [1, 6], [6, 7],
[1, 7], [3, 7], [7, 9], [3, 8], [8, 9], [7, 9]]
(%i5) memberp(x):=member(x,s);
(%o5)                     memberp(x) := member(x, s)
(%i6) w:full_listify(set_partitions({1,2,3}));
(%o6) [[[1], [2], [3]], [[1], [2, 3]], [[1, 2], [3]], [[1, 2, 3]],
[[1, 3], [2]]]
(%i7) sublist(w,lambda([x],every(memberp,x)));
(%o7)                           [[[1, 3], [2]]]
(%i8) ```
Run Example
```set_partitions({1,2,3});
(%o1) {{{1}, {2}, {3}}, {{1}, {2, 3}}, {{1, 2}, {3}}, {{1, 2, 3}},
{{1, 3}, {2}}}
(%i2) ```

### Related Help

Help for Set_partitions