Implements an interval cell along with interval algebra
Takes in either a single number (float, int), a list, or a tuple and returns the [low, high] in the standard interval form. In the case of a single value, the low and high will both be the single value. In the case of a list or tuple, the low and high will be the min and max of the collection, respectively.
| Parameters: | value (int, float, complex, list, tuple) – The the number or collection of numbers to be used for the low and high boundaries |
|---|---|
| Returns: | IntervalCell |
| Raises: | Exception |
>>> a = IntervalCell.coerce(5)
>>> a
5.00
>>> b = IntervalCell.coerce([3,7])
>>> b
[3.00,7.00]
>>> c = IntervalCell.coerce((1,6,5,9,2))
>>> c
[1.00,9.00]
Creates a new instance with bounds of 0 to infinity
| Returns: | IntervalCell |
|---|
>>> x = IntervalCell(1,1)
>>> y = x.stem()
>>> y
[0.00,inf]
Number of possible values in the interval. Boundaries are inclusive
| Returns: | int – Length of interval |
|---|
>>> a = IntervalCell(1,2)
>>> b = IntervalCell(12,19)
>>> a.size()
2
>>> b.size()
8
Determines whether other and self can coexist. Two intervals are contradictory if they are disjoint, i.e. if their intersection is empty
| Parameters: | other – IntervalCell or coercible value |
|---|---|
| Returns: | bool |
| Raises: | Exception |
>>> w = IntervalCell(1,2)
>>> x = IntervalCell(1,1)
>>> y = IntervalCell(2,2)
>>> z = IntervalCell(0,3)
>>> x.is_contradictory(y)
True
>>> w.is_contradictory(z)
False
>>> x.is_contradictory(w)
False
Returns true if other is more specific than self, i.e. other is bounded within self.
| Parameters: | other – IntervalCell or coercible value |
|---|---|
| Returns: | bool |
| Raises: | Exception |
>>> x = IntervalCell(1,1)
>>> y = IntervalCell(2,2)
>>> z = IntervalCell(0,3)
>>> z.is_entailed_by(x)
True
>>> z.is_entailed_by(y)
True
>>> x.is_entailed_by(y)
False
Returns true if two intervals are the same
| Parameters: | other – IntervalCell or coercible value |
|---|---|
| Returns: | bool |
| Raises: | Exception |
>>> x = IntervalCell(1,1)
>>> z = IntervalCell(0,3)
>>> x.is_equal(1)
True
>>> z.is_equal([0,3])
True
>>> x.is_equal(z)
False
Merges the two values. The self argument is modified, while other is not.
| Parameters: | other – IntervalCell or coercible value |
|---|---|
| Returns: | bool |
| Raises: | Exception |
>>> x = IntervalCell(0,3)
>>> y = IntervalCell(2,2)
>>> a = x.merge(y)
>>> a
2.00
Note
merge modifies the self argument as a side effect.
>>> w = IntervalCell(1,7)
>>> z = IntervalCell(3,9)
>>> b = w.merge(z)
>>> b
[3.00,7.00]
w has been modified.
>>> w
[3.00,7.00]
z has not.
>>> z
[3.00,9.00]
Applies a mathematic function to the interval arithmetic template: generate all combinations of low/high values and then take the widest bounds (min/max) for the result.
| Parameters: |
|
|---|---|
| Returns: | IntervalCell |
| Raises: | Exception |
>>> a = IntervalCell(1,4)
>>> b = IntervalCell(3,5)
>>> result = a.map(b,lambda x,y: x+y)
>>> result
[4.00,9.00]
>>> result = a.map(b,lambda x,y: x-y)
>>> result
[-4.00,1.00]