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

2018-09-03 Thread Jacco van Dorp
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

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

2018-09-01 Thread Jonathan Fine
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 I > having a 2:30am brain fart? Let's see.

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

2018-08-31 Thread Oscar Benjamin
On Thu, 30 Aug 2018 at 17:36, Stephan Houben wrote: > > I would also like to point out that the current behavior of Fraction > is consistent with other parts of the numeric system, e.g. > 1/1 produces 1.0 (rather than 1) > math.sqrt(4) produces 2.0 (rather than 2) > 1j-1j produces 0j (rather than

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

2018-08-31 Thread Neil Girdhar
On Thu, Aug 30, 2018 at 9:03 AM Steven D'Aprano wrote: > On Wed, Aug 29, 2018 at 09:39:05PM -0700, Neil Girdhar wrote: > > > Would there be any problem with changing: > > > > In [4]: Fraction(1, 1) ** Fraction(2, 3) > > Out[4]: 1.0 > > > > In [5]: Fraction(-1, 1) ** Fraction(2, 3) > > Out[5]:

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

2018-08-30 Thread Greg Ewing
Neil Girdhar wrote: Powers of other numbers have to keep the same behavior since in general those kinds of expressions don't create rational numbers. There are infinitely many other rational numbers that *could* be given the same treatment, though, e.g. (-8) ** (2/3). If you don't want to

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

2018-08-30 Thread Brendan Barnwell
On 2018-08-30 00:07, Greg Ewing wrote:> Jonathan Goble wrote: >> How? Raising something to the 2/3 power means squaring it and then >> taking the cube root of it. > > On reflection, "wrong" is not quite accurate. A better > word might be "surprising". > > (-1) ** (2/3) == 1 would imply that 1 **

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

2018-08-30 Thread Stephan Houben
I would also like to point out that the current behavior of Fraction is consistent with other parts of the numeric system, e.g. 1/1 produces 1.0 (rather than 1) math.sqrt(4) produces 2.0 (rather than 2) 1j-1j produces 0j (rather than 0.0 or 0) So in general the type of the output is determined by

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

2018-08-30 Thread Paul Moore
On Thu, 30 Aug 2018 at 14:06, Nicolas Rolin wrote: > I think you could take the implementation further and decide that any > power of Fraction(1) is Fraction(1) and any positive power of Fraction(0) > is Fraction(0). > I woudn't be shocked that Fraction(1) ** 3.7 == Fraction(1) and > Fraction(0)

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

2018-08-30 Thread Nicolas Rolin
I think you could take the implementation further and decide that any power of Fraction(1) is Fraction(1) and any positive power of Fraction(0) is Fraction(0). I woudn't be shocked that Fraction(1) ** 3.7 == Fraction(1) and Fraction(0) ** 3.7 == 0. However the implementation for Fraction(-1)

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

2018-08-30 Thread Steven D'Aprano
On Wed, Aug 29, 2018 at 09:39:05PM -0700, Neil Girdhar wrote: > Would there be any problem with changing: > > In [4]: Fraction(1, 1) ** Fraction(2, 3) > Out[4]: 1.0 > > In [5]: Fraction(-1, 1) ** Fraction(2, 3) > Out[5]: (-0.4998+0.8660254037844387j) > > In [6]: Fraction(0, 1) **

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

2018-08-30 Thread Paul Moore
On Thu, 30 Aug 2018 at 12:04, Jonathan Fine wrote: > First, the docs for the fraction module could be improved. Here's the > page and it's history. > > https://docs.python.org/3/library/fractions.html > https://github.com/python/cpython/commits/3.7/Doc/library/fractions.rst > > Already,

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

2018-08-30 Thread Neil Girdhar
Hey, no worries. I do think though that people should feel free to suggest ideas even if they have never contributed anything. I read python-ideas for the discussion. Thank you for your feedback about my suggestion. On Thu, Aug 30, 2018 at 8:18 AM Jonathan Fine wrote: > Hi Neil > > When I

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

2018-08-30 Thread Jonathan Fine
Hi Neil When I wrote my previous message, I didn't know who you were, or your previous contributions. Perhaps I should have. But I didn't. If I had known, my remarks would have been different. In particular, I would have acknowledged your previous contributions. I apologise for any offence I may

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

2018-08-30 Thread Neil Girdhar
;0067a655-4f82-479f-9970-5b72dc079...@googlegroups.com> > Created on:30 August 2018 at 05:39 (Delivered after 74 seconds) > From:Neil Girdhar > To:python-ideas > Subject:[Python-ideas] Fix some special cases in Fractions? > > Paul > ___

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

2018-08-30 Thread Paul Moore
u have the wrong address for the list in your mail client? Message ID<0067a655-4f82-479f-9970-5b72dc079...@googlegroups.com> Created on:30 August 2018 at 05:39 (Delivered after 74 seconds) From:Neil Girdhar To:python-ideas Subject:[Pytho

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

2018-08-30 Thread Neil Girdhar
On Thu, Aug 30, 2018 at 7:13 AM Paul Moore wrote: > (You're still not fixing your mail headers. Please do, it's hard to be > bothered responding if I keep having to fix your mails in order to do > so). > Sorry about that, I don't understand where it's coming from. I'm never using google

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

2018-08-30 Thread Neil Girdhar
On Thu, Aug 30, 2018 at 7:03 AM Jonathan Fine wrote: > Hi Neil > > Summary: You say something should be done. But by who? Perhaps the > should starts with you. > What does this mean? Are you asking who is going to do the implementation? I posted here to get feedback about whether it would be

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

2018-08-30 Thread Neil Girdhar
Thanks for the feedback. On Thu, Aug 30, 2018 at 7:13 AM Paul Moore wrote: > (You're still not fixing your mail headers. Please do, it's hard to be > bothered responding if I keep having to fix your mails in order to do > so). > > On Thu, 30 Aug 2018 at 11:28, Neil Girdhar wrote: > > > > But

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

2018-08-30 Thread Paul Moore
(You're still not fixing your mail headers. Please do, it's hard to be bothered responding if I keep having to fix your mails in order to do so). On Thu, 30 Aug 2018 at 11:28, Neil Girdhar wrote: > > But I'm only asking for fractional powers of -1, 0, and 1. Is that really a > complex issue?

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

2018-08-30 Thread Jonathan Fine
Hi Neil Summary: You say something should be done. But by who? Perhaps the should starts with you. Warning: This has been written quickly, and might have rough edges. If so, I apologise. You wrote > But I'm only asking for fractional powers of -1, 0, and 1. Is that really a > complex issue?

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

2018-08-30 Thread Neil Girdhar
On Thu, Aug 30, 2018 at 5:51 AM Nicolas Rolin 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

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

2018-08-30 Thread Jonathan Fine
Jeroen Demeyer wrote from sympy import Rational Rational(1,2) ** Rational(2,3) > 2**(1/3)/2 Rational(1,1) ** Rational(2,3) > 1 Rational(-1,1) ** Rational(2,3) > (-1)**(2/3) Rational(0,1) ** Rational(2,3) > 0 Thank you very much for this, Jeroen. Most helpful. Perhaps

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

2018-08-30 Thread Nicolas Rolin
>> 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

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

2018-08-30 Thread Neil Girdhar
On Thu, Aug 30, 2018 at 5:27 AM Greg Ewing wrote: > Neil Girdhar wrote: > > 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. >

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

2018-08-30 Thread Jeroen Demeyer
With gmpy2 (note that mpq=fractions, mpfr=floating-point reals): >>> from gmpy2 import mpq >>> mpq("1/1") ** mpq("2/3") mpfr('1.0') >>> mpq("-1/1") ** mpq("2/3") mpfr('nan') >>> mpq("0/1") ** mpq("2/3") mpfr('0.0') ___ Python-ideas mailing list

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

2018-08-30 Thread Jeroen Demeyer
On 2018-08-30 11:11, Jonathan Fine wrote: If anyone has time and ready access, it would help to know what https://www.sympy.org/en/index.html does with this. It handles such powers symbolically, not actually returning a numerical result: >>> from sympy import Rational >>> Rational(1,2) **

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

2018-08-30 Thread Greg Ewing
Neil Girdhar wrote: 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. This is not like Fraction where we know that x ** Fraction(1, 3)

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

2018-08-30 Thread Neil Girdhar
On Thu, Aug 30, 2018 at 5:11 AM Jonathan Fine wrote: > Hi Neil > > We wrote > > >> This gives the same results as Python's Fraction, except for your > >> example [6]. There, it gives the Fraction(0) you ask for. > >> > >> If the smart mathematicians and computer scientists that wrote gp/pari >

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

2018-08-30 Thread Jeroen Demeyer
On 2018-08-30 11:05, Jonathan Fine wrote: I'm used to using a number theory computer algebra system https://pari.math.u-bordeaux.fr/. I don't think that a comparison with PARI is very relevant because PARI doesn't really have a type system the way that Python does. For example the fraction

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

2018-08-30 Thread Jonathan Fine
Hi Neil We wrote >> This gives the same results as Python's Fraction, except for your >> example [6]. There, it gives the Fraction(0) you ask for. >> >> If the smart mathematicians and computer scientists that wrote gp/pari >> get the same answers, it suggests to me that improvement would be >>

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

2018-08-30 Thread Jonathan Fine
Hi Neil You wrote: > Would there be any problem with changing: > In [4]: Fraction(1, 1) ** Fraction(2, 3) > Out[4]: 1.0 > In [5]: Fraction(-1, 1) ** Fraction(2, 3) > Out[5]: (-0.4998+0.8660254037844387j) > In [6]: Fraction(0, 1) ** Fraction(2, 3) > Out[6]: 0.0 > I'd like these to

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

2018-08-30 Thread Neil Girdhar
On Thu, Aug 30, 2018 at 4:38 AM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Neil Girdhar writes: > > > There are a lot of misunderstandings in this thread. It's probably > > best to start by reading up on the roots of unity ( > >

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

2018-08-30 Thread Stephen J. Turnbull
Neil Girdhar writes: > There are a lot of misunderstandings in this thread. It's probably > best to start by reading up on the roots of unity ( > https://en.wikipedia.org/wiki/Root_of_unity). That's not very polite, especially in context where somebody has already conceded that his "wrong"

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

2018-08-30 Thread Neil Girdhar
On Thu, Aug 30, 2018 at 4:01 AM Paul Moore wrote: > On Thu, 30 Aug 2018 at 08:38, Neil Girdhar wrote: > > > > There are a lot of misunderstandings in this thread. It's probably best > to start by reading up on the roots of unity ( > https://en.wikipedia.org/wiki/Root_of_unity). The key ideas

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

2018-08-30 Thread Paul Moore
Sorry if this gets double posted. Can people using Google Groups *please* adjust the mail headers so that mailing list posters can reply without getting errors? Ideally stop using Google Groups, but if you have to, please consider those that don't. Specifically, please remove the Google Groups

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

2018-08-30 Thread Paul Moore
On Thu, 30 Aug 2018 at 08:38, Neil Girdhar wrote: > > There are a lot of misunderstandings in this thread. It's probably best to > start by reading up on the roots of unity > (https://en.wikipedia.org/wiki/Root_of_unity). The key ideas are that a real > number has two complex square roots,

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

2018-08-30 Thread Neil Girdhar
There are a lot of misunderstandings in this thread. It's probably best to start by reading up on the roots of unity ( https://en.wikipedia.org/wiki/Root_of_unity). The key ideas are that a real number has two complex square roots, three complex cube roots, and so on. Normally, in Python, we

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

2018-08-30 Thread Greg Ewing
Jonathan Goble wrote: How? Raising something to the 2/3 power means squaring it and then taking the cube root of it. On reflection, "wrong" is not quite accurate. A better word might be "surprising". (-1) ** (2/3) == 1 would imply that 1 ** (3/2) == -1. I suppose that could be considered true

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

2018-08-30 Thread Chris Angelico
On Thu, Aug 30, 2018 at 4:30 PM, Jonathan Goble wrote: > On Thu, Aug 30, 2018, 2:08 AM Greg Ewing > 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,

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

2018-08-30 Thread Neil Girdhar
On Thu, Aug 30, 2018 at 2:09 AM Greg Ewing wrote: > Jeroen Demeyer wrote: > > On 2018-08-30 06:39, Neil Girdhar wrote: > > > >> I'd like these to be Fraction(1), Fraction(1), and Fraction(0). > > > > Why? I cannot think of any natural use case why you would want Fractions > > for a few special

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

2018-08-30 Thread Jonathan Goble
On Thu, Aug 30, 2018, 2:08 AM Greg Ewing 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 I having a 2:30am brain fart? >

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

2018-08-30 Thread Greg Ewing
Jeroen Demeyer wrote: On 2018-08-30 06:39, Neil Girdhar wrote: I'd like these to be Fraction(1), Fraction(1), and Fraction(0). Why? I cannot think of any natural use case why you would want Fractions for a few special cases on an operation which returns non-Fractions generically. Also,

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

2018-08-29 Thread Jeroen Demeyer
On 2018-08-30 06:39, Neil Girdhar wrote: I'd like these to be Fraction(1), Fraction(1), and Fraction(0). Why? I cannot think of any natural use case why you would want Fractions for a few special cases on an operation which returns non-Fractions generically. I consider it a feature to know

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

2018-08-29 Thread Neil Girdhar
Would there be any problem with changing: In [4]: Fraction(1, 1) ** Fraction(2, 3) Out[4]: 1.0 In [5]: Fraction(-1, 1) ** Fraction(2, 3) Out[5]: (-0.4998+0.8660254037844387j) In [6]: Fraction(0, 1) ** Fraction(2, 3) Out[6]: 0.0 I'd like these to be Fraction(1), Fraction(1), and