Exemplo n.º 1
0
def is_right_regular(mclan, _checked=True) -> bool:
    """Return whether ``mclan`` is right-regular.

    :return: ``True`` if ``mclan`` is :term:`right-regular`, ``False`` if not, or `Undef()` if
        ``mclan`` is not a :term:`multiclan`.
    """
    if _checked:
        if not is_member(mclan):
            return _undef.make_or_raise_undef2(mclan)
    else:
        assert is_member_or_undef(mclan)
        if mclan is _undef.Undef():
            return _undef.make_or_raise_undef(2)
    if mclan.cached_right_regular == _mo.CacheStatus.UNKNOWN:
        # The empty set is already handled in Set().__init__ via flags initialization.
        if mclan.cached_is_not_right_functional:
            mclan.cache_right_regular(_mo.CacheStatus.IS_NOT)
            return False
        itr = iter(mclan.data)
        rel = next(itr)
        if not _relations.is_right_functional(rel):
            mclan.cache_right_regular(_mo.CacheStatus.IS_NOT)
            return False
        right_set = rel.get_right_set()
        right_regular = all(
            _relations.is_right_functional(rel) and right_set == rel.get_right_set() for rel in itr)
        mclan.cache_regular(_mo.CacheStatus.from_bool(right_regular))
    return mclan.cached_is_regular
Exemplo n.º 2
0
def is_right_regular(mclan, _checked=True) -> bool:
    """Return whether ``mclan`` is right-regular.

    :return: ``True`` if ``mclan`` is :term:`right-regular`, ``False`` if not, or `Undef()` if
        ``mclan`` is not a :term:`multiclan`.
    """
    if _checked:
        if not is_member(mclan):
            return _undef.make_or_raise_undef2(mclan)
    else:
        assert is_member_or_undef(mclan)
        if mclan is _undef.Undef():
            return _undef.make_or_raise_undef(2)
    if mclan.cached_right_regular == _mo.CacheStatus.UNKNOWN:
        # The empty set is already handled in Set().__init__ via flags initialization.
        if mclan.cached_is_not_right_functional:
            mclan.cache_right_regular(_mo.CacheStatus.IS_NOT)
            return False
        itr = iter(mclan.data)
        rel = next(itr)
        if not _relations.is_right_functional(rel):
            mclan.cache_right_regular(_mo.CacheStatus.IS_NOT)
            return False
        right_set = rel.get_right_set()
        right_regular = all(
            _relations.is_right_functional(rel)
            and right_set == rel.get_right_set() for rel in itr)
        mclan.cache_regular(_mo.CacheStatus.from_bool(right_regular))
    return mclan.cached_is_regular
Exemplo n.º 3
0
def is_right_functional(clan, _checked=True) -> bool:
    """Return whether ``clan`` is right-functional.

    :return: ``True`` if every :term:`relation` in ``clan`` is :term:`right-functional`, ``False``
        if not, or `Undef()` if ``clan`` is not a :term:`clan`.
    """
    if _checked:
        if not is_member(clan):
            return _undef.make_or_raise_undef()
    else:
        assert is_member(clan)

    if clan.cached_right_functional == _mo.CacheStatus.UNKNOWN:
        # The empty set is already handled in Set().__init__ via flags initialization.
        right_functional = all(_relations.is_right_functional(rel, _checked=False) for rel in clan)
        clan.cache_right_functional(_mo.CacheStatus.from_bool(right_functional))
    return clan.cached_is_right_functional
Exemplo n.º 4
0
def is_right_functional(clan, _checked=True) -> bool:
    """Return whether ``clan`` is right-functional.

    :return: ``True`` if every :term:`relation` in ``clan`` is :term:`right-functional`, ``False``
        if not, or `Undef()` if ``clan`` is not a :term:`clan`.
    """
    if _checked:
        if not is_member(clan):
            return _undef.make_or_raise_undef2(clan)
    else:
        assert is_member_or_undef(clan)
        if clan is _undef.Undef():
            return _undef.make_or_raise_undef(2)
    if clan.cached_right_functional == CacheStatus.UNKNOWN:
        # The empty set is already handled in Set().__init__ via flags initialization.
        right_functional = all(
            _relations.is_right_functional(rel, _checked=False)
            for rel in clan)
        clan.cache_right_functional(CacheStatus.from_bool(right_functional))
    return clan.cached_is_right_functional
Exemplo n.º 5
0
def is_right_functional(mo: _mo.MathObject, _checked: bool = True) -> bool:
    r"""Return whether ``mo`` is :term:`right-functional` or `Undef()` if not applicable.

    Is implemented for :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_right_functional == _mo.CacheStatus.IS:
        return True
    if mo.cached_right_functional == _mo.CacheStatus.IS_NOT:
        return False
    if mo.cached_right_functional == _mo.CacheStatus.N_A:
        return _undef.make_or_raise_undef(2)

    # Check type (right-functional is only defined on Sets and Multisets) and algebra memberships.
    if not mo.is_set and not mo.is_multiset:
        mo.cache_right_functional(_mo.CacheStatus.N_A)
        return _undef.make_or_raise_undef(2)
    if _relations.is_member(mo):
        return _relations.is_right_functional(mo, _checked=False)
    if _clans.is_member(mo):
        return _clans.is_right_functional(mo, _checked=False)
    if _multiclans.is_member(mo):
        return _multiclans.is_right_functional(mo, _checked=False)

    # Check higher (not yet defined) algebras.
    right_functional = _is_powerset_property(mo, _clans.get_ground_set(),
                                             is_right_functional)
    if right_functional is not _undef.Undef():
        mo.cache_right_functional(_mo.CacheStatus.from_bool(right_functional))
        return right_functional

    # Nothing applied: 'right-functional' is not defined.
    mo.cache_right_functional(_mo.CacheStatus.N_A)
    return _undef.make_or_raise_undef(2)
Exemplo n.º 6
0
def is_right_functional(mo: _mo.MathObject, _checked: bool=True) -> bool:
    r"""Return whether ``mo`` is :term:`right-functional` or `Undef()` if not applicable.

    Is implemented for :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_right_functional == _mo.CacheStatus.IS:
        return True
    if mo.cached_right_functional == _mo.CacheStatus.IS_NOT:
        return False
    if mo.cached_right_functional == _mo.CacheStatus.N_A:
        return _undef.make_or_raise_undef(2)

    # Check type (right-functional is only defined on Sets and Multisets) and algebra memberships.
    if not mo.is_set and not mo.is_multiset:
        mo.cache_right_functional(_mo.CacheStatus.N_A)
        return _undef.make_or_raise_undef(2)
    if _relations.is_member(mo):
        return _relations.is_right_functional(mo, _checked=False)
    if _clans.is_member(mo):
        return _clans.is_right_functional(mo, _checked=False)
    if _multiclans.is_member(mo):
        return _multiclans.is_right_functional(mo, _checked=False)

    # Check higher (not yet defined) algebras.
    right_functional = _is_powerset_property(mo, _clans.get_ground_set(), is_right_functional)
    if right_functional is not _undef.Undef():
        mo.cache_right_functional(_mo.CacheStatus.from_bool(right_functional))
        return right_functional

    # Nothing applied: 'right-functional' is not defined.
    mo.cache_right_functional(_mo.CacheStatus.N_A)
    return _undef.make_or_raise_undef(2)