Often times functions might return Undefined in Mathematica, e.g. when the Volume@RegionIntersection is called for 2 objects which have no overlapping volume. A simple If statement checking if the return has been indeed Undefined does not seem to work. For example, a=Undefined; If[a == Undefined, Print["yes"]] ends up printing the command itself.

  • How can we check if a variable (or a function return) such as a has been assigned as Undefined and assign a different value to it in that case?
  • 1
    $\begingroup$ Can you show a simple version of your function that returns Undefined? $\endgroup$
    – bill s
    Commented Nov 28, 2019 at 18:30
  • $\begingroup$ You might want to use RegionDisjoint on the two regions before trying to compute the intersection. $\endgroup$
    – Carl Woll
    Commented Nov 28, 2019 at 19:03
  • $\begingroup$ @CarlWoll Thanks, indeed I should be checking for that in the first place, but to save computational time (as my current intersection detection routine is already very slow, this is about the post I mentioned to you earlier), I skipped checking for disjointness beforehand. $\endgroup$
    – user52181
    Commented Nov 28, 2019 at 19:27
  • $\begingroup$ @bills MassDefect have provided one such example in their answer below. $\endgroup$
    – user52181
    Commented Nov 28, 2019 at 19:28

1 Answer 1


You should be able to use SameQ (===).

Volume[RegionIntersection[Circle[{0, 0}, 1], Circle[{2, 2}, 1]]] === Undefined
(* True *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.