def pow(self) -> 'BSet': this_map = self.map this_domain = this_map.keys() start = BRelation() queue = [start] result = BSet(start) while not len(queue) == 0: current_set = queue.pop(0) for e1 in this_domain: domain_element = e1 _range = this_map[domain_element] for e2 in _range: range_element = e2 next_relation = current_set.union( BRelation.fromSet( BSet(BTuple(domain_element, range_element)))) previous_size = result.size() result = result.union(BSet(next_relation)) if previous_size < result.size(): queue.append(next_relation) return result
def front(self) -> 'BRelation': return self.domainSubstraction(BSet(self.card()))
def _range(self) -> 'BSet': _set = reduce(lambda a, b: a.union(b), self.map.values(), set()) return BSet(*list(_set))
def pow1(self) -> 'BSet': return self.pow().difference(BSet(BRelation()))
def _range(self) -> 'BSet': _range = reduce(lambda a, b: a.update(b), self.map.values(), immutables.Map()) return BSet(_range)
class BUtils: BOOL = BSet(BBoolean(True), BBoolean(False))