How can we override a Mathematica built-in function using itself in the definition?
For example, the DiracDelta function is not defined for complex numbers like:
In[1]:= N[DiracDelta[1 + 2 I]]
Out[1]= DiracDelta[1. + 2. I]
But how can we change its behavior for something similar to this?
Unprotect[DiracDelta];
DiracDelta[x_] := DiracDelta[Re[x] + Im[x]];
Protect[DiractDelta];
With this approach we receive an infinite recursion error.
We could define another function, like DiractDelta2[x_] with the expected behavior, but the problem is more because I'd needing to see some simplifications when I'm expanding my series, and for those cases it is ok to define it that way.
Attempts
OldDiracDelta = DiracDelta;
Unprotect[DiracDelta];
DiracDelta[x_] := OldDiracDelta[Re[x] + Im[x]];
Protect[DiractDelta];
(* But unfortunately this still incurs in the infinite recursion error. *)
DiracDelta[Complex[x_,y_]]:=DiracDelta[x +y](not commenting on the sensibility of such a definition). – Daniel Lichtblau May 06 '20 at 19:43DiracDelta[Complex[x_,y_]]:=DiracDelta[x +y]do not always work as expected. If you have something likeDiractDelta[I]it doesn't resolve. If you extend more, like addingDiractDelta[I*x_] := DiracDelta[x]it works but I've seen a lot of other cases appearing, unfortunately. Maybe I need to try something using ComplexExpand first. – GarouDan May 07 '20 at 02:03