New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zero to the zeroeth power: Complex numbers not consistent with others. #5504
Comments
From @smlsPerl 6 agrees with pretty much all programming languages that 0**0 == 1, and does so consistently for the Int, int, Rat, FatRat, and Num types. Just the Complex type doesn't play along: ➜ say (0+0i) ** 0; ➜ say (0+0i) ** (0+0i); I think these should both of these print 1+0i. ------ Mathematical background: ------ The value of "Zero to the power of zero" seems to be a historically controversial topic in mathematics: https://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_power_of_zero From that wiki article I gather that (0**0 == 1) is popular among those working with practical formulae and actual values, and (0**0 == undefined) popular among those focusing theoretical considerations about limits. Unsurprisingly, programming languages have sided with the former definition... In any case, I don't see a reason to treat Complex differently from the other numeric types. Then again, I'm not a mathematician. Input from an expert would be appreciated. ------ Other programming languages: ------ The ones I checked, seem to agree with my line of thought: Perl 5: $ perl -E 'use Math::Complex; say cplx(0,0) ** 0;' Ruby: $ ruby -e 'puts Complex(0,0) ** 0' Python: $ python For more examples, see: http://rosettacode.org/wiki/Zero_to_the_zero_power |
From @smlsAs a counter-point, the C++ standard library seems to think that 0+0i ** 0+0i == NaN+NaN\i: So maybe there *are* reasons for not extending the (practically convenient but theoretically dubious) 0⁰=1 definition to complex numbers? Still couldn't find any language or source to back up Perl 6's (0+0i ** 0+0i == 0+0i) though. |
From @smlsComparison table of the different cases of "zero to the zeroeth power" in Rakudo: n n**0 0**n n**n I think that's a pretty clear indication that the Complex case is in need of fixing. - either make all entries in the bottom row produce 1+0i (like Perl 5, Python, Ruby) Again, input from someone well versed in math programming would be great. |
From @zoffixznetOn Sat, 10 Sep 2016 23:17:33 -0700, smls75@gmail.com wrote:
Thanks for the report. The 0+0i case was returned because the case that does "zero to any power is zero" did not consider the power of zero. The NaNs in our case (and I suspect in C's case) are due to intermediary math operations involving logs and log(0) is a -Inf, which the rest of operations mangled further into a NaN Fixed for all cases to return 1+0i in: rakudo/rakudo@7f322436c9 |
The RT System itself - Status changed from 'new' to 'open' |
@zoffixznet - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#128785 (status was 'resolved')
Searchable as RT128785$
The text was updated successfully, but these errors were encountered: