[Python-ideas] Fix some special cases in Fractions?
Neil Girdhar
mistersheik at gmail.com
Thu Aug 30 06:27:21 EDT 2018
On Thu, Aug 30, 2018 at 5:51 AM Nicolas Rolin <nicolas.rolin at tiime.fr>
wrote:
>
>
>
>>> 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.
>
But I'm only asking for fractional powers of -1, 0, and 1. Is that really
a complex issue?
You are right that the fractional power of -1 and 1 has multiple values,
but the fractional power of zero has a unique value.
>
> 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).
>
That's how I use the fractions package. If you look at my example code,
that seems like the kind of problem Fraction should make it easy to work
with. And yet, there was a wrinkle where I had to calculate Fraction(-1)
** Fraction(a, b).
>
> --
>
> *Nicolas Rolin*
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python-ideas/aZIHpPhe0mw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python-ideas/aZIHpPhe0mw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180830/b78160ca/attachment-0001.html>
More information about the Python-ideas
mailing list