7.1. IntervalArithmetic

This module implements interval arithmetic.

class IntervalArithmetic.Interval(*args, **kwargs)[source]

Bases: object

Interval [inf, sup] in the float domain.

An interval can be constructed using a couple (inf, sup) or an object that support the __getitem__() interface:

Interval(inf, sup)
Interval((inf, sup))
Interval(iterable)
Interval(interval)

To get the interval boundaries, use the inf and sup attribute.

An empty interval is defined with inf and sup set to None.

To compute the union of two intervals use:

i3 = i1 | i2
i1 |= i2

To compute the intersection of two intervals use:

i3 = i1 & i2
i1 &= i2

It returns an empty interval if the intersection is null.

center

Return the interval’s center.

clone()

alias of copy()

copy()[source]

Return a clone of the interval.

enlarge(dx)[source]

Enlarge the interval of dx.

intersect(i1, i2)[source]

Test whether the interval intersects with i2?

is_empty()[source]

Test if the interval is empty.

is_included_in(i1, i2)[source]

Test whether the interval is included in i1?

is_left_open
is_outside_of(i1, i2)[source]

Test whether the interval is outside of i2?

is_right_open
length

Return sup - inf.

map_in(interval_reference)[source]

Return a new interval shifted of interval_reference.inf.

map_x_in(x, clamp=False)[source]

Return x - inf. If clamp parameter is set True then the value is clamped in the interval.

radius

Return length / 2.

unmap_x_in(x)[source]

Return x + inf.

zero_length()[source]

Return sup == inf.

class IntervalArithmetic.IntervalInt(*args, **kwargs)[source]

Bases: IntervalArithmetic.Interval

Interval [inf, sup] in the integer domain.

is_left_open
is_right_open
iter()[source]
length

Return sup - inf +1.

length_float

Return sup - inf.

slice

Return a slice instance.

class IntervalArithmetic.IntervalIntSupOpen(*args)[source]

Bases: IntervalArithmetic.IntervalInt

Interval [inf, sup[ in the integer domain.

exclude(i1, i2)[source]

Compute the subset intervals of i1 given an exclusion interval i2.

It returns None if the intervals don’t intersect or i1 is included in i2. Else it returns a list of couples (interval, excluded_flag) where interval is a subset of the interval i1 and excluded_flag indicated if the subset is excluded.

intersect(i1, i2)[source]

Does the interval intersect with i2?

minus(i1, i2)[source]

Return a list of intervals corresponding to i1 - intersection of i1 and i2. If i2 is included in i1 then two intervals can be returned. If the compution is not defined then None is returned.

class IntervalArithmetic.Interval2D(x, y)[source]

Bases: object

Interval [inf, sup]*[inf, sup] in the float domain.

The components can be accessed using the x and y attribute, or using an index interface where the index 0 maps to x and 1 to y, respectively.

area

Return the area.

bounding_box

Return the corresponding bounding box (x.inf, y.inf, x.sup, y.sup).

center

Return the interval’s center.

clone()

alias of copy()

copy()[source]

Return a clone of the interval.

diagonal

Return the diagonal’s length.

enlarge(dx)[source]

Enlarge the interval of dx.

intersect(i2)[source]

Test whether the interval intersects with i2?

is_empty()[source]

Test if the interval is empty.

is_included_in(i2)[source]

Test whether the interval is included in i2?

map_in(interval_reference)[source]

Construct a new interval shifted of interval_reference.inf.

map_xy_in(x, y, clamp=False)[source]

Return (x - y.inf, y - y.inf).

radius

Return the horizontal and vertical radius.

shift(dx, dy)[source]

Shift the interval of (dx, dy).

size

Return the horizontal and vertical length.

unmap_xy_in(x, y)[source]

Return (x + y.inf, y + y.inf).

class IntervalArithmetic.IntervalInt2D(x, y)[source]

Bases: IntervalArithmetic.Interval2D

Interval [inf, sup]*[inf, sup] in the integer domain.

iter()[source]