Skip to content

Commit

Permalink
sagemathgh-36202: some micro-details in Dyck words and Parking functions
Browse files Browse the repository at this point in the history
    
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: sagemath#36202
Reported by: Frédéric Chapoton
Reviewer(s): Matthias Köppe
  • Loading branch information
Release Manager committed Sep 10, 2023
2 parents 3441558 + 700333d commit 328988d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
27 changes: 17 additions & 10 deletions src/sage/combinat/dyck_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def _repr_lattice(self, type=None, labelling=None, underpath=True) -> str:
final_fall = " "
else:
final_fall = " _" + "__" * (length_of_final_fall - 1)
row = " "*(n - alst[-1] - 1) + final_fall + "\n"
row = " " * (n - alst[-1] - 1) + final_fall + "\n"
for i in range(n - 1):
c = 0
row = row + " "*(n-i-2-alst[-i-2])
Expand Down Expand Up @@ -1982,23 +1982,30 @@ def number_of_parking_functions(self) -> int:
from sage.arith.misc import multinomial
return multinomial(self.rise_composition())

def list_parking_functions(self):
def list_parking_functions(self) -> list:
r"""
Return all parking functions whose supporting Dyck path is ``self``.
EXAMPLES::
sage: DyckWord([1,1,0,0,1,0]).list_parking_functions()
Permutations of the multi-set [1, 1, 3]
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()
Standard permutations of 3
[[1, 1, 3], [1, 3, 1], [3, 1, 1]]
"""
return list(self.parking_functions())

def parking_functions(self):
r"""
Iterate over parking functions whose supporting Dyck path is ``self``.
EXAMPLES::
sage: list(DyckWord([1,1,0,1,0,0]).parking_functions())
[[1, 1, 2], [1, 2, 1], [2, 1, 1]]
"""
from sage.combinat.parking_functions import ParkingFunction
alist = self._area_sequence_iter()
return Permutations([i - ai + 1 for i, ai in enumerate(alist)])
# TODO: upon implementation of ParkingFunction class
# map(ParkingFunction, Permutations([i - alist[i]+1 for i in range(len(alist))]))
for pi in Permutations([i - ai + 1 for i, ai in enumerate(alist)]):
yield ParkingFunction(pi)

def reading_permutation(self) -> Permutation:
r"""
Expand Down
12 changes: 9 additions & 3 deletions src/sage/combinat/parking_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,17 @@ def __init__(self, parent, lst):
<class 'sage.combinat.parking_functions.ParkingFunctions_n_with_category.element_class'>
sage: type(b)
<class 'sage.combinat.parking_functions.ParkingFunctions_n_with_category.element_class'>
Some checks for more general inputs::
sage: PF = ParkingFunction((1, 1, 2, 2, 5, 6))
sage: PF = ParkingFunction(Permutation([4,2,3,1]))
"""
if isinstance(lst, ParkingFunction):
lst = list(lst)
if not isinstance(lst, list):
raise TypeError('input must be a list')
try:
lst = list(lst)
except TypeError:
raise TypeError('input must be convertible to a list')
if parent is None:
parent = ParkingFunctions_n(len(lst))
ClonableArray.__init__(self, parent, lst)
Expand Down

0 comments on commit 328988d

Please sign in to comment.