Reputation: 109
How can I convert a Union object in Sympy to a list of sub intervals?
E.g. convert this:
(-oo, a] U [b, oo)
to this:
[(-oo,a], [b,oo)]
Upvotes: 4
Views: 356
Reputation: 1957
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 interval union is (-∞, ∞)
Upvotes: 5