On Tue, Sep 6, 2011 at 1:51 PM, kcrisman <kcris...@gmail.com> wrote: > What happens in Python 3.x, where I understand there *is* some kind of > rational object? Maybe we should be oriented toward compatibility > with that, if it's relevant. I didn't see a discussion of that in > this thread, my apologies if I missed it.
I'm finding it hard to understand what's going on in Python 3, but here it is: Python 3.2.2 (default, Sep 5 2011, 04:33:58) [GCC 4.6.1 20110819 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 1/4 0.25 >>> 2**(-2) 0.25 Hmmm. OK, so what's this rational concept number that Python 3 has? It must be: >>> from fractions import Fraction >>> Fraction(1, 4) Fraction(1, 4) >>> Fraction(1, 4) + Fraction(2, 3) Fraction(11, 12) Ah, alright. However: >>> Fraction(1/4) Fraction(1, 4) >>> Fraction(2/3) Fraction(6004799503160661, 9007199254740992) So this can get confusing really quick. What's going on is that Fraction takes a python float and finds the closest rational approximation where the denominator is bounded by a default (large) bound that can be modified by passing an optional argument. Note that the fractions module is actually present in python 2.6 (so it's in Sage right now!) but (a) Fraction(1/2) will fail from the sage prompt because 1/2 is first preprocessed into a Sage rational, and Fraction() doesn't know what to do with that and (b) even if you do sage -python you will see different behaviour than in Python 3, e.g. Fraction(2/3) will return Fraction(0, 1) because in python 2.6 you have 2/3=0, while in python 3+ you have 2/3=0.66666... I'm not sure we can stay compatible with Python on this *and* retain our sanity. Best, Alex -- Alex Ghitza -- Lecturer in Mathematics -- The University of Melbourne -- http://aghitza.org -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org