Converting Union Object to Interval List

How can I convert a Union object in Sympy to a list of extra intervals?

eg. convert this:

(-oo, a] U [b, oo)

:

[(-oo,a], [b,oo)]
+4
source share
1 answer
In [1]: var("a, b")
Out[1]: (a, b)

In [2]: u = Union(Interval(-oo, a), Interval(b, oo))

In [3]: u
Out[3]: (-∞, a] ∪ [b, ∞)

In [4]: u.args
Out[4]: ((-∞, a], [b, ∞))

Note: if b <a, then the union interval is (-∞, ∞)

+4
source

All Articles