@@ -252,6 +252,73 @@ def is_greedy(self):
252
252
return False
253
253
return True
254
254
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
+
255
322
def tau (self , i ):
256
323
r"""
257
324
Return the operator `\tau_i` on linear extensions ``self`` of a poset.
@@ -855,6 +922,7 @@ class LinearExtensionsOfPosetWithHooks(LinearExtensionsOfPoset):
855
922
Linear extensions such that the poset has well-defined
856
923
hook lengths (i.e., d-complete).
857
924
"""
925
+
858
926
def cardinality (self ):
859
927
r"""
860
928
Count the number of linear extensions using a hook-length formula.
@@ -879,6 +947,7 @@ class LinearExtensionsOfForest(LinearExtensionsOfPoset):
879
947
r"""
880
948
Linear extensions such that the poset is a forest.
881
949
"""
950
+
882
951
def cardinality (self ):
883
952
r"""
884
953
Use Atkinson's algorithm to compute the number of linear extensions.
@@ -902,6 +971,7 @@ class LinearExtensionsOfMobile(LinearExtensionsOfPoset):
902
971
r"""
903
972
Linear extensions for a mobile poset.
904
973
"""
974
+
905
975
def cardinality (self ):
906
976
r"""
907
977
Return the number of linear extensions by using the determinant
0 commit comments