Пример #1
0
 def test_binary_multi_extend_errors(self):
     self.assertRaises(
         AttributeError,
         lambda: extension.binary_multi_extend(1, 2, sets.union))
     self.assertRaises(
         AttributeError,
         lambda: extension.binary_multi_extend(Multiset(1), 2, sets.union))
     self.assertRaises(
         AttributeError,
         lambda: extension.binary_multi_extend(1, Multiset(2), sets.union))
Пример #2
0
    def cross_intersect(multiclan1: 'P(P(M x M) x N)',
                        multiclan2: 'PP(M x M)',
                        _checked=True) -> 'PP(M x M)':
        r"""Return the :term:`cross-intersection` of ``multiclan1`` and ``multiclan2``.

        :return: The :term:`binary multi-extension` of :term:`intersection` from the :term:`algebra
            of relations` (which inherits it from the :term:`algebra of sets`) to the :term:`algebra
            of multiclans` applied to ``multiclan1`` and ``multiclan2``, or `Undef()` if
            ``multiclan1`` or ``multiclan2`` are not :term:`multiclan`\s.
        """
        if _checked:
            if not is_member(multiclan1):
                return _undef.make_or_raise_undef2(multiclan1)
            if not is_member(multiclan2):
                return _undef.make_or_raise_undef2(multiclan2)
        else:
            assert is_member_or_undef(multiclan1)
            assert is_member_or_undef(multiclan2)
            if multiclan1 is _undef.Undef() or multiclan2 is _undef.Undef():
                return _undef.make_or_raise_undef(2)
        result = _extension.binary_multi_extend(multiclan1,
                                                multiclan2,
                                                _functools.partial(
                                                    _sets.intersect,
                                                    _checked=False),
                                                _checked=False)
        if not result.is_empty:
            result.cache_multiclan(_mo.CacheStatus.IS)
            if multiclan1.cached_is_functional or multiclan2.cached_is_functional:
                result.cache_functional(_mo.CacheStatus.IS)
            if multiclan1.cached_is_right_functional or multiclan2.cached_is_right_functional:
                result.cache_right_functional(_mo.CacheStatus.IS)
        return result
Пример #3
0
    def cross_right_functional_union(
            multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)',
            _checked=True) -> 'P(P(M x M) x N)':
        r"""Return the :term:`cross-right-functional union` of ``multiclan1`` and ``multiclan2``.

        :return: The :term:`binary multi-extension` of the :term:`right-functional union` from the
            :term:`algebra of relations` to the :term:`algebra of multiclans`, applied to
            ``multiclan1`` and ``multiclan2``, or `Undef()` if ``multiclan1`` or ``multiclan2`` are
            not :term:`multiclan`\s.
        """
        if _checked:
            if not is_member(multiclan1):
                return _undef.make_or_raise_undef()
            if not is_member(multiclan2):
                return _undef.make_or_raise_undef()
        else:
            assert is_member(multiclan1)
            assert is_member(multiclan2)
        result = _extension.binary_multi_extend(multiclan1, multiclan2, _functools.partial(
            _relations.right_functional_union, _checked=False), _checked=False)
        if not result.is_empty:
            result.cache_multiclan(_mo.CacheStatus.IS)
            result.cache_right_functional(_mo.CacheStatus.IS)
            if multiclan1.cached_is_not_functional or multiclan2.cached_is_not_functional:
                result.cache_functional(_mo.CacheStatus.IS_NOT)
        return result
