What is the number of interval ranges in the union of sympy?

Asked 2 years ago, Updated 2 years ago, 131 views

s What is the number of interval ranges in the Union of sympy?
②Is this OK? I tried "Union→Interval→Union".
Thank you for your cooperation.

from sympathy import*
k = Symbol ('k')
ineq = 'k**2-40>0'
an1 = solo_univariate_inequality (sympify(ineq), k, relational = False)
print('#',ineq,':',ans1)
my_Union0=list(ans1.args[0:1])[0]
my_Union1=list(ans1.args[1:2])[0]
print('#my_Union0:', my_Union0)
print('#my_Union1:', my_Union1)
ans2 = my_Union0.union(my_Union1)
print('#Undo:',ans2)
# k**2-40>0: Union (Interval.open (-oo, -2*sqrt(10)), Interval.open (2*sqrt(10),oo))
# my_Union0: Interval.open (-oo,-2*sqrt(10))
# my_Union1: Interval.open(2*sqrt(10),oo)
# Undo: Union (Interval.open (-oo, -2*sqrt(10)), Interval.open (2*sqrt(10),oo)

python sympy

2022-09-29 22:16

1 Answers

If there are more than two intervals in Union, I think I can count them.
Question Inter When there is only one interval?
Q2 Please tell me how to use the Python loop.
Thank you for your additional questions.

(Reference)
https://stackoverflow.com/questions/60917259/sympy-get-constituent-subsets-from-union

from sympathy import*
k = Symbol ('k')
ineq = 'k**2-40>0'
my_Union=solve_univariate_inequality(sympify(ineq), k, relational=False)
print('#', my_Union)
n = 0
total_list = [ ]
for subset in my_Union.args:
    n = n+1
    total_list.append(subset)

for i in range(n):
    # print(i)
    if i == 0:
       my_Union2=total_list[i]
    else:
       my_Union2=my_Union2+total_list[i]
print('#', my_Union2)
print('#',n)
# Union (Interval.open (-oo,-2*sqrt(10)), Interval.open(2*sqrt(10),oo))
# Union (Interval.open (-oo,-2*sqrt(10)), Interval.open(2*sqrt(10),oo))
# 2


2022-09-29 22:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.