def is_absolute_member(obj: _mo.MathObject) -> bool: """Return whether ``obj`` is a member of the :term:`absolute ground set` of this algebra. :return: ``True`` if ``obj`` is an :term:`absolute clan`, ``False`` if not. .. note:: This function may call :meth:`~.MathObject.get_ground_set` on ``obj``. The result of this operation is cached. """ if obj.cached_is_not_clan: # If known to not be a clan, it's also not an absolute clan. No further caching. return False # The `or` clause in this `if` statement is a safety thing. It should never hit. if obj.cached_absolute == _mo.CacheStatus.UNKNOWN or obj.cached_clan == _mo.CacheStatus.UNKNOWN: # The 'absolute' state has not yet been cached. Determine whether obj is an absolute clan. is_absolute_clan = obj.get_ground_set().is_subset(get_absolute_ground_set()) if obj.cached_clan == _mo.CacheStatus.UNKNOWN: if is_absolute_clan: # If it is an absolute clan, it is also a clan. obj.cache_clan(_mo.CacheStatus.IS) else: # If it is not an absolute clan, it may still be a clan. is_clan = is_member(obj) if not is_clan: # If it is neither an absolute clan nor a clan, exit. (That it is not a clan # has already been cached in is_member().) return False # At this point, cached_clan == IS. Cache whether this is an absolute clan. assert obj.cached_is_clan obj.cache_absolute(_mo.CacheStatus.from_bool(is_absolute_clan)) # At this point, cached_clan == IS. Return whether it is an absolute clan. return obj.cached_is_absolute
def is_absolute_member(obj: _mo.MathObject) -> bool: """Return whether ``obj`` is a member of the :term:`absolute ground set` of this algebra. :return: ``True`` if ``obj`` is an :term:`absolute clan`, ``False`` if not. .. note:: This function may call :meth:`~.MathObject.get_ground_set` on ``obj``. The result of this operation is cached. """ if obj.cached_is_not_clan: # If known to not be a clan, it's also not an absolute clan. No further caching. return False # The `or` clause in this `if` statement is a safety thing. It should never hit. if obj.cached_absolute == _mo.CacheStatus.UNKNOWN or obj.cached_clan == _mo.CacheStatus.UNKNOWN: # The 'absolute' state has not yet been cached. Determine whether obj is an absolute clan. is_absolute_clan = obj.get_ground_set().is_subset( get_absolute_ground_set()) if obj.cached_clan == _mo.CacheStatus.UNKNOWN: if is_absolute_clan: # If it is an absolute clan, it is also a clan. obj.cache_clan(_mo.CacheStatus.IS) else: # If it is not an absolute clan, it may still be a clan. is_clan = is_member(obj) if not is_clan: # If it is neither an absolute clan nor a clan, exit. (That it is not a clan # has already been cached in is_member().) return False # At this point, cached_clan == IS. Cache whether this is an absolute clan. assert obj.cached_is_clan obj.cache_absolute(_mo.CacheStatus.from_bool(is_absolute_clan)) # At this point, cached_clan == IS. Return whether it is an absolute clan. return obj.cached_is_absolute
def is_member(obj: _mo.MathObject) -> bool: """Return whether ``obj`` is a member of the :term:`ground set` of this :term:`algebra`. :return: ``True`` if ``obj`` is a :term:`clan`, ``False`` if not. .. note:: This function may call :meth:`~.MathObject.get_ground_set` on ``obj``. The result of this operation is cached. """ if obj.cached_clan == _mo.CacheStatus.UNKNOWN: is_clan = obj.get_ground_set().is_subset(get_ground_set()) obj.cache_clan(_mo.CacheStatus.from_bool(is_clan)) return obj.cached_is_clan