Пример #4
0
    def cross_intersect(multiclan1: 'P(P(M x M) x N)', multiclan2: 'PP(M x M)',
                        _checked=True) -> 'PP(M x M)':
        r"""Return the :term:`cross-intersection` of ``multiclan1`` and ``multiclan2``.

        :return: The :term:`binary multi-extension` of :term:`intersection` from the :term:`algebra
            of relations` (which inherits it from the :term:`algebra of sets`) to the :term:`algebra
            of multiclans` applied to ``multiclan1`` and ``multiclan2``, or `Undef()` if
            ``multiclan1`` or ``multiclan2`` are not :term:`multiclan`\s.
        """
        if _checked:
            if not is_member(multiclan1):
                return _undef.make_or_raise_undef2(multiclan1)
            if not is_member(multiclan2):
                return _undef.make_or_raise_undef2(multiclan2)
        else:
            assert is_member_or_undef(multiclan1)
            assert is_member_or_undef(multiclan2)
            if multiclan1 is _undef.Undef() or multiclan2 is _undef.Undef():
                return _undef.make_or_raise_undef(2)
        result = _extension.binary_multi_extend(multiclan1, multiclan2, _functools.partial(
            _sets.intersect, _checked=False), _checked=False)
        if not result.is_empty:
            result.cache_multiclan(_mo.CacheStatus.IS)
            if multiclan1.cached_is_functional or multiclan2.cached_is_functional:
                result.cache_functional(_mo.CacheStatus.IS)
            if multiclan1.cached_is_right_functional or multiclan2.cached_is_right_functional:
                result.cache_right_functional(_mo.CacheStatus.IS)
        return result
Пример #5
0
    def compose(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)',
                _checked=True) -> 'P(P(M x M) x N)':
        r"""Return the composition of ``multiclan1`` with ``multiclan2``.

        :return: The :term:`binary multi-extension` of :term:`composition` from the
            :term:`algebra of relations` to the :term:`algebra of multiclans`, applied to
            ``multiclan1`` and ``multiclan2``, or `Undef()` if ``multiclan1`` or ``multiclan2``
            are not :term:`multiclan`\s.
        """
        if _checked:
            if not is_member(multiclan1):
                return _undef.make_or_raise_undef2(multiclan1)
            if not is_member(multiclan2):
                return _undef.make_or_raise_undef2(multiclan2)
        else:
            assert is_member_or_undef(multiclan1)
            assert is_member_or_undef(multiclan2)
            if multiclan1 is _undef.Undef() or multiclan2 is _undef.Undef():
                return _undef.make_or_raise_undef(2)
        result = _extension.binary_multi_extend(multiclan1, multiclan2, _functools.partial(
            _relations.compose, _checked=False), _checked=False)
        if not result.is_empty:
            result.cache_multiclan(_mo.CacheStatus.IS)
            if multiclan1.cached_is_absolute and multiclan2.cached_is_absolute:
                result.cache_absolute(_mo.CacheStatus.IS)
            if multiclan1.cached_is_functional and multiclan2.cached_is_functional:
                result.cache_functional(_mo.CacheStatus.IS)
            if multiclan1.cached_is_right_functional and multiclan2.cached_is_right_functional:
                result.cache_right_functional(_mo.CacheStatus.IS)
        return result
Пример #6
0
    def compose(multiclan1: 'P(P(M x M) x N)',
                multiclan2: 'P(P(M x M) x N)',
                _checked=True) -> 'P(P(M x M) x N)':
        r"""Return the composition of ``multiclan1`` with ``multiclan2``.

        :return: The :term:`binary multi-extension` of :term:`composition` from the
            :term:`algebra of relations` to the :term:`algebra of multiclans`, applied to
            ``multiclan1`` and ``multiclan2``, or `Undef()` if ``multiclan1`` or ``multiclan2``
            are not :term:`multiclan`\s.
        """
        if _checked:
            if not is_member(multiclan1):
                return _undef.make_or_raise_undef2(multiclan1)
            if not is_member(multiclan2):
                return _undef.make_or_raise_undef2(multiclan2)
        else:
            assert is_member_or_undef(multiclan1)
            assert is_member_or_undef(multiclan2)
            if multiclan1 is _undef.Undef() or multiclan2 is _undef.Undef():
                return _undef.make_or_raise_undef(2)
        result = _extension.binary_multi_extend(multiclan1,
                                                multiclan2,
                                                _functools.partial(
                                                    _relations.compose,
                                                    _checked=False),
                                                _checked=False)
        if not result.is_empty:
            result.cache_multiclan(_mo.CacheStatus.IS)
            if multiclan1.cached_is_absolute and multiclan2.cached_is_absolute:
                result.cache_absolute(_mo.CacheStatus.IS)
            if multiclan1.cached_is_functional and multiclan2.cached_is_functional:
                result.cache_functional(_mo.CacheStatus.IS)
            if multiclan1.cached_is_right_functional and multiclan2.cached_is_right_functional:
                result.cache_right_functional(_mo.CacheStatus.IS)
        return result
