Ask Your Question

When is 0^0 NaN in Sage?

asked 2010-09-08 16:04:29 +0200

ccanonc gravatar image

updated 2015-01-14 09:52:21 +0200

FrédéricC gravatar image

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

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

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2010-09-21 04:14:44 +0200

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/ 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)


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.

edit flag offensive delete link more

answered 2010-09-09 23:55:53 +0200

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

Power::indet: Indeterminate expression 0  encountered.

Out[1]= Indeterminate
edit flag offensive delete link more

answered 2010-12-10 04:24:22 +0200

mandrake gravatar image

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

>> version
ans = (R2009b)
>> 0^0
ans =
edit flag offensive delete link more

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


Asked: 2010-09-08 16:04:29 +0200

Seen: 693 times

Last updated: Dec 10 '10