Skip to content

Commit bbe8511

Browse files
author
Release Manager
committed
Trac #33762: fine tuning details in Tamari interval posets
URL: https://trac.sagemath.org/33762 Reported by: chapoton Ticket author(s): Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents 4018507 + 68de80f commit bbe8511

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

src/sage/combinat/interval_posets.py

+26-30
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class TamariIntervalPoset(Element,
186186
The Tamari interval of size 0 induced by relations []
187187
"""
188188
@staticmethod
189-
def __classcall_private__(cls, *args, **opts):
189+
def __classcall_private__(cls, *args, **opts) -> TIP:
190190
r"""
191191
Ensure that interval-posets created by the enumerated sets and
192192
directly are the same and that they are instances of
@@ -246,7 +246,7 @@ def __init__(self, parent, size, relations=None, check=True):
246246
Element.__init__(self, parent)
247247

248248
self._cover_relations = tuple(self._poset.cover_relations())
249-
self._latex_options = dict()
249+
self._latex_options = {}
250250

251251
def set_latex_options(self, D):
252252
r"""
@@ -537,7 +537,7 @@ def draw_decreasing(i, j) -> str:
537537

538538
return start + nodes + relations + end
539539

540-
def poset(self):
540+
def poset(self) -> Poset:
541541
r"""
542542
Return ``self`` as a labelled poset.
543543
@@ -2531,8 +2531,8 @@ def extract_tree(x, y, tilt, common):
25312531
break
25322532
return BinaryTree([left_tree, right_tree], check=False)
25332533

2534-
TIP = self.parent()
2535-
return [TIP.from_binary_trees(extract_tree(cx, cy, t_low, common),
2534+
tip = self.parent()
2535+
return [tip.from_binary_trees(extract_tree(cx, cy, t_low, common),
25362536
extract_tree(cx, cy, t_up, common))
25372537
for cx, cy in common]
25382538

@@ -3042,12 +3042,12 @@ def final_forest(element) -> TIP:
30423042
"""
30433043
if isinstance(element, TamariIntervalPoset):
30443044
return element.final_forest()
3045-
elif element in DyckWords():
3045+
if element in DyckWords():
30463046
binary_tree = element.to_binary_tree_tamari()
30473047
elif element in BinaryTrees() or element in LabelledBinaryTrees():
30483048
binary_tree = element
30493049
else:
3050-
raise ValueError("do not know how to construct the final forest of {}".format(element))
3050+
raise ValueError(f"do not know how to construct the final forest of {element}")
30513051

30523052
def get_relations(bt, start=1):
30533053
r"""
@@ -3074,7 +3074,7 @@ def get_relations(bt, start=1):
30743074
relations.extend([(j, index) for j in rroots])
30753075
return roots, relations, rindex
30763076

3077-
roots, relations, index = get_relations(binary_tree)
3077+
_, relations, index = get_relations(binary_tree)
30783078
P = FinitePoset(DiGraph([list(range(1, index)), relations],
30793079
format='vertices_and_edges')) # type:ignore
30803080
return TamariIntervalPoset(P, check=False) # type:ignore
@@ -3146,16 +3146,15 @@ def initial_forest(element) -> TIP:
31463146
Traceback (most recent call last):
31473147
...
31483148
ValueError: do not know how to construct the initial forest of mont
3149-
31503149
"""
31513150
if isinstance(element, TamariIntervalPoset):
31523151
return element.initial_forest()
3153-
elif element in DyckWords():
3152+
if element in DyckWords():
31543153
binary_tree = element.to_binary_tree_tamari()
31553154
elif element in BinaryTrees() or element in LabelledBinaryTrees():
31563155
binary_tree = element
31573156
else:
3158-
raise ValueError("do not know how to construct the initial forest of {}".format(element))
3157+
raise ValueError(f"do not know how to construct the initial forest of {element}")
31593158

31603159
def get_relations(bt, start=1):
31613160
r"""
@@ -3182,7 +3181,7 @@ def get_relations(bt, start=1):
31823181
relations.extend([(j, index) for j in lroots])
31833182
return roots, relations, rindex
31843183

3185-
roots, relations, index = get_relations(binary_tree)
3184+
_, relations, index = get_relations(binary_tree)
31863185
P = FinitePoset(DiGraph([list(range(1, index)), relations],
31873186
format='vertices_and_edges')) # type:ignore
31883187
return TamariIntervalPoset(P, check=False) # type:ignore
@@ -3437,7 +3436,6 @@ def from_minimal_schnyder_wood(graph) -> TIP:
34373436
sage: TIP.from_minimal_schnyder_wood(G)
34383437
The Tamari interval of size 3 induced by relations [(2, 3), (2, 1)]
34393438
"""
3440-
from sage.graphs.digraph import DiGraph
34413439
from sage.combinat.dyck_word import DyckWord
34423440
color_a = graph.incoming_edges(-1)[0][2]
34433441
color_b = graph.incoming_edges(-2)[0][2]
@@ -3468,20 +3466,18 @@ def from_minimal_schnyder_wood(graph) -> TIP:
34683466
def clockwise_labelling(gr, vertex):
34693467
if len(gr) == 1:
34703468
return [vertex]
3471-
else:
3472-
lbl = [vertex]
3473-
for w in voisins_in[vertex]:
3474-
lbl += clockwise_labelling(gr, w)
3475-
return lbl
3469+
lbl = [vertex]
3470+
for w in voisins_in[vertex]:
3471+
lbl += clockwise_labelling(gr, w)
3472+
return lbl
34763473

34773474
def profil(gr, vertex):
34783475
if len(gr) == 1:
34793476
return []
3480-
else:
3481-
lbl = []
3482-
for w in voisins_in[vertex]:
3483-
lbl += [1] + profil(gr, w) + [0]
3484-
return lbl
3477+
lbl = []
3478+
for w in voisins_in[vertex]:
3479+
lbl += [1] + profil(gr, w) + [0]
3480+
return lbl
34853481

34863482
dyckword_bottom = profil(graph0, -1)
34873483
# this is the profile of the planar graph graph0
@@ -3503,8 +3499,8 @@ def profil(gr, vertex):
35033499

35043500
dyckword_bottom = DyckWord(dyckword_bottom) # type:ignore
35053501
dyckword_top = DyckWord(dyckword_top) # type:ignore
3506-
TIP = TamariIntervalPosets(len(dyckword_bottom) // 2)
3507-
return TIP.from_dyck_words(dyckword_bottom, dyckword_top)
3502+
tip = TamariIntervalPosets(len(dyckword_bottom) // 2)
3503+
return tip.from_dyck_words(dyckword_bottom, dyckword_top)
35083504

35093505
def __call__(self, *args, **keywords):
35103506
r"""
@@ -3534,7 +3530,7 @@ def __call__(self, *args, **keywords):
35343530
if len(args) == 1 and isinstance(args[0], FinitePoset):
35353531
return self.element_class(self, args[0])
35363532

3537-
return super(TamariIntervalPosets, self).__call__(*args, **keywords)
3533+
return super().__call__(*args, **keywords)
35383534

35393535
def le(self, el1, el2) -> bool:
35403536
r"""
@@ -3669,7 +3665,7 @@ def __init__(self, size):
36693665
"""
36703666
# there is a natural order on interval-posets through inclusions
36713667
# that is why we use the FinitePosets category
3672-
super(TamariIntervalPosets_size, self).__init__(category=(FinitePosets(), FiniteEnumeratedSets()))
3668+
super().__init__(category=(FinitePosets(), FiniteEnumeratedSets()))
36733669

36743670
self._size = size
36753671

@@ -3680,7 +3676,7 @@ def _repr_(self) -> str:
36803676
sage: TamariIntervalPosets(3)
36813677
Interval-posets of size 3
36823678
"""
3683-
return "Interval-posets of size {}".format(self._size)
3679+
return f"Interval-posets of size {self._size}"
36843680

36853681
def __contains__(self, x) -> bool:
36863682
r"""
@@ -3813,10 +3809,10 @@ def random_element(self) -> TIP:
38133809
from sage.graphs.generators.random import RandomTriangulation
38143810
n = self._size
38153811
tri = RandomTriangulation(n + 3)
3816-
TIP = TamariIntervalPosets
3812+
tip = TamariIntervalPosets
38173813
schnyder = minimal_schnyder_wood(tri, root_edge=(-1, -2),
38183814
check=False)
3819-
return TIP.from_minimal_schnyder_wood(schnyder)
3815+
return tip.from_minimal_schnyder_wood(schnyder)
38203816

38213817
@lazy_attribute
38223818
def _parent_for(self):

0 commit comments

Comments
 (0)