Пример #7
0
    def cross_functional_union(mclan1: 'P(P(M x M) x N)',
                               mclan2: 'P(P(M x M) x N)',
                               _checked=True) -> 'P(P(M x M) x N)':
        r"""Return the :term:`cross-functional union` of ``mclan1`` and ``mclan2``.

        :return: The :term:`binary multi-extension` of the :term:`functional union` from the
            :term:`algebra of relations` to the :term:`algebra of multiclans`, applied to
            ``mclan1`` and ``mclan2``, or `Undef()` if ``mclan1`` or ``mclan2`` are
            not :term:`multiclan`\s.
        """
        if _checked:
            if not is_member(mclan1):
                return _undef.make_or_raise_undef2(mclan1)
            if not is_member(mclan2):
                return _undef.make_or_raise_undef2(mclan2)
        else:
            assert is_member_or_undef(mclan1)
            assert is_member_or_undef(mclan2)
            if mclan1 is _undef.Undef() or mclan2 is _undef.Undef():
                return _undef.make_or_raise_undef(2)
        result = _extension.binary_multi_extend(
            mclan1,
            mclan2,
            _functools.partial(_relations.functional_union, _checked=False),
            _checked=False)
        if not result.is_empty:
            result.cache_multiclan(CacheStatus.IS)
            result.cache_functional(CacheStatus.IS)
            if mclan1.cached_is_not_right_functional or mclan2.cached_is_not_right_functional:
                result.cache_right_functional(CacheStatus.IS_NOT)
        return result
    def test_intersect(self):
        self._check_wrong_argument_types_binary(intersect)

        result = intersect(_set1, _set2)
        self.assertEqual(result, _set1i2)
        a_c_0 = Multiset([Multiset('a'), Multiset('a'), Multiset('c'), Multiset()])
        ci = extension.binary_multi_extend(_ab_c, _ac_a, intersect)
        self.assertEqual(ci, a_c_0)
 def test_union(self):
     self._check_wrong_argument_types_binary(union)
     result = union(_set1, _set2)
     self.assertEqual(result, _set1u2)
     abc_ab_ac = Multiset([Multiset('a', 'b', 'c'), Multiset('a', 'b'), Multiset('a', 'c'),
                           Multiset('a', 'c')])
     ab_c = _ab_c
     ac_a = _ac_a
     cu = extension.binary_multi_extend(ab_c, ac_a, union)
     self.assertEqual(cu, abc_ab_ac)
    def test_intersect(self):
        self._check_wrong_argument_types_binary(intersect)

        result = intersect(_set1, _set2)
        self.assertEqual(result, _set1i2)
        a_c_0 = Multiset(
            [Multiset('a'),
             Multiset('a'),
             Multiset('c'),
             Multiset()])
        ci = extension.binary_multi_extend(_ab_c, _ac_a, intersect)
        self.assertEqual(ci, a_c_0)
 def test_union(self):
     self._check_wrong_argument_types_binary(union)
     result = union(_set1, _set2)
     self.assertEqual(result, _set1u2)
     abc_ab_ac = Multiset([
         Multiset('a', 'b', 'c'),
         Multiset('a', 'b'),
         Multiset('a', 'c'),
         Multiset('a', 'c')
     ])
     ab_c = _ab_c
     ac_a = _ac_a
     cu = extension.binary_multi_extend(ab_c, ac_a, union)
     self.assertEqual(cu, abc_ab_ac)
