[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

1653.0. "Combinatorial Cell formula" by NYTP03::TJIONAS (George, NY TP Resource Center) Fri Aug 14 1992 01:16

    I need a formula to ... generate all possible combination out of
    a set of N numbers (say stored in an array[N]) taken L numbers of
    that set (the simplest choice which is the one I need for now is when L=N)
    I know there are N**L combination (possible choices).
    
    Set = { A[1],A[2], .., A[N] } , j=1,...,N
    
    As an example with N=2 and L=2 I have
    
    C(1,*) ----> ( A[1], A[1] )
    C(2,*) ----> ( A[1], A[2] )
    C(3,*) ----> ( A[2], A[1] )
    C(4,*) ----> ( A[2], A[2] )
    
    * indicates from 1, to 2 (1 to N in the general case)
    
    What I need is a "cell" formula f(j,i) for the (N**L) x N matrix
    C(i, j) so I can populate it based on values from the given set
    of A[j], j=1,..N in the ordering indicated by the above example.
    
    C(i, j) = A[f(j,i)]     (what is this f(j,i) function?)
    
    where j=1,2,...,N
          i=1,2,...,N**L
    
    For example, C(3, 1) = A[2], C(3,2) = A[1]
    
    Can anybody help ?
    
    	Thanks for your help
    
    George
T.RTitleUserPersonal
Name
DateLines
1653.1BEING::EDPAlways mount a scratch monkey.Fri Aug 14 1992 12:597
    Re .0:
    
    f(j,i) = ((i / N^(j-1)) % N) + 1, where "^" is exponentiation and "%"
    is remainder (as in "y % x" is the remainder when y is divided by x).
    
    
    				-- edp
1653.2Something isn't right - Something is missingNYTP03::TJIONASGeorge, NY TP Resource CenterSun Aug 16 1992 14:5816
    This formula doesn't seem to work. I applied for N=2 and from the set
    of {0, 1} and it gives me:
    
    C(1,*) ---> 1 0
    C(2,*) ---> 0 1
    C(3,*) ---> 0 0
    C(4,*) ---> 0 0
    
    where the correct combinations should be:
    C(1,*) ---> 0 0
    C(2,*) ---> 0 1
    C(3,*) ---> 1 0
    C(4,*) ---> 1 1
    
    George
    
1653.3BEING::EDPAlways mount a scratch monkey.Mon Aug 17 1992 13:0833
    Re .2:
    
    The formula is correct; I will give an example.  But first, why do you
    expect to get zeroes from the function?  In .0, your list shows 1s and
    2s, as in { A[1], A[2] }.  I wrote the function to return 1s and 2s. 
    If you want zeroes, it has to be changed.  Also, my function will
    return the combinations in a different order than you expect, but it
    will return all of them correctly.  If you want to change the order, I
    can tinker with it somewhat.
    
    Here is an example for C(2,*):
    
    	f(j,i) = ((i / N^(j-1)) % N) + 1
    
    	f(1,2) = ((2 / 2^(1-1)) % 2) + 1
    	       = ((2 / 2^  0  ) % 2) + 1
    	       = ((2 /  1     ) % 2) + 1
    	       = (   2          % 2) + 1
    	       =                0    + 1
    	       =                     1.
    
    	f(2,2) = ((2 / 2^(2-1)) % 2) + 1
    	       = ((2 / 2^  1  ) % 2) + 1
    	       = ((2 /  2     ) % 2) + 1
    	       = (   1          % 2) + 1
    	       =                1    + 1
    	       =                     2.
    
    (Note that "/" represents integer division here, so that 7/2 would be 3,
    not 3.5.)
    
    
    				-- edp
1653.4clarifying the unclearNYTP03::TJIONASGeorge, NY TP Resource CenterMon Aug 17 1992 21:22130
                  <<< 2B::NOTES1:[NOTES$LIBRARY]MATH.NOTE;7 >>>
                            -< Mathematics at DEC >-
================================================================================
Note 1653.3                Combinatorial Cell formula                     3 of 3
BEING::EDP "Always mount a scratch monkey."          33 lines  17-AUG-1992 09:08
--------------------------------------------------------------------------------
    
>    The formula is correct; I will give an example.  But first, why do you
>    expect to get zeroes from the function?  In .0, your list shows 1s and
>    2s, as in { A[1], A[2] }.  I wrote the function to return 1s and 2s. 
>    If you want zeroes, it has to be changed.  Also, my function will
>    return the combinations in a different order than you expect, but it
>    will return all of them correctly.  If you want to change the order, I
>    can tinker with it somewhat.

I wasn't intended for zeroes from the function. What I wanted to say (maybe
not clearly enough) was that my sample is:

     { A[1], A[2] } = { 0, 1 } where A[1]=0 and A[2]=1

I probably think that I've expressed the problem in a consfussing way.

In my equation C(i, j) = A[f(j,i)] the notation f(j,i) it only indicates
"function of i and j" with no preference in the order of i,j in f() like
in mathematics.

