Ask Your Question
0

how to correctly check that integration evaluated?

asked 2018-06-20 17:23:42 +0200

Nasser gravatar image

What is the correct way in sage to check that the result of integration has evaluated? I.e. the result has no unevaluated integrate remaining in it?

The way I am checking fail in some cases. For example

sage: var('x')
sage: anti=integrate((4*x - sqrt(-x^2 + 1))/(sqrt(-x^2 + 1) + 5), x)

sage: anti
-x - 4*sqrt(-x^2 + 1) + 5*integrate(1/(sqrt(x + 1)*sqrt(-x + 1) + 5), x) + 20*log(sqrt(-x^2 + 1) + 5)

The above did not fully evaluate, since there is an integrate inside the result returned. But when I do

sage: isinstance(anti.operator(), sage.symbolic.integration.integral.IndefiniteIntegral)
False

I was expecting to get True. It failed the check, because integrate was not the first operator. This one works

sage: anti=integrate(1/(sqrt(x + 1)*sqrt(-x + 1) + 5), x) 
sage: isinstance(anti.operator(), sage.symbolic.integration.integral.IndefiniteIntegral)
True

So what is the correct way to tell sage to scan the whole expression and if there is an instance of integrate any where, to return True

Thank you

--Nasser

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2018-06-20 19:45:51 +0200

joaoff gravatar image

Does this help? this is just an idea. You can improve it, of course.

var('x')
anti=integrate((4*x - sqrt(-x^2 + 1))/(sqrt(-x^2 + 1) + 5), x)
#anti=integrate(1/(sqrt(x + 1)*sqrt(-x + 1) + 5), x)
if str(anti).find("integrate") != -1:
    print("Result contains unevaluated integral!")
anti

Output:

Result contains unevaluated integral!
-x - 4*sqrt(-x^2 + 1) + 5*integrate(1/(sqrt(x + 1)*sqrt(-x + 1) + 5), x) + 20*log(sqrt(-x^2 + 1) + 5)
edit flag offensive delete link more
0

answered 2018-06-20 23:30:27 +0200

Emmanuel Charpentier gravatar image

You must parse (recursively) the output expression, and tchack that tour tree does not contain any integrate call (i. e. a subexpression whose operator is sage.all.integrate. This must be recursive because integrate may return a sum or a product whose one term or factr is an unevaluated integrate call...

The implementation is Left As An Exercise (TM) to the reader (who may be wise to check if a general parsng function exists in Sage... or in some Python library...).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-06-20 17:23:42 +0200

Seen: 178 times

Last updated: Jun 20 '18