Ask Your Question
4

Solved: Why does integrate(psi(y)*f(y),y) return an error but integrate(psi(t,y)*f(t,y),y) works?

asked 2018-08-08 06:41:12 -0600

hausdorff gravatar image

updated 2018-08-16 10:34:23 -0600

Hi there,

I am trying get an symbolic expression for the convolution $$ (\psi \star f)(x) := \int\limits_{\mathbb{R}} \psi(x-y) f(y) {d y} $$

of two functions $ f, \psi: \mathbb{R} \to \mathbb{R} $ as follows:

var('y')
psi = function('psi')(y)
f = function('f')(y)
integrate(psi(x-y)*f(y),y)

upon which I get the error message

RuntimeError: ECL says: Error executing code in Maxima:

If I add an extra argument to the two functions and define them as $$ f, \psi : \mathbb{R} \times \mathbb{R} \to \mathbb{R} $$ as follows:

var('t')
psi = function('psi')(t,y)
f = function('f')(t,y)
integrate(psi(t,x-y)*f(t,y),y)

there is a surprise, it suddenly works! I get the desired symbolic expression on which I can run diff(..,x) and all the other built-in functions.

TL;DR Why does integrate(psi(y)*f(y),y) return an error?

Solution Use sympy backend for symbolic integration as in integrate(psi(x-y)*f(y),y, algorithm="sympy")

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2018-08-09 04:14:03 -0600

Emmanuel Charpentier gravatar image

I think that's a bug in the Sage-to-maxima interface. Compare :

sage: var('y') 
....: psi = function('psi')(y) 
....: f = function('f')(y) 
....: 
y
sage: (psi(x-y)*f(y)).maxima_methods().integrate(y)
integrate(f(y)*psi(x - y), y)
sage: (psi(x-y)*f(y)).maxima_methods().integrate(y).diff(x)
integrate(f(y)*D[0](psi)(x - y), y)

with :

sage: (psi(x-y)*f(y)).integrate(y)
---------------------------------------------------------------------------

[ Long backtrace ]

RuntimeError: ECL says: Error executing code in Maxima:

BTW :

sage: integrate(psi(x-y)*f(y),y, algorithm="sympy")
integrate(f(y)*psi(x - y), y)
sage: integrate(psi(x-y)*f(y),y, algorithm="sympy").diff(x)
integrate(f(y)*D[0](psi)(x - y), y)
sage: integrate(psi(x-y)*f(y),y, algorithm="giac")
integrate(f(y)*psi(x - y), y)
sage: integrate(psi(x-y)*f(y),y, algorithm="giac").diff(x)
integrate(f(y)*D[0](psi)(x - y), y)

Another exemple of this quirk (against an old saw by Leibnitz, IIRC) :

sage: foo=arctan(x).diff(x).subs(x^2==-p).maxima_methods().powerseries(p,0).subs
....: (p==-x^2).simplify(); foo
sum((-1)^i5*x^(2*i5), i5, 0, +Infinity)
sage: foo.maxima_methods().integrate(x)
sum((-1)^i5*x^(2*i5 + 1)/(2*i5 + 1), i5, 0, +Infinity)
sage: foo.integrate(x)
---------------------------------------------------------------------------

[ Long backtrace again... ]

RuntimeError: Encountered operator mismatch in maxima-to-sr translation

and integrate(foo, x) gives the same final error message.

I encounter the same problem (and the same "solution") in Trac#13071. Other integration Trac tickets may have a similar origin, (but I lack the time needed to check them...).

edit flag offensive delete link more

Comments

Thank you very much, that is a very thorough answer!

Just started playing around with SAGE, didn't expect the underlying cracks to show up that quickly....

Do you think I should file another ticket or can I somehow 'push' yours?

hausdorff gravatar imagehausdorff ( 2018-08-16 10:25:01 -0600 )edit

The cracks do exist, but are not that frequent... The point of Sage is to group various tools under a uniform framework, thus easing the use of mutually incompatible tools. The existence of chacks must not be an obstacle (and those cracks can be repaired, hopefully..).

I am not yet ready to file a new ticket about this specif point (inconsistency between two Maxima interfaces) : I do not have enough information on the specifics of the problem (and not enough time to dig them up). The ticket I quoted is but an example... But feel free to go ahead.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2018-08-16 10:50:31 -0600 )edit

That's good to know, I'll take it as an exception then -- and nothing better to understand the software then a bug being explained!

hausdorff gravatar imagehausdorff ( 2018-08-16 12:02:38 -0600 )edit
1

answered 2018-08-09 03:32:47 -0600

eric_g gravatar image

This is definitely a bug, which seems to originate from the name psi for one of the two functions: it is confused with Maxima's special function psi, see http://maxima.sourceforge.net/docs/ma...

If you replace psi by another name, everything works:

sage: f = function('f')
sage: g = function('g')
sage: y = var('y')
sage: integrate(g(x-y)*f(y), y)
integrate(f(y)*g(x - y), y)
edit flag offensive delete link more

Comments

Thank you for the quick answer! I struggled to format my post -- what are the html tags for the nice verbatim code block?

hausdorff gravatar imagehausdorff ( 2018-08-16 10:37:46 -0600 )edit

seems to be a whitespace indent Found it!

hausdorff gravatar imagehausdorff ( 2018-08-16 11:56:40 -0600 )edit

Alternatively, you can select the code block with the mouse and click on the button "101010" in the header bar.

eric_g gravatar imageeric_g ( 2018-08-17 07:18:13 -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

Stats

Asked: 2018-08-08 06:41:12 -0600

Seen: 80 times

Last updated: Aug 16