In Mathematica 12.2
Differences[{Quantity[1, "mm"], Quantity[1, "mm"]}]
gives
{Quantity[0, "Millimeters"]}
In Mathematica 13.1, same expression gives
{0}
with no unit!
This introduces inconsistency. For example
StandardDeviation@
Differences[{Quantity[1, "mm"], Quantity[1, "mm"], Quantity[2, "mm"],
Quantity[3, "mm"]}]
prompts errors in 13.1, while no problem in 12.2
In the documentaion of Differences, it says
Differences[list] is equivalent to ListConvolve[{1,-1},list].
But it is not!
ListConvolve[{1, -1}, {Quantity[1, "mm"], Quantity[1, "mm"]}]
gives
{Quantity[0, "Millimeters"]}
What is changed for Differences in 13.1? It seems like a bug. Are there some other side effects of this potential change?
Update
A patch I can think of is
Unprotect[Differences]
Differences[x : {__Quantity}] := ListConvolve[{1, -1}, x];
Protect[Differences]
But I do not know if Unprotect and Protect a built-in function will have undesirable side effect or not. Anyone knows?
Differences[list] /. {0 -> Quantity[0, QuantityUnit[list[[1]]]]}– Bob Hanlon Jul 21 '22 at 15:210 mmis definitely not the same as0, see here for an extended comment. – Roman Jul 21 '22 at 17:00Quantity[1, "Millimeters"] - Quantity[1, "Millimeters"]withSubtract[Quantity[1, "Millimeters"], Quantity[1, "Millimeters"]]– Jason B. Jul 21 '22 at 17:57Subtract. I even guessSubtractandDifferencesare related in the internal. – matheorem Jul 22 '22 at 01:22