From a03127b6c863b09a27870d4997e1d8ffddbb5a35 Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Tue, 19 Mar 2024 19:15:43 +0900 Subject: [PATCH] Implement a bool for posets. --- src/sage/combinat/posets/posets.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 36f4d1eee10..6db41768e1e 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -1230,6 +1230,21 @@ def unwrap(self, element): else: return element.element + def __bool__(self) -> bool: + r""" + Return if ``self`` is empty or not. + + EXAMPLES:: + + sage: P = Poset((divisors(15), attrcall("divides")), facade=True) + sage: bool(P) + True + sage: P = Poset() + sage: bool(P) + False + """ + return bool(self._elements) + def __contains__(self, x) -> bool: r""" Return ``True`` if ``x`` is an element of the poset.