CombinatorialCase012: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
* <apll>M</apll> unlabeled balls (0), <apll>N</apll> labeled boxes (1), at least one ball per box (2)
* <apll>M</apll> unlabeled balls (0), <apll>N</apll> labeled boxes (1), at least one ball per box (2)
* Not <apll>⎕IO</apll>-sensitive
* Not <apll>⎕IO</apll>-sensitive
* Allows Lexicographic order
* Counted result is an integer scalar
* Counted result is an integer scalar
* Generated result is an integer matrix.
* Generated result is an integer matrix.
Line 78: Line 79:


<pre>
<pre>
       012 1‼5 3
       12 1‼5 3 ⍝ Compositions in unspecified order
1 1 3
2 1 2
1 2 2
3 1 1
2 2 1
1 3 1
      12 2‼5 3 ⍝ Compositions in Lexicographic order
1 1 3
1 1 3
1 2 2
1 2 2
Line 85: Line 93:
2 2 1
2 2 1
3 1 1
3 1 1
      12 3‼5 3 ⍝ Gray Code order for Compositions not implemented as yet
NONCE ERROR
      12 3‼5 3
          ∧
       ⍝ Compositions of M into N parts
       ⍝ Compositions of M into N parts
       ⍝ Unlabeled balls, labeled boxes, ≥1 # Balls per Box
       ⍝ Unlabeled balls, labeled boxes, ≥1 # Balls per Box
       012 1‼5 5
       12 2‼5 5
1 1 1 1 1
1 1 1 1 1
       012 1‼5 4
       12 2‼5 4
1 1 1 2
1 1 1 2
1 1 2 1
1 1 2 1
1 2 1 1
1 2 1 1
2 1 1 1
2 1 1 1
       012 1‼5 3
       12 2‼5 3
1 1 3
1 1 3
1 2 2
1 2 2
Line 101: Line 114:
2 2 1
2 2 1
3 1 1
3 1 1
       012 1‼5 2
       12 2‼5 2
1 4
1 4
2 3
2 3
3 2
3 2
4 1
4 1
       012 1‼5 1
       12 2‼5 1
5
5
</pre>
</pre>

Latest revision as of 16:50, 21 October 2017

This case produces Compositions of the number M into N 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 M as the sum of N positive integers. It can also be thought of as a Partition of M into N Ordered Parts.

  • M unlabeled balls (0), N labeled boxes (1), at least one ball per box (2)
  • Not ⎕IO-sensitive
  • Allows Lexicographic order
  • Counted result is an integer scalar
  • Generated result is an integer matrix.

The count for this function is (M-N)!M-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:

 
 
 
 


1 2 3
 
 
 

 

1 2 3
 
 


 
 
1 2 3
 

 
 
 

1 2 3
 

 

 
 
1 2 3


 
 
 
 
1 2 3

The diagram above corresponds to

      12 1‼5 3 ⍝ Compositions in unspecified order
1 1 3
2 1 2
1 2 2
3 1 1
2 2 1
1 3 1
      12 2‼5 3 ⍝ Compositions in Lexicographic order
1 1 3
1 2 2
1 3 1
2 1 2
2 2 1
3 1 1
      12 3‼5 3 ⍝ Gray Code order for Compositions not implemented as yet
NONCE ERROR
      12 3‼5 3
          ∧

      ⍝ Compositions of M into N parts
      ⍝ Unlabeled balls, labeled boxes, ≥1 # Balls per Box
      12 2‼5 5
1 1 1 1 1
      12 2‼5 4
1 1 1 2
1 1 2 1
1 2 1 1
2 1 1 1
      12 2‼5 3
1 1 3
1 2 2
1 3 1
2 1 2
2 2 1
3 1 1
      12 2‼5 2
1 4
2 3
3 2
4 1
      12 2‼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‼M N ↔ +\0 ¯1↓012 1‼⍠1 N M+1
012 1‼M N ↔ ¯2-\(010 1‼⍠1 N M-1),M

where ‼⍠1 uses the Variant operator to evaluate in origin 1.