Exemplo n.º 1
0
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 relation`, ``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_relation:
        # If known to not be a relation, it's also not an absolute relation. 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_relation == _mo.CacheStatus.UNKNOWN:
        # The 'absolute' state has not yet been cached. Determine whether obj is an absolute
        # relation.
        is_absolute_relation = obj.get_ground_set().is_subset(get_absolute_ground_set())
        if obj.cached_relation == _mo.CacheStatus.UNKNOWN:
            if is_absolute_relation:
                # If it is an absolute relation, it is also a relation.
                obj.cache_relation(_mo.CacheStatus.IS)
            else:
                # If it is not an absolute relation, it may still be a relation.
                is_relation = is_member(obj)
                if not is_relation:
                    # If it is neither an absolute relation nor a relation, exit. (That it is not a
                    # relation has already been cached in is_member().)
                    return False
        # At this point, cached_relation == IS. Cache whether this is an absolute relation.
        assert obj.cached_is_relation
        obj.cache_absolute(_mo.CacheStatus.from_bool(is_absolute_relation))
    # At this point, cached_relation == IS. Return whether it is an absolute relation.
    return obj.cached_is_absolute
Exemplo n.º 2
0
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 relation`, ``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_relation:
        # If known to not be a relation, it's also not an absolute relation. 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_relation == _mo.CacheStatus.UNKNOWN:
        # The 'absolute' state has not yet been cached. Determine whether obj is an absolute
        # relation.
        is_absolute_relation = obj.get_ground_set().is_subset(
            get_absolute_ground_set())
        if obj.cached_relation == _mo.CacheStatus.UNKNOWN:
            if is_absolute_relation:
                # If it is an absolute relation, it is also a relation.
                obj.cache_relation(_mo.CacheStatus.IS)
            else:
                # If it is not an absolute relation, it may still be a relation.
                is_relation = is_member(obj)
                if not is_relation:
                    # If it is neither an absolute relation nor a relation, exit. (That it is not a
                    # relation has already been cached in is_member().)
                    return False
        # At this point, cached_relation == IS. Cache whether this is an absolute relation.
        assert obj.cached_is_relation
        obj.cache_absolute(_mo.CacheStatus.from_bool(is_absolute_relation))
    # At this point, cached_relation == IS. Return whether it is an absolute relation.
    return obj.cached_is_absolute
Exemplo n.º 3
0
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:`relation`, ``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_relation == _mo.CacheStatus.UNKNOWN:
        is_relation = obj.get_ground_set().is_subset(get_ground_set())
        obj.cache_relation(_mo.CacheStatus.from_bool(is_relation))
    return obj.cached_is_relation
Exemplo n.º 4
0
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:`relation`, ``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_relation == _mo.CacheStatus.UNKNOWN:
        is_relation = obj.get_ground_set().is_subset(get_ground_set())
        obj.cache_relation(_mo.CacheStatus.from_bool(is_relation))
    return obj.cached_is_relation