How can I make Mathematica agree that 0^0 = 1?

0

Occasionally I encounter messages like

Power::indet: Indeterminate expression (0. + 0. I)^0 encountered.

(or just 0^0). I believe I can safely declare these to be 1 for all of my purposes. Is there a way to build this in?

მამუკა ჯიბლაძე

Posted 2017-07-18T04:48:40.967

Reputation: 1 831

Question was closed 2017-07-18T05:15:43.463

@MichaelE2 Oh I see thanks. Could not find that for some reason, I honestly tried searching for 0^0. Let us mark it as duplicate. Although I already learned from the answer below some additional possibilities, but still... – მამუკა ჯიბლაძე – 2017-07-18T05:14:34.820

1@m_goldberg The way it was before your edit looked nicer with all that color-coding, are there specific reasons why your version is better? – მამუკა ჯიბლაძე – 2017-07-18T05:38:03.620

The formatting I applied to the error message is the formatting we have been using for such on this site for all the years I have been a member. The idea is that messages should be distinct from code. – m_goldberg – 2017-07-18T06:05:53.810

@m_goldberg I see. Pity. I wonder if somebody could be asked to extend color coding to messages too. Besides, it is just a random choice of convention which ones should go with four spaces and which with >!, no? – მამუკა ჯიბლაძე – 2017-07-18T06:18:24.320

Messages issued in Mathematica do not have color coding. Messages are are mixture of text and code. It is probably more trouble that it would be worth to try to get lexical scanner to distinguish what is text and what is code. – m_goldberg – 2017-07-18T07:11:02.387

@m_goldberg Actually my 11.0.1.0 does color them (the head is red and the rest pale grey). Besides, if you paste them here through four spaces, they automatedly get more color coding distinctions than just chunks of code, so I wonder why is that feature there if they should not be entered like that... – მამუკა ჯიბლაძე – 2017-07-18T07:17:25.970

Answers

4

Operator overloading is one way.

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

You should add also the cases like Power[0.,0.]. When you want to clear your own definitions, Unprotect, Clear, Protect.

Kiro

Posted 2017-07-18T04:48:40.967

Reputation: 1 326

1It should of course be stressed that you do this only if you know what you're doing (e.g. combinatorial as opposed to analytic operations). – J. M.'s ennui – 2017-07-30T03:52:16.707

I 100 % agree with you. While the list of things you should do even if you don't know what you are doing is very short, this one might have deserved an explicit warning. – Kiro – 2017-07-31T05:35:28.417