I am doing a calculation and sometimes in the middle of the calculation a parameter evaluates to the following

ft = 3/2 (Interval[{-∞, ∞}] - 
 0.182269836621496581329460089919307050446571501722246222934`32. \
 (Interval[{Indeterminate, Indeterminate}] + 
    Interval[{-∞, ∞}]) - 
 0.0509521859494036386356673163441370150570327833689743828576`32. \
  (Interval[{Indeterminate, Indeterminate}] + 
    Interval[{-∞, ∞}]));

I am trying to identify the "Infinity" "Interval" "Indeterminate" so I can stop the calculation and warn the user. I do the following

Print[MemberQ[N[uSolz],ComplexInfinity]];
Print[MemberQ[N[uSolz],Infinity]];
Print[MemberQ[N[uSolz],Indeterminate]];
Print[MemberQ[N[uSolz],Indeterminate]];

or

Print[StringMemberQ[ToString[uSolz],"Indeterminate"]]

or I evaluated my function in some points because normally uSolz has r as a variable.

rrange=N[Range[0,2,(0-2)/1000]];
Print[N[uSolz/.r->rrange]];

From above I was hoping to get some infinity etc.

None of them worked for me. Any ideas?

  • 2
    maybe Not@FreeQ[#, DirectedInfinity[_] | Indeterminate, {0, Infinity}] &@N[uSolz]? – kglr Oct 12 at 12:10
  • 2
    I'd replace DirectedInfinity[_] with _DirectedInfinity in @kglr's pattern, so that ComplexInfinity is caught as well. – J. M. is computer-less Oct 12 at 12:16
  • @J.M. good point. DirectedInfinity[___] works as well but is longer. – kglr Oct 12 at 12:21
  • @kglr @ J.M It looks like it is working :) , thank you. – Erdem Oct 12 at 12:41
up vote 4 down vote accepted
f = Not[FreeQ[#, _DirectedInfinity | Indeterminate, {0, ∞}]]&
f @ ft

True

Note that Infinity, Indeterminate etc. are not numbers:

NumberQ[Infinity]
NumberQ[Indeterminate]
NumberQ[ComplexInfinity]

False

False

False

So, you can define a predicate to identify Interval objects with a non-number element:

badIntervalQ[Interval[a__]] := AnyTrue[Flatten @ a, Not@*NumberQ]

Check:

FreeQ[ft, _Interval?badIntervalQ]

False

meaning that ft contains a bad interval.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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