Esempio n. 1
0
    def test_is_subset_of(self):
        self._check_wrong_argument_types_binary(is_subset_of)

        result1 = is_subset_of(_set1, _set1u2)
        self.assertTrue(result1)
        result2 = is_subset_of(_set1, _set2)
        self.assertFalse(result2)
    def test_is_subset_of(self):
        self._check_wrong_argument_types_binary(is_subset_of)

        result1 = is_subset_of(_set1, _set1u2)
        self.assertTrue(result1)
        result2 = is_subset_of(_set1, _set2)
        self.assertFalse(result2)
Esempio n. 3
0
def functional_add(rel: 'P(M x M)', element: 'M x M') -> 'P(M x M)':
    """Add ``element`` to ``rel`` and return the new :term:`relation`.

    :param rel: The source data. Must be a :term:`relation`. It must not contain a :term:`couplet`
        with the same :term:`left component` as ``element``.
    :param element: The element to be added to ``rel``. Must be a :class:`~.Couplet` and its
        :term:`left component` must not be a left component in ``rel``.
    :return: The new relation, composed of ``rel`` and ``element``.
    """
    if not is_member(rel):
        return _make_or_raise_undef()
    if not isinstance(element, _mo.Couplet):
        return _make_or_raise_undef()
    if _sets.is_subset_of(_mo.Set(element.left), get_lefts(rel)):
        return _make_or_raise_undef(2)
    result_relation = _sets.union(rel, _mo.Set(element))
    return result_relation
Esempio n. 4
0
def functional_add(func: 'P(M x M)', element: 'M x M') -> 'P(M x M)':
    """Add ``element`` to ``func`` and return the new functional relation.

    :param func: The source data. Must be a :term:`function`. It must not contain a :term:`couplet`
        with the same :term:`left component` as ``element``.
    :param element: The element to be added to ``func``. Must be a :class:`~.Couplet` and its
        :term:`left component` must not be a left component in ``func``.
    :return: The new relation, composed of ``func`` and ``element``.
    """
    if not is_member(func) or not is_functional(func):
        return _undef.make_or_raise_undef2(func)
    if not _couplets.is_member(element):
        return _undef.make_or_raise_undef2(element)
    if _sets.is_subset_of(_mo.Set(element.left), get_lefts(func)):
        return _undef.make_or_raise_undef(2)
    element_func = _mo.Set(element).cache_relation(_mo.CacheStatus.IS)
    result = _sets.union(func, element_func)
    assert result.cached_is_relation and is_functional(result)
    result.cache_functional(_mo.CacheStatus.IS)
    return result
Esempio n. 5
0
def functional_add(func: 'P(M x M)', element: 'M x M') -> 'P(M x M)':
    """Add ``element`` to ``func`` and return the new functional relation.

    :param func: The source data. Must be a :term:`function`. It must not contain a :term:`couplet`
        with the same :term:`left component` as ``element``.
    :param element: The element to be added to ``func``. Must be a :class:`~.Couplet` and its
        :term:`left component` must not be a left component in ``func``.
    :return: The new relation, composed of ``func`` and ``element``.
    """
    if not is_member(func) or not is_functional(func):
        return _undef.make_or_raise_undef2(func)
    if not _couplets.is_member(element):
        return _undef.make_or_raise_undef2(element)
    if _sets.is_subset_of(_mo.Set(element.left), get_lefts(func)):
        return _undef.make_or_raise_undef(2)
    element_func = _mo.Set(element).cache_relation(_mo.CacheStatus.IS)
    result = _sets.union(func, element_func)
    assert result.cached_is_relation and is_functional(result)
    result.cache_functional(_mo.CacheStatus.IS)
    return result
Esempio n. 6
0
for elem in nums:
    print(elem, " ")
print(1 in nums)
print(7 in nums)

# Sets can be unioned, intersected, set-minused. Relations such as is_subset and is_superset are
# defined.
a = Set(1, 2)
b = Set(2, 3)

import algebraixlib.algebras.sets as sets

print("union(a, b) = {}".format(sets.union(a, b)))
print("intersect(a, b) = {}".format(sets.intersect(a, b)))
print("minus(a, b) = {}".format(sets.minus(a, b)))
print("is_subset(a, b) = {}".format(sets.is_subset_of(a, b)))
print("is_superset(a, {{1}}) = {}".format(sets.is_superset_of(a, Set(1))))

# We can use a Couplet to model a single truth, such as 'blue'^'sky' or 'jeff'^'name'. By collecting
# multiple Couplets together in a set, we form a mathematical model of a data record. This data
# structure, called a binary relation (abbreviated from hereon as simply 'relation'), is the
# fundamental data type in a Data Algebra program.
record_relation = Set(Couplet('id', 123), Couplet('name', 'jeff'), Couplet('loves', 'math'),
                      Couplet('loves', 'code'))
print(record_relation)

# Some relations, specify a function from left to right. This is the case when every left
# value maps to exactly one right value. Such a relation is called "left functional".
# Likewise, a relation can be said to be "right functional" when every right value maps
# to exactly one left value.
import algebraixlib.algebras.relations as relations
Esempio n. 7
0
for elem in nums:
    print(elem, " ")
print(1 in nums)
print(7 in nums)

# Sets can be unioned, intersected, set-minused. Relations such as is_subset and is_superset are
# defined.
a = Set(1, 2)
b = Set(2, 3)

import algebraixlib.algebras.sets as sets

print("union(a, b) = {}".format(sets.union(a, b)))
print("intersect(a, b) = {}".format(sets.intersect(a, b)))
print("minus(a, b) = {}".format(sets.minus(a, b)))
print("is_subset(a, b) = {}".format(sets.is_subset_of(a, b)))
print("is_superset(a, {{1}}) = {}".format(sets.is_superset_of(a, Set(1))))

# We can use a Couplet to model a single truth, such as 'sky'->'blue' or 'name'->'jeff'. By
# collecting multiple Couplets together in a set, we form a mathematical model of a data record.
# This data structure, called a binary relation (abbreviated from hereon as simply 'relation'), is
# the fundamental data type in a Data Algebra program.
record_relation = Set(Couplet('id', 123), Couplet('name', 'jeff'),
                      Couplet('loves', 'math'), Couplet('loves', 'code'))
print(record_relation)

# Some relations, specify a function from left to right. This is the case when every left
# value maps to exactly one right value. Such a relation is called "left functional".
# Likewise, a relation can be said to be "right functional" when every right value maps
# to exactly one left value.
import algebraixlib.algebras.relations as relations