Numeric

class IntervalCell(low=None, high=None)[source]

Implements an interval cell along with interval algebra

static coerce(value)[source]

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]
stem()[source]

Creates a new instance with bounds of 0 to infinity

Returns:IntervalCell
>>> x = IntervalCell(1,1)
>>> y = x.stem()
>>> y
[0.00,inf]
size()[source]

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
is_contradictory(other)[source]

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
is_entailed_by(other)[source]

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
is_equal(other)[source]

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
merge(other)[source]

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]
map(other, function)[source]

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:
  • other (IntervalCell) – IntervalCell or coercible value
  • function (function) – Mathematical function to be applied to the bounds of the interval. Must take two arguments and return a number
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]
get_tuple()[source]

Returns (low, high) tuple

>>> x = IntervalCell(1,2)
>>> xTuple = x.get_tuple()
>>> xTuple
(1,2)
to_latex()[source]

Returns an interval representation

test_hashes()[source]

Tests for cases where LOW and HIGH values of the interval have the same sum, the same diff, etc.

Previous topic

Sets

Next topic

Posets

This Page