Wiki

Clone wiki

dart_trotter / compositions

Home | Permutations | Combinations | Amalgams | Compositions | Subsets | Compounds | Inverses | About

Compositions

The Compositions constructor accepts two arguments: the number of items to take from a set and a list containing the items in the set.

For example, the following line creates a pseudo-list containing all the 3-compositions of the strings "a" to "e".

var s = new Selections(3, characters("abcde"));

To see how many compositions are "contained" in s, we can check s.length. We can retrieve the individual compositions by index, e.g., s[0].

How are Compositions arranged?

In this library, Compositions are arrangements of items taken from a set for which:

  • Order is not important.
  • Items are replaced.

For example, consider the following set of trotters:

There are 35 3-compositions of trotters taken from this set. They are arranged by the algorithm as follows:

(dot, dot, dot)

Note:

In the original trotter library I used the term selections to mean combinations with replacement. In combinatorics literature, however, selections is generally more appropriately used to generically mean combinations or permutations. To avoid confusion, then, as of trotter 0.9.5 I decided to use the term compositions to mean combinations with replacement. This seems approproate in that it suggests that order is not important (a body composed of A and B is also composed of B and A) and that items can be reused (a body can be composed of two parts A to one part B).

Updated