In previous versions of Mathematica Missing[]- Missing[] would output Missing[]- Missing[]. In the current version is outputs 0. Is there a way to get Mathematica to revert back to the old output? The new implementation is reeking havoc with my archival code.

  • 1
    $\begingroup$ Missing was introduced in 10.0. I just verified that in 10.0.2, Missing[]-Missing[] evaluates to 0. Missing[] + Missing[] evaluates to 2 Missing[]. I have not used Missing much, but as I remember it never behaved specially with arithmetic (like Indeterminate and Undefined do). $\endgroup$ – Szabolcs Jan 18 '18 at 20:29
  • $\begingroup$ Perhaps what you mean is that Dataset handles Missing specially, and causes the arithmetic results you are referring to. Missing[] itself doesn't have special properties, and doesn't evaluate specially outside of Dataset. If you see changed behaviour with Dataset, please show an example in the question. $\endgroup$ – Szabolcs Jan 18 '18 at 20:32
  • 1
    $\begingroup$ For example, in 11.2, ds = Dataset[{1, Missing[], 2}]; ds[# - #&] // Normal results in {0, Missing["Indeterminate"], 0} and not {0, 0, 0}. I.e. the special behaviour inside Dataset is still present and works as before. $\endgroup$ – Szabolcs Jan 18 '18 at 20:33
  • $\begingroup$ Replacing Missing with Indeterminate solve a whole bunch of issues. $\endgroup$ – Wintermute Jan 19 '18 at 19:24
  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$ – Kuba Jan 23 '18 at 21:27

You could try something like:

Missing /: Plus[a_Missing, b__] := Indeterminate

Your example:

Missing[] - Missing[]



In addition to the approaches in the comments, you could also Block Missing when performing computations. For example:

SetAttributes[missingArithmetic, HoldFirst];

missingArithmetic[expr_] := Block[{Missing = Indeterminate&},






  • $\begingroup$ But what about 1 - Missing[]? Sorry, couldn't resist :-) $\endgroup$ – Szabolcs Jan 18 '18 at 21:10
  • $\begingroup$ You're right, that's a case where UpValues won't work. $\endgroup$ – Carl Woll Jan 18 '18 at 21:15
  • $\begingroup$ But you can add an UpValue to Times. However, it gets messy quickly, as it is unclear what set of functions should be considered. $\endgroup$ – Szabolcs Jan 18 '18 at 21:23
  • 1
    $\begingroup$ How about Missing /: head_Symbol[___, _Missing, ___] := Indeterminate /; MemberQ[Attributes[head], NumericFunction]? It does feel dangerous and I imagine it might have a noticeable performance impact ... I haven't tested. But it does work even on Sin[Missing[]]. $\endgroup$ – Szabolcs Jan 18 '18 at 21:27
  • $\begingroup$ or Missing /: (_?System`Dump`HeldNumericFunctionQ)[___, _Missing, ___] := Indeterminate? $\endgroup$ – kglr Jan 18 '18 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.