Deprecated combinations¶
AUTHORS:
- Mike Hansen (2007): initial implementation
- Vincent Delecroix (2014): deprecation
-
sage.combinat.choose_nk.
ChooseNK
(n, k)¶ All possible choices of k elements out of range(n) without repetitions.
The elements of the output are tuples of Python int (and not Sage Integer).
This was deprecated in trac ticket #10534 for
Combinations()
(oritertools.combinations
for doing iteration).EXAMPLES:
sage: from sage.combinat.choose_nk import ChooseNK sage: c = ChooseNK(4,2) doctest:...: DeprecationWarning: ChooseNk is deprecated and will be removed. Use Combinations instead (or combinations from the itertools module for iteration) See http://trac.sagemath.org/10534 for details. sage: c.first() [0, 1] sage: c.list() [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]
-
sage.combinat.choose_nk.
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.
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)
-
sage.combinat.choose_nk.
rank
(comb, n, check=True)¶ Return the rank of
comb
in the subsets ofrange(n)
of sizek
wherek
is the length ofcomb
.The algorithm used is based on combinadics and James McCaffrey’s MSDN article. See: Wikipedia article 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 sage: choose_nk.rank((0,1,2,3), 3) Traceback (most recent call last): ... ValueError: len(comb) must be <= n sage: choose_nk.rank((0,0), 2) Traceback (most recent call last): ... ValueError: comb must be a subword of (0,1,...,n) sage: choose_nk.rank([1,2], 3) 2 sage: choose_nk.rank([0,1,2], 3) 0