Ask Your Question
0

how to correctly check that integration evaluated?

asked 2018-06-20 10:23:42 -0500

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 12:45:51 -0500

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 16:30:27 -0500

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 10:23:42 -0500

Seen: 39 times

Last updated: Jun 20