예제 #1
0
def diag(*args, _checked=True) -> 'PP(M x M)':
    """Return a clan diagonal of the arguments.

    :param args: Pass in the elements from which the :term:`clan diagonal` is formed. (If you want
        to pass in an iterable, you need to prefix it with an asterisk ``*``.)
    """
    clan = _mo.Set(_relations.diag(*args, _checked=_checked), direct_load=True)
    clan.cache_clan(_mo.CacheStatus.IS)
    clan.cache_functional(_mo.CacheStatus.IS).cache_right_functional(_mo.CacheStatus.IS)
    clan.cache_reflexive(_mo.CacheStatus.IS).cache_symmetric(_mo.CacheStatus.IS)
    clan.cache_regular(_mo.CacheStatus.IS).cache_right_regular(_mo.CacheStatus.IS)
    return clan
예제 #2
0
    def test_diagonal(self):
        base_set = Set(Atom(1))
        diag_rels = [relations.diag(*base_set), relations.diag(1)]
        for diag_rel in diag_rels:
            self.assertEqual(diag_rel.cardinality, 1)
            self.assertTrue(relations.is_member(diag_rel))
            self.assertTrue(diag_rel.has_element(Couplet(1, 1)))

        base_set = Set(Atom(1), Atom('a'))
        diag_clan = clans.diag(1, 'a')
        self.assertEqual(diag_clan.cardinality, 1)
        diag_rels = [
            relations.diag(*base_set),
            relations.diag(1, 'a'),
            sets.single(diag_clan)
        ]
        for diag_rel in diag_rels:
            self.assertEqual(diag_rel.cardinality, 2)
            self.assertTrue(relations.is_member(diag_rel))
            self.assertTrue(diag_rel.has_element(Couplet(1, 1)))
            self.assertTrue(diag_rel.has_element(Couplet('a', 'a')))

        arg1 = Set(1, 2, 3)
        arg2 = [v for v in Set(1, 2, 3)]
        result_diag = Set(Couplet(1, 1), Couplet(2, 2), Couplet(3, 3))
        self.assertEqual(relations.diag(*arg1), result_diag)
        self.assertEqual(relations.diag(*arg2), result_diag)
예제 #3
0
    def test_diagonal(self):
        base_set = Set(Atom(1))
        diag_rels = [
            relations.diag(*base_set), relations.diag(1)]
        for diag_rel in diag_rels:
            self.assertEqual(diag_rel.cardinality, 1)
            self.assertTrue(relations.is_member(diag_rel))
            self.assertTrue(diag_rel.has_element(Couplet(1, 1)))

        base_set = Set(Atom(1), Atom('a'))
        diag_clan = clans.diag(1, 'a')
        self.assertEqual(diag_clan.cardinality, 1)
        diag_rels = [
            relations.diag(*base_set), relations.diag(1, 'a'), sets.single(diag_clan)]
        for diag_rel in diag_rels:
            self.assertEqual(diag_rel.cardinality, 2)
            self.assertTrue(relations.is_member(diag_rel))
            self.assertTrue(diag_rel.has_element(Couplet(1, 1)))
            self.assertTrue(diag_rel.has_element(Couplet('a', 'a')))

        arg1 = Set(1, 2, 3)
        arg2 = [v for v in Set(1, 2, 3)]
        result_diag = Set(Couplet(1, 1), Couplet(2, 2), Couplet(3, 3))
        self.assertEqual(relations.diag(*arg1), result_diag)
        self.assertEqual(relations.diag(*arg2), result_diag)
예제 #4
0
def diag(*args, _checked=True) -> 'P(P(M x M) x N)':
    """Return a multiclan diagonal of the arguments.

    :param args: Pass in the elements from which the :term:`clan diagonal` is formed. (If you want
        to pass in an iterable, you need to prefix it with an asterisk ``*``.)
    """
    rels = _relations.diag(*args, _checked=_checked)
    if rels is _undef.Undef():
        return _undef.make_or_raise_undef(2)
    clan = _mo.Multiset(rels, direct_load=True)
    clan.cache_multiclan(_mo.CacheStatus.IS)
    clan.cache_functional(_mo.CacheStatus.IS).cache_right_functional(_mo.CacheStatus.IS)
    clan.cache_reflexive(_mo.CacheStatus.IS).cache_symmetric(_mo.CacheStatus.IS)
    clan.cache_regular(_mo.CacheStatus.IS).cache_right_regular(_mo.CacheStatus.IS)
    return clan
예제 #5
0
def diag(*args, _checked=True) -> 'PP(M x M)':
    """Return a clan diagonal of the arguments.

    :param args: Pass in the elements from which the :term:`clan diagonal` is formed. (If you want
        to pass in an iterable, you need to prefix it with an asterisk ``*``.)
    """
    rels = _relations.diag(*args, _checked=_checked)
    if rels is _undef.Undef():
        return _undef.make_or_raise_undef(2)
    clan = _mo.Set(rels, direct_load=True)
    clan.cache_clan(CacheStatus.IS)
    clan.cache_functional(CacheStatus.IS).cache_right_functional(
        CacheStatus.IS)
    clan.cache_reflexive(CacheStatus.IS).cache_symmetric(CacheStatus.IS)
    clan.cache_regular(CacheStatus.IS).cache_right_regular(CacheStatus.IS)
    return clan