Building on Hans's idea, one can use WithCleanup
to localized the redefinition of Power
to a single execution:
runInCombinatorialMode // ClearAll;
runInCombinatorialMode // Attributes = {HoldAll};
runInCombinatorialMode[code_] := WithCleanup[
Unprotect@Power;
0^0 = 1;
Protect@Power
,
code,
Unprotect@Power;
0^0 =.;
Protect@Power
];
runInCombinatorialMode[
vec = Range[0, 4];
Total[vec^vec]
]
(* 289 *)
0^0
Power::indet: Indeterminate expression 0^0 encountered.
(* Indeterminate *)