12

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?

matheorem
  • 17,132
  • 8
  • 45
  • 115

0 Answers0