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 13:41:12 +0100

hausdorff gravatar image

updated 2018-08-16 17:34:23 +0100

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
2

answered 2018-08-09 11:14:03 +0100

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 17:25:01 +0100 )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 17:50:31 +0100 )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 19:02:38 +0100 )edit
2

answered 2018-08-09 10:32:47 +0100

eric_g gravatar image

updated 2019-03-13 00:08:00 +0100

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)

UPDATE (13 March 2019): the bug is now tracked via the ticket #27475.

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 17:37:46 +0100 )edit

seems to be a whitespace indent Found it!

hausdorff gravatar imagehausdorff ( 2018-08-16 18:56:40 +0100 )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 14:18:13 +0100 )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 13:41:12 +0100

Seen: 785 times

Last updated: Mar 13 '19