@@ -255,23 +255,23 @@ def is_greedy(self):
255
255
def is_supergreedy (self ):
256
256
r"""
257
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 `.
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 `.
267
267
268
268
Informally, a linear extension is supergreedy if it "always
269
269
goes up and receedes the least"; in other words, supergreedy
270
270
linear extensions are depth-first linear extensions.
271
271
For more details see [KTZ1987]_.
272
272
273
273
EXAMPLES::
274
-
274
+
275
275
sage: X = [0,1,2,3,4,5,6]
276
276
sage: Y = [[0,5],[1,4],[1,5],[3,6],[4,3],[5,6],[6,2]]
277
277
sage: P = Poset((X,Y), cover_relations = True, facade=False)
@@ -294,31 +294,23 @@ def is_supergreedy(self):
294
294
sage: T.linear_extensions()[0].is_supergreedy()
295
295
True
296
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 :
297
+ H = self .poset ().hasse_diagram ()
298
+ L = sources = H .sources ()
299
+ linext = []
300
+ for e in self :
301
+ if e not in L :
319
302
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 ]
320
312
return True
321
-
313
+
322
314
def tau (self , i ):
323
315
r"""
324
316
Return the operator `\tau_i` on linear extensions ``self`` of a poset.
0 commit comments