Ticket #13271 (closed defect: fixed)

Opened 10 months ago

Last modified 9 months ago

wrong sign with function Ei and limit

Reported by: dkrenn Owned by: burcin
Priority: major Milestone: sage-5.3
Component: symbolics Keywords: Ei limit sign
Cc: nbruin, benjaminfjones, dsm Work issues:
Report Upstream: N/A Reviewers: Benjamin Jones
Authors: Karl-Dieter Crisman Merged in: sage-5.3.beta2
Dependencies: #11143 Stopgaps:

Description (last modified by benjaminfjones) (diff)

We have

sage: (Ei(-Z)).limit(Z=oo)
Infinity

which is wrong, since it should be 0. It seems that there goes something wrong with the - sign. This can be also seen here:

sage: (Ei(-Z)).limit(Z=1000)   
-Ei(1000)
sage: (Ei(-Z)).limit(Z=1000).n()
-1.97204513714124e431

But

sage: Ei(-1000).n()
-5.07089306023517e-438
sage: -Ei(1000).n()
-1.97204513714124e431

which are the correct results.


Apply trac_13271-Ei-maxima.2.patch Download to Sage library.

Attachments

trac_13271-Ei-maxima.2.patch Download (1.7 KB) - added by benjaminfjones 10 months ago.
added indentation to new doctest block

Change History

comment:1 Changed 10 months ago by kcrisman

  • Cc nbruin added

Just as a data point, we still get this after #11143, unsurprisingly given that that doesn't touch Maxima.

This is a little weird, since in both Maxima in current Sage and in Maxima 5.27

(%i5) limit(expintegral_ei(-z),z,inf);
(%o5)                                  0

Further,

sage: A = Ei(-Z)._maxima_()
sage: A.limit(Z,'inf')
0

Using the Maxima lib version is ok too.

I have a feeling that the following is the problem,

sage: sage.interfaces.maxima_lib.sr_to_max(SR(Ei(-Z)))
<ECL: ((%GAMMA_INCOMPLETE) 0 ((MTIMES) |$z| -1))>

combined with

(%i1) limit(gamma_incomplete(0,-Z),Z,inf);
(%o1)                              infinity

So somehow this is completely bypassing the symbol table. I am out of my depth in our ECL conversions...

comment:2 Changed 10 months ago by kcrisman

Or maybe I'm not.

sage.functions.other.Ei : lambda X : [[max_gamma_incomplete], 0, X]

which is  here. I was kind of wondering about this in #11143, but since that didn't touch that I figured it was okay.  Mathworld seems to indicate that this conversion isn't quite right (where by "isn't quite right" I mean "wrong"), and who knows what this would imply for complex Z. Yikes.

Last edited 10 months ago by kcrisman (previous) (diff)

comment:3 Changed 10 months ago by kcrisman

  • Cc benjaminfjones, dsm added

comment:4 Changed 10 months ago by kcrisman

In fact, this makes no sense whatsoever. We should change the two lone references to max_gamma_incomplete to use the appropriate thing for Ei instead. This dates from the very start of the ECL conversions at #7377. Unless the Maxima expintegral_ei is somehow less powerful than the incomplete gamma?

I'm going to try just eliminating all that.

comment:5 Changed 10 months ago by kcrisman

Huh.

Apply

  • sage/interfaces/maxima_lib.py

    diff --git a/sage/interfaces/maxima_lib.py b/sage/interfaces/maxima_lib.py
    a b  
    11651165max_psi=EclObject("$PSI") 
    11661166max_array=EclObject("ARRAY") 
    11671167mdiff=EclObject("%DERIVATIVE") 
    1168 max_gamma_incomplete=sage_op_dict[sage.functions.other.gamma_inc] 
    11691168max_lambert_w=sage_op_dict[sage.functions.log.lambert_w] 
    11701169 
    11711170def mrat_to_sage(expr): 
     
    13581357    sage.functions.log.polylog : lambda N,X : [[mqapply],[[max_li, max_array],N],X], 
    13591358    sage.functions.other.psi1 : lambda X : [[mqapply],[[max_psi, max_array],0],X], 
    13601359    sage.functions.other.psi2 : lambda N,X : [[mqapply],[[max_psi, max_array],N],X], 
    1361     sage.functions.exp_integral.Ei : lambda X : [[max_gamma_incomplete], 0, X], 
    13621360    sage.functions.log.lambert_w : lambda N,X : [[max_lambert_w], X] if N==EclObject(0) else [[mqapply],[[max_lambert_w, max_array],N],X] 
    13631361} 

to get

sage: var('Z')
Z
sage: (Ei(-Z)).limit(Z=oo)
0
sage: (Ei(-Z)).limit(Z=1000)
Ei(-1000)
sage: (Ei(-Z)).limit(Z=1000).n()
-5.07089306023517e-438

Tests look good.

comment:6 Changed 10 months ago by kcrisman

  • Dependencies set to #11143
  • Authors set to Karl-Dieter Crisman

In theory, fixing this doesn't need #11143, but might as well do it on that since it's about the same thing.

Oops, still need to add doctests...

comment:7 Changed 10 months ago by kcrisman

  • Status changed from new to needs_review

Not that I'm guaranteeing this didn't mess anything else up. But it seems like a better solution overall than keeping the old hack.

comment:8 follow-up: ↓ 10 Changed 10 months ago by benjaminfjones

  • Reviewers set to Benjamin Jones

Looks good to me, and nice catch. I think it makes sense to have this ticket depend on 11143 so the doctests can be added to the right place. Hopefully that ticket will make it through the gauntlet soon!

I noticed missing indentation in the doctest block you added. I'll post a quick reviewer patch. If it looks ok to you, I'll set this to positive review.

Last edited 10 months ago by benjaminfjones (previous) (diff)

Changed 10 months ago by benjaminfjones

added indentation to new doctest block

comment:9 Changed 10 months ago by benjaminfjones

  • Description modified (diff)

comment:10 in reply to: ↑ 8 Changed 10 months ago by kcrisman

I noticed missing indentation in the doctest block you added. I'll post a quick reviewer patch. If it looks ok to you, I'll set this to positive review.

Please do. I can't believe I indented them wrong - that's what happens when you're doing a patch at 11 PM. Thanks for catching this.

comment:11 Changed 10 months ago by benjaminfjones

  • Status changed from needs_review to positive_review

comment:12 Changed 9 months ago by jdemeyer

  • Status changed from positive_review to closed
  • Resolution set to fixed
  • Merged in set to sage-5.3.beta2
Note: See TracTickets for help on using tickets.