Ask Your Question
1

Sage could be even more clever - How to force the use of 'sympy' backend for simplifying symbolic integrals?

asked 2018-08-16 11:54:20 -0600

hausdorff gravatar image

Hi there,

I have noticed the following problem:

sage: f = function('f')(x)                                                                                                                                 
sage: var('h')
sage: integrate(exp(h)*exp(x)*f(x),x)
integrate(e^(h + x)*f(x), x)

The workaround seems to be using the sympy backend for symbolic integration

sage: integrate(exp(h)*exp(x)*f(x),x,algorithm='sympy')                                                                                              
e^h*integrate(e^x*f(x), x)

which always seems to be a good idea as I learned from @Emmanuel Charpentier over here.

Now I would like to force the use of algorith='sympy' for simplifying these integrate(...) expressions globally. Unfortunately, the simplify() command does not allow to set this option.

sage: integrate(exp(h)*exp(x)*f(x),x)                                                                                                                
integrate(e^(h + x)*f(x), x)                                                                                                                         
sage: _.simplify()                                                                                                                                   
integrate(e^(h + x)*f(x), x)

TL;DR How can I force sage to pull out these type of exponential constants from the integral with the simplify() command?

edit retag flag offensive close merge delete

Comments

If simplify() does not allow setting different backends for different kinds of expressions then that's a feature that might be worth adding, and I'm sure patches would be welcome :)

Iguananaut gravatar imageIguananaut ( 2018-08-16 12:32:45 -0600 )edit

I wouldn't (yet) use sympy as the default backend for integration :

  • more than a few times, sympy seems to start an infinite loop, and "never" returns ("never" meaning that, back from my coffee break, I hit C-c C-c...) ;

  • sympy tends to give answers in terms of functions not yet implemented in Sage, (Meijer G, polar numbers, etc...), which it is unable to re-express in Sage-palatable terms ;

In other words, these functions should be handled on Sage side before any step in the direction of making sympy the default for anything.

Someone called rws (whose real name escapes my aging neurons at the moment...) is doing a gigantic job of enhancing the Sage-sympy. This could come handy if/when sympy implements rubi as planned...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2018-08-16 18:06:36 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-08-16 12:19:49 -0600

tmonteil gravatar image

updated 2018-08-16 12:21:33 -0600

You can go back-and-forth from sage to sympy, i.e. turn your expression into a sympy one then ask sympy to factor it, then transform it back into a sage object:

sage: i = integrate(exp(h)*exp(x)*f(x),x) ; i
integrate(e^(h + x)*f(x), x)

sage: i._sympy_().factor()._sage_()
e^h*integrate(e^x*f(x), x)
edit flag offensive delete link more

Comments

Thanks, that was the workaround I was looking for!

hausdorff gravatar imagehausdorff ( 2018-08-31 12:45:16 -0600 )edit

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-08-16 11:54:20 -0600

Seen: 55 times

Last updated: Aug 16