Skip to content

Commit 9bebc62

Browse files
author
Nadia Lafrenière
committed
Merge branch 'u/nadialafreniere/from_lehmer_cocode' of git://trac.sagemath.org/sage into t/34184/from_lehmer_cocode
2 parents cd1e2b1 + df79b85 commit 9bebc62

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/sage/combinat/permutation.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7500,6 +7500,32 @@ def from_lehmer_code(lehmer, parent=None):
75007500
parent = Permutations()
75017501
return parent(p)
75027502

7503+
def from_lehmer_cocode(lehmer, parent=Permutations()):
7504+
r"""
7505+
Return the permutation with Lehmer cocode ``lehmer``.
7506+
7507+
The Lehmer cocode of a permutation `p` is defined as the
7508+
list `(c_1, c_2, \ldots, c_n)`, where `c_i` is the number
7509+
of `j < i` such that `p(j) > p(i)`.
7510+
7511+
EXAMPLES::
7512+
7513+
sage: import sage.combinat.permutation as permutation
7514+
sage: lcc = Permutation([2,1,5,4,3]).to_lehmer_cocode(); lcc
7515+
[0, 1, 0, 1, 2]
7516+
sage: permutation.from_lehmer_cocode(lcc)
7517+
[2, 1, 5, 4, 3]
7518+
"""
7519+
p = []
7520+
i = 1
7521+
lehmer.reverse()
7522+
open_spots = list(range(1,len(lehmer)+1))
7523+
for ivi in lehmer:
7524+
p.append(open_spots.pop(len(lehmer)-i-ivi))
7525+
i += 1
7526+
p.reverse()
7527+
return parent(p)
7528+
75037529
def from_reduced_word(rw, parent=None):
75047530
r"""
75057531
Return the permutation corresponding to the reduced word ``rw``.

0 commit comments

Comments
 (0)