Пример #12
0
    def superstrict(multiclan1: 'P(P(M x M) x N)',
                    multiclan2: 'P(P(M x M) x N)',
                    _checked=True) -> 'P(P(M x M) x N)':
        r"""Return the superstriction of ``multiclan1`` and ``multiclan2``.

        The :term:`superstriction` of two :term:`multiclan`\s is a multiclan that contains all
        :term:`relation`\s from ``multiclan1`` that are a :term:`supermultiset` of a relation from
        ``multiclan2``.

        :return: The :term:`binary multi-extension` of :term:`superstriction` from the
            :term:`algebra of relations` (which inherits it from the :term:`algebra of sets`) to the
            :term:`algebra of multiclans` applied to ``multiclan1`` and ``multiclan2``, or `Undef()`
            if ``multiclan1`` or ``multiclan2`` are not :term:`multiclan`\s.
        """
        if _checked:
            if not is_member(multiclan1):
                return _undef.make_or_raise_undef2(multiclan1)
            if not is_member(multiclan2):
                return _undef.make_or_raise_undef2(multiclan2)
        else:
            assert is_member_or_undef(multiclan1)
            assert is_member_or_undef(multiclan2)
            if multiclan1 is _undef.Undef() or multiclan2 is _undef.Undef():
                return _undef.make_or_raise_undef(2)
        result = _extension.binary_multi_extend(multiclan1,
                                                multiclan2,
                                                _functools.partial(
                                                    _sets.superstrict,
                                                    _checked=False),
                                                _checked=False)
        for elem, multi in result.data.items():
            result.data[elem] = multiclan2.data[elem]
        if not result.is_empty:
            result.cache_multiclan(_mo.CacheStatus.IS)
            if multiclan1.cached_is_functional:
                result.cache_functional(_mo.CacheStatus.IS)
            if multiclan1.cached_is_right_functional:
                result.cache_right_functional(_mo.CacheStatus.IS)
            if multiclan1.cached_is_reflexive:
                result.cache_reflexive(_mo.CacheStatus.IS)
            if multiclan1.cached_is_symmetric:
                result.cache_symmetric(_mo.CacheStatus.IS)
            if multiclan1.cached_is_transitive:
                result.cache_transitive(_mo.CacheStatus.IS)
            if multiclan1.cached_is_regular:
                result.cache_regular(_mo.CacheStatus.IS)
            if multiclan1.cached_is_right_regular:
                result.cache_right_regular(_mo.CacheStatus.IS)
        return result
