refine with multiple variables

50 views
Skip to first unread message

Joseph Nasser

unread,
Oct 31, 2022, 3:10:05 PM10/31/22
to sympy
Hello,

I would like to check whether an inequality with multiple variables is satisfied under certain assumptions on the variables. Is this supported? Using refine seems to work with one variable but not a multi-variable expression. I am using Sympy 1.11.1 

from sympy import Q
var('z w', real=True)
refine(z**2 > 0, Q.positive(z)) # Returns BooleanTrue, expected behavior
refine(z**2 + w**2 > 0, Q.positive(z) & Q.positive(w)) #does not return a Boolean type

Thanks

Oscar Benjamin

unread,
Nov 1, 2022, 8:22:41 AM11/1/22
to sy...@googlegroups.com
Ideally things like this would work but support for multivariate
systems of inequalities is practically nonexistent in refine right
now.

Oscar
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/f0f91ba2-4432-419d-a832-9e43b5bd1b7en%40googlegroups.com.

Aaron Meurer

unread,
Nov 1, 2022, 7:03:21 PM11/1/22
to sy...@googlegroups.com
This is currently only implemented in ask(), and you have to use
Q.positive(x) instead of x > 0 (ask does not yet know how to deal with
inequalities directly):

>>> ask(Q.positive(z**2), Q.positive(z))
True
>>> ask(Q.positive(z**2 + w**2), Q.positive(z) & Q.positive(w))
True

Aaron Meurer

Jeremy Monat

unread,
Nov 2, 2022, 11:21:09 PM11/2/22
to sy...@googlegroups.com
Perhaps relevant: A new page on reducing ("solving") sets of inequalities has recently been published to the dev version of the documentation.

Jeremy Monat


Joseph Nasser

unread,
Nov 3, 2022, 5:02:11 PM11/3/22
to sy...@googlegroups.com
Thanks to all for the comments - much appreciated. Aaron's suggestion to use ask() is sufficient for me at the moment. It would be great to support relational inequalities between variables (eg, z > w) in the future. 



You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/tVo7iZx1ts0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAO00iLjFYopHD1cdsWuVG%3D%2BeTpvhjWNFMHWfNfD1%3DLe%2BGTHc8g%40mail.gmail.com.

Chris Smith

unread,
Nov 4, 2022, 9:55:05 PM11/4/22
to sympy
For simple domains like this, the old assumptions work. Just define `var('z w', positive=True)` and then the inequalities evaluate.

You might try AccumBounds for more complicated expressions

B = AccumBounds
(z**2 - w**2).subs(z,B(0,1)).subs(w,B(0,2))
AccumBounds(-4,1)

/c

Reply all
Reply to author
Forward
0 new messages