First time here? Check out the FAQ!

Ask Your Question
0

When is 0^0 NaN in Sage?

asked 14 years ago

ccanonc gravatar image

updated 10 years ago

FrédéricC gravatar image

sage: 1 == 0^0 == 0**0 == pow(0,0)
True

sage: power_mod(0,0,2)
Traceback (click to the left of this block for traceback)
...
ArithmeticError: 0^0 is undefined.



http://en.wikipedia.org/wiki/Exponentiation#IEEE_floating_point_standard

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
2

answered 14 years ago

jsrn gravatar image

Here 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.

Preview: (hide)
link
1

answered 14 years ago

Jason Grout gravatar image

In 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
Preview: (hide)
link
0

answered 14 years ago

mandrake gravatar image

As an input: Matlab computes 0^0 to 1.

>> version
ans =
7.9.0.529 (R2009b)
>> 0^0
ans =
     1
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 14 years ago

Seen: 858 times

Last updated: Dec 10 '10