On May 4, 2009, at 10:45 AM, kcrisman wrote:

> Dear support,
>
> I assume this is known, but I am wondering whether it should be
> treated as a bug, or whether someone using len() on lists should be
> assumed to know it might then be operated on with Python /, not
> Sage /, as opposed to the preparser catching this sort of thing.

len() is a Python builtin, which is a good indication that it will  
return Python types (especially when acting on a Python type). In  
fact, there's no way on the c-api level to return a Sage integer, as  
len() always returns a c long. This is similar to range returning a  
list of python ints.

> sage: len([2,2])/len([2,3,4])
> 0
>
> Thanks for any suggestions on what to do with this - right now I have
> to do
>
> sage: Integer(len([2,2]))/Integer(len([2,3,4]))
> 2/3

Yep, that's how to do it. (Note that only one of the numerator/ 
denominator needs to be cast, as coercion will cast the other.)

sage: Integer(2)/int(3)
2/3
sage: int(2)/Integer(3)
2/3
sage: int(2)/int(3)
0

- Robert


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to