summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Delecroix <20100.delecroix@gmail.com>2014-06-06 23:19:12 +0200
committerVincent Delecroix <20100.delecroix@gmail.com>2014-06-06 23:19:12 +0200
commit1995fca0cc79b20ffc8863e425e50c614e61a02b (patch)
tree5172cf0aca48eb2e5fff2680969207971d2b3c10
parenttrac #10534: deprecate ChooseNK and use Combinations instead (diff)
trac #10534: remove imports in choose_nk + deprecate SplitNK
-rw-r--r--src/sage/combinat/choose_nk.py3
-rw-r--r--src/sage/combinat/split_nk.py124
2 files changed, 24 insertions, 103 deletions
diff --git a/src/sage/combinat/choose_nk.py b/src/sage/combinat/choose_nk.py
index 083e0ad..0a91ebd 100644
--- a/src/sage/combinat/choose_nk.py
+++ b/src/sage/combinat/choose_nk.py
@@ -21,10 +21,7 @@ AUTHORS:
#
# http://www.gnu.org/licenses/
#*****************************************************************************
-import sage.misc.prandom as rnd
from sage.rings.arith import binomial
-from combinat import CombinatorialClass
-import itertools
def ChooseNK(n, k):
"""
diff --git a/src/sage/combinat/split_nk.py b/src/sage/combinat/split_nk.py
index 440ffa9..61d98ae 100644
--- a/src/sage/combinat/split_nk.py
+++ b/src/sage/combinat/split_nk.py
@@ -1,11 +1,11 @@
"""
-Low-level splits
+Derecated splits
Authors:
- Mike Hansen (2007): original version
-- Vincent Delecroix (2011): improvements
+- Vincent Delecroix (2014): deprecation
"""
#*****************************************************************************
# Copyright (C) 2007 Mike Hansen <mhansen@gmail.com>,
@@ -22,11 +22,6 @@ Authors:
# http://www.gnu.org/licenses/
#*****************************************************************************
-from sage.rings.arith import binomial
-import sage.misc.prandom as rnd
-import sage.combinat.choose_nk as choose_nk
-from combinat import CombinatorialClass
-
def SplitNK(n, k):
"""
Returns the combinatorial class of splits of a the set range(n)
@@ -35,100 +30,29 @@ def SplitNK(n, k):
EXAMPLES::
sage: from sage.combinat.split_nk import SplitNK
- sage: S = SplitNK(5,2); S
- Splits of {0, ..., 4} into a set of size 2 and one of size 3
+ sage: S = SplitNK(5,2)
+ doctest:...: DeprecationWarning: SplitNk is deprecated and will be
+ removed. Use OrderedSetPartitions instead.
+ See http://trac.sagemath.org/10534 for details.
+ sage: S
+ Ordered set partitions of {0, 1, 2, 3, 4} into parts of size [2, 3]
sage: S.first()
- [(0, 1), (2, 3, 4)]
+ [{0, 1}, {2, 3, 4}]
sage: S.last()
- [(3, 4), (0, 1, 2)]
+ [{3, 4}, {0, 1, 2}]
sage: S.list()
- [[(0, 1), (2, 3, 4)],
- [(0, 2), (1, 3, 4)],
- [(0, 3), (1, 2, 4)],
- [(0, 4), (1, 2, 3)],
- [(1, 2), (0, 3, 4)],
- [(1, 3), (0, 2, 4)],
- [(1, 4), (0, 2, 3)],
- [(2, 3), (0, 1, 4)],
- [(2, 4), (0, 1, 3)],
- [(3, 4), (0, 1, 2)]]
+ [[{0, 1}, {2, 3, 4}],
+ [{0, 2}, {1, 3, 4}],
+ [{0, 3}, {1, 2, 4}],
+ [{0, 4}, {1, 2, 3}],
+ [{1, 2}, {0, 3, 4}],
+ [{1, 3}, {0, 2, 4}],
+ [{1, 4}, {0, 2, 3}],
+ [{2, 3}, {0, 1, 4}],
+ [{2, 4}, {0, 1, 3}],
+ [{3, 4}, {0, 1, 2}]]
"""
- return SplitNK_nk(n,k)
-
-class SplitNK_nk(CombinatorialClass):
- def __init__(self, n, k):
- """
- TESTS::
-
- sage: from sage.combinat.split_nk import SplitNK
- sage: S = SplitNK(5,2)
- sage: S == loads(dumps(S))
- True
- """
- self._n = n
- self._k = k
-
- def _repr_(self):
- """
- TESTS::
-
- sage: from sage.combinat.split_nk import SplitNK
- sage: repr(SplitNK(5,2)) #indirect doctest
- 'Splits of {0, ..., 4} into a set of size 2 and one of size 3'
- """
- return "Splits of {0, ..., %s} into a set of size %s and one of size %s" % (self._n - 1, self._k, self._n - self._k)
-
- def cardinality(self):
- """
- Returns the number of choices of set partitions of range(n) into a
- set of size k and a set of size n-k.
-
- EXAMPLES::
-
- sage: from sage.combinat.split_nk import SplitNK
- sage: SplitNK(5,2).cardinality()
- 10
- """
- return binomial(self._n,self._k)
-
- def __iter__(self):
- """
- An iterator for all set partitions of range(n) into a set of size k
- and a set of size n-k in lexicographic order.
-
- EXAMPLES::
-
- sage: from sage.combinat.split_nk import SplitNK
- sage: for c in SplitNK(5,2): print c
- [(0, 1), (2, 3, 4)]
- [(0, 2), (1, 3, 4)]
- [(0, 3), (1, 2, 4)]
- [(0, 4), (1, 2, 3)]
- [(1, 2), (0, 3, 4)]
- [(1, 3), (0, 2, 4)]
- [(1, 4), (0, 2, 3)]
- [(2, 3), (0, 1, 4)]
- [(2, 4), (0, 1, 3)]
- [(3, 4), (0, 1, 2)]
- """
- range_n = range(self._n)
- for kset in choose_nk.ChooseNK(self._n,self._k):
- yield [kset, tuple(filter(lambda x: x not in kset, range_n))]
-
- def random_element(self):
- """
- Returns a random set partition of range(n) into a set of size k and
- a set of size n-k.
-
- EXAMPLES::
-
- sage: from sage.combinat.split_nk import SplitNK
- sage: SplitNK(5,2).random_element()
- [(0, 2), (1, 3, 4)]
- """
- r = rnd.sample(xrange(self._n), self._n)
- r0 = r[:self._k]
- r1 = r[self._k:]
- r0.sort()
- r1.sort()
- return [tuple(r0), tuple(r1)]
+ from sage.misc.superseded import deprecation
+ from sage.combinat.set_partition_ordered import OrderedSetPartitions
+ deprecation(10534, "SplitNk is deprecated and will be removed. Use OrderedSetPartitions instead.")
+ return OrderedSetPartitions(range(n), [k, n-k])