0^0 undefined

17 views
Skip to first unread message

Georg

unread,
Jan 29, 2008, 1:18:00 PM1/29/08
to sage-newbie
Hi,
is there a way so that
0^0
yields 1.
thanks in advance, Georg

Hector Villafuerte

unread,
Jan 29, 2008, 4:45:12 PM1/29/08
to sage-...@googlegroups.com


Well, 0^0 is an indeterminate form:
http://en.wikipedia.org/wiki/Indeterminate_form#The_form_00

So, do you mean something like this?
sage: assume(x>0)
sage: limit(x^x, x=0)
1

Best,
--
Hector

Georg

unread,
Jan 30, 2008, 8:07:25 AM1/30/08
to sage-newbie
I know that it's an indeterminate form, thats why you can define it
however you want to fit your special purposes,
for example in the gmp library 0^0 yields 1, i.e. they define 0^0 :=
1,
my question was if there exists a way to define 0^0 in sage (or in
python),
so that in this case their is a well defined result instead of a "0^0
is undefined" error.

thanks, Georg

David Joyner

unread,
Jan 30, 2008, 8:32:26 AM1/30/08
to sage-...@googlegroups.com

Sympy does that but may redefine other things as well:

sage: from sympy import *
sage: 0^0
1

>
> thanks, Georg
>
> >
>

William Stein

unread,
Jan 30, 2008, 8:37:29 AM1/30/08
to sage-...@googlegroups.com
On Jan 30, 2008 8:07 AM, Georg <georg.gra...@gmail.com> wrote:
>
> I know that it's an indeterminate form, thats why you can define it
> however you want to fit your special purposes,
> for example in the gmp library 0^0 yields 1, i.e. they define 0^0 :=
> 1,
> my question was if there exists a way to define 0^0 in sage (or in
> python),

No, there isn't, not at runtime, since the integers are a precompiled
extension to Python. However, I've posted a patch here

http://trac.sagemath.org/sage_trac/ticket/1983

which will change this behavior in Sage so that 0^0 does yield 1.
This is consistent with PARI, Magma, Maple, GMP, MPFR, Python,
etc., so makes sense for Sage to do.

> so that in this case their is a well defined result instead of a "0^0
> is undefined" error.
>
> thanks, Georg
>
> >
>

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

William Stein

unread,
Jan 30, 2008, 8:37:45 AM1/30/08
to sage-...@googlegroups.com

Don't do this. It will be very confusing, e.g.,
since Sympy Integers are drastically different from Sage and doing the above
makes all integer literals Sympy integers.

sage: from sympy import *

sage: factor(15)
15
sage: type(2/3)
<class 'sympy.core.numbers.Rational'>
sage: type(15)
<class 'sympy.core.numbers.Integer'>

William

Georg

unread,
Feb 1, 2008, 6:06:34 AM2/1/08
to sage-newbie
> sage: from sympy import *
> sage: factor(15)
> 15
> sage: type(2/3)
> <class 'sympy.core.numbers.Rational'>
> sage: type(15)
> <class 'sympy.core.numbers.Integer'>

Btw, why this behaviour?, if you write
from sympy import *
in a normal python script integer literals just stay int's
why is this different in sage

Georg
>
> William

William Stein

unread,
Feb 1, 2008, 8:39:50 AM2/1/08
to sage-...@googlegroups.com, Ondrej Certik

Sage wraps all integers literals in Integer(...), and evidently
sympy redefines the Integer function. I'm definitely not sure
that is a good thing.

William

Georg

unread,
Feb 1, 2008, 10:26:25 AM2/1/08
to sage-newbie
> Sage wraps all integers literals in Integer(...), and evidently
> sympy redefines the Integer function. I'm definitely not sure
> that is a good thing.

At least it's confusing and causes bugs, in my script i have the
following line

#!/usr/bin/env sage
lberror = Integer(round(RR(log(psi(i), 2))))

where i want to evaluate the possibly symbolic expression log(psi(i))
as Integer, inserting the line
from sympy import *
would leed to an error,
for beginners these different integer types are yet confusing enough,
Georg
Reply all
Reply to author
Forward
0 new messages