10

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!

Chen Stats Yu
  • 4,986
  • 2
  • 24
  • 50

2 Answers2

16

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

Ricbit
  • 155
  • 6
rhermans
  • 36,518
  • 4
  • 57
  • 149
  • 1
    Thanks! That should solve all my numerical optimization problems! – Chen Stats Yu Oct 26 '14 at 22:54
  • I did try to contain, say using Exp[x], which should be >0. But during the optimization, I still get 0.0^0. – Chen Stats Yu Oct 26 '14 at 22:57
  • 2
    @chen, maybe you can try changing Power[0, 0] = 1 to Power[0|0., 0|0.] = 1. – kglr Oct 27 '14 at 00:04
  • 7
    $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)$. – robjohn Dec 14 '15 at 06:33
  • Can one define 0 Log[0] = 1? – H. Kenan Mar 08 '19 at 10:58
  • 5
    In some areas of math like combinatorics, $0^0 = 1$ is pretty much the standard interpretation, so it does make sense. – qwr Mar 28 '20 at 04:31
  • It's OK to down-vote, bit it would be nice to have a note explaining why. – rhermans May 09 '23 at 10:28
7

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
xyz
  • 605
  • 4
  • 38
  • 117