Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'public/combinat/permutations_std_set-21069' of git://tr…
Browse files Browse the repository at this point in the history
…ac.sagemath.org/sage into public/combinat/permutations_std_set-21069
  • Loading branch information
Travis Scrimshaw committed Oct 17, 2016
2 parents 3a83086 + 7548e6e commit 3cc7873
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/sage/combinat/dyck_word.py
Expand Up @@ -1743,7 +1743,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))])
Expand Down
44 changes: 27 additions & 17 deletions src/sage/combinat/permutation.py
Expand Up @@ -5014,8 +5014,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']
Expand Down Expand Up @@ -5073,12 +5075,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)
Expand Down Expand Up @@ -5285,9 +5295,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"""
Expand Down Expand Up @@ -5720,7 +5730,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)
Expand All @@ -5730,12 +5740,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
Expand All @@ -5749,17 +5759,17 @@ 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)

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)
Expand All @@ -5768,7 +5778,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)
Expand Down

0 comments on commit 3cc7873

Please sign in to comment.