Ask Your Question

desolve initial condition involving e gives strange answer

asked 2018-10-14 23:20:07 +0200

PW gravatar image

updated 2023-01-09 23:59:47 +0200

tmonteil gravatar image

I'm trying to do some basic differential equations in Sage. When I run the following:

y = function('y')(t)
de1 = t^3*diff(y, t) + 4*t^2*y == e^(t^2)
desolve(de1, y, ics = [1,e])

The output is

1/2*(e^(t^2) + y(t))/t^4

My expectation is that there shouldn't by any y(t) term in the output. If I make a seemingly meaningless tweak to my initial conditions:

desolve(de1, y, ics = [1,e*1])

I get the expected output of

1/2*(e + e^(t^2))/t^4

If I change the initial conditions to [1, e/2], I again get the output I expect. I haven't been able to reproduce this issue with any other example. Maybe the issue just comes in converting Sage's version of e into Maxima? Does anyone know what is going on here?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2018-10-15 11:27:23 +0200

tmonteil gravatar image

updated 2018-10-15 11:28:10 +0200

Indeed, a raw e leads to a symbolic constant, while e*1 leads to a symbolic expression:

sage: type(e)
<type 'sage.symbolic.constants_c.E'>
sage: type(e*1)
<type 'sage.symbolic.expression.Expression'>

Thanks for reporting, this is now trac ticket 26490.

edit flag offensive delete link more

answered 2018-10-15 11:16:56 +0200

rburing gravatar image

updated 2018-10-15 11:37:33 +0200

Looking at the source of desolve the difference is in how the variable tempic is set, namely the offending expression is (dvar==ics[1])._maxima_():

sage: y == e
e == y(t)


sage: y == 1*e
y(t) == e

So it seems that Sage cannot be trusted to preserve the ordering LHS = RHS of an equation. This is definitely a bug which should be reported.

edit flag offensive delete link more



This is very weird, only the constant e reverses the equalities:

sage: var('x')
sage: x == sage.symbolic.constants.pi
x == pi
sage: x == sage.symbolic.constants.e
e == x
sage: x == sage.symbolic.constants.catalan
x == catalan
sage: x == sage.symbolic.constants.euler_gamma
x == euler_gamma
sage: x == sage.symbolic.constants.I
x == I

Looking at the source code, e is handled by the dedicated src/sage/symbolic/constants_c.pyx.

tmonteil gravatar imagetmonteil ( 2018-10-15 11:33:47 +0200 )edit

Nice ink bucket...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2018-10-15 13:57:01 +0200 )edit

I created trac ticket 26492 for this larger issue.

tmonteil gravatar imagetmonteil ( 2018-10-15 15:14:03 +0200 )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


Asked: 2018-10-14 23:20:07 +0200

Seen: 600 times

Last updated: Oct 15 '18