Re: Decimals and other numbers

2015-01-10 Thread alister
On Fri, 09 Jan 2015 19:57:20 -0800, Devin Jeanpierre wrote: > On Fri, Jan 9, 2015 at 7:05 PM, Gregory Ewing > wrote: >> It's far from clear what *anything* multiplied by itself zero times >> should be. >> >> A better way of thinking about what x**n for integer n means is this: >> Start with 1, an

Re: Decimals and other numbers

2015-01-09 Thread Devin Jeanpierre
On Fri, Jan 9, 2015 at 7:05 PM, Gregory Ewing wrote: > It's far from clear what *anything* multiplied by > itself zero times should be. > > A better way of thinking about what x**n for integer > n means is this: Start with 1, and multiply it by > x n times. The result of this is clearly 1 when n >

Re: Decimals and other numbers

2015-01-09 Thread Gregory Ewing
Steven D'Aprano wrote: I'm just sketching an informal proof. If you want to make it vigorous I think the usual term is "rigorous", unless the mathematician is taking some kind of stimulant... :-) -- Greg -- https://mail.py

Re: Decimals and other numbers

2015-01-09 Thread Gregory Ewing
Steven D'Aprano wrote: Arguably, *integer* 0**0 could be zero, on the basis that you can't take limits of integer-valued quantities, and zero times itself zero times surely has to be zero. It's far from clear what *anything* multiplied by itself zero times should be. A better way of thinking a

Re: Decimals and other numbers

