Код: Выделить всё
import sympy
inf = sympy.oo
inf_neg = -sympy.oo
inf_zoo = sympy.zoo
inf_neg_zoo = -sympy.zoo
for v in [inf, inf_neg, inf_zoo, inf_neg_zoo, sympy.Symbol("a")+sympy.Symbol("b")+inf]:
if isinstance(v, sympy.core.numbers.Infinity | sympy.core.numbers.NegativeInfinity | sympy.core.numbers.ComplexInfinity):
print(v,"is some type of Infinity")
else:
print(v, "is not infinite")
if v in [sympy.S.Infinity, sympy.S.NegativeInfinity, sympy.S.ComplexInfinity]:
print(v,"is some type of Infinity")
else:
print(v, "is not infinite")
if v == sympy.oo or -v == sympy.oo or v == sympy.zoo:
print(v,"is some type of Infinity")
else:
print(v, "is not infinite")
Код: Выделить всё
oo is is some type of Infinite (isinstance)
oo is is some type of Infinite (sympy.S.xxx)
oo is is some type of Infinite (sympy.xxx)
-oo is is some type of Infinite (isinstance)
-oo is is some type of Infinite (sympy.S.xxx)
-oo is is some type of Infinite (sympy.xxx)
zoo is is some type of Infinite (isinstance)
zoo is is some type of Infinite (sympy.S.xxx)
zoo is is some type of Infinite (sympy.xxx)
zoo is is some type of Infinite (isinstance)
zoo is is some type of Infinite (sympy.S.xxx)
zoo is is some type of Infinite (sympy.xxx)
a + b + oo is not infinite
a + b + oo is not infinite
a + b + oo is not infinite
Однако мой вопрос заключается в том, есть ли более элегантный способ проверки бесконечности в Sympy, потому что во многих ситуациях, таких как моя, мне просто нужно знать, является ли выражение бесконечным, а не какой тип бесконечности.
PS: Я искал в документации Sympy и исходном коде, но не нашел других типов бесконечности.>
Подробнее здесь: https://stackoverflow.com/questions/798 ... e-in-sympy
Мобильная версия