The equation could be written also C[i,j] = A[f(i,j)]. The only importance
(my mistake - my ommision) I meant was that i,j are indices (subscripts) in
C[i,j] and the result of f() is an index in A[].

I can't get the results when I fully expand for every C(j,i) even when
based on an incorrect problem.
    
    	f(j,i) = ((i / N^(j-1)) % N) + 1
        --------------------------------
	f(1,1) = ((1 / 2^(1-1)) % 2) + 1
 	       = ((1 / 2^  0  ) % 2) + 1
               = ((1 / 1      ) % 2) + 1
               = (   1        ) % 2) + 1
               =                1    + 1
               =                     2.      
        ====> C(1,1) = A[f(1,1)] = A[2] = 1
    
 	f(1,2) = ((2 / 2^(1-1)) % 2) + 1
    	       = ((2 / 2^  0  ) % 2) + 1
    	       = ((2 /  1     ) % 2) + 1
    	       = (   2          % 2) + 1
    	       =                0    + 1
    	       =                     1.      
        ====> C(2,1) = A[f(1,2] = A[1] = 0
    
    	f(2,1) = ((1 / 2^(2-1)) % 2) + 1
    	       = ((1 / 2^  1  ) % 2) + 1
    	       = ((1 / 2      ) % 2) + 1
    	       = (   0          % 2) + 1
    	       =                0    + 1
    	       =                     1.      
        ====> C(1,2) = A[f(2,1)] = A[1]=0

 	f(2,2) = ((2 / 2^(2-1)) % 2) + 1
    	       = ((2 / 2^  1  ) % 2) + 1
    	       = ((2 / 2      ) % 2) + 1
    	       = (   1          % 2) + 1
    	       =                1    + 1
    	       =                     2.      
        ====> C(2,2) = A[f(2,2)] = A[2] = 1

    	f(3,1) = ((1 / 2^(3-1)) % 2) + 1
    	       = ((1 / 2^  2  ) % 2) + 1
    	       = ((1 / 4      ) % 2) + 1
    	       = (   0          % 2) + 1
    	       =                0    + 1
    	       =                     1.      
        ====> C(1,3) = A[f(3,1)] = A[1] = 0

    	f(3,2) = ((2 / 2^(3-1)) % 2) + 1
    	       = ((2 / 2^  2  ) % 2) + 1
    	       = ((2 / 4      ) % 2) + 1
    	       = (   0          % 2) + 1
    	       =                0    + 1
    	       =                     1.      
        ====> C(2,3) = A[f(3,2)] = A[1] = 0

    	f(4,1) = ((1 / 2^(4-1)) % 2) + 1
    	       = ((1 / 2^  3  ) % 2) + 1
    	       = ((1 / 8      ) % 2) + 1
    	       = (   0          % 2) + 1
    	       =                0    + 1
    	       =                     1.      
        ====> C(1,4) = A[f(4,1)] = A[1] = 0

    	f(4,2) = ((2 / 2^(4-1)) % 2) + 1
    	       = ((2 / 2^  3  ) % 2) + 1
    	       = ((2 / 8      ) % 2) + 1
    	       = (   0          % 2) + 1
    	       =                0    + 1
    	       =                     1.      
        ====> C(2,4) = A[f(4,2)] = A[1] = 0

But the elements C[1,3], C[2,3], C[1,4], C[2,4] are not defined.
My array (matrix) is C 4x2, not C 2x4.

I,ve tried to interchange the role of i and j in formula i.e. f(i,j0 instead
of f(j,i). Other than starting off giving valid answers then proceeding further
for the rest of the elements it stacks with the same (unchanged) invalid tuple.

As I've tried to indicate in my discription C[i,j] grows vertically, not
horizontally. This is when I wrote:

>    C(i, j) = A[f(j,i)]     (what is this f(j,i) function?)
>
>    where j=1,2,...,N
>          i=1,2,...,N**L

and I am looking for the elements:

    C(1,1) (and the result should be) =  A[0] = 0
    C(1,2) (and the result should be) =  A[0] = 0

    C(2,1) (and the result should be) =  A[0] = 0
    C(2,2) (and the result should be) =  A[1] = 1

    C(3,1) (and the result should be) =  A[1] = 1
    C(3,2) (and the result should be) =  A[0] = 0

    C(4,1) (and the result should be) =  A[1] = 1
    C(4,2) (and the result should be) =  A[1] = 1

George
    
1653.5BEING::EDPAlways mount a scratch monkey.Tue Aug 18 1992 12:4816
    Re .4:
    
    C(1,1) = A[f(1,1)] = A[2] = 1.
    C(1,2) = A[f(2,1)] = A[1] = 0.
    
    C(2,1) = A[f(1,2)] = A[1] = 0.
    C(2,2) = A[f(2,2)] = A[2] = 1.
    
    C(3,1) = A[f(1,3)] = A[2] = 1.
    C(3,2) = A[f(2,3)] = A[2] = 1.
    
    C(4,1) = A[f(1,4)] = A[1] = 0.
    C(4,2) = A[f(2,4)] = A[1] = 0.
    
    
    				-- edp