From 01963652a467b29bf94cf4eb74c92779775d7441 Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Sat, 20 Aug 2016 21:18:33 -0500 Subject: [PATCH 1/2] Making permutations [1,...,n] be standard. --- src/sage/combinat/permutation.py | 44 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 07b26f5c8ab..5868a91d49b 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -5009,8 +5009,10 @@ def __classcall_private__(cls, n=None, k=None, **kwargs): Standard permutations sage: Permutations(5, 3) Permutations of {1,...,5} of length 3 + sage: Permutations([1,2,3,4,6]) + Permutations of the set [1, 2, 3, 4, 6] sage: Permutations([1,2,3,4,5]) - Permutations of the set [1, 2, 3, 4, 5] + Standard permutations of 5 """ valid_args = ['descents', 'bruhat_smaller', 'bruhat_greater', 'recoils_finer', 'recoils_fatter', 'recoils', 'avoiding'] @@ -5068,12 +5070,20 @@ def __classcall_private__(cls, n=None, k=None, **kwargs): else: return Permutations_nk(n,k) else: - #In this case, we have that n is a list - if [n.index(_) for _ in n] == list(range(len(n))): - if k is None: - return Permutations_set(n) + # In this case, we have that n is a list + # Because of UniqueRepresentation, we require the elements + # to be hashable + if len(set(n)) == len(n): + if list(n) == range(1, len(n)+1): + if k is None: + return StandardPermutations_n(len(n)) + else: + return Permutations_nk(len(n), k) else: - return Permutations_setk(n,k) + if k is None: + return Permutations_set(n) + else: + return Permutations_setk(n,k) else: if k is None: return Permutations_mset(n) @@ -5280,9 +5290,9 @@ def random_element(self): EXAMPLES:: sage: Permutations(3,2).random_element() - [0, 1] + [1, 2] """ - return sample(range(self.n), self.k) + return sample(range(1, self.n+1), self.k) class Permutations_mset(Permutations): r""" @@ -5715,7 +5725,7 @@ def __init__(self, s, k): """ TESTS:: - sage: P = Permutations([1,2,3],2) + sage: P = Permutations([1,2,4],2) sage: TestSuite(P).run() """ Permutations_set.__init__(self, s) @@ -5725,12 +5735,12 @@ def __contains__(self, x): """ EXAMPLES:: - sage: p = Permutations([1,2,3],2) - sage: [1,2,3] in p + sage: p = Permutations([1,2,4],2) + sage: [1,2,4] in p False sage: [2,2] in p False - sage: [1,3] in p + sage: [1,4] in p True sage: [2,1] in p True @@ -5744,8 +5754,8 @@ def _repr_(self): """ TESTS:: - sage: repr(Permutations([1,2,3],2)) - 'Permutations of the set [1, 2, 3] of length 2' + sage: repr(Permutations([1,2,4],2)) + 'Permutations of the set [1, 2, 4] of length 2' """ return "Permutations of the set %s of length %s"%(list(self._set), self.k) @@ -5753,8 +5763,8 @@ def __iter__(self): """ EXAMPLES:: - sage: [i for i in Permutations([1,2,3],2)] # indirect doctest - [[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]] + sage: [i for i in Permutations([1,2,4],2)] + [[1, 2], [1, 4], [2, 1], [2, 4], [4, 1], [4, 2]] """ for perm in itertools.permutations(self._set, self.k): yield self.element_class(self, perm) @@ -5763,7 +5773,7 @@ def random_element(self): """ EXAMPLES:: - sage: Permutations([1,2,3],2).random_element() + sage: Permutations([1,2,4], 2).random_element() [1, 2] """ return sample(self._set, self.k) From 7548e6e8cfbeb0983133edfe6ec712dae3b7415a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 23 Aug 2016 20:34:29 +0200 Subject: [PATCH 2/2] trac 21069 fixing a doctest in Dyck words --- src/sage/combinat/dyck_word.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/combinat/dyck_word.py b/src/sage/combinat/dyck_word.py index 1c68aecee7a..6f4bf094aec 100644 --- a/src/sage/combinat/dyck_word.py +++ b/src/sage/combinat/dyck_word.py @@ -1742,7 +1742,7 @@ def list_parking_functions(self): sage: DyckWord([1,1,1,0,0,0]).list_parking_functions() Permutations of the multi-set [1, 1, 1] sage: DyckWord([1,0,1,0,1,0]).list_parking_functions() - Permutations of the set [1, 2, 3] + Standard permutations of 3 """ alist = self.to_area_sequence() return Permutations([i - alist[i]+1 for i in range(len(alist))])