[Python-ideas] Fix some special cases in Fractions?

Nicolas Rolin nicolas.rolin at tiime.fr
Thu Aug 30 05:50:11 EDT 2018


>> Right, but we already have some special cases:
>
> In [8]: Fraction(2, 3) ** Fraction(3, 1)
> Out[8]: Fraction(8, 27)
>
> Fraction.__pow__ already tries to return Fraction objects where possible.
>


I think the main point to see here is what the scope of a built-in function
should be.
For a fraction module in the stdlib, I would expect that it handle
"symbolically" any fraction multiplication or division of fractions, and
integer power of fractions.
Those are simple and useful cases, that can arise a bit anywhere. Power of
non-integer is a way more complex issue (notably because power of a
non-integer is not a function), and returning the same output as float is
at least an honest way of dealing with those cases.

I'm not really sure a stdlib should even try do deal with that. If I want
to have a symbolic way of handling complex power of fractions, I should
import a specific math library whose specific job is to get this right (the
same way if you want to do matrix stuff you have to import numpy).


--

*Nicolas Rolin*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180830/2d7f4fef/attachment.html>


More information about the Python-ideas mailing list