Skip to content

Commit f526423

Browse files
author
Release Manager
committed
gh-34970: add is_supergreedy() to linear extensions This is my pull request originally created on trac, which I thought pushing on github. Fixes #24700 URL: #34970 Reported by: Rohan Garg Reviewer(s): Dima Pasechnik, Martin Rubey, Rohan Garg, Tobias Diez
2 parents 46a6105 + 2c15778 commit f526423

File tree

2 files changed

+26
-33
lines changed

2 files changed

+26
-33
lines changed

src/doc/en/reference/references/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3879,6 +3879,7 @@ REFERENCES:
38793879
set as the intersection of super greedy linear extensions. Order 4,
38803880
293-311 (1987).
38813881
:doi:`10.1007/BF00337892`
3882+
38823883
.. [Kuh1987] \W. Kühnel, "Minimal triangulations of Kummer varieties",
38833884
Abh. Math. Sem. Univ. Hamburg 57 (1987), 7-20.
38843885

src/sage/combinat/posets/linear_extensions.py

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -255,23 +255,23 @@ def is_greedy(self):
255255
def is_supergreedy(self):
256256
r"""
257257
Return ``True`` if the linear extension is supergreedy.
258-
259-
A linear extension `[x_1<x_2<...<x_t]` of a finite ordered
260-
set `P=(P, <)` is *super greedy* if it can be obtained using
261-
the following procedure: Choose `x_1` to be a minimal
262-
element of `P`; suppose `x_1,...,x_i` have been chosen;
263-
define `p(x)` to be the largest `j\leq i` such that `x_j<x`
264-
if such a `j` exists and 0 otherwise; choose `x_{i+1}`
265-
to be a minimal element of `P-\{x_1,...,x_i\}` which
266-
maximizes `p`.
258+
259+
A linear extension of a poset `P` with elements `\{x_1,x_2,...,x_t\}`
260+
is *super greedy*, if it can be obtained using the following
261+
algorithm: choose `x_1` to be a minimal element of `P`;
262+
suppose `X = \{x_1,...,x_i\}` have been chosen; let `M` be
263+
the set of minimal elements of `P\setminus X`. If there is an element
264+
of `M` which covers an element `x_j` in `X`, then let `x_{i+1}`
265+
be one of these such that `j` is maximal; otherwise, choose `x_{i+1}`
266+
to be any element of `M`.
267267
268268
Informally, a linear extension is supergreedy if it "always
269269
goes up and receedes the least"; in other words, supergreedy
270270
linear extensions are depth-first linear extensions.
271271
For more details see [KTZ1987]_.
272272
273273
EXAMPLES::
274-
274+
275275
sage: X = [0,1,2,3,4,5,6]
276276
sage: Y = [[0,5],[1,4],[1,5],[3,6],[4,3],[5,6],[6,2]]
277277
sage: P = Poset((X,Y), cover_relations = True, facade=False)
@@ -294,31 +294,23 @@ def is_supergreedy(self):
294294
sage: T.linear_extensions()[0].is_supergreedy()
295295
True
296296
"""
297-
P = self.poset()
298-
H = P.hasse_diagram()
299-
300-
def next_elements(H, linext):
301-
k = len(linext)
302-
S = []
303-
while not S:
304-
if not k:
305-
S = [x for x in H.sources() if x not in linext]
306-
else:
307-
S = [x for x in H.neighbor_out_iterator(linext[k-1]) if x not in linext and all(low in linext for low in H.neighbor_in_iterator(x))]
308-
k -= 1
309-
return S
310-
if not self:
311-
return True
312-
if self[0] not in H.sources():
313-
return False
314-
for i in range(len(self)-2):
315-
X = next_elements(H,self[:i+1])
316-
if self[i+1] in X:
317-
continue
318-
else:
297+
H = self.poset().hasse_diagram()
298+
L = sources = H.sources()
299+
linext = []
300+
for e in self:
301+
if e not in L:
319302
return False
303+
linext.append(e)
304+
for y in reversed(linext):
305+
L = [x for x in H.neighbor_out_iterator(y)
306+
if x not in linext
307+
and all(low in linext for low in H.neighbor_in_iterator(x))]
308+
if L:
309+
break
310+
else:
311+
L = sources = [x for x in sources if x not in linext]
320312
return True
321-
313+
322314
def tau(self, i):
323315
r"""
324316
Return the operator `\tau_i` on linear extensions ``self`` of a poset.

0 commit comments

Comments
 (0)