I'm using SymPy to handle symbolic mathematics involving possibly infinite values. I need to define a symbol y>=0
and y<=sympy.inf
and tried the following but the behaviour is not as I would expect it:
import sympy
y = sympy.symbols("y", finite=False, extended_nonnegative=True)
print(y >= 0) # True (as expected)
print(y < sympy.oo) # False (should be uncertain)
print(y > 19) # True (should be uncertain)
How to ensure the last two comparisons ain't evaluated?
I'm using SymPy to handle symbolic mathematics involving possibly infinite values. I need to define a symbol y>=0
and y<=sympy.inf
and tried the following but the behaviour is not as I would expect it:
import sympy
y = sympy.symbols("y", finite=False, extended_nonnegative=True)
print(y >= 0) # True (as expected)
print(y < sympy.oo) # False (should be uncertain)
print(y > 19) # True (should be uncertain)
How to ensure the last two comparisons ain't evaluated?
Share Improve this question asked Mar 15 at 13:31 CorramCorram 3331 gold badge3 silver badges17 bronze badges 6 | Show 1 more comment1 Answer
Reset to default -1From the docs
when an inequality is indeterminate: we get an instance of StrictGreaterThan which represents the inequality as a symbolic expression.
which refers to
x = Symbol('x')
type(x > 0)
<class 'sympy.core.relational.StrictGreaterThan'>
In this case it returns
type(y > 19)
<class 'sympy.logic.boolalg.BooleanTrue'>
which is not Python's True
but a sympy's symbolic boolean
>>> (y > 19) is True
False
>>> type(y < sympy.oo)
<class 'sympy.logic.boolalg.BooleanFalse'>
>>> y.is_infinite is True
True
>>> sympy.core.relational.StrictLessThan(y, sympy.oo)
False
>>> type(sympy.core.relational.StrictLessThan(y, sympy.oo))
<class 'sympy.logic.boolalg.BooleanFalse'>
>>> sympy.Eq(y, sympy.oo)
True
>>> type(y)
<class 'sympy.core.symbol.Symbol'>
>>> type(sympy.oo)
<class 'sympy.core.numbers.Infinity'>
oo
. You declared it to beextended_nonnegative
so it is a nonnegative element of the extended reals. You also said it is not finite so it must beoo
. If you have some other idea of whaty
is supposed to represent then that is not what the stated assumptions mean: docs.sympy./latest/guides/assumptions.html#predicates – Oscar Benjamin Commented Mar 15 at 14:12y = sympy.symbols("y", extended_nonnegative=True)
doesn't work. For some reason, SymPy thinks thaty < sympy.oo
wheny
is defined this way.) – user2357112 Commented Mar 15 at 15:00symbols('y', extended_nonnegative=True) < oo
is a bug which should be reported to github. For implementing the Archimedean copula I think that the main question here is probably not relevant. It would be better to ask about what you are actually trying to do rather than this question about the assumptions system and inequalities. – Oscar Benjamin Commented Mar 15 at 16:08