[Python-ideas] Fix some special cases in Fractions?
Jacco van Dorp
j.van.dorp at deonet.nl
Mon Sep 3 03:00:59 EDT 2018
If we wanted to be mathematically correct, taking a 4th root should give
you 4 answers. You could return a tuple of (4, -4, 4j, -4j) for a 4th root
of 256. It actually makes power to a Fraction(2, 4) unequal with a
Fraction(1, 2) calculating this way. (which, from what I can tell, is
exactly your point - don't just take a power and a square root for a
fractional power, reduce it to a float or whatever first to get
well-defined behaviour. )
But full mathematical correctness is probably not what we want either.
Current behaviour IMO is the only solution that returns only 1 answer but
does something sensible in all cases.
Op za 1 sep. 2018 om 20:35 schreef Jonathan Fine <jfine2358 at gmail.com>:
> Greg Ewing and Jonathan Goble wrote
> >> Also, Fraction(1) for the second case would be flat-out wrong.
> > How? Raising something to the 2/3 power means squaring it and then taking
> > the cube root of it. -1 squared is 1, and the cube root of 1 is 1. Or am
> > having a 2:30am brain fart?
> Let's see. What about computing the Fraction(2, 4) power by first
> squaring and then taking the fourth root. Let's start with (-16).
> Square to get +256. And then the fourth root is +4. I've just followed
> process Jonathan G suggested, without noticing that Fraction(2, 4) is
> equal to Fraction(1, 2).
> But Fraction(1, 2) is the square root. And -16 requires complex
> numbers for its square root. The problem, I think, may not be doing
> something sensible in any particular case. Rather, it could be doing
> something sensible and coherent in all cases. A bit like trying to fit
> a carpet that is cut to the wrong size for the room.
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas