Skip to content

Commit

Permalink
further details in posets
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Jan 22, 2024
1 parent b34ac5f commit 2266a35
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
25 changes: 14 additions & 11 deletions src/sage/combinat/posets/hasse_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,11 +1109,11 @@ def moebius_function_matrix(self, algorithm='cython'):
m[(i, k)] = -ZZ.sum(m[(j, k)]
for j in available
if k in greater_than[j])
M = matrix(ZZ, n, n, m, sparse=True)
M = matrix(ZZ, n, n, m, sparse=True) # noqa: F821
elif algorithm == "matrix":
M = self.lequal_matrix().inverse_of_unit()
elif algorithm == "cython":
M = moebius_matrix_fast(self._leq_storage)
M = moebius_matrix_fast(self._leq_storage) # noqa: F821
else:
raise ValueError("unknown algorithm")
self._moebius_function_matrix = M
Expand Down Expand Up @@ -1187,7 +1187,7 @@ def coxeter_transformation(self, algorithm='cython'):
if algorithm == 'matrix':
return - self.lequal_matrix() * self.moebius_function_matrix().transpose()
elif algorithm == 'cython':
return coxeter_matrix_fast(self._leq_storage)
return coxeter_matrix_fast(self._leq_storage) # noqa: F821
else:
raise ValueError("unknown algorithm")

Expand Down Expand Up @@ -1324,11 +1324,11 @@ def _leq_matrix_boolean(self):
Finite Field of size 2
"""
n = self.order()
R = GF(2)
R = GF(2) # noqa: F821
one = R.one()
greater_than = self._leq_storage
D = {(i, j): one for i in range(n) for j in greater_than[i]}
M = matrix(R, n, n, D, sparse=True)
M = matrix(R, n, n, D, sparse=True) # noqa: F821
M.set_immutable()
return M

Expand Down Expand Up @@ -1359,7 +1359,7 @@ def _leq_matrix(self):
n = self.order()
greater_than = self._leq_storage
D = {(i, j): 1 for i in range(n) for j in greater_than[i]}
return matrix(ZZ, n, n, D, sparse=True, immutable=True)
return matrix(ZZ, n, n, D, sparse=True, immutable=True) # noqa: F821

def lequal_matrix(self, boolean=False):
r"""
Expand Down Expand Up @@ -1544,7 +1544,7 @@ def _meet(self):
self._meet_semilattice_failure = ()
n = self.cardinality()
if n == 0:
return matrix(0)
return matrix(0) # noqa: F821
meet = [[-1 for x in range(n)] for x in range(n)]
lc = [self.neighbors_in(x) for x in range(n)] # Lc = lower covers

Expand All @@ -1564,7 +1564,7 @@ def _meet(self):
meet[y][x] = q
if q == -1:
self._meet_semilattice_failure += ((x, y),)
return matrix(ZZ, meet)
return matrix(ZZ, meet) # noqa: F821

def meet_matrix(self):
r"""
Expand Down Expand Up @@ -1708,7 +1708,7 @@ def _join(self):
self._join_semilattice_failure = ()
n = self.cardinality()
if n == 0:
return matrix(0)
return matrix(0) # noqa: F821
join = [[-1 for x in range(n)] for x in range(n)]
uc = [self.neighbors_out(x) for x in range(n)] # uc = upper covers

Expand All @@ -1729,7 +1729,7 @@ def _join(self):
if q == -1:
self._join_semilattice_failure += ((x, y),)

return matrix(ZZ, join)
return matrix(ZZ, join) # noqa: F821

def join_matrix(self):
r"""
Expand Down Expand Up @@ -3143,7 +3143,7 @@ def atoms_of_congruence_lattice(self):

return min_congruences

def congruence(self, parts, start=None, stop_pairs=[]):
def congruence(self, parts, start=None, stop_pairs=None):
"""
Return the congruence ``start`` "extended" by ``parts``.
Expand Down Expand Up @@ -3207,6 +3207,9 @@ def congruence(self, parts, start=None, stop_pairs=[]):
from sage.sets.disjoint_set import DisjointSet
from copy import copy

if stop_pairs is None:
stop_pairs = []

n = self.order()
mt = self.meet_matrix()
jn = self.join_matrix()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/posets/lattices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ def join(L):
return (B, [self._vertex_to_element(e) for e in A])
else:
return B
assert False, "BUG: breadth() in lattices.py have an error."
raise RuntimeError("BUG: breadth() in lattices.py have an error")

Check warning on line 2006 in src/sage/combinat/posets/lattices.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/posets/lattices.py#L2006

Added line #L2006 was not covered by tests

def complements(self, element=None):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/posets/poset_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@ def YoungFibonacci(n):

covers = []
current_level = ['']
for i in range(1, n + 1):
for _ in range(1, n + 1):
new_level = set()
for low in current_level:
ind = low.find('1')
Expand Down
10 changes: 8 additions & 2 deletions src/sage/combinat/posets/posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4715,7 +4715,7 @@ def isomorphic_subposets(self, other):
return [self.subposet([self._list[i] for i in x]) for x in sorted({frozenset(y) for y in L})]

# Caveat: list is overridden by the method list above!!!
def antichains(self, element_constructor=type([])):
def antichains(self, element_constructor=None):
"""
Return the antichains of the poset.
Expand Down Expand Up @@ -4779,6 +4779,9 @@ def antichains(self, element_constructor=type([])):
"""
vertex_to_element = self._vertex_to_element

if element_constructor is None:
element_constructor = list

def f(antichain):
return element_constructor(vertex_to_element(x) for x in antichain)
result = self._hasse_diagram.antichains(element_class=f)
Expand Down Expand Up @@ -4921,7 +4924,7 @@ def dilworth_decomposition(self):
chains.append(chain)
return chains

def chains(self, element_constructor=type([]), exclude=None):
def chains(self, element_constructor=None, exclude=None):
"""
Return the chains of the poset.
Expand Down Expand Up @@ -4969,6 +4972,9 @@ def chains(self, element_constructor=type([]), exclude=None):
.. SEEALSO:: :meth:`maximal_chains`, :meth:`antichains`
"""
if element_constructor is None:
element_constructor = list

if exclude is not None:
exclude = [self._element_to_vertex(x) for x in exclude]
result = self._hasse_diagram.chains(element_class=element_constructor,
Expand Down

0 comments on commit 2266a35

Please sign in to comment.