CombinatorialCase012: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
This case produces '''Compositions | This case produces '''Compositions of the number <apll>L</apll> into <apll>R</apll> parts'''. A composition is a way of representing a number as the sum of all positive integers, in this case it’s a way of representing <apll>L</apll> as the sum of <apll>R</apll> positive integers. It can also be thought of as a partition of <apll>L</apll> into <apll>R</apll> ordered parts. | ||
* <apll>L</apll> unlabeled balls (0), <apll>R</apll> labeled boxes (1), at least one ball per box (2) | * <apll>L</apll> unlabeled balls (0), <apll>R</apll> labeled boxes (1), at least one ball per box (2) |
Revision as of 20:45, 29 April 2017
This case produces Compositions of the number L into R parts. A composition is a way of representing a number as the sum of all positive integers, in this case it’s a way of representing L as the sum of R positive integers. It can also be thought of as a partition of L into R ordered parts.
- L unlabeled balls (0), R labeled boxes (1), at least one ball per box (2)
- Not ⎕IO-sensitive
- Counted result is an integer scalar
- Generated result is an integer matrix.
The count for this function is (L-R)!L-1.
For example:
If we have 5 unlabeled balls (●●●●●) and 3 labeled boxes (123) with at least one ball per box, there are 6 (↔ (5-3)!5-1) ways to meet these criteria:
|
|
|
|
|
|
The diagram above corresponds to
012 1‼5 3 1 1 3 1 2 2 1 3 1 2 1 2 2 2 1 3 1 1 ⍝ Compositions of L into R parts ⍝ Unlabeled balls, labeled boxes, ≥1 # Balls per Box 012 1‼5 5 1 1 1 1 1 012 1‼5 4 1 1 1 2 1 1 2 1 1 2 1 1 2 1 1 1 012 1‼5 3 1 1 3 1 2 2 1 3 1 2 1 2 2 2 1 3 1 1 012 1‼5 2 1 4 2 3 3 2 4 1 012 1‼5 1 5
In general, because the counts of both compositions (012) and combinations (010) is a binomial coefficient, there might be a mapping between the two, and indeed there is, as seen by the following identities:
010 1‼L R ↔ +\0 ¯1↓012 1‼⍠1 R L+1 012 1‼L R ↔ ¯2-\(010 1‼⍠1 R L-1),L
where ‼⍠1 uses the Variant operator ⍠ to evaluate ‼ in origin 1.