On Sat, Jul 24, 2010 at 2:29 PM, Burcin Erocal <[email protected]> wrote:
> Hi,
>
> At Sage Days 24, I learned that Python allows the user to do arithmetic
> with bools:
>
> In [1]: 5+True
> Out[1]: 6
>
> In [2]: True + False
> Out[2]: 1
>
> In [3]: 5+False
> Out[3]: 5
>
> Sage seems to follow this convention as well:
>
> sage: 5 + True
> 6
> sage: 5. - True
> 4.00000000000000
>
> I can't see any use cases for this convention. I believe all these
> examples should just raise a TypeError. IMHO, code relying on this
> feature is very likely to be buggy.
>
> Apparently the symbolic ring doesn't handle things so well [1], but I'm
> not decided what the "fix" should be. :)
>
> [1] http://trac.sagemath.org/sage_trac/ticket/9560
>
> Any comments?

I do think that Sage symbolics should (eventually) support symbolic
booleans where True maps to 1 and False maps to 0.

See http://en.wikipedia.org/wiki/Iverson_bracket for use cases and prior art.

However, I would slightly prefer an explicit rather than implicit conversion.

Implicit:

  sgn(x) = (x > 0) - (x < 0)

Explicit:

  sgn(x) = iverson(x > 0) - iverson(x < 0)

So I wouldn't mind if the implicit conversions from bools to SR became
an error instead.

At any rate, the current behavior is definitely wrong :)

Carl

-- 
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to