Exemple #1
0
def get_rights_for_left(mclan: 'P(P(M x M) x N)', left: '( M )', _checked=True) -> 'P(M x N)':
    """Return the multiset of the right components of all couplets in the multiclan ``mclan``
    associated with the left component ``left``.

    :return: The :term:`right multiset` of the :term:`multiclan` ``mclan`` associated with the
        :term:`left component` ``left`` or `Undef()` if ``mclan`` is not a multiclan.
    """
    if _checked:
        if not is_member(mclan):
            return _undef.make_or_raise_undef2(mclan)
        if left is _undef.Undef():
            return _mo.Set()
        left = _mo.auto_convert(left)
    else:
        assert is_member_or_undef(mclan)
        assert _mo.is_mathobject_or_undef(left)
        if mclan is _undef.Undef():
            return _undef.make_or_raise_undef(2)
        if left is _undef.Undef():
            return _mo.Set()
    clan_itr = iter(mclan)
    rights = _sets.multify(_relations.get_rights_for_left(next(clan_itr), left, _checked=False))
    for rel in clan_itr:
        rights = _multisets.add(
            _sets.multify(_relations.get_rights_for_left(rel, left, _checked=False)),
            rights, _checked=False)
    if not rights.is_empty:
        if mclan.cached_is_absolute:
            rights.cache_absolute(_mo.CacheStatus.IS)
    return rights
    def test_simple_operations(self):
        result = union(_multiset1, _multiset2)
        self.assertEqual(result, Multiset(_collections.Counter("badog")))

        result = add(_multiset1, _multiset2)
        self.assertEqual(result, _multiset3)

        result = intersect(_multiset1, _multiset2)
        self.assertEqual(result, Multiset(_collections.Counter("d")))

        result = minus(_multiset_magic, _multiset1)
        self.assertEqual(result, Multiset(_collections.Counter("racaabra")))

        p1 = Multiset(_collections.Counter("aaa"))
        p2 = Multiset(_collections.Counter("bbb"))
        p3 = Multiset(_collections.Counter("ccc"))
        combined = Set({p1, p2, p3})
        result = big_union(combined)
        self.assertEqual(result, Multiset(_collections.Counter("abc" * 3)))

        result = big_intersect(
            Set({
                _multiset_magic,
                Multiset(_collections.Counter("abc" * 3)),
                Multiset("a", "a", "b", "c")
            }))
        self.assertEqual(result, Multiset(_collections.Counter("aabc")))
def get_rights_for_left(mclan: 'P(P(M x M) x N)',
                        left: '( M )',
                        _checked=True) -> 'P(M x N)':
    """Return the multiset of the right components of all couplets in the multiclan ``mclan``
    associated with the left component ``left``.

    :return: The :term:`right multiset` of the :term:`multiclan` ``mclan`` associated with the
        :term:`left component` ``left`` or `Undef()` if ``mclan`` is not a multiclan.
    """
    if _checked:
        if not is_member(mclan):
            return _undef.make_or_raise_undef2(mclan)
        if left is _undef.Undef():
            return _mo.Set()
        left = _mo.auto_convert(left)
    else:
        assert is_member_or_undef(mclan)
        assert _mo.is_mathobject_or_undef(left)
        if mclan is _undef.Undef():
            return _undef.make_or_raise_undef(2)
        if left is _undef.Undef():
            return _mo.Set()
    clan_itr = iter(mclan)
    rights = _sets.multify(
        _relations.get_rights_for_left(next(clan_itr), left, _checked=False))
    for rel in clan_itr:
        rights = _multisets.add(_sets.multify(
            _relations.get_rights_for_left(rel, left, _checked=False)),
                                rights,
                                _checked=False)
    if not rights.is_empty:
        if mclan.cached_is_absolute:
            rights.cache_absolute(_mo.CacheStatus.IS)
    return rights
    def test_simple_operations(self):
        result = union(_multiset1, _multiset2)
        self.assertEqual(result, Multiset(_collections.Counter("badog")))

        result = add(_multiset1, _multiset2)
        self.assertEqual(result, _multiset3)

        result = intersect(_multiset1, _multiset2)
        self.assertEqual(result, Multiset(_collections.Counter("d")))

        result = minus(_multiset_magic, _multiset1)
        self.assertEqual(result, Multiset(_collections.Counter("racaabra")))

        p1 = Multiset(_collections.Counter("aaa"))
        p2 = Multiset(_collections.Counter("bbb"))
        p3 = Multiset(_collections.Counter("ccc"))
        combined = Set({p1, p2, p3})
        result = big_union(combined)
        self.assertEqual(result, Multiset(_collections.Counter("abc" * 3)))

        result = big_intersect(Set(
            {_multiset_magic, Multiset(_collections.Counter("abc" * 3)),
             Multiset("a", "a", "b", "c")}))
        self.assertEqual(result, Multiset(_collections.Counter("aabc")))
    def test_addition(self):
        self._check_wrong_argument_types_binary(add)

        result = add(_set1, _set2)
        self.assertEqual(result, _set1a2)
    def test_addition(self):
        self._check_wrong_argument_types_binary(add)

        result = add(_set1, _set2)
        self.assertEqual(result, _set1a2)
    print("multiset's union takes the max of all the multiples merges the arguments into one "
          "result multiset.\n")

# Multiset Intersect Operation Example
simple_intersect = _multisets.intersect(ms_1, ms_2)

print(str(ms_1) + ' INTERSECT ' + str(ms_2))
print('=> EVALUATES TO ' + str(simple_intersect))

ms_4 = _mo.Multiset({'b': 2})
if ms_4 == simple_intersect:
    print("multiset's intersect takes the min of all the multiples merges the arguments into one "
          "result multiset.\n")

# Multiset Addition operation Example
simple_addition = _multisets.add(ms_1, ms_2)

print(str(ms_1) + ' ADDITION ' + str(ms_2))
print('=> EVALUATES TO ' + str(simple_addition))

ms_5 = _mo.Multiset({'a': 3, 'b': 5, 'c': 1})
if ms_5 == simple_addition:
    print("multiset's addition sums all the multiples of like values in the arguments into one "
          "result multiset.\n")

# Multiset Intersect Operation Example
simple_minus = _multisets.minus(ms_1, ms_2)

print(str(ms_1) + ' MINUS ' + str(ms_2))
print('=> EVALUATES TO ' + str(simple_minus))
        "result multiset.\n")

# Multiset Intersect Operation Example
simple_intersect = _multisets.intersect(ms_1, ms_2)

print(str(ms_1) + ' INTERSECT ' + str(ms_2))
print('=> EVALUATES TO ' + str(simple_intersect))

ms_4 = _mo.Multiset({'b': 2})
if ms_4 == simple_intersect:
    print(
        "multiset's intersect takes the min of all the multiples merges the arguments into one "
        "result multiset.\n")

# Multiset Addition operation Example
simple_addition = _multisets.add(ms_1, ms_2)

print(str(ms_1) + ' ADDITION ' + str(ms_2))
print('=> EVALUATES TO ' + str(simple_addition))

ms_5 = _mo.Multiset({'a': 3, 'b': 5, 'c': 1})
if ms_5 == simple_addition:
    print(
        "multiset's addition sums all the multiples of like values in the arguments into one "
        "result multiset.\n")

# Multiset Intersect Operation Example
simple_minus = _multisets.minus(ms_1, ms_2)

print(str(ms_1) + ' MINUS ' + str(ms_2))
print('=> EVALUATES TO ' + str(simple_minus))