SymPy: Union of symbolic interval

I have two Sympy intervals (Interval(1, m), Interval(1, m+1))

where m>=1

. I want to make a Union of these two intervals. The result should be[1,m+1]

Unfortunately, I was unable to pass the limit to Sympy m

.

Where is my actual code with the "too mesh generic" answer:

m = symbols('m', integer=True)
Union(Interval(1, m), Interval(1, m+1))
>> [1, m] U [1, m + 1]

      

I have tried using the function reduce

without any success ...

Any help would be greatly appreciated.

Thank!

+3


source to share


1 answer


We can get the desired result by creating a new interval12 like this:

m=Symbol('m',positive=True)
interval1 = Interval(0,m)
interval2 = Interval(0,m+4)
union12 = interval1.union(interval2)
interval12 = Interval(union12.inf,union12.sup)
print interval1, interval2, interval12

      



output:

[0, m] [0, m + 4] [0, m + 4]

      

0


source







All Articles