SymPy.jl icon indicating copy to clipboard operation
SymPy.jl copied to clipboard

Max and Min not catching some vararg symbols calls

Open djsegal opened this issue 8 years ago • 4 comments

for example,

using SymPy
@syms x

max(0, log(x))

raises the following error:

ERROR: DomainError: in asBool(::SymPy.Sym) at /Applications/JuliaPro-0.5.1.1.app/Contents/Resources/pkgs-0.5.1.1/lib/v0.5/SymPy/src/logical.jl:101 in max(::Int64, ::SymPy.Sym) at ./operators.jl:87

djsegal avatar Jun 02 '17 20:06 djsegal

This is probably an ordering problem!

  • max(0, log(x)) --> DomainError

  • max(log(x), 0) --> Max(0, log(x))

djsegal avatar Jun 02 '17 20:06 djsegal

The code would throw in Python sympy as well.

In [1]: from sympy import init_session
   ...: init_session()
   ...: 
IPython console for SymPy 1.0 (Python 3.5.3-64-bit) (ground types: python)

These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)
>>> init_printing()

Documentation can be found at http://docs.sympy.org/1.0/

In [2]: min([0,x])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-46ea8625ecbc> in <module>()
----> 1 min([0,x])

/home/michele/local/miniconda3/lib/python3.5/site-packages/sympy/core/relational.py in __nonzero__(self)
    193 
    194     def __nonzero__(self):
--> 195         raise TypeError("cannot determine truth value of Relational")
    196 
    197     __bool__ = __nonzero__

TypeError: cannot determine truth value of Relational

mzaffalon avatar Jun 02 '17 20:06 mzaffalon

This is a sympy issue (not SymPy.jl).

Therefore, closing this

djsegal avatar Jun 03 '17 03:06 djsegal

Reopening, as the response to @djsegal 's question here offers an interesting way to extend the signature to Sym objects without ambiguity warnings. For example

Base.min(x::Sym, a) = sympy_meth(:Min, x, a)
Base.min(a, x::Union{SA, Real}) where {SA <: Sym} = sympy_meth(:Min, x, a)

(or a generality) will match Sym objects in a later position than the first.

jverzani avatar Jun 05 '17 11:06 jverzani