ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 10 Dec 2010 04:24:22 +0100When is 0^0 NaN in Sage?https://ask.sagemath.org/question/7676/when-is-00-nan-in-sage/sage: 1 == 0^0 == 0**0 == pow(0,0) <br>
True <br>
<br>
sage: power_mod(0,0,2) <br>
Traceback (click to the left of this block for traceback) <br>
... <br>
ArithmeticError: 0^0 is undefined. <br>
<hr>
<br>
[http://en.wikipedia.org/wiki/Exponentiation#IEEE\_floating\_point\_standard][1]
[1]: http://en.wikipedia.org/wiki/Exponentiation#IEEE_floating_point_standardWed, 08 Sep 2010 16:04:29 +0200https://ask.sagemath.org/question/7676/when-is-00-nan-in-sage/Answer by Jason Grout for <p>sage: 1 == 0^0 == 0**0 == pow(0,0) <br/>
True <br/>
<br/>
sage: power_mod(0,0,2) <br/>
Traceback (click to the left of this block for traceback) <br/>
... <br/>
ArithmeticError: 0^0 is undefined. <br/>
</p><hr/>
<br/>
<a href="http://en.wikipedia.org/wiki/Exponentiation#IEEE_floating_point_standard">http://en.wikipedia.org/wiki/Exponentiation#IEEE_floating_point_standard</a><p></p>
https://ask.sagemath.org/question/7676/when-is-00-nan-in-sage/?answer=11643#post-id-11643In the code, I see that that power_mod makes a special case for 0^0. Maybe it shouldn't? Mathematica leaves it as a more correct Indeterminate
Mathematica 7.0 for Mac OS X x86 (64-bit)
Copyright 1988-2008 Wolfram Research, Inc.
In[1]:= 0^0
0
Power::indet: Indeterminate expression 0 encountered.
Out[1]= Indeterminate
Thu, 09 Sep 2010 23:55:53 +0200https://ask.sagemath.org/question/7676/when-is-00-nan-in-sage/?answer=11643#post-id-11643Answer by mandrake for <p>sage: 1 == 0^0 == 0**0 == pow(0,0) <br/>
True <br/>
<br/>
sage: power_mod(0,0,2) <br/>
Traceback (click to the left of this block for traceback) <br/>
... <br/>
ArithmeticError: 0^0 is undefined. <br/>
</p><hr/>
<br/>
<a href="http://en.wikipedia.org/wiki/Exponentiation#IEEE_floating_point_standard">http://en.wikipedia.org/wiki/Exponentiation#IEEE_floating_point_standard</a><p></p>
https://ask.sagemath.org/question/7676/when-is-00-nan-in-sage/?answer=11845#post-id-11845As an input: Matlab computes `0^0` to `1`.
>> version
ans =
7.9.0.529 (R2009b)
>> 0^0
ans =
1
Fri, 10 Dec 2010 04:24:22 +0100https://ask.sagemath.org/question/7676/when-is-00-nan-in-sage/?answer=11845#post-id-11845Answer by jsrn for <p>sage: 1 == 0^0 == 0**0 == pow(0,0) <br/>
True <br/>
<br/>
sage: power_mod(0,0,2) <br/>
Traceback (click to the left of this block for traceback) <br/>
... <br/>
ArithmeticError: 0^0 is undefined. <br/>
</p><hr/>
<br/>
<a href="http://en.wikipedia.org/wiki/Exponentiation#IEEE_floating_point_standard">http://en.wikipedia.org/wiki/Exponentiation#IEEE_floating_point_standard</a><p></p>
https://ask.sagemath.org/question/7676/when-is-00-nan-in-sage/?answer=11682#post-id-11682Here is another case:
sage: GF(7)(0)^0
---------------------------------------------------------------------------
ArithmeticError Traceback (most recent call last)
/home/jsrn/local/sage/<ipython console> in <module>()
/home/jsrn/local/sage/sage-4.5.3/local/lib/python2.6/site-packages/sage/rings/finite_rings/integer_mod.so in sage.rings.finite_rings.integer_mod.IntegerMod_int.__pow__ (sage/rings/finite_rings/integer_mod.c:16942)()
ArithmeticError: 0^0 is undefined.
The same goes for polynomial rings over fields: `GF(7)[x](0)^0`.
I think that the primary thing is for Sage to be consistent; as you hinted at, I would think that the following invariants should always hold:
a^x == a**x == pow(a,x)
and
a^x mod n == pow(a,x,n) == power_mod(a,x,n)
For all rings in which they make sense. The 0^0 case is sometimes convenient to define to 1, sometimes 0 and sometimes NaN, so I would think that always giving an error is sensible. It is kind of annoying to often have to work around in general formulas, but on the other hand, in each of these cases, Sage will force you to consider the behaviour that makes mathematical sense for you; otherwise, you might miss rare cases of errors. As an alternative, some sort of global setting (or ring-specific setting) might be added, so one could set the value.
The behaviour of `simplify` is another discussion, I guess. There, it might prove _very_ annoying to not simplify `0^some_expr`, but then again, I do like consistency.
Maybe this should be taken to sage_devel; maybe it has already been there? Sorry for the discussion-like quality of the answer.Tue, 21 Sep 2010 04:14:44 +0200https://ask.sagemath.org/question/7676/when-is-00-nan-in-sage/?answer=11682#post-id-11682