8
$\begingroup$

This question already has an answer here:

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$

marked as duplicate by Mr.Wizard Oct 27 '14 at 5:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5
$\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$
11
$\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$
  • 1
    $\begingroup$ Thanks! That should solve all my numerical optimization problems! $\endgroup$ – Chen Stats Yu Oct 26 '14 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$ – Chen Stats Yu Oct 26 '14 at 22:57
  • 1
    $\begingroup$ @chen, maybe you can try changing Power[0, 0] = 1 to Power[0|0., 0|0.] = 1. $\endgroup$ – kglr Oct 27 '14 at 0:04
  • 3
    $\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 '15 at 6:33
  • $\begingroup$ Can one define 0 Log[0] = 1? $\endgroup$ – H. Kenan Mar 8 at 10:58

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