Function Repository Resource:

# IntervalComplement

Calculate the complement of intervals

Contributed by: Sander Huisman
 ResourceFunction["IntervalComplement"][intervalall,interval1,interval2,…] gives the interval representing all the points of intervalall that are not in any of the intervali.

## Details and Options

ResourceFunction["IntervalComplement"] only works on Interval objects with bounds that are real and not symbolic.
ResourceFunction["IntervalComplement"] supports the intervals to have -∞ and +∞ bounds.

## Examples

### Basic Examples (2)

Calculate the complement of two intervals:

 In[1]:=
 Out[1]=

Intervals can be disjoint:

 In[2]:=
 Out[2]=

### Scope (6)

"Subtract" two Interval objects from another interval object:

 In[3]:=
 Out[3]=

Subtracting an interval might create a disjoint interval:

 In[4]:=
 Out[4]=

Unbounded intervals can be used:

 In[5]:=
 Out[5]=
 In[6]:=
 Out[6]=
 In[7]:=
 Out[7]=

If there is full overlap an empty interval is returned:

 In[8]:=
 Out[8]=

An empty interval stays empty:

 In[9]:=
 Out[9]=

Complementing with an empty interval has no effect:

 In[10]:=
 Out[10]=

### Applications (1)

Calculate the absolute complement of the interval [-5,5] by taking the relative complement with the full interval:

 In[11]:=
 Out[13]=

### Properties and Relations (2)

Compare the complement with the IntervalUnion and the IntervalIntersection of two intervals:

 In[14]:=
 Out[16]=

Compare to regular sets:

 In[17]:=
 Out[19]=

### Possible Issues (1)

Intervals need to be numeric, if the input is symbolic it will stay unevaluated:

 In[20]:=
 Out[20]=

### Neat Examples (1)

Visualize the "subtraction" of multiple intervals (red) from a base interval (green):

 In[21]:=
 Out[24]=

SHuisman

## Version History

• 1.0.0 – 22 May 2019