Package sage :: Package combinat :: Module choose_nk
[hide private]
[frames] | no frames]

Module choose_nk

source code


Alternating sign matrices



Classes [hide private]
  ChooseNK
Functions [hide private]
 
rank(comb, n)
Returns the rank of comb in the subsets of range(n) of size k.
source code
 
_comb_largest(a, b, x)
Returns the largest w < a such that binomial(w,b) <= x.
source code
 
from_rank(r, n, k)
Returns the combination of rank r in the subsets of range(n) of size k when listed in lexicographic order.
source code
Function Details [hide private]

rank(comb, n)

source code 

Returns the rank of comb in the subsets of range(n) of
size k.

The algorithm used is based on combinadics and James
McCaffrey's MSDN article.
See: http://en.wikipedia.org/wiki/Combinadic

EXAMPLES:
    sage: import sage.combinat.choose_nk as choose_nk
    sage: choose_nk.rank([], 3)
    0
    sage: choose_nk.rank([0], 3)
    0
    sage: choose_nk.rank([1], 3)
    1
    sage: choose_nk.rank([2], 3)
    2
    sage: choose_nk.rank([0,1], 3)
    0
    sage: choose_nk.rank([0,2], 3)
    1
    sage: choose_nk.rank([1,2], 3)
    2
    sage: choose_nk.rank([0,1,2], 3)
    0        

_comb_largest(a, b, x)

source code 

Returns the largest w < a such that binomial(w,b) <= x.

EXAMPLES:
    sage: from sage.combinat.choose_nk import _comb_largest
    sage: _comb_largest(6,3,10)
    5
    sage: _comb_largest(6,3,5)
    4

from_rank(r, n, k)

source code 

Returns the combination of rank r in the subsets of range(n)
of size k when listed in lexicographic order.

The algorithm used is based on combinadics and James
McCaffrey's MSDN article. 
See: http://en.wikipedia.org/wiki/Combinadic


EXAMPLES:
    sage: import sage.combinat.choose_nk as choose_nk
    sage: choose_nk.from_rank(0,3,0)
    []
    sage: choose_nk.from_rank(0,3,1)
    [0]
    sage: choose_nk.from_rank(1,3,1)
    [1]
    sage: choose_nk.from_rank(2,3,1)
    [2]
    sage: choose_nk.from_rank(0,3,2)
    [0, 1]
    sage: choose_nk.from_rank(1,3,2)
    [0, 2]
    sage: choose_nk.from_rank(2,3,2)
    [1, 2]
    sage: choose_nk.from_rank(0,3,3)
    [0, 1, 2]