CombinatorialCase012: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
No edit summary
 
Line 93: Line 93:
2 2 1
2 2 1
3 1 1
3 1 1
       12 3‼5 3 ⍝ Gray Code order not implemented as yet
       12 3‼5 3 ⍝ Gray Code order for Compositions not implemented as yet
NONCE ERROR
NONCE ERROR
       12 3‼5 3
       12 3‼5 3

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.