Opened 11 years ago

Closed 10 years ago

#13271 closed defect (fixed)

wrong sign with function Ei and limit

Reported by: Daniel Krenn Owned by: Burcin Erocal
Priority: major Milestone: sage-5.3
Component: symbolics Keywords: Ei limit sign
Cc: Nils Bruin, Benjamin Jones, D.S. McNeil Merged in: sage-5.3.beta2
Authors: Karl-Dieter Crisman Reviewers: Benjamin Jones
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #11143 Stopgaps:

Status badges

Description (last modified by Benjamin Jones)

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 to Sage library.

Attachments (1)

trac_13271-Ei-maxima.2.patch (1.7 KB) - added by Benjamin Jones 11 years ago.
added indentation to new doctest block

Download all attachments as: .zip

Change History (13)

comment:1 Changed 11 years ago by Karl-Dieter Crisman

Cc: Nils Bruin 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 11 years ago by Karl-Dieter Crisman

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 11 years ago by Karl-Dieter Crisman (previous) (diff)

comment:3 Changed 11 years ago by Karl-Dieter Crisman

Cc: Benjamin Jones D.S. McNeil added

comment:4 Changed 11 years ago by Karl-Dieter Crisman

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 11 years ago by Karl-Dieter Crisman

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 11 years ago by Karl-Dieter Crisman

Authors: Karl-Dieter Crisman
Dependencies: #11143

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 11 years ago by Karl-Dieter Crisman

Status: newneeds_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 Changed 11 years ago by Benjamin Jones

Reviewers: 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 11 years ago by Benjamin Jones (previous) (diff)

Changed 11 years ago by Benjamin Jones

added indentation to new doctest block

comment:9 Changed 11 years ago by Benjamin Jones

Description: modified (diff)

comment:10 in reply to:  8 Changed 11 years ago by Karl-Dieter Crisman

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 11 years ago by Benjamin Jones

Status: needs_reviewpositive_review

comment:12 Changed 10 years ago by Jeroen Demeyer

Merged in: sage-5.3.beta2
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.