Skip to main content
Post Closed as "Duplicate" by MarcoB, Kuba, user9660, Michael E2, Mr.Wizard
added 53 characters in body
Source Link
yode
  • 27.2k
  • 4
  • 66
  • 174

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]

enter image description here

Or like the Divide

Unprotect[Divide];
Divide[0, 0] := "NAN"
Divide[0, 0]
0/0
Divide[2, 3]

enter image description here

As you can see,the original Differences will get {}

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]

enter image description here

Or like the Divide

Unprotect[Divide];
Divide[0, 0] := "NAN"
Divide[0, 0]
0/0
Divide[2, 3]

enter image description here

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]

enter image description here

Or like the Divide

Unprotect[Divide];
Divide[0, 0] := "NAN"
Divide[0, 0]
0/0
Divide[2, 3]

enter image description here

Source Link
yode
  • 27.2k
  • 4
  • 66
  • 174

How to change the built-in function?

As you can see,the original Differences will get {}

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]

enter image description here

Or like the Divide

Unprotect[Divide];
Divide[0, 0] := "NAN"
Divide[0, 0]
0/0
Divide[2, 3]

enter image description here