### The Maxima on-line user's manual

Algebra Calculator

#### 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; lets 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 lets 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) ```

### Related Examples

##### 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