Skip to content

Commit 328988d

Browse files
author
Release Manager
committed
gh-36202: some micro-details in Dyck words and Parking functions This is - widening the input type of ParkingFunction to allow for tuples and list-like objects - enhancing the method "list_parking_functions" of Dyck words to return Parking functions, and creating an iterator ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. URL: #36202 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents 3441558 + 700333d commit 328988d

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/sage/combinat/dyck_word.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def _repr_lattice(self, type=None, labelling=None, underpath=True) -> str:
539539
final_fall = " "
540540
else:
541541
final_fall = " _" + "__" * (length_of_final_fall - 1)
542-
row = " "*(n - alst[-1] - 1) + final_fall + "\n"
542+
row = " " * (n - alst[-1] - 1) + final_fall + "\n"
543543
for i in range(n - 1):
544544
c = 0
545545
row = row + " "*(n-i-2-alst[-i-2])
@@ -1982,23 +1982,30 @@ def number_of_parking_functions(self) -> int:
19821982
from sage.arith.misc import multinomial
19831983
return multinomial(self.rise_composition())
19841984

1985-
def list_parking_functions(self):
1985+
def list_parking_functions(self) -> list:
19861986
r"""
19871987
Return all parking functions whose supporting Dyck path is ``self``.
19881988
19891989
EXAMPLES::
19901990
19911991
sage: DyckWord([1,1,0,0,1,0]).list_parking_functions()
1992-
Permutations of the multi-set [1, 1, 3]
1993-
sage: DyckWord([1,1,1,0,0,0]).list_parking_functions()
1994-
Permutations of the multi-set [1, 1, 1]
1995-
sage: DyckWord([1,0,1,0,1,0]).list_parking_functions()
1996-
Standard permutations of 3
1992+
[[1, 1, 3], [1, 3, 1], [3, 1, 1]]
19971993
"""
1994+
return list(self.parking_functions())
1995+
1996+
def parking_functions(self):
1997+
r"""
1998+
Iterate over parking functions whose supporting Dyck path is ``self``.
1999+
2000+
EXAMPLES::
2001+
2002+
sage: list(DyckWord([1,1,0,1,0,0]).parking_functions())
2003+
[[1, 1, 2], [1, 2, 1], [2, 1, 1]]
2004+
"""
2005+
from sage.combinat.parking_functions import ParkingFunction
19982006
alist = self._area_sequence_iter()
1999-
return Permutations([i - ai + 1 for i, ai in enumerate(alist)])
2000-
# TODO: upon implementation of ParkingFunction class
2001-
# map(ParkingFunction, Permutations([i - alist[i]+1 for i in range(len(alist))]))
2007+
for pi in Permutations([i - ai + 1 for i, ai in enumerate(alist)]):
2008+
yield ParkingFunction(pi)
20022009

20032010
def reading_permutation(self) -> Permutation:
20042011
r"""

src/sage/combinat/parking_functions.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,17 @@ def __init__(self, parent, lst):
222222
<class 'sage.combinat.parking_functions.ParkingFunctions_n_with_category.element_class'>
223223
sage: type(b)
224224
<class 'sage.combinat.parking_functions.ParkingFunctions_n_with_category.element_class'>
225+
226+
Some checks for more general inputs::
227+
228+
sage: PF = ParkingFunction((1, 1, 2, 2, 5, 6))
229+
sage: PF = ParkingFunction(Permutation([4,2,3,1]))
225230
"""
226-
if isinstance(lst, ParkingFunction):
227-
lst = list(lst)
228231
if not isinstance(lst, list):
229-
raise TypeError('input must be a list')
232+
try:
233+
lst = list(lst)
234+
except TypeError:
235+
raise TypeError('input must be convertible to a list')
230236
if parent is None:
231237
parent = ParkingFunctions_n(len(lst))
232238
ClonableArray.__init__(self, parent, lst)

0 commit comments

Comments
 (0)