Sage: Ticket #7661: maxima interface gives precedence to function dictionary instead of local variables
https://trac.sagemath.org/ticket/7661
<p>
From the sage-devel thread:
</p>
<p>
<a class="ext-link" href="http://groups.google.com/group/sage-devel/t/c89582242c83a349"><span class="icon"></span>http://groups.google.com/group/sage-devel/t/c89582242c83a349</a>
</p>
<pre class="wiki">On Fri, 11 Dec 2009 13:46:31 +0100
Nathann Cohen <nathann.cohen@gmail.com> wrote:
> sage: var('delta k')
> sage: m1=2*delta**2 + 2**2*delta*k
> sage: n=delta*k+2
> sage: m2=(2*delta)**2+(k-1)*4
> sage: m=(delta+delta*k-(delta-1))
> sage: ((m1/n)-(m2/n)).expand().simplify()
</pre><p>
On 4.3.rc0, I get this:
</p>
<pre class="wiki">TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and
'<class 'sage.functions.generalized.FunctionDiracDelta'>'
</pre><p>
The Maxima interface seems to give precedence to the global function
dictionary instead of the local variables when converting Maxima output
back to Sage expressions.
</p>
<pre class="wiki">sage: dirac_delta(x)
dirac_delta(x)
sage: maxima(dirac_delta(x))
delta(x)
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/7661
Trac 1.1.6wasSat, 30 Jan 2010 23:28:06 GMT
https://trac.sagemath.org/ticket/7661#comment:1
https://trac.sagemath.org/ticket/7661#comment:1
<p>
People run into this all the time, evidently:
</p>
<pre class="wiki">[15:21] --> SageWWW has joined this channel (~SageWWW@64.241.37.140).
[15:23] <SageWWW> hey guys. what do you think about http://pastebin.ca/1772520
[15:24] <SageWWW> d = var('delta'), so now d is a reference to a sage.symbolic.expression.Expression
[15:25] <SageWWW> but when we try to add it to something else, it thinks its a sage.functions.generalized.FunctionDiracDelta
[15:27] <wstein> http://trac.sagemath.org/sage_trac/ticket/7661
</pre>
TicketeigenlambdaSun, 31 Jan 2010 07:10:34 GMT
https://trac.sagemath.org/ticket/7661#comment:2
https://trac.sagemath.org/ticket/7661#comment:2
<p>
sage: d = var('delta')
sage: e = d._maxima_()
sage: sage.calculus.calculus.symbolic_expression_from_maxima_element(e)
dirac_delta
</p>
<p>
somewhere in symbolic_expression_from_maxima_element(), the string from maxima is looked up in sage.calculus.calculus._syms, which by default has 'delta': dirac_delta . So this is what's happening, next, SR() barfs on trying to turn dirac_delta into a symbolic expression, at which point people who just wanted their variable 'delta' back get confused and frustrated.
</p>
<p>
sage: del sage.calculus.calculus._syms<a class="missing wiki">delta?</a>
sage: sage.calculus.calculus.symbolic_expression_from_maxima_element(e)
delta
</p>
<p>
That may not be such a good idea, however, since what sage calls dirac_delta, maxima refers to as delta. Nevertheless, since reset('delta') appears to remove delta from that dictionary, perhaps var('delta') should also do so?
</p>
<p>
Of course, what happens when someone does a Laplace transform with delta as a sage variable will then come out confusing and wrong. At least the current behavior is merely broken.
</p>
TicketburcinMon, 05 Apr 2010 10:24:35 GMTstatus, priority changed; author set
https://trac.sagemath.org/ticket/7661#comment:3
https://trac.sagemath.org/ticket/7661#comment:3
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>priority</strong>
changed from <em>major</em> to <em>critical</em>
</li>
<li><strong>author</strong>
set to <em>Burcin Erocal</em>
</li>
</ul>
<p>
<a class="attachment" href="https://trac.sagemath.org/attachment/ticket/7661/trac_7661-maxima_convert_back.patch" title="Attachment 'trac_7661-maxima_convert_back.patch' in Ticket #7661">attachment:trac_7661-maxima_convert_back.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/7661/trac_7661-maxima_convert_back.patch" title="Download"></a> fixes the problem reported above, and a similar problem with function conversions back from maxima reported in <a class="closed ticket" href="https://trac.sagemath.org/ticket/8459#comment:2" title="Comment 2 for Ticket #8459">comment:2:ticket:8459</a>.
</p>
TicketburcinTue, 06 Apr 2010 15:39:06 GMTattachment set
https://trac.sagemath.org/ticket/7661
https://trac.sagemath.org/ticket/7661
<ul>
<li><strong>attachment</strong>
set to <em>trac_7661-maxima_convert_back.patch</em>
</li>
</ul>
TicketburcinTue, 06 Apr 2010 15:42:51 GMT
https://trac.sagemath.org/ticket/7661#comment:4
https://trac.sagemath.org/ticket/7661#comment:4
<p>
I updated <a class="attachment" href="https://trac.sagemath.org/attachment/ticket/7661/trac_7661-maxima_convert_back.patch" title="Attachment 'trac_7661-maxima_convert_back.patch' in Ticket #7661">attachment:trac_7661-maxima_convert_back.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/7661/trac_7661-maxima_convert_back.patch" title="Download"></a> to remove a doctest fix broken by a previous patch in my queue (<a class="closed ticket" href="https://trac.sagemath.org/ticket/6949" title="enhancement: add symbolic max and min functions (closed: fixed)">#6949</a>, <code>symbol...</code> line in sage/symbolic/ring.pyx).
</p>
<p>
This patch depends on <a class="closed ticket" href="https://trac.sagemath.org/ticket/7748" title="defect: Make incomplete gamma function symbolic (closed: fixed)">#7748</a>.
</p>
Ticketrobert.marikFri, 09 Apr 2010 08:15:04 GMT
https://trac.sagemath.org/ticket/7661#comment:5
https://trac.sagemath.org/ticket/7661#comment:5
<p>
Thanks for working onthis. Is <a class="closed ticket" href="https://trac.sagemath.org/ticket/7748" title="defect: Make incomplete gamma function symbolic (closed: fixed)">#7748</a> the only prerequisity? I installed three patches as described at <a class="closed ticket" href="https://trac.sagemath.org/ticket/7748" title="defect: Make incomplete gamma function symbolic (closed: fixed)">#7748</a> and got the following error
</p>
<pre class="wiki">patching file sage/calculus/calculus.py
Hunk #3 succeeded at 1414 with fuzz 1 (offset -4 lines).
Hunk #5 FAILED at 1455
1 out of 14 hunks FAILED -- saving rejects to file sage/calculus/calculus.py.rej
abort: patch failed to apply
</pre>
TicketburcinFri, 09 Apr 2010 10:46:48 GMTowner changed
https://trac.sagemath.org/ticket/7661#comment:6
https://trac.sagemath.org/ticket/7661#comment:6
<ul>
<li><strong>owner</strong>
changed from <em>was</em> to <em>burcin</em>
</li>
</ul>
<p>
AFAICT, <a class="closed ticket" href="https://trac.sagemath.org/ticket/8237" title="defect: Sage does not recognize Maxima's complex infinity (closed: fixed)">#8237</a> also changes that code. Can you try with <a class="closed ticket" href="https://trac.sagemath.org/ticket/8237" title="defect: Sage does not recognize Maxima's complex infinity (closed: fixed)">#8237</a> applied?
</p>
<p>
I'm sorry for the dependency hell we get into with these patches for every release. I don't know any way to automatically get a list of dependencies for a patch in my queue.
</p>
<p>
Thanks for your time Robert.
</p>
Ticketrobert.marikFri, 09 Apr 2010 14:23:42 GMT
https://trac.sagemath.org/ticket/7661#comment:7
https://trac.sagemath.org/ticket/7661#comment:7
<p>
Hello Burcin
</p>
<p>
I think that two lines should be removed from the patch
</p>
<pre class="wiki">global _syms
_syms = sage.symbolic.pynac.symbol_table.get('maxima', {})
</pre><p>
I updated your patch, it is now <a class="ext-link" href="http://user.mendelu.cz/marik/sage/trac_7661-maxima_convert_back2.patch"><span class="icon"></span>http://user.mendelu.cz/marik/sage/trac_7661-maxima_convert_back2.patch</a>
</p>
<p>
If everything will work, I'll return in few (several) hours with positive review (tests in functions, interfaces, symbolics and calculus passed, now running all the test).
</p>
<p>
Robert
</p>
TicketburcinFri, 09 Apr 2010 14:34:40 GMT
https://trac.sagemath.org/ticket/7661#comment:8
https://trac.sagemath.org/ticket/7661#comment:8
<p>
OK. That is one approach to solving this problem. Now we need to rebase the patch at <a class="closed ticket" href="https://trac.sagemath.org/ticket/8237" title="defect: Sage does not recognize Maxima's complex infinity (closed: fixed)">#8237</a> so that it applies on top of these. Removing the offending hunk from <code>calculus.py</code> should be enough for that.
</p>
<p>
Note that your updated patch shows you as the author. I'd appreciate it if you changed that back.
</p>
<p>
Thanks.
</p>
Ticketrobert.marikFri, 09 Apr 2010 16:52:06 GMTstatus changed
https://trac.sagemath.org/ticket/7661#comment:9
https://trac.sagemath.org/ticket/7661#comment:9
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
</ul>
<p>
Sure, it was intended as temporary patch and from this reason I did not upload to trac server unless tested. I got some doctest failures in three files. See <a class="ext-link" href="http://boxen.math.washington.edu/home/marik/"><span class="icon"></span>http://boxen.math.washington.edu/home/marik/</a> and the files a, b and c.
</p>
<p>
I think that b is simple to fix, but have no idea about a and c.
</p>
Ticketrobert.marikFri, 09 Apr 2010 17:36:31 GMTcc set
https://trac.sagemath.org/ticket/7661#comment:10
https://trac.sagemath.org/ticket/7661#comment:10
<ul>
<li><strong>cc</strong>
<em>robert.marik</em> added
</li>
</ul>
TicketburcinFri, 09 Apr 2010 18:54:11 GMTattachment set
https://trac.sagemath.org/ticket/7661
https://trac.sagemath.org/ticket/7661
<ul>
<li><strong>attachment</strong>
set to <em>trac_7661-maxima_convert_back.take2.patch</em>
</li>
</ul>
<p>
apply only this patch
</p>
TicketburcinFri, 09 Apr 2010 18:57:13 GMT
https://trac.sagemath.org/ticket/7661#comment:11
https://trac.sagemath.org/ticket/7661#comment:11
<p>
Thanks a lot for the quick feedback.
</p>
<ul><li><code>a</code> is because you have the pynac package from <a class="closed ticket" href="https://trac.sagemath.org/ticket/8644" title="defect: update pynac to 0.1.12 (closed: fixed)">#8644</a> installed, but not the corresponding patch from <a class="closed ticket" href="https://trac.sagemath.org/ticket/8565" title="defect: atan2(-pi,0) throws "divide by zero" (closed: fixed)">#8565</a>.
</li><li><code>b</code> is a simple import problem, fixed by the updated <a class="attachment" href="https://trac.sagemath.org/attachment/ticket/7661/trac_7661-maxima_convert_back.take2.patch" title="Attachment 'trac_7661-maxima_convert_back.take2.patch' in Ticket #7661">attachment:trac_7661-maxima_convert_back.take2.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/7661/trac_7661-maxima_convert_back.take2.patch" title="Download"></a>
</li><li>I can't reproduce <code>c</code> here. It doesn't seem to be related to the changes in ticket. Do you have any other patches applied?
</li></ul>
Ticketrobert.marikSat, 10 Apr 2010 17:29:35 GMTstatus changed
https://trac.sagemath.org/ticket/7661#comment:12
https://trac.sagemath.org/ticket/7661#comment:12
<ul>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_review</em>
</li>
</ul>
<p>
I tested it on a fresh install and seems that all a,b,c are resolved.
I am running all tests again, to be sure :)
</p>
Ticketrobert.marikSat, 10 Apr 2010 19:31:20 GMTstatus changed; reviewer set
https://trac.sagemath.org/ticket/7661#comment:13
https://trac.sagemath.org/ticket/7661#comment:13
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
<li><strong>reviewer</strong>
set to <em>Robert Mařík</em>
</li>
</ul>
<p>
Tests passed, postive review, thanks for fixing - very very usefull ticket.
</p>
<p>
Release manager: apply only trac_7661-maxima_convert_back.take2.patch
</p>
TicketjhpalmieriThu, 15 Apr 2010 20:15:35 GMTstatus changed; resolution, merged set
https://trac.sagemath.org/ticket/7661#comment:14
https://trac.sagemath.org/ticket/7661#comment:14
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>merged</strong>
set to <em>sage-4.4.alpha0</em>
</li>
</ul>
<p>
Merged "trac_7661-maxima_convert_back.take2.patch" in 4.4.alpha0
</p>
Ticket