Skip to content

Commit 60d884a

Browse files
author
Release Manager
committed
Trac #34184: from_lehmer_cocode
New feature to make it possible to get a permutation from its Lehmer cocode. A function to get the Lehmer cocode of a given permutation already exists. URL: https://trac.sagemath.org/34184 Reported by: nadialafreniere Ticket author(s): Nadia Lafrenière Reviewer(s): Jessica Striker, Travis Scrimshaw
2 parents 56ed81e + 0158e18 commit 60d884a

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
@@ -7552,6 +7552,32 @@ def from_lehmer_code(lehmer, parent=None):
75527552
parent = Permutations()
75537553
return parent(p)
75547554

7555+
def from_lehmer_cocode(lehmer, parent=Permutations()):
7556+
r"""
7557+
Return the permutation with Lehmer cocode ``lehmer``.
7558+
7559+
The Lehmer cocode of a permutation `p` is defined as the
7560+
list `(c_1, c_2, \ldots, c_n)`, where `c_i` is the number
7561+
of `j < i` such that `p(j) > p(i)`.
7562+
7563+
EXAMPLES::
7564+
7565+
sage: import sage.combinat.permutation as permutation
7566+
sage: lcc = Permutation([2,1,5,4,3]).to_lehmer_cocode(); lcc
7567+
[0, 1, 0, 1, 2]
7568+
sage: permutation.from_lehmer_cocode(lcc)
7569+
[2, 1, 5, 4, 3]
7570+
"""
7571+
p = []
7572+
ell = len(lehmer)
7573+
i = ell-1
7574+
open_spots = list(range(1, ell+1))
7575+
for ivi in reversed(lehmer):
7576+
p.append(open_spots.pop(i-ivi))
7577+
i -= 1
7578+
p.reverse()
7579+
return parent(p)
7580+
75557581
def from_reduced_word(rw, parent=None):
75567582
r"""
75577583
Return the permutation corresponding to the reduced word ``rw``.

0 commit comments

Comments
 (0)