Пример #13
0
    def superstrict(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)',
                    _checked=True) -> 'P(P(M x M) x N)':
        r"""Return the superstriction of ``multiclan1`` and ``multiclan2``.

        The :term:`superstriction` of two :term:`multiclan`\s is a multiclan that contains all
        :term:`relation`\s from ``multiclan1`` that are a :term:`supermultiset` of a relation from
        ``multiclan2``.

        :return: The :term:`binary multi-extension` of :term:`superstriction` from the
            :term:`algebra of relations` (which inherits it from the :term:`algebra of sets`) to the
            :term:`algebra of multiclans` applied to ``multiclan1`` and ``multiclan2``, or `Undef()`
            if ``multiclan1`` or ``multiclan2`` are not :term:`multiclan`\s.
        """
        if _checked:
            if not is_member(multiclan1):
                return _undef.make_or_raise_undef2(multiclan1)
            if not is_member(multiclan2):
                return _undef.make_or_raise_undef2(multiclan2)
        else:
            assert is_member_or_undef(multiclan1)
            assert is_member_or_undef(multiclan2)
            if multiclan1 is _undef.Undef() or multiclan2 is _undef.Undef():
                return _undef.make_or_raise_undef(2)
        result = _extension.binary_multi_extend(multiclan1, multiclan2, _functools.partial(
            _sets.superstrict, _checked=False), _checked=False)
        for elem, multi in result.data.items():
            result.data[elem] = multiclan2.data[elem]
        if not result.is_empty:
            result.cache_multiclan(_mo.CacheStatus.IS)
            if multiclan1.cached_is_functional:
                result.cache_functional(_mo.CacheStatus.IS)
            if multiclan1.cached_is_right_functional:
                result.cache_right_functional(_mo.CacheStatus.IS)
            if multiclan1.cached_is_reflexive:
                result.cache_reflexive(_mo.CacheStatus.IS)
            if multiclan1.cached_is_symmetric:
                result.cache_symmetric(_mo.CacheStatus.IS)
            if multiclan1.cached_is_transitive:
                result.cache_transitive(_mo.CacheStatus.IS)
            if multiclan1.cached_is_regular:
                result.cache_regular(_mo.CacheStatus.IS)
            if multiclan1.cached_is_right_regular:
                result.cache_right_regular(_mo.CacheStatus.IS)
        return result
Пример #14
0
    def cross_union(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)',
                    _checked=True) -> 'P(P(M x M) x N)':
        r"""Return the :term:`cross-union` of ``multiclan1`` and ``multiclan2``.

        :return: The :term:`binary multi-extension` of :term:`union` from the
            :term:`algebra of relations` (which inherits it from the :term:`algebra of multisets`)
            to the :term:`algebra of multiclans` applied to ``multiclan1`` and ``multiclan2``,
            or `Undef()` if ``multiclan1`` or ``multiclan2`` are not :term:`multiclan`\s.
        """
        if _checked:
            if not is_member(multiclan1):
                return _make_or_raise_undef()
            if not is_member(multiclan2):
                return _make_or_raise_undef()
        else:
            assert is_member(multiclan1)
            assert is_member(multiclan2)
        return _extension.binary_multi_extend(multiclan1, multiclan2, partial(
            _sets.union, _checked=False), _checked=False)
Пример #15
0
    def functional_cross_union(multiclan1: 'P(P(M x M) x N)', multiclan2: 'P(P(M x M) x N)',
                               _checked=True) -> 'P(P(M x M) x N)':
        r"""Return the :term:`left-functional cross-union` of ``multiclan1`` and ``multiclan2``.

        :return: The :term:`binary multi-extension` of the :term:`left-functional union` from the
            :term:`algebra of relations` to the :term:`algebra of multiclans`, applied to
            ``multiclan1`` and ``multiclan2``, or `Undef()` if ``multiclan1`` or ``multiclan2`` are
            not :term:`multiclan`\s.
        """
        if _checked:
            if not is_member(multiclan1):
                return _make_or_raise_undef()
            if not is_member(multiclan2):
                return _make_or_raise_undef()
        else:
            assert is_member(multiclan1)
            assert is_member(multiclan2)
        return _extension.binary_multi_extend(multiclan1, multiclan2, partial(
            _relations.functional_union, _checked=False), _checked=False)
Пример #16
0
 def test_binary_multi_extend_errors(self):
     self.assertRaises(AttributeError, lambda: extension.binary_multi_extend(1, 2, sets.union))
     self.assertRaises(AttributeError, lambda: extension.binary_multi_extend(Multiset(1), 2, sets.union))
     self.assertRaises(AttributeError, lambda: extension.binary_multi_extend(1, Multiset(2), sets.union))
Пример #17
0
 def test_binary_multi_extend_errors(self):
     self.assertIs(extension.binary_multi_extend(1, 2, sets.union), Undef())
     self.assertIs(extension.binary_multi_extend(Multiset(1), 2, sets.union), Undef())
     self.assertIs(extension.binary_multi_extend(1, Multiset(2), sets.union), Undef())