Interval

From Open Ideas

Jump to: navigation, search

Contents

Definition

An interval of an (partially) ordered set $M$ is the set $I \subset M$ with the property that given two elements $l,u$ of $M$, $l \leq u$, any element $x$ satisfying $l \leq x$ and $x \leq u$ is also in $I$.

Codebook

Construction

To create an interval of double values the factory method create can be used.

IDoubleInterval open = DoubleInterval.create(10.0, 20.0, Closure.NONE);  
// represents the open interval (10, 20)
 
IDoubleInterval right_closed = DoubleInterval.create(-10.0, 10.0, Closure.RIGHT); 
// represents the right-closed (left-open) interval (-10, 10]
 
IDoubleInterval left_closed = DoubleInterval.create(0.0, Double.POSITIVE_INFINITY, Closure.LEFT); 
// represents the left-closed (right-open) interval [-10, ∞)
 
IDoubleInterval closed = DoubleInterval.create(3.15, 3.15, Clossure.BOTH); 
// represents the closed interval [3.15, 3.15]

If only integer values are needed, then an instance of IIntInterval can be created the same way.

IIntInterval iClosed = IIntInterval.create(-12, 12);

Note that only closed integer intervals can be created but this is no restriction.

The concept can be generalized to higher dimensions. First, the lower bound and the upper bound are created (instances of IDoublePoint2D or IDoublePointND), then the set is created by means of the two points.

IDoublePoint2D lBound2D = DoublePoint2D.create(0.0, -5.0);
IDoublePoint2D uBound2D = DoublePoint2D.create(10.0, 5.0);
IDoubleCuboid<IDoublePoint2D> rectangle = DoubleRectangle.create(lBound2D, uBound2D);

The object rectangle represents the set $M \subset D^{2}$ defined by

Methods

This class has the standart question methods, which gives values of the class like getBounds() etc. Furthermore it has lebesgueRectangular() which delivers the lenght of the interval. If an interval like the one "closed" above consists only of one point, this measure is zero. Another self-explaining method is containsPoint(Double).

Let $a$ and $b$ be two intervals. Mentionable is the method compareTo(IDoubleCuboid). This is used a.compareTo(b) and it returns -1, 0 or 1. -1 is returned if the lower bound of $a$ is smaller than the one of $b$ or if they are equal and the upper bound of $a$ is smaller than the one of $b$. If the two intervals are the same (ignoring the closed/open border) it returns 0. In all other cases, so if the bounds of $a$ are bigger than $b$'s we get 1.

Next interesting method is isSuperset(IDoubleCuboid). This returns true if all points of the interval passed to this method lies in the first interval. But attention: This method ignores openess and closedness!

The method intersection(Double Cuboid) does what the name promises: it returns the intersection of the two intervals. This method regards the borders of the intervals.

DisjointDoubleIntervals

If one has many intervals in one list, its possible that these intervals cover each other. But this could be a problem if one wants to define a function on it, for example. To avoid this problem, there exists the class DisjointDoubleInterval. The class offers two possible ways (granularity) to get rid off covered intervals:

Granularity.FINE
Granularity.COARSE

If you choose the fine one, the class will devide all intervals such that there arise many small intervals, for example: You have two intervals: $A = [0, 5]$ und $B = [2, 7]$ The class will make from this the following intervals: $A' = [0, 2)$, $B' = [2, 5]$ and $C' = (5, 7]$. The class conserves the original borders as possible.

When you take Granularity.COARSE the intervals which cover each other will put together in one big. But if there are holes between two intervals, these holes stay. Example: We have $A = [0, 5]$, $B = [2, 7]$ und $C = (45, 89)$. The result will be: $A' = [0, 7]$ and $B' = (45,89)$.

If one has, like the examples here, only integer, one can use the class DisjointIntIntervals which is the same, but especially for integer.

See also

Personal tools