Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Calculate the complement of intervals
ResourceFunction["IntervalComplement"][intervalall,interval1,interval2,…] gives the interval representing all the points of intervalall that are not in any of the intervali. |
Calculate the complement of two intervals:
| In[1]:= |
| Out[1]= |
Intervals can be disjoint:
| In[2]:= |
| Out[2]= |
"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]= |
Calculate the absolute complement of the interval [-5,5] by taking the relative complement with the full interval:
| In[11]:= | ![]() |
| Out[13]= | ![]() |
Compare the complement with the IntervalUnion and the IntervalIntersection of two intervals:
| In[14]:= | ![]() |
| Out[16]= | ![]() |
Compare to regular sets:
| In[17]:= | ![]() |
| Out[19]= | ![]() |
Intervals need to be numeric, if the input is symbolic it will stay unevaluated:
| In[20]:= |
| Out[20]= |
Visualize the "subtraction" of multiple intervals (red) from a base interval (green):
| In[21]:= | ![]() |
| Out[24]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License