Opened 11 years ago

Closed 10 years ago

# wrong sign with function Ei and limit

Reported by: Owned by: Daniel Krenn Burcin Erocal major sage-5.3 symbolics Ei limit sign Nils Bruin, Benjamin Jones, D.S. McNeil sage-5.3.beta2 Karl-Dieter Crisman Benjamin Jones N/A #11143

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.

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

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.

Huh.

Apply

• ## sage/interfaces/maxima_lib.py

diff --git a/sage/interfaces/maxima_lib.py b/sage/interfaces/maxima_lib.py
 a max_psi=EclObject("\$PSI") max_array=EclObject("ARRAY") mdiff=EclObject("%DERIVATIVE") max_gamma_incomplete=sage_op_dict[sage.functions.other.gamma_inc] max_lambert_w=sage_op_dict[sage.functions.log.lambert_w] def mrat_to_sage(expr): sage.functions.log.polylog : lambda N,X : [[mqapply],[[max_li, max_array],N],X], sage.functions.other.psi1 : lambda X : [[mqapply],[[max_psi, max_array],0],X], sage.functions.other.psi2 : lambda N,X : [[mqapply],[[max_psi, max_array],N],X], sage.functions.exp_integral.Ei : lambda X : [[max_gamma_incomplete], 0, X], 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] }

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 → #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: new → 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 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_review → positive_review

### comment:12 Changed 10 years ago by Jeroen Demeyer

Merged in: → sage-5.3.beta2 → fixed positive_review → closed
Note: See TracTickets for help on using tickets.