Due to some bug shown in Differences of Quantities gives different result in different Mathematica version, I add an additional definition to Subtract. But I found it will severely slow down Szabolcs' BoolEval function.
A fresh Mathematica kernel, run
array = RandomReal[1, 1000000];
Pick[array, ResourceFunction["BoolEval"][array > 0.5],
1]; // RepeatedTiming
gives
{0.0163395, Null}
Another fresh Mathematica kernal, run
Unprotect[Subtract];
Subtract[x_Quantity, y_Quantity] := x - y;
Protect[Subtract];
array = RandomReal[1, 1000000];
Pick[array, ResourceFunction["BoolEval"][array > 0.5],
1]; // RepeatedTiming
gives
{0.521434, Null}
Why does adding an additional definition affect so much? What is more, how to fix Subtract quantity bug without affecting BoolEval?
update
Now I know how to fix Subtract quantity bug without affecting BoolEval. In the BoolEval package, replace all Subtract[a,b] and similar with a-b, then it will not affected by new definition of Subtract. But I still do not know why adding an additional Subtract definition affect so much?
Subtractis faster than-. That is whyBoolEvalpackage useSubtract. And that makes my updated fix not perfect in terms of performance. Sad : ( – matheorem Jul 14 '23 at 12:35Unprotect[Quantity]; Quantity /: Subtract[x_Quantity, y_Quantity] := x - y; Protect[Quantity];instead behave? – Carl Woll Jul 14 '23 at 13:30