2015-01-09 Thread Devin Jeanpierre
On Fri, Jan 9, 2015 at 2:20 AM, Steven D'Aprano wrote: -snip- > I don't understand what you're trying to say here. You can't just > arbitrarily declare that 0**1 equals something other than 0 (or for that > matter, doesn't equal anything at all). You can, actually. It's just silly. (Similarly, yo

Re: Decimals and other numbers

2015-01-09 Thread Chris Angelico
On Fri, Jan 9, 2015 at 11:24 PM, Steven D'Aprano wrote: >> 5 * 0 * 0 * 0 * 0 = 0 > > Where did the 5 come from? > > You're effectively saying that 0**0 becomes 5*0**0, then cancelling the 0**0 > because they're all zeroes and so don't matter, leaving 5. And that simply > doesn't work. If it did wo

Re: Decimals and other numbers

2015-01-09 Thread Steven D'Aprano
I want to emphasis that I'm not really arguing that 0**0 should evaluate as 0. That's probably the least useful thing we can have out of the four possibilities: - return 1 - return NAN - raise an exception - return 0 But in the spirit of the Devil's Advocate, I mentioned that there was an argumen

Re: Decimals and other numbers

2015-01-09 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Steven D'Aprano : > >> mathematicians with a pragmatic bent > > You shouldn't call engineers and scientists mathematicians ("with a > pragmatic bent"). Rigor is an absolute requirement for any mathematics. I wasn't referring to engineers, scientists, short-order cooks or

Re: Decimals and other numbers

2015-01-09 Thread Chris Angelico
On Fri, Jan 9, 2015 at 9:20 PM, Steven D'Aprano wrote: > On the basis that m**n means m multiplied by itself n times: > > 5**4 = 5*5*5*5 = 625 > > that gives us: > > 0**0 = zero multiplied by itself zero times. > > You can multiply 0 by any number you like, and the answer will always be 0, > not 1

Re: Decimals and other numbers

2015-01-09 Thread Steven D'Aprano
I think we're in violent agreement here, nevertheless I think you're right for the wrong reasons. See below... Devin Jeanpierre wrote: > On Fri, Jan 9, 2015 at 12:49 AM, Steven D'Aprano > wrote: >> Devin Jeanpierre wrote: >> >>> On Thu, Jan 8, 2015 at 6:43 PM, Dave Angel wrote: What you d

Re: Decimals and other numbers

2015-01-09 Thread Marko Rauhamaa
Steven D'Aprano : > Devin Jeanpierre wrote: > No you can't -- that would make arithmetic inconsistent. 0**1 is > perfectly well defined as 0 however you look at it: You *could* leave 0**1 undefined. You *could* leave 7+0 undefined. However, that would make mathematical proofs more complex as they

Re: Decimals and other numbers

2015-01-09 Thread Marko Rauhamaa
Steven D'Aprano : > mathematicians with a pragmatic bent You shouldn't call engineers and scientists mathematicians ("with a pragmatic bent"). Rigor is an absolute requirement for any mathematics. Marko -- https://mail.python.org/mailman/listinfo/python-list

Re: Decimals and other numbers

2015-01-09 Thread Marko Rauhamaa
Chris Angelico : > I'm not a mathematical expert, so I don't quite 'get' this. How does > this justify 0**0 being equal to 0.5? Many operations like this are defined in terms of some very strong argument of uniqueness. Ultimately, the key point is safety in mathematical deductions. One minimal re

Re: Decimals and other numbers

2015-01-09 Thread Devin Jeanpierre
On Fri, Jan 9, 2015 at 12:58 AM, Devin Jeanpierre wrote: >> Arguably, *integer* 0**0 could be zero, on the basis that you can't take >> limits of integer-valued quantities, and zero times itself zero times >> surely has to be zero. I should have responded in more detail here, sorry. If you aren'

Re: Decimals and other numbers

2015-01-09 Thread Jussi Piitulainen
Devin Jeanpierre writes: [...] > domain of the natural numbers. Knuth says that thought of > combinatorially on the naturals, x**y counts the number of mappings > from a set of x values to a set of y values. It's the other way around, of course: from a set of y values to a set of x values. Whi

Re: Decimals and other numbers

2015-01-09 Thread Devin Jeanpierre
On Fri, Jan 9, 2015 at 12:49 AM, Steven D'Aprano wrote: > Devin Jeanpierre wrote: > >> On Thu, Jan 8, 2015 at 6:43 PM, Dave Angel wrote: >>> What you don't say is which behavior you actually expected. Since 0**0 >>> is undefined mathematically, I'd expect either an exception or a NAN >>> result.

Re: Decimals and other numbers

2015-01-09 Thread Devin Jeanpierre
Marko, your argument is "this function x**y(a, x) must be continuous on [0, inf), and to be continuous at 0, 0**0 must be a". Since there are many possible values of a, this is not a "justification", this is a proof by contradiction that the premise was faulty: x**y(a, x) doesn't have to be continu

Re: Decimals and other numbers

2015-01-09 Thread Steven D'Aprano
Devin Jeanpierre wrote: > On Thu, Jan 8, 2015 at 6:43 PM, Dave Angel wrote: >> What you don't say is which behavior you actually expected. Since 0**0 >> is undefined mathematically, I'd expect either an exception or a NAN >> result. > > It can be undefined, if you choose for it to be. You can a

Re: Decimals and other numbers

2015-01-08 Thread Dave Angel
On 01/09/2015 02:37 AM, Chris Angelico wrote: On Fri, Jan 9, 2015 at 6:28 PM, Marko Rauhamaa wrote: Devin Jeanpierre : If 0**0 is defined, it must be 1. You can "justify" any value a within [0, 1]. For example, choose y(a, x) = log(a, x) Then, limy(a, x) = 0 x -> 0+ and

Re: Decimals and other numbers

2015-01-08 Thread Chris Angelico
On Fri, Jan 9, 2015 at 6:28 PM, Marko Rauhamaa wrote: > Devin Jeanpierre : > >> If 0**0 is defined, it must be 1. > > You can "justify" any value a within [0, 1]. For example, choose > >y(a, x) = log(a, x) > > Then, > > limy(a, x) = 0 >x -> 0+ > > and: > >lim[x -> 0+] x**y(a, x

Re: Decimals and other numbers

2015-01-08 Thread Marko Rauhamaa
Devin Jeanpierre : > If 0**0 is defined, it must be 1. You can "justify" any value a within [0, 1]. For example, choose y(a, x) = log(a, x) Then, limy(a, x) = 0 x -> 0+ and: lim[x -> 0+] x**y(a, x) = a For example, >>> a = 0.5 >>> x = 1e-100 >>> y = math.log(a, x)

Re: Decimals and other numbers

2015-01-08 Thread Marko Rauhamaa
Dave Angel : > What you don't say is which behavior you actually expected. Since 0**0 > is undefined mathematically, I'd expect either an exception or a NAN > result. IEEE 754 mandates that 0**0 should evaluate to 1: http://en.wikipedia.org/wiki/NaN#Operations_generating_NaN> The standar

Re: Decimals and other numbers

2015-01-08 Thread Devin Jeanpierre
Thanks Ben, with your encouragement I have filed http://bugs.python.org/issue23201 -- Devin On Thu, Jan 8, 2015 at 7:03 PM, Ben Finney wrote: > Dave Angel writes: > >> What you don't say is which behavior you actually expected. Since >> 0**0 is undefined mathematically, I'd expect either an ex

Re: Decimals and other numbers

2015-01-08 Thread Ben Finney
Dave Angel writes: > What you don't say is which behavior you actually expected. Since > 0**0 is undefined mathematically, I'd expect either an exception or a > NAN result. Do you think that the ‘int’ and ‘float’ types, which do produce a number result for ‘0 ** 0’, are buggy and should be fixe

Re: Decimals and other numbers

2015-01-08 Thread Devin Jeanpierre
On Thu, Jan 8, 2015 at 6:43 PM, Dave Angel wrote: > What you don't say is which behavior you actually expected. Since 0**0 is > undefined mathematically, I'd expect either an exception or a NAN result. It can be undefined, if you choose for it to be. You can also choose to not define 0**1, of co

Re: Decimals and other numbers

2015-01-08 Thread Chris Rebert
On Thu, Jan 8, 2015 at 6:33 PM, Devin Jeanpierre wrote: > I noticed some very PHP-ish behavior today: > import decimal x = 0 y = float(x) z = decimal.Decimal(x) x == y == z == x > True x ** x > 1 y**y > 1.0 z**z > Traceback (most recent call last): > File

Re: Decimals and other numbers

2015-01-08 Thread Dave Angel
On 01/08/2015 09:33 PM, Devin Jeanpierre wrote: I noticed some very PHP-ish behavior today: import decimal x = 0 y = float(x) z = decimal.Decimal(x) x == y == z == x True x ** x 1 y**y 1.0 z**z Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/decimal

Re: Decimals and other numbers

2015-01-08 Thread Ben Finney
Devin Jeanpierre writes: > decimal.InvalidOperation: 0 ** 0 > > I'd file a bug report but I'm anticipating some rational (heh) > explanation. Any ideas? First note that it's explicitly documented as an invalid operation . So someone has at least thought about it and deliberately decided it shoul