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

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 close merge delete

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 :)

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...

Sort by » oldest newest most voted

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)

more