ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 15 Oct 2018 15:14:03 +0200desolve initial condition involving e gives strange answerhttps://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/I'm trying to do some basic differential equations in Sage. When I run the following:
var('t')
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?Sun, 14 Oct 2018 23:20:07 +0200https://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/Answer by tmonteil for <p>I'm trying to do some basic differential equations in Sage. When I run the following:</p>
<pre><code>var('t')
y = function('y')(t)
de1 = t^3*diff(y, t) + 4*t^2*y == e^(t^2)
desolve(de1, y, ics = [1,e])
</code></pre>
<p>The output is </p>
<pre><code>1/2*(e^(t^2) + y(t))/t^4
</code></pre>
<p>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:</p>
<pre><code>desolve(de1, y, ics = [1,e*1])
</code></pre>
<p>I get the expected output of</p>
<pre><code>1/2*(e + e^(t^2))/t^4
</code></pre>
<p>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?</p>
https://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/?answer=43950#post-id-43950Indeed, 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](https://trac.sagemath.org/ticket/26490).Mon, 15 Oct 2018 11:27:23 +0200https://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/?answer=43950#post-id-43950Answer by rburing for <p>I'm trying to do some basic differential equations in Sage. When I run the following:</p>
<pre><code>var('t')
y = function('y')(t)
de1 = t^3*diff(y, t) + 4*t^2*y == e^(t^2)
desolve(de1, y, ics = [1,e])
</code></pre>
<p>The output is </p>
<pre><code>1/2*(e^(t^2) + y(t))/t^4
</code></pre>
<p>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:</p>
<pre><code>desolve(de1, y, ics = [1,e*1])
</code></pre>
<p>I get the expected output of</p>
<pre><code>1/2*(e + e^(t^2))/t^4
</code></pre>
<p>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?</p>
https://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/?answer=43949#post-id-43949Looking at the [source of `desolve`](https://github.com/sagemath/sage/blob/master/src/sage/calculus/desolvers.py) 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)
versus
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.Mon, 15 Oct 2018 11:16:56 +0200https://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/?answer=43949#post-id-43949Comment by tmonteil for <p>Looking at the <a href="https://github.com/sagemath/sage/blob/master/src/sage/calculus/desolvers.py">source of <code>desolve</code></a> the difference is in how the variable <code>tempic</code> is set, namely the offending expression is <code>(dvar==ics[1])._maxima_()</code>:</p>
<pre><code>sage: y == e
e == y(t)
</code></pre>
<p>versus</p>
<pre><code>sage: y == 1*e
y(t) == e
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/?comment=43951#post-id-43951This is very weird, only the constant `e` reverses the equalities:
sage: var('x')
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`.Mon, 15 Oct 2018 11:33:47 +0200https://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/?comment=43951#post-id-43951Comment by Emmanuel Charpentier for <p>Looking at the <a href="https://github.com/sagemath/sage/blob/master/src/sage/calculus/desolvers.py">source of <code>desolve</code></a> the difference is in how the variable <code>tempic</code> is set, namely the offending expression is <code>(dvar==ics[1])._maxima_()</code>:</p>
<pre><code>sage: y == e
e == y(t)
</code></pre>
<p>versus</p>
<pre><code>sage: y == 1*e
y(t) == e
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/?comment=43953#post-id-43953Nice ink bucket...Mon, 15 Oct 2018 13:57:01 +0200https://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/?comment=43953#post-id-43953Comment by tmonteil for <p>Looking at the <a href="https://github.com/sagemath/sage/blob/master/src/sage/calculus/desolvers.py">source of <code>desolve</code></a> the difference is in how the variable <code>tempic</code> is set, namely the offending expression is <code>(dvar==ics[1])._maxima_()</code>:</p>
<pre><code>sage: y == e
e == y(t)
</code></pre>
<p>versus</p>
<pre><code>sage: y == 1*e
y(t) == e
</code></pre>
<p>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.</p>
https://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/?comment=43954#post-id-43954I created [trac ticket 26492](https://trac.sagemath.org/ticket/26492) for this larger issue.Mon, 15 Oct 2018 15:14:03 +0200https://ask.sagemath.org/question/43946/desolve-initial-condition-involving-e-gives-strange-answer/?comment=43954#post-id-43954