def get_str(self): """Return the instance's string representation.""" if len(self.data) == 1: return str(_get_single_iter_elem(self.data)) else: unsorted_strings = [str(elem) for elem in self.data] return '({elems})'.format(elems=' U '.join(elem for elem in sorted(unsorted_strings)))
def get_ground_set(self) -> _structure.Structure: """Return the ground Multiset of the lowest-level algebra of this :class:`Multiset`.""" if len(self.data) == 0: return _structure.Structure() elements_ground_set = _structure.Union(elem.get_ground_set() for elem in self.data) if len(elements_ground_set.data) == 1: return _structure.PowerSet(_structure.CartesianProduct( _get_single_iter_elem(elements_ground_set.data), _structure.GenesisSetN())) else: return _structure.PowerSet(_structure.CartesianProduct( elements_ground_set, _structure.GenesisSetN()))
def is_same(self, other: Structure) -> bool: """Return ``True`` if ``self`` is structurally equivalent to ``other``. :param other: Must be an instance of `Structure`. :return: ``True`` if ``self`` is structurally equivalent to ``other``. """ assert isinstance(other, Structure) if isinstance(other, Union): return self.data == other.data else: if len(self.data) == 1: # Compare the one element against 'other'. return _get_single_iter_elem(self.data).is_same(other) else: # self is a 'real' union, so the 'other' must also be a union. return False