As you can see,the original Differences
will get {}
when your parameter is a list with one element just.
Differences /@ {{1, 2, 3}, {4, 5}, {6}}
{{1, 1}, {1}, {}}
Then we can change it like this
Unprotect[Differences];
Differences[{a_}] := {a};
Differences /@ {{1, 2, 3}, {4, 5}, {6}}
{{1, 1}, {1}, {6}}
But the same method don't fit the Times
and Divide
Unprotect[Times];
Times[0, 0] := "NAN"
Times[0, 0]
0*0
Times[2, 3]
Or like the Divide
Unprotect[Divide];
Divide[0, 0] := "NAN"
Divide[0, 0]
0/0
Divide[2, 3]
Times
etc? This is a really bad idea for such elementary functions, as it will mess up your system in unpredictable ways and bite you in the end. Is there a deeper reason not to use a custom function? $\endgroup$Differences
. So, addingDownValues
for them is not very effective. $\endgroup$Times
and friends. $\endgroup$Times
,Divide
,Differences
etc. to process the non-special cases afterwards. There is simply no way to reliably changeTimes
, for example. Its definition is hard-coded into the system. Even if you could, you shouldn't: do you really think Mathematica's own functions don't rely on a consistent concept of multiplication? $\endgroup$