Max and Min not catching some vararg symbols calls
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
This is probably an ordering problem!
-
max(0, log(x))-->DomainError -
max(log(x), 0)-->Max(0, log(x))
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
This is a sympy issue (not SymPy.jl).
Therefore, closing this
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.