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
Head[r]===Integrate
? $\endgroup$