Sage: Ticket #8237: Sage does not recognize Maxima's complex infinity
https://trac.sagemath.org/ticket/8237
<p>
As subject says:
</p>
<pre class="wiki">sage: maxima('inf').sage()
+Infinity
sage: maxima('infinity').sage()
+Infinity
</pre><p>
From Maxima manual
</p>
<pre class="wiki">Constant: inf
inf represents real positive infinity.
Constant: infinity
infinity represents complex infinity.
Constant: minf
minf represents real minus (i.e., negative) infinity.
</pre><p>
As a cosequence, Sage fails to evaluate limit of 1/x at x=0. Maxima gives correct result (complex infinity)
</p>
<pre class="wiki">sage: maxima('limit(1/x,x,0)')
infinity
sage: maxima('limit(1/x,x,0)').sage()
+Infinity
sage: limit(1/x,x=0)
+Infinity
sage: maxima('limit(1/x,x,0,plus)')
inf
sage: maxima('limit(1/x,x,0,plus)').sage()
+Infinity
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/8237
Trac 1.1.6robert.marikThu, 11 Feb 2010 17:16:31 GMT
https://trac.sagemath.org/ticket/8237#comment:1
https://trac.sagemath.org/ticket/8237#comment:1
<p>
reported on <a class="ext-link" href="http://groups.google.cz/group/sage-devel/browse_thread/thread/350697c3650a3b76"><span class="icon"></span>sage-devel</a>
</p>
Ticketrobert.marikThu, 11 Feb 2010 18:22:17 GMTowner, summary changed
https://trac.sagemath.org/ticket/8237#comment:2
https://trac.sagemath.org/ticket/8237#comment:2
<ul>
<li><strong>owner</strong>
changed from <em>burcin</em> to <em>robert.marik</em>
</li>
<li><strong>summary</strong>
changed from <em>Sage does not recognize Maxima's complex ininity</em> to <em>Sage does not recognize Maxima's complex infinity</em>
</li>
</ul>
Ticketrobert.marikThu, 11 Feb 2010 18:22:45 GMTowner changed
https://trac.sagemath.org/ticket/8237#comment:3
https://trac.sagemath.org/ticket/8237#comment:3
<ul>
<li><strong>owner</strong>
changed from <em>robert.marik</em> to <em>burcin</em>
</li>
</ul>
TicketkcrismanThu, 11 Feb 2010 19:51:52 GMT
https://trac.sagemath.org/ticket/8237#comment:4
https://trac.sagemath.org/ticket/8237#comment:4
<p>
Right now, there doesn't seem to be a lot of distinction in Sage between unsigned and signed infinity, though of course as you point out there should be. From sage.rings.infinity.py:
</p>
<pre class="wiki"> Note: the shorthand oo is predefined in Sage to be the same as
+Infinity in the infinity ring. It is considered equal to, but not
the same as Infinity in the UnsignedInfinityRing::
sage: oo
+Infinity
sage: oo is InfinityRing.0
True
sage: oo is UnsignedInfinityRing.0
False
sage: oo == UnsignedInfinityRing.0
True
</pre><p>
There is unsigned_infinity, but the following seems problematic:
</p>
<pre class="wiki">sage: unsigned_infinity
Infinity
sage: Infinity
+Infinity
</pre><p>
What the heck?
</p>
TicketburcinThu, 11 Feb 2010 22:00:42 GMTattachment set
https://trac.sagemath.org/ticket/8237
https://trac.sagemath.org/ticket/8237
<ul>
<li><strong>attachment</strong>
set to <em>trac_8237-maxima_infinity.patch</em>
</li>
</ul>
<p>
fix conversion of different infinities back from maxima
</p>
TicketburcinThu, 11 Feb 2010 22:02:17 GMTstatus changed; author, milestone set
https://trac.sagemath.org/ticket/8237#comment:5
https://trac.sagemath.org/ticket/8237#comment:5
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>author</strong>
set to <em>Burcin Erocal</em>
</li>
<li><strong>milestone</strong>
set to <em>sage-4.3.3</em>
</li>
</ul>
<p>
I uploaded a patch, please review.
</p>
TicketkcrismanFri, 12 Feb 2010 02:38:21 GMTstatus changed; reviewer set
https://trac.sagemath.org/ticket/8237#comment:6
https://trac.sagemath.org/ticket/8237#comment:6
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
<li><strong>reviewer</strong>
set to <em>Karl-Dieter Crisman</em>
</li>
</ul>
<p>
Looks good, but does it duplicate some of lines 1841ff of sage/calculus/calculus.py?
</p>
<pre class="wiki">from sage.rings.infinity import infinity, minus_infinity
register_symbol(infinity, dict(maxima='inf'))
register_symbol(minus_infinity, dict(maxima='minf'))
</pre><p>
Since
</p>
<pre class="wiki">sage: type(infinity)
<class 'sage.rings.infinity.PlusInfinity'>
sage: type(SR(infinity))
<type 'sage.symbolic.expression.Expression'>
</pre><p>
my guess is that, at least for completeness, calculus.py should also import unsigned_infinity and have a line added with
</p>
<pre class="wiki">register_symbol(unsigned_infinity, dict(maxima='infinity'))
</pre><p>
Also, my taste in doctests is to also include the original example, not (only) the underlying cause:
</p>
<pre class="wiki">sage: limit(1/x,x=0)
Infinity
sage: limit(1/x,x=0,dir='above')
+Infinity
sage: limit(1/x,x=0,dir='below')
-Infinity
</pre><p>
which of course works great now. These are very minor quibbles, of course, but might as well be done.
</p>
<p>
Also, in doctesting it doesn't like sage: sage: as the prefix (though one could argue this is a bug itself), and
</p>
<pre class="wiki">devel/sage/sage/calculus/functional.py", line 313:
sage: lim(1/x, x=0)
Expected:
+Infinity
Got:
Infinity
</pre>
Ticketrobert.marikFri, 12 Feb 2010 18:34:13 GMTcc set
https://trac.sagemath.org/ticket/8237#comment:7
https://trac.sagemath.org/ticket/8237#comment:7
<ul>
<li><strong>cc</strong>
<em>robert.marik</em> added
</li>
</ul>
TicketburcinSat, 20 Feb 2010 14:30:17 GMTattachment set
https://trac.sagemath.org/ticket/8237
https://trac.sagemath.org/ticket/8237
<ul>
<li><strong>attachment</strong>
set to <em>trac_8237-maxima_infinity.take2.patch</em>
</li>
</ul>
<p>
apply only this patch
</p>
TicketburcinSat, 20 Feb 2010 14:36:11 GMTstatus changed
https://trac.sagemath.org/ticket/8237#comment:8
https://trac.sagemath.org/ticket/8237#comment:8
<ul>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_review</em>
</li>
</ul>
<p>
I was trying to get the first patch out quickly, so it ended up being too sloppy. I hope <a class="attachment" href="https://trac.sagemath.org/attachment/ticket/8237/trac_8237-maxima_infinity.take2.patch" title="Attachment 'trac_8237-maxima_infinity.take2.patch' in Ticket #8237">attachment:trac_8237-maxima_infinity.take2.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/8237/trac_8237-maxima_infinity.take2.patch" title="Download"></a> is cleaner. :)
</p>
<p>
I think it's more natural to put the maxima conversions for different infinities in <code>sage/symbolic/constants.py</code> where all the other constants are declared, so I removed the lines in <code>calculus.py</code>. I also added doctests with <code>limit(1/x, ...)</code>.
</p>
TicketrosskWed, 24 Feb 2010 12:40:10 GMTreviewer changed
https://trac.sagemath.org/ticket/8237#comment:9
https://trac.sagemath.org/ticket/8237#comment:9
<ul>
<li><strong>reviewer</strong>
changed from <em>Karl-Dieter Crisman</em> to <em>Karl-Dieter Crisman, Ross Kyprianou</em>
</li>
</ul>
<p>
By exercising a number of arithmetic use cases, viz.
</p>
<pre class="wiki">for k in (1, 1.0, 1/2, x, 1+I, -1, -1.0, -1/2, -x, -1-I):
print k, k + Infinity , k + +Infinity, k + -Infinity
for k in (1, 1.0, 1/2, x, 1+I, -1, -1.0, -1/2, -x, -1-I):
print k, Infinity -k , +Infinity -k, -Infinity -k
for k in (1, 1.0, 1/2, x, 1+I, -1, -1.0, -1/2, -x, -1-I):
print k, k / Infinity , k / +Infinity, k / -Infinity
for k in (1, 1.0, 1/2, x, -1, -1.0, -1/2, -x):
print k, k * Infinity , k * +Infinity, k * -Infinity
</pre><p>
there were a small number of things to note<br />
</p>
<p>
(a) the same answer resulted, regardless of whether (unsigned) Infinity or +Infinity was used. Query: Just to make sure we are getting the results we designed for... Currently +Infinity (or -Infinity) is being returned regardless of whether a signed or unsigned infinity is used. Should (unsigned) Infinity be returned when (unsigned) Infinity is used?<br />
</p>
<p>
(b) what seems to be an inconsistency occurs when mixing Infinity with complex numbers (same thing holds when we replace Infinity with +Infinity or with -Infinity)
</p>
<pre class="wiki"># the following combinations of complex and infinity are ok
I + Infinity # +Infinity
I - Infinity # -Infinity
I / Infinity # 0
# the following crash with Arithmetic Error
Infinity / I
Infinity * I
I * Infinity
# isnt I+Infinity (for example) just as meaningful/less as I*Infinity ?
</pre><p>
(c) Im curious about the following expressions
</p>
<pre class="wiki">x * Infinity
-x * Infinity
</pre><p>
These return <code>+Infinity</code> and <code>-Infinity</code> respectively. But what if x is negative real? (should be opposite answers). The following tries to demonstrate this for two vars (z and x), both declared real in two different ways
</p>
<pre class="wiki">sage: var('z',domain='real')
z
sage: assume(x,'real',x<0,z<0)
sage: assumptions()
[x is real, x < 0, z < 0]
sage: x*+Infinity
+Infinity
sage: z*+Infinity
+Infinity
</pre><p>
(is this another ticket "make Infinity work with assumptions/declarations"?)
</p>
TicketburcinWed, 24 Feb 2010 16:51:02 GMT
https://trac.sagemath.org/ticket/8237#comment:10
https://trac.sagemath.org/ticket/8237#comment:10
<p>
Hi Ross,
</p>
<p>
It's likely that there are inconsistencies in the way infinity is handled by pynac. For instance it definitely doesn't handle interactions with the complex <code>I</code> well. I implemented support for infinity in pynac to provide a basis for better series expansions and limit computations. However, I didn't have time to actually use it for anything later.
</p>
<p>
I suggest we keep this issue focused on the conversion problem in the maxima interface so it can be reviewed and merged quickly. You can open separate tickets for the problems in pynac related to infinity. The fact that assumptions are not passed on to pynac should be yet another ticket.
</p>
<p>
BTW, this article might help decide what behavior we expect w.r.t. arithmetic involving infinity.
</p>
<p>
<a class="ext-link" href="http://dx.doi.org/10.1016/j.jsc.2004.12.002"><span class="icon"></span>http://dx.doi.org/10.1016/j.jsc.2004.12.002</a>
</p>
TicketrosskThu, 25 Feb 2010 07:53:32 GMT
https://trac.sagemath.org/ticket/8237#comment:11
https://trac.sagemath.org/ticket/8237#comment:11
<p>
Burcin.<br />
</p>
<p>
I *did* think it unlikely all these issues would be addressed in one ticket ;-) I guess I was trying to be diligent in reviewing (and Im interested in getting involved in "symbolics" development some time, so the extended exercising of the symbolics module is part of my familiarization process - I even started looking at the code!)<br />
</p>
<p>
The tests I did above (plus others involving limits) warrant a positive review vote from me. Ill let Karl-Dieter sign it off when he wants, as he has reviewed the code as well.
</p>
TicketburcinMon, 12 Apr 2010 08:33:08 GMTattachment set
https://trac.sagemath.org/ticket/8237
https://trac.sagemath.org/ticket/8237
<ul>
<li><strong>attachment</strong>
set to <em>trac_8237-maxima_infinity.take3.patch</em>
</li>
</ul>
<p>
apply only this patch
</p>
TicketburcinMon, 12 Apr 2010 08:35:08 GMT
https://trac.sagemath.org/ticket/8237#comment:12
https://trac.sagemath.org/ticket/8237#comment:12
<p>
I rebased the patch so that it applies cleanly after <a class="closed ticket" href="https://trac.sagemath.org/ticket/7661" title="defect: maxima interface gives precedence to function dictionary instead of ... (closed: fixed)">#7661</a>.
</p>
<p>
This ticket depends on <a class="closed ticket" href="https://trac.sagemath.org/ticket/7661" title="defect: maxima interface gives precedence to function dictionary instead of ... (closed: fixed)">#7661</a>. Only <a class="attachment" href="https://trac.sagemath.org/attachment/ticket/8237/trac_8237-maxima_infinity.take3.patch" title="Attachment 'trac_8237-maxima_infinity.take3.patch' in Ticket #8237">attachment:trac_8237-maxima_infinity.take3.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/8237/trac_8237-maxima_infinity.take3.patch" title="Download"></a> should be applied.
</p>
TicketkcrismanFri, 23 Apr 2010 16:30:35 GMT
https://trac.sagemath.org/ticket/8237#comment:13
https://trac.sagemath.org/ticket/8237#comment:13
<p>
This looks wonderful to me, but unfortunately I don't have a current build of the alphas for 4.4, so I can't actually test it. I'd give is a positive review if I could!
</p>
Ticketrobert.marikThu, 29 Apr 2010 06:05:47 GMTstatus, reviewer changed
https://trac.sagemath.org/ticket/8237#comment:14
https://trac.sagemath.org/ticket/8237#comment:14
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
<li><strong>reviewer</strong>
changed from <em>Karl-Dieter Crisman, Ross Kyprianou</em> to <em>Karl-Dieter Crisman, Ross Kyprianou, Robert Mařík</em>
</li>
</ul>
<p>
Works for me, long tests passed on 4.4.rc0.
</p>
<p>
Since also kcrisman wrote "This looks wonderful to me .... I'd give is a positive review if I could!" I think that the ticket deserves positive review.
</p>
<p>
Positive review. Apply only trac_8237-maxima_infinity.take3.patch
</p>
TicketmvnguSat, 08 May 2010 22:09:54 GMTstatus changed; resolution, merged set
https://trac.sagemath.org/ticket/8237#comment:15
https://trac.sagemath.org/ticket/8237#comment:15
<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.2.alpha0</em>
</li>
</ul>
<p>
Merged <a class="ext-link" href="http://trac.sagemath.org/sage_trac/attachment/ticket/8237/trac_8237-maxima_infinity.take3.patch"><span class="icon"></span>trac_8237-maxima_infinity.take3.patch</a>.
</p>
Ticket