2
$\begingroup$

This seems something that must have been asked before, but I am not able to find something.

Integrate does not return status nor throw error when it can't find antiderivative. It just returns the input back. So can't use Check on not.

So how would one check if it solved the integral or not?

Currently I check if First of the result of the integration is the same as the integrand. Since if it failed, then the First of the input will be the integrand.

expr = Sin[x];
r = Integrate[expr, x];
If[r[[1]] === expr, Print["failed"], Print["passed"]]
     (*passed*)

While this

expr = Sin[x Exp[x]];
r = Integrate[expr, x];
If[r[[1]] === expr, Print["failed"], Print["passed"]]
   (*failed*)

But the above seems like a hack to me. There should be a more robust and systematic way to do this. Any suggestions?

Version 10.02

$\endgroup$
2
  • 6
    $\begingroup$ Why not just check Head[r]===Integrate? $\endgroup$
    – Jens
    Dec 20, 2014 at 1:14
  • $\begingroup$ @Jens sure. This sounds like a smart way to go about it. I did not think about it. $\endgroup$
    – Nasser
    Dec 20, 2014 at 1:32

1 Answer 1

3
$\begingroup$

In case you have expression like:

expr =a Sin[x Exp[x]];

I would use:

r = Integrate[expr,x];

If[FreeQ[r, Integrate, -1], Print["passed"], Print["failed"]]
$\endgroup$

Your Answer

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

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