Skip to content

Commit 3b94a2e

Browse files
author
Release Manager
committed
gh-pr-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, Rohan Garg, Tobias Diez
2 parents 0b88463 + 2083932 commit 3b94a2e

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3821,6 +3821,10 @@ REFERENCES:
38213821
*Bethe ansatz and inverse scattering transform in a periodic
38223822
box-ball system*, Nuclear Phys. B **747**, no. 3 (2006), 354--397.
38233823
3824+
.. [KTZ1987] Kierstead, H.A., Trotter, W.T. & Zhou, B. Representing an ordered
3825+
set as the intersection of super greedy linear extensions. Order 4,
3826+
293-311 (1987).
3827+
:doi:`10.1007/BF00337892`
38243828
.. [Kuh1987] \W. Kühnel, "Minimal triangulations of Kummer varieties",
38253829
Abh. Math. Sem. Univ. Hamburg 57 (1987), 7-20.
38263830

src/sage/combinat/posets/linear_extensions.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,73 @@ def is_greedy(self):
252252
return False
253253
return True
254254

255+
def is_supergreedy(self):
256+
r"""
257+
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`.
267+
268+
Informally, a linear extension is supergreedy if it "always
269+
goes up and receedes the least"; in other words, supergreedy
270+
linear extensions are depth-first linear extensions.
271+
For more details see [KTZ1987]_.
272+
273+
EXAMPLES::
274+
275+
sage: X = [0,1,2,3,4,5,6]
276+
sage: Y = [[0,5],[1,4],[1,5],[3,6],[4,3],[5,6],[6,2]]
277+
sage: P = Poset((X,Y), cover_relations = True, facade=False)
278+
sage: for l in P.linear_extensions():
279+
....: if l.is_supergreedy():
280+
....: print(l)
281+
[1, 4, 3, 0, 5, 6, 2]
282+
[0, 1, 4, 3, 5, 6, 2]
283+
[0, 1, 5, 4, 3, 6, 2]
284+
285+
sage: Q = posets.PentagonPoset()
286+
sage: for l in Q.linear_extensions():
287+
....: if not l.is_supergreedy():
288+
....: print(l)
289+
[0, 2, 1, 3, 4]
290+
291+
TESTS::
292+
293+
sage: T = Poset()
294+
sage: T.linear_extensions()[0].is_supergreedy()
295+
True
296+
"""
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:
319+
return False
320+
return True
321+
255322
def tau(self, i):
256323
r"""
257324
Return the operator `\tau_i` on linear extensions ``self`` of a poset.
@@ -855,6 +922,7 @@ class LinearExtensionsOfPosetWithHooks(LinearExtensionsOfPoset):
855922
Linear extensions such that the poset has well-defined
856923
hook lengths (i.e., d-complete).
857924
"""
925+
858926
def cardinality(self):
859927
r"""
860928
Count the number of linear extensions using a hook-length formula.
@@ -879,6 +947,7 @@ class LinearExtensionsOfForest(LinearExtensionsOfPoset):
879947
r"""
880948
Linear extensions such that the poset is a forest.
881949
"""
950+
882951
def cardinality(self):
883952
r"""
884953
Use Atkinson's algorithm to compute the number of linear extensions.
@@ -902,6 +971,7 @@ class LinearExtensionsOfMobile(LinearExtensionsOfPoset):
902971
r"""
903972
Linear extensions for a mobile poset.
904973
"""
974+
905975
def cardinality(self):
906976
r"""
907977
Return the number of linear extensions by using the determinant

0 commit comments

Comments
 (0)