0
$\begingroup$

Sometimes, Residue can't find a solution or it doesn't exists. For example:

Residue[1/Sqrt[x], {x, 0}]

The output is:

res(1/Sqrt[x],{x,0})

Is there a way to catch the error, to ask the output something like FailureQ?

If I expect the result to be a number after using Residue, then NumericQ does the job, but if the result should depend on other symbols, it's not enough.

Another idea is to use TextString and check if it says "Residue[" in the beginning of the string

StringMatchQ[TextString[output], "Residue[*"]

but there has to be something more elegant.

$\endgroup$

1 Answer 1

1
$\begingroup$

If by "failed", you mean that it doesn't change the result any further, you can just check to see if the result has head Residue like so.

EnforceResidue[expr_, {z_, z0_}, opts : OptionsPattern[Residue]] :=
  With[{result = Residue[expr, {z, z0}, opts]},
   Switch[result,
    _Residue,
    Failure["ResidueFailure",
     <|"MessageTemplate" -> 
       "Couldn't evaluate residue of `Expression`",
      "MessageParameters" -> <|"Expression" -> HoldForm[expr]|>|>],
    _,
    result]];
$\endgroup$

Your Answer

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

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