Hi Team!

I'm using sympy to programmatically solve systems of equations, that are 
essentially linear, but some equations contain Max or Min in some easy 
manner. However, sympy.solve seems to throw a NotImplementedError in such 
cases. This makes sense, if currently Min and Max are not supported by 
sympy.solve.

That said, if I rewrite the equations to Piecwise, then it can solve the 
system in many cases. But sometimes it throws an Invalid NaN comparison 
somewhere in relational.py. See below for a minimal example that reproduces 
the issue (system is x=Max(1, y), y=Max(2, x)).

I'm not quite sure if this is the intended behaviour or not, but I don't 
know enough of the inner workings of sympy to identify the direct cause of 
the NaN comparison exception. The solution I'm looking for here is x=y>=2. 
Now if I only give one equation (say, x=Max(1,x)), then the Piecewise 
version throws me a NotImplementedError, but also tells me that the 
solution is likely containing the region x>1, which is helpful. 

Finally, solveset corretly identifies the interval solution for x=Max(1,x) 
for reals, but I don't know is solveset can be directly called somehow on a 
system or not.

So my questions are:
1) Is the expected behaviour for sympy.solve for the Piecewise case to 
throw a NaN comparison exception, or is this a sign of some underlying 
issue in sympy.solve for Piecewise functions?
2) Is sympy.solve expected to rewrite Min and Max to Piecewise at some 
point in the future? I found some piece of code in 
solvers/solvers.py:944-957 which does some sort of rewriting for Abs, but 
didn't find any for Min or Max.
3) From some reading on the sympy docs page, I figured solveset is expected 
to be the future solver. Is there a direct way I can apply solveset on a 
system, rather than on one equation?
4) If the answer to 3) is yes, is there also a way which provides a stable 
output that I can use in a programmatic way?

Thanks for the help!
Gábor

#######################################
## Minimal working example reproducing the error: ##
#######################################

import sympy
x, y = sympy.symbols('x y', real=True)
sys = [sympy.Eq(x, sympy.Max(y, 1)), sympy.Eq(y, sympy.Max(2, x))]
variables = (x, y)
sympy.solve(sys, variables)
new_sys = [eq.rewrite(sympy.Piecewise) for eq in sys]
sympy.solve(new_sys, variables)

-- 
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/sympy/99c54068-efa4-4133-81ba-e03b90cc4d52n%40googlegroups.com.

Reply via email to