def is_right_regular(mo: _mo.MathObject, _checked: bool = True) -> bool: r"""Return whether ``mo`` is :term:`right-regular` or `Undef()` if not applicable. Is implemented for :term:`clan`\s, :term:`multiclan`\s and :term:`set`\s of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or :term:`multiset`\s of clans. """ # pylint: disable=too-many-return-statements if _checked: if not isinstance(mo, _mo.MathObject): return _undef.make_or_raise_undef() # Check cache status. if mo.cached_right_regular == _mo.CacheStatus.IS: return True if mo.cached_right_regular == _mo.CacheStatus.IS_NOT: return False if mo.cached_right_regular == _mo.CacheStatus.N_A: return _undef.make_or_raise_undef(2) # Check type (right-regular is only defined on Sets and Multisets) and algebra memberships. if not mo.is_set and not mo.is_multiset: mo.cache_right_regular(_mo.CacheStatus.N_A) return _undef.make_or_raise_undef(2) if _clans.is_member(mo): return _clans.is_right_regular(mo, _checked=False) if _multiclans.is_member(mo): return _multiclans.is_right_regular(mo, _checked=False) # Check higher (not yet defined) algebras. if mo.get_ground_set().get_powerset_level(_clans.get_ground_set()) > 0: mo_iter = iter(mo) elem1 = next(mo_iter) if not is_right_regular(elem1): mo.cache_right_regular(_mo.CacheStatus.IS_NOT) return False elem1_rights = elem1.get_rights() right_regular = all( is_right_regular(elem, _checked=False) and elem.get_rights() == elem1_rights for elem in mo_iter) mo.cache_right_regular(_mo.CacheStatus.from_bool(right_regular)) return mo.cached_is_right_regular # Nothing applied: 'right-regular' is not defined. mo.cache_right_regular(_mo.CacheStatus.N_A) return _undef.make_or_raise_undef(2)
def is_right_regular(mo: _mo.MathObject, _checked: bool=True) -> bool: r"""Return whether ``mo`` is :term:`right-regular` or `Undef()` if not applicable. Is implemented for :term:`clan`\s, :term:`multiclan`\s and :term:`set`\s of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or :term:`multiset`\s of clans. """ # pylint: disable=too-many-return-statements if _checked: if not isinstance(mo, _mo.MathObject): return _undef.make_or_raise_undef() # Check cache status. if mo.cached_right_regular == _mo.CacheStatus.IS: return True if mo.cached_right_regular == _mo.CacheStatus.IS_NOT: return False if mo.cached_right_regular == _mo.CacheStatus.N_A: return _undef.make_or_raise_undef(2) # Check type (right-regular is only defined on Sets and Multisets) and algebra memberships. if not mo.is_set and not mo.is_multiset: mo.cache_right_regular(_mo.CacheStatus.N_A) return _undef.make_or_raise_undef(2) if _clans.is_member(mo): return _clans.is_right_regular(mo, _checked=False) if _multiclans.is_member(mo): return _multiclans.is_right_regular(mo, _checked=False) # Check higher (not yet defined) algebras. if mo.get_ground_set().get_powerset_level(_clans.get_ground_set()) > 0: mo_iter = iter(mo) elem1 = next(mo_iter) if not is_right_regular(elem1): mo.cache_right_regular(_mo.CacheStatus.IS_NOT) return False elem1_rights = elem1.get_rights() right_regular = all( is_right_regular(elem, _checked=False) and elem.get_rights() == elem1_rights for elem in mo_iter) mo.cache_right_regular(_mo.CacheStatus.from_bool(right_regular)) return mo.cached_is_right_regular # Nothing applied: 'right-regular' is not defined. mo.cache_right_regular(_mo.CacheStatus.N_A) return _undef.make_or_raise_undef(2)
def is_reflexive(mo: _mo.MathObject, _checked: bool = True) -> bool: r"""Return whether ``mo`` is :term:`reflexive` or `Undef()` if not applicable. Is implemented for :term:`couplet`\s, :term:`relation`\s, :term:`clan`\s, :term:`multiclan`\s and :term:`set`\s of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or :term:`multiset`\s of relations. """ # pylint: disable=too-many-return-statements if _checked: if not isinstance(mo, _mo.MathObject): return _undef.make_or_raise_undef() # Check cache status. if mo.cached_reflexive == _mo.CacheStatus.IS: return True if mo.cached_reflexive == _mo.CacheStatus.IS_NOT: return False if mo.cached_reflexive == _mo.CacheStatus.N_A: return _undef.make_or_raise_undef(2) # Check types and algebra memberships. if _couplets.is_member(mo): return _couplets.is_reflexive(mo, _checked=False) if not mo.is_set and not mo.is_multiset: mo.cache_reflexive(_mo.CacheStatus.N_A) return _undef.make_or_raise_undef(2) if _relations.is_member(mo): return _relations.is_reflexive(mo, _checked=False) if _clans.is_member(mo): return _clans.is_reflexive(mo, _checked=False) if _multiclans.is_member(mo): return _multiclans.is_reflexive(mo, _checked=False) # Check higher (not yet defined) algebras. reflexive = _is_powerset_property(mo, _clans.get_ground_set(), is_reflexive) if reflexive is not _undef.Undef(): mo.cache_reflexive(_mo.CacheStatus.from_bool(reflexive)) return reflexive # Nothing applied: 'reflexive' is not defined. mo.cache_reflexive(_mo.CacheStatus.N_A) return _undef.make_or_raise_undef(2)
def is_reflexive(mo: _mo.MathObject, _checked: bool=True) -> bool: r"""Return whether ``mo`` is :term:`reflexive` or `Undef()` if not applicable. Is implemented for :term:`couplet`\s, :term:`relation`\s, :term:`clan`\s, :term:`multiclan`\s and :term:`set`\s of (sets of ...) clans. Is also defined (but not yet implemented) for any combination of sets or :term:`multiset`\s of relations. """ # pylint: disable=too-many-return-statements if _checked: if not isinstance(mo, _mo.MathObject): return _undef.make_or_raise_undef() # Check cache status. if mo.cached_reflexive == _mo.CacheStatus.IS: return True if mo.cached_reflexive == _mo.CacheStatus.IS_NOT: return False if mo.cached_reflexive == _mo.CacheStatus.N_A: return _undef.make_or_raise_undef(2) # Check types and algebra memberships. if _couplets.is_member(mo): return _couplets.is_reflexive(mo, _checked=False) if not mo.is_set and not mo.is_multiset: mo.cache_reflexive(_mo.CacheStatus.N_A) return _undef.make_or_raise_undef(2) if _relations.is_member(mo): return _relations.is_reflexive(mo, _checked=False) if _clans.is_member(mo): return _clans.is_reflexive(mo, _checked=False) if _multiclans.is_member(mo): return _multiclans.is_reflexive(mo, _checked=False) # Check higher (not yet defined) algebras. reflexive = _is_powerset_property(mo, _clans.get_ground_set(), is_reflexive) if reflexive is not _undef.Undef(): mo.cache_reflexive(_mo.CacheStatus.from_bool(reflexive)) return reflexive # Nothing applied: 'reflexive' is not defined. mo.cache_reflexive(_mo.CacheStatus.N_A) return _undef.make_or_raise_undef(2)