Skip to content

moving linear_intervals_count to hasse as iterator #40245

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions src/sage/combinat/posets/hasse_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2433,13 +2433,56 @@
"""
return chain_poly(self._leq_storage)._sage_('q') # noqa: F821

def linear_intervals_count(self):
"""
Return the enumeration of linear intervals w.r.t. their cardinality.

An interval is linear if it is a total order.

OUTPUT: an iterator of integers

.. SEEALSO:: :meth:`is_linear_interval`

EXAMPLES::

sage: P = posets.BubblePoset(3,3)
sage: H = P._hasse_diagram
sage: list(H.linear_intervals_count())
[245, 735, 438, 144, 24]
"""
if not self:
return

Check warning on line 2454 in src/sage/combinat/posets/hasse_diagram.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/posets/hasse_diagram.py#L2454

Added line #L2454 was not covered by tests
# precomputation helps for speed:
_ = self._leq_storage

stock = [(x, x, x) for x in self]
yield len(stock)
exposant = 0
while True:
exposant += 1
next_stock = []
short_stock = [(ch[0], ch[2]) for ch in stock]
for xmin, cov_xmin, xmax in stock:
for y in self.neighbor_out_iterator(xmax):
if exposant == 1:
next_stock.append((xmin, y, y))
elif (cov_xmin, y) in short_stock:
if self.is_linear_interval(xmin, y):
next_stock.append((xmin, cov_xmin, y))
if next_stock:
yield len(next_stock)
stock = next_stock
else:
break

def is_linear_interval(self, t_min, t_max) -> bool:
"""
Return whether the interval ``[t_min, t_max]`` is linear.

This means that this interval is a total order.

EXAMPLES::

sage: # needs sage.modules
sage: P = posets.PentagonPoset()
sage: H = P._hasse_diagram
Expand Down
26 changes: 1 addition & 25 deletions src/sage/combinat/posets/posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2772,31 +2772,7 @@ def linear_intervals_count(self) -> list[int]:
"""
if not self.cardinality():
return []
# precomputation helps for speed:
if self.cardinality() > 60:
self.lequal_matrix()

H = self._hasse_diagram
stock = [(x, x, x) for x in H]
poly = [len(stock)]
exposant = 0
while True:
exposant += 1
next_stock = []
short_stock = [(ch[0], ch[2]) for ch in stock]
for xmin, cov_xmin, xmax in stock:
for y in H.neighbor_out_iterator(xmax):
if exposant == 1:
next_stock.append((xmin, y, y))
elif (cov_xmin, y) in short_stock:
if H.is_linear_interval(xmin, y):
next_stock.append((xmin, cov_xmin, y))
if next_stock:
poly.append(len(next_stock))
stock = next_stock
else:
break
return poly
return list(self._hasse_diagram.linear_intervals_count())

def is_linear_interval(self, x, y) -> bool:
"""
Expand Down
Loading