Sets

class SetIntersectionCell(domain, value_or_values=None)[source]

Represents iterable unordered elements.

Parameters:
  • domain (iterable) – Initial domain
  • value_or_values (list) – Optional default values. All values must be in the specified domain.
Raises:

Exception

stem()[source]

Spawns a new SetCell of the same domain

Returns:SetIntersectionCell
>>> a = SetIntersectionCell([1,2,3])
>>> b = a.stem()
>>> b
{1,2,3}
coerce(value)[source]

Ensures that a value is a SetCell

Parameters:value – A Cell or value in self‘s domain
Returns:SetIntersectionCell
Raises:CellConstructionFailure
>>> a = SetIntersectionCell([1,2,3])
>>> b = a.coerce([1,2])
>>> b
{1,2}
>>> c = a.coerce(1)
>>> c
{1}
same_domain(other)[source]

Cheap pointer comparison or symmetric difference operation to ensure domains are the same

Parameters:other (SetCell) – SetCell to be compared
Returns:bool
>>> a = SetIntersectionCell([1,2,3])
>>> b = SetIntersectionCell([2,3,1])
>>> c = SetIntersectionCell([1,2])
>>> a.same_domain(b)
True
>>> a.same_domain(c)
False
is_equal(other)[source]

True iff all members are the same

Parameters:other (SetCell) – SetCell to be compared
Returns:bool
Raises:CellConstructionFailure
>>> a = SetIntersectionCell(range(10))
>>> b = SetIntersectionCell(range(10),[1,3,5])
>>> c = SetIntersectionCell([1,3,5])
>>> a.is_equal(b)
False
>>> b.is_equal(c)
True
is_contradictory(other)[source]

What does it mean for one set to contradict another? Two sets are contradictory when they are disjoint.

Parameters:other (SetCell) – A SetCell to be compared
Returns:bool
Raises:CellConstructionFailure
>>> a = SetIntersectionCell(['a','b','c'])
>>> b = SetIntersectionCell(['d','e','f'])
>>> c = SetIntersectionCell(['c','d'])
>>> a.is_contradictory(b)
True
>>> a.is_contradictory(c)
False
>>> b.is_contradictory(c)
False
is_entailed_by(other)[source]

Fewer members = more information (exception is empty set, which means all members of the domain)

If the two SetCells do not have the same domain, this method returns False.

If the two SetCells have the same domain, then self is entailed by other if self.values is a subset of other.values, or if other.values is empty (None).

param other:A SetCell to be tested
type other:SetCell
returns:bool
>>> a = SetIntersectionCell(range(10),[1,2,3])
>>> b = SetIntersectionCell(range(5),[1,2,3])
>>> c = SetIntersectionCell(range(10),[1,2])
>>> a.is_entailed_by(b)
False
>>> a.is_entailed_by(c)
True
>>> c.is_entailed_by(a)
False
contains(value)[source]

Returns True iff value is in the set

Parameters:other – A value that may or may not be in the domain of self.
Returns:bool
>>> a = SetIntersectionCell(['red','blue','green'],['red','blue'])
>>> b = SetIntersectionCell(['red','blue','green'])
>>> a.contains('red')
True
>>> a.contains('green')
False
>>> b.contains('green')
True
get_values()[source]

Returns the values of the set, or the domain as a set if no values were specified at construction.

Returns:set
>>> x = SetIntersectionCell(['a','b','c'])
>>> y = SetIntersectionCell(['a','b','c'],['a','b'])
>>> x.get_values()
set(['a', 'c', 'b'])
>>> y.get_values()
set(['a', 'b'])
merge(other)[source]

We can merge unless the merge results in an empty set – a contradiction. This method results in the intersection of the two SetCells.

Note

This method modifies the self argument.

Parameters:other (SetCell) – SetCell to merge with
Returns:SetCell
Raises:Contradiction, CellConstructionFailure
>>> a = SetIntersectionCell(range(10),range(10))
>>> b = SetIntersectionCell(range(10),[1,2,3])
>>> a.merge(b)
{1,2,3}
>>> c = SetIntersectionCell(range(7),[2,3,4])
>>> a.merge(c)
{2,3}
to_dot()[source]

For Graphviz rendering

to_latex()

For Graphviz rendering

class SetUnionCell(domain, value_or_values=None)[source]

SetUnionCell inherits from SetIntersectionCell and breaks monotonicity. Initially, its values are equal to its domain, and then after 1 or more updates, its values become the UNION of all of the updates

merge(other)[source]

We can merge unless the two sets are contradictory, i.e. they are disjoint. The resulting merge will be the union of the two sets.

Note

This method will modify the self argument.

Parameters:other (SetCell) – SetCell to merge with
Returns:SetCell
Raises:Contradiction, CellConstructionFailure
>>> a = SetUnionionCell(range(10),range(5))
>>> b = SetUnionionCell(range(10),range(3,8))
>>> a.merge(b)
{0,1,2,3,4,5,6,7,8}

Previous topic

Lists

Next topic

Numeric

This Page