Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add is_supergreedy() to linear extensions #34970

Merged
merged 24 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
86fc48d
added is_supergreedy() function
Sandstorm831 Jan 16, 2023
cef5e45
implemented diff algo, for borderline cases
Sandstorm831 Jan 18, 2023
200441d
correcting function for disjoint set of points
Sandstorm831 Jan 22, 2023
5cd17f1
correcting function
Sandstorm831 Jan 24, 2023
1406cdc
documentation changes
Sandstorm831 Jan 24, 2023
7cd5a2a
minor chagnges
Sandstorm831 Feb 6, 2023
13f8b7a
Merge branch 'develop' into u/gh-Sandstorm831/24700
tobiasdiez Feb 8, 2023
297d317
fixing_failing_tests
Sandstorm831 Feb 8, 2023
359389e
Merge branch 'u/gh-Sandstorm831/24700' of https://github.com/Sandstor…
Sandstorm831 Feb 8, 2023
75b9ed3
minor documentation correction
Sandstorm831 Feb 9, 2023
52d2a59
Update linear_extensions.py
Sandstorm831 Feb 12, 2023
6da7a3d
corrected TeX maths in docstrings
Sandstorm831 Feb 12, 2023
4fc747e
further fixes to supergreedy docstring
dimpase Feb 12, 2023
bb8cc91
Added Reference
Sandstorm831 Feb 13, 2023
b79e509
Merge branch 'develop' into u/gh-Sandstorm831/24700
Sandstorm831 Feb 14, 2023
40db71d
adding reference
Sandstorm831 Feb 14, 2023
150b9ba
reformatting function
Sandstorm831 Feb 19, 2023
ea4903e
Merge branch 'develop' into u/gh-Sandstorm831/24700
Sandstorm831 Feb 21, 2023
c84344a
optimizing the function
Sandstorm831 Feb 23, 2023
92f6620
improving understandability
Sandstorm831 Feb 25, 2023
0148485
Merge branch 'develop' into u/gh-Sandstorm831/24700
Sandstorm831 Feb 26, 2023
262d0a0
improving definition of supergreedy
Sandstorm831 Feb 26, 2023
4a29e1c
fixing docstrings
Sandstorm831 Feb 26, 2023
2c15778
implementing a concise function
Sandstorm831 Feb 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/doc/en/reference/references/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3870,6 +3870,7 @@ REFERENCES:
set as the intersection of super greedy linear extensions. Order 4,
293-311 (1987).
:doi:`10.1007/BF00337892`

.. [Kuh1987] \W. Kühnel, "Minimal triangulations of Kummer varieties",
Abh. Math. Sem. Univ. Hamburg 57 (1987), 7-20.

Expand Down
58 changes: 25 additions & 33 deletions src/sage/combinat/posets/linear_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,23 +255,23 @@ def is_greedy(self):
def is_supergreedy(self):
r"""
Return ``True`` if the linear extension is supergreedy.
A linear extension `[x_1<x_2<...<x_t]` of a finite ordered
set `P=(P, <)` is *super greedy* if it can be obtained using
the following procedure: Choose `x_1` to be a minimal
element of `P`; suppose `x_1,...,x_i` have been chosen;
define `p(x)` to be the largest `j\leq i` such that `x_j<x`
if such a `j` exists and 0 otherwise; choose `x_{i+1}`
to be a minimal element of `P-\{x_1,...,x_i\}` which
maximizes `p`.

A linear extension of a poset `P` with elements `\{x_1,x_2,...,x_t\}`
is *super greedy*, if it can be obtained using the following
algorithm: choose `x_1` to be a minimal element of `P`;
suppose `X = \{x_1,...,x_i\}` have been chosen; let `M` be
the set of minimal elements of `P\setminus X`. If there is an element
of `M` which covers an element `x_j` in `X`, then let `x_{i+1}`
be one of these such that `j` is maximal; otherwise, choose `x_{i+1}`
to be any element of `M`.

Informally, a linear extension is supergreedy if it "always
goes up and receedes the least"; in other words, supergreedy
linear extensions are depth-first linear extensions.
For more details see [KTZ1987]_.

EXAMPLES::

sage: X = [0,1,2,3,4,5,6]
sage: Y = [[0,5],[1,4],[1,5],[3,6],[4,3],[5,6],[6,2]]
sage: P = Poset((X,Y), cover_relations = True, facade=False)
Expand All @@ -294,31 +294,23 @@ def is_supergreedy(self):
sage: T.linear_extensions()[0].is_supergreedy()
True
"""
P = self.poset()
H = P.hasse_diagram()

def next_elements(H, linext):
k = len(linext)
S = []
while not S:
if not k:
S = [x for x in H.sources() if x not in linext]
else:
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))]
k -= 1
return S
if not self:
return True
if self[0] not in H.sources():
return False
for i in range(len(self)-2):
X = next_elements(H,self[:i+1])
if self[i+1] in X:
continue
else:
H = self.poset().hasse_diagram()
L = sources = H.sources()
linext = []
for e in self:
if e not in L:
return False
linext.append(e)
for y in reversed(linext):
L = [x for x in H.neighbor_out_iterator(y)
if x not in linext
and all(low in linext for low in H.neighbor_in_iterator(x))]
if L:
break
else:
L = sources = [x for x in sources if x not in linext]
return True

def tau(self, i):
r"""
Return the operator `\tau_i` on linear extensions ``self`` of a poset.
Expand Down