10
$\begingroup$

Many occasions, where I need to work numerically with functions. For a variable strictly between 0 and 1, during the optimization, it could become 0.^0 or 0^0, which then become indeterminate.enter image description here

Is there a way to define this 0^0=1?

What are the possible down side of defining such relationship?

Thanks!

$\endgroup$
2

2 Answers 2

7
$\begingroup$

With the help of @Michael E2 in my question

Case $\frac{0}{0}$

In this case,you can define your function like this:

func1[a_,b_]:=0 /;b==0
func1[a_,b_]:=a/b

Test

func1[0, 0]
1

Case$0.^0$

So you can use the /; to avoid $0.^0$

func2[x_,0]:=1/;x==0||x==0.
func2[x_,y_:0]:=x^y    

Test

 func2[0, 0]
1
 func2[0., 0]
1
$\endgroup$
16
$\begingroup$

Yes, by doing this (similar to this):

Unprotect[Power];
Power[0|0., 0|0.] = 1;
Protect[Power];

If you want to revert to normal:

Unprotect[Power];
ClearAll[Power];
Protect[Power];

The downside is that it doesn't make sense mathematically, and from a false premise you could reach a false conclusion. You better constrain your function in some other way. Try reading on conditional definitions here: Condition

$\endgroup$
7
  • 1
    $\begingroup$ Thanks! That should solve all my numerical optimization problems! $\endgroup$ Oct 26, 2014 at 22:54
  • $\begingroup$ I did try to contain, say using Exp[x], which should be >0. But during the optimization, I still get 0.0^0. $\endgroup$ Oct 26, 2014 at 22:57
  • 2
    $\begingroup$ @chen, maybe you can try changing Power[0, 0] = 1 to Power[0|0., 0|0.] = 1. $\endgroup$
    – kglr
    Oct 27, 2014 at 0:04
  • 7
    $\begingroup$ $0^0=1$ does make sense mathematically. Just because $\lim\limits_{(x,y)\to(0,0)}x^y$ is indeterminate does not mean that $0^0$ should be left undefined. In most practical cases, $0^0=1$ is what is wanted. We should simply note that $x^y$ is not continuous at $(0,0)$. $\endgroup$
    – robjohn
    Dec 14, 2015 at 6:33
  • 5
    $\begingroup$ In some areas of math like combinatorics, $0^0 = 1$ is pretty much the standard interpretation, so it does make sense. $\endgroup$
    – qwr
    Mar 28, 2020 at 4:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.