<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 30, 2018 at 4:01 AM Paul Moore <<a href="mailto:p.f.moore@gmail.com">p.f.moore@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, 30 Aug 2018 at 08:38, Neil Girdhar <<a href="mailto:mistersheik@gmail.com" target="_blank">mistersheik@gmail.com</a>> wrote:<br>
><br>
> There are a lot of misunderstandings in this thread.  It's probably best to start by reading up on the roots of unity (<a href="https://en.wikipedia.org/wiki/Root_of_unity" rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/Root_of_unity</a>).  The key ideas are that a real number has two complex square roots, three complex cube roots, and so on.<br>
<br>
The complexities of fractional powers aside, the type of a result<br>
should not depend on the values of the arguments. So I'm -1 on this<br>
change for that reason alone.<br>
<br></blockquote><div><br></div><div>Just so you know, it already does depend on the type of the arguments.</div><div><br></div><div><div>In [4]: Fraction(2) ** Fraction(1, 2)</div><div>Out[4]: 1.4142135623730951</div><div><br></div><div>In [5]: Fraction(2) ** Fraction(3, 1)</div><div>Out[5]: Fraction(8, 1)</div></div><div><br></div><div>Like a lot of types, Fraction tries to return a Fraction if it can.  This is consistent with how math.sqrt of a float returns a float and never a complex, and same for numpy.cbrt.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Questions of which root it's appropriate to take are separate, and IMO<br>
the sensible option is to follow the behaviour of float, for which we<br>
have<br>
<br>
>>> (-1)**(2/3)<br>
(-0.4999999999999998+0.8660254037844387j)<br></blockquote><div><br></div><div>But -1 ** Fraction(2, 3) is closer to cube_root(-1 ** 2) than it is to the floating behavior.</div><div><br></div><div>The reason the floating behavior returns what it does is, if I understand correctly, to try to stay on the same complex branch as the power varies.  In other words, we want branch continuity in the power.  After all, floating point values have some inaccuracy, and we wouldn't want chaotic behavior, i.e., small changes to the power to have drastic changes to the result.</div><div><br></div><div>This is not like Fraction where we know that x ** Fraction(1, 3) is a genuine cube root, and so why not return the principal cube, which we know to be real valued for real valued x?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
>>> (1)**(2/3)<br>
1.0<br>
>>> (0)**(2/3)<br>
0.0 </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
So current behaviour of Fraction is correct on that basis, IMO.<br>
<br>
Paul<br>
</blockquote></div></div>