On Tuesday, May 12, 2015 at 12:28:31 AM UTC-7, Nathann Cohen wrote:
>
> 2) Return "Unknown" instead of False in the __bool__ function od symbolic 
> comparisons (yes/no)
>

I'd expect that not to be an option. I expect that `__bool__` can only 
return True or False. You could raise an exception, though, but then you'd 
need to find out when to do that.

Incidentally, the docstring of Expression.__nonzero__, which is responsible 
for this (oddly enough, Expression.__nonzero__ does not give the custom 
docstring, but Expression.__hash__ does, so cython is somehow treating 
these (which are both slot routines!) differently) isn't consistent: It 
claims that it will return True unless sage can establish that the 
expression is equal to zero, which would suggest "True" for "cannot decide" 
would be the appropriate answer. The tests clearly indicate otherwise, 
however.

Anyway, the penalty for wrapping our max shouldn't be too bad if we do it 
in cython:

cython("""
from sage.symbolic.expression import Expression
from sage.functions.min_max import max_symbolic
def mymax(*arg):
  if any(isinstance(a,Expression) for a in arg):
      return max_symbolic(*arg)
  else:
      return max(*arg)
""")

sage: %timeit mymax(1,2,3,4)
1000000 loops, best of 3: 1.32 µs per loop
sage: %timeit max(1,2,3,4)
1000000 loops, best of 3: 489 ns per loop

I haven't checked how optimized the code generated by the `any` is, but 
perhaps this can be optimized further. 

Or you can go all the way and basically reimplement min_max:

https://github.com/python/cpython/blob/master/Python/bltinmodule.c#L1462

(should be a little shorter in cython) and bail on a typecheck of the 
arguments. Then the penalty should be pretty minimal.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to