Example #1
0
    def test_power_set(self):
        # self._check_argument_types_unary_undef(power_set)
        self.assertIs(power_set(Undef()), Undef())

        s1 = Set(1, 2, 3)
        p1 = Set(Set(), Set(1), Set(2), Set(3), Set(1, 2), Set(1, 3), Set(2, 3), Set(1, 2, 3))
        self.assertEqual(p1, power_set(s1))
    def test_power_set(self):
        # self._check_argument_types_unary_undef(power_set)
        self.assertIs(power_set(Undef()), Undef())

        s1 = Set(1, 2, 3)
        p1 = Set(Set(), Set(1), Set(2), Set(3), Set(1, 2), Set(1, 3), Set(2, 3), Set(1, 2, 3))
        self.assertEqual(p1, power_set(s1))
Example #3
0
functional_relation = Set(Couplet('subject', 123), Couplet('name', 'james'), Couplet('level', 10))
print(relations.get_right(functional_relation, 'subject'))
print(relations.get_left(functional_relation, 123))
print(relations.get_right(record_relation,
                                'loves'))  # See non-functional record_relation above.

# Function evaluation syntax makes this more concise.
print("functional_relation('subject') =", functional_relation('subject'))
print("functional_relation(123) =", functional_relation(123))

# The power set of a set S, which we'll denote as P(S), is the set of all subsets of S. Note how in
# the example below, the elements of set_s are numbers, and the elements of powerset_s are sets of
# numbers.
set_s = Set(1, 2, 3)
powerset_s = sets.power_set(set_s)
print("S := ", set_s)
print("P(S) = ", powerset_s)

# Consider that if C is the set of all Couplets, then the set of all relations R can be defined as
# P(C), that is, every relation is a subset of the set of all Couplets. It turns out that we can
# exploit this relationship by "extending" operations on Couplets up to relations to make them useful
# there. To extend a unary operation such as couplets.transpose, we apply it to every Couplet in a
# relation, which results in another relation.
import algebraixlib.extension as extension

first_relation = Set(Couplet('a', 1), Couplet('b', 2), Couplet('c', 3))
transposed_relation = extension.unary_extend(first_relation, couplets.transpose)
print("transposed_relation:", transposed_relation)

# Similarly, a binary operation like couplets.composition can be extended by applying to every element
Example #4
0
functional_relation = Set(Couplet('subject', 123), Couplet('name', 'james'),
                          Couplet('level', 10))
print(relations.get_right(functional_relation, 'subject'))
print(relations.get_left(functional_relation, 123))
print(relations.get_right(
    record_relation, 'loves'))  # See non-functional record_relation above.

# Function evaluation syntax makes this more concise.
print("functional_relation('subject') =", functional_relation('subject'))
print("functional_relation(123) =", functional_relation(123))

# The power set of a set S, which we'll denote as P(S), is the set of all subsets of S. Note how in
# the example below, the elements of set_s are numbers, and the elements of powerset_s are sets of
# numbers.
set_s = Set(1, 2, 3)
powerset_s = sets.power_set(set_s)
print("S := ", set_s)
print("P(S) = ", powerset_s)

# Consider that if C is the set of all Couplets, then the set of all relations R can be defined as
# P(C), that is, every relation is a subset of the set of all Couplets. It turns out that we can
# exploit this relationship by "extending" operations on Couplets up to relations to make them
# useful there. To extend a unary operation such as couplets.transpose, we apply it to every
# Couplet in a relation, which results in another relation.
import algebraixlib.extension as extension

first_relation = Set(Couplet('a', 1), Couplet('b', 2), Couplet('c', 3))
transposed_relation = extension.unary_extend(first_relation,
                                             couplets.transpose)
print("transposed_relation:", transposed_relation)