From dcbdf00ffcb2f05292ba3f3d336aa07843b13106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jori=20M=C3=A4ntysalo?= Date: Thu, 7 Jul 2016 13:17:30 +0300 Subject: [PATCH 1/3] Add certificate to is_relatively_complemented(). --- src/sage/combinat/posets/lattices.py | 38 +++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/sage/combinat/posets/lattices.py b/src/sage/combinat/posets/lattices.py index 2b98f555758..0c45f246db8 100644 --- a/src/sage/combinat/posets/lattices.py +++ b/src/sage/combinat/posets/lattices.py @@ -802,7 +802,7 @@ def is_complemented(self): """ return self._hasse_diagram.is_complemented_lattice() - def is_relatively_complemented(self): + def is_relatively_complemented(self, certificate=False): """ Return ``True`` if the lattice is relatively complemented, and ``False`` otherwise. @@ -810,6 +810,13 @@ def is_relatively_complemented(self): A lattice is relatively complemented if every interval of it is a complemented lattice. + INPUT: + + - ``certificate``, a Boolean -- If ``False`` (the default), return + only truth value. If ``True``, return either + ``(True, None)`` or ``(False, (a, b, c))``, where `b` is the + only element that covers `a` and is covered by `c`. + EXAMPLES:: sage: L = LatticePoset({1: [2, 3, 4, 8], 2: [5, 6], 3: [5, 7], @@ -833,6 +840,11 @@ def is_relatively_complemented(self): sage: L.is_relatively_complemented() False + We can also get a non-complemented 3-element interval:: + + sage: L.is_relatively_complemented(certificate=True) + (False, (1, 6, 11)) + TESTS:: sage: [Posets.ChainPoset(i).is_relatively_complemented() for @@ -863,19 +875,27 @@ def is_relatively_complemented(self): H = self._hasse_diagram n = H.order() if n < 3: - return True + return (True, None) if certificate else True # Quick check: the lattice must be atomic and coatomic. - if H.out_degree(0) != H.in_degree().count(1): - return False - if H.in_degree(n-1) != H.out_degree().count(1): - return False + if not certificate: + if H.out_degree(0) != H.in_degree().count(1): + return False + if H.in_degree(n-1) != H.out_degree().count(1): + return False for e1 in range(n-1): C = Counter(flatten([H.neighbors_out(e2) for e2 in H.neighbors_out(e1)])) - if any(c == 1 and len(H.closed_interval(e1, e3)) == 3 for e3, c in C.iteritems()): - return False - return True + for e3, c in C.iteritems(): + if c == 1 and len(H.closed_interval(e1, e3)) == 3: + if not certificate: + return False + e2 = H.neighbors_in(e3)[0] + e1 = H.neighbors_in(e2)[0] + return (False, (self._vertex_to_element(e1), + self._vertex_to_element(e2), + self._vertex_to_element(e3))) + return (True, None) if certificate else True def breadth(self, certificate=False): r""" From f8aca83288afbeea6a78ff1db2787b2a2f808234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jori=20M=C3=A4ntysalo?= Date: Fri, 8 Jul 2016 10:17:36 +0300 Subject: [PATCH 2/3] Restructure input-output blocks. --- src/sage/combinat/posets/lattices.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/sage/combinat/posets/lattices.py b/src/sage/combinat/posets/lattices.py index 0c45f246db8..45e0c0409db 100644 --- a/src/sage/combinat/posets/lattices.py +++ b/src/sage/combinat/posets/lattices.py @@ -812,10 +812,15 @@ def is_relatively_complemented(self, certificate=False): INPUT: - - ``certificate``, a Boolean -- If ``False`` (the default), return - only truth value. If ``True``, return either - ``(True, None)`` or ``(False, (a, b, c))``, where `b` is the - only element that covers `a` and is covered by `c`. + - ``certificate`` -- (default: ``False``) Whether to return + a certificate if the lattice is not relatively complemented. + + OUTPUT: + + - If ``certificate=True`` return either ``(True, None)`` or + ``(False, (a, b, c))``, where `b` is the only element that + covers `a` and is covered by `c`. + - If ``certificate=False`` return ``True`` or ``False``. EXAMPLES:: From 1213a37113d442434e2dba2ef211f33fd9ec18e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jori=20M=C3=A4ntysalo?= Date: Mon, 11 Jul 2016 22:02:17 +0300 Subject: [PATCH 3/3] Output block format. --- src/sage/combinat/posets/lattices.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/combinat/posets/lattices.py b/src/sage/combinat/posets/lattices.py index 45e0c0409db..06429e84083 100644 --- a/src/sage/combinat/posets/lattices.py +++ b/src/sage/combinat/posets/lattices.py @@ -819,8 +819,8 @@ def is_relatively_complemented(self, certificate=False): - If ``certificate=True`` return either ``(True, None)`` or ``(False, (a, b, c))``, where `b` is the only element that - covers `a` and is covered by `c`. - - If ``certificate=False`` return ``True`` or ``False``. + covers `a` and is covered by `c`. If ``certificate=False`` + return ``True`` or ``False``. EXAMPLES::