CombinatorialCase012: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
mNo edit summary
Line 1: Line 1:
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.
This case produces '''Compositions of the number <apll>M</apll> into <apll>N</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>M</apll> as the sum of <apll>N</apll> positive integers.  It can also be thought of as a partition of <apll>M</apll> into <apll>N</apll> ordered parts.


* <apll>L</apll> unlabeled balls (0), <apll>R</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
* Counted result is an integer scalar
* Counted result is an integer scalar
* Generated result is an integer matrix.
* Generated result is an integer matrix.


The count for this function is <apll>(L-R)!L-1</apll>.
The count for this function is <apll>(M-N)!M-1</apll>.


For example:
For example:
Line 85: Line 85:
2 2 1
2 2 1
3 1 1
3 1 1
       ⍝ Compositions of L into R 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
       012 1‼5 5
Line 113: Line 113:


<pre>
<pre>
010 1‼L R ↔ +\0 ¯1↓012 1‼⍠1 R L+1
010 1‼M N ↔ +\0 ¯1↓012 1‼⍠1 N M+1
012 1‼L R ↔ ¯2-\(010 1‼⍠1 R L-1),L
012 1‼M N ↔ ¯2-\(010 1‼⍠1 N M-1),M
</pre>
</pre>


where <apll>‼⍠1</apll> uses the Variant operator <apll>⍠</apll> to evaluate <apll>‼</apll> in origin <apll>1</apll>.
where <apll>‼⍠1</apll> uses the Variant operator <apll>⍠</apll> to evaluate <apll>‼</apll> in origin <apll>1</apll>.

Revision as of 22:10, 14 May 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
  • 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

      012 1‼5 3
1 1 3
1 2 2
1 3 1
2 1 2
2 2 1
3 1 1
      ⍝ Compositions of M into N 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‼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.