Opened 2 years ago
Last modified 8 months ago
#14821 new defect
Weird error in exponential integral
Reported by: | ppurka | Owned by: | burcin |
---|---|---|---|
Priority: | major | Milestone: | sage-6.4 |
Component: | calculus | Keywords: | |
Cc: | nbruin | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by ppurka)
This is so trivial that I am surprised this bug even exists. :) Present since at least sage-5.2 till present versions.
The following integral works
H = exp(-x) H.integral(x, 0, 1) -e^(-1) + 1
But the following integral errors out
H = exp(-1.0 * x) H.integral(x, 0, 1) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_19.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("SCA9IGV4cCgtMS4wKjEwXi0xKngpCkguaW50ZWdyYWwoeCwgMCwgMSk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module> File "/tmp/tmpE7_LAK/___code___.py", line 4, in <module> exec compile(u'H.integral(x, _sage_const_0 , _sage_const_1 ) File "", line 1, in <module> File "expression.pyx", line 9058, in sage.symbolic.expression.Expression.integral (sage/symbolic/expression.cpp:37991) File "/usr/local/src/sage/sage-5.2.server/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.py", line 683, in integrate return definite_integral(expression, v, a, b) File "function.pyx", line 432, in sage.symbolic.function.Function.__call__ (sage/symbolic/function.cpp:4941) File "/usr/local/src/sage/sage-5.2.server/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.py", line 173, in _eval_ return integrator(*args) File "/usr/local/src/sage/sage-5.2.server/local/lib/python2.7/site-packages/sage/symbolic/integration/external.py", line 21, in maxima_integrator result = maxima.sr_integral(expression, v, a, b) File "/usr/local/src/sage/sage-5.2.server/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.py", line 746, in sr_integral raise error RuntimeError: ECL says: In function GCD, the value of the second argument is 1.0 which is not of the expected type INTEGER
Change History (9)
comment:1 Changed 2 years ago by ppurka
- Description modified (diff)
comment:2 Changed 2 years ago by kcrisman
Almost certainly the same error (see this sage-support thread:
sage: integral(exp(-300.0/(-0.064*x+14.0)),x,0.0,120.0)
and also this ask.sagemath question.
The real underlying issue is the one at this Maxima bug; basically, we use keepfloat:true in Maxima so that things like the integral of e^(-x^2) come out right, but this causes things to go wrong in these examples.
And Nils' comment still applies, that it's not clear why something with a float in it should be integrated symbolically (rather than numerically) at all. I think this is an important point, though I'm not sure how to resolve it in such a ridiculously simple case as yours. Note that I updated the Maxima bug, and with keepfloat:false it is ridiculously accurate as a float.
That said, we should still have a better error message, and ideally just a correct answer.
comment:3 Changed 2 years ago by ppurka
- deleted dumb comment (look at the diff and comment:5 if you want to know why I deleted this :) -
I saw you mention in the ticket whether it is user error to provide a floating number -1.0 in the exponential function. The -1.0 used in the example is just an example. I had a more complicated number there. It really surprised me when the integral failed. Such kind of integrals should never fail.
comment:4 Changed 2 years ago by kcrisman
- Cc nbruin added
Wait, I'm confused. What does the value of the derivative have to do with keepfloat and this behavior?
sage: H = exp(-.00001*x) sage: H.integral(x,0,1) <same error> sage: plot(H,(x,0,1),ymin=0) <essentially constant plot>
The reason why Nils and others consider this to be close to user error is that it's not clear what a non-numerical integral of an integral with floats in it should mean. The indefinite integral would be inaccurate by definition. Or am I misrepresenting something, Nils?
One possible workaround I see is that we could catch this error and ask the user whether they wanted a numerical integral, or even return a numerical integral. We haven't seen this in circumstances without exponentials of floats.
Another thing to note is that it's the endpoints being floats which caused keepfloat to be necessary. We could investigate whether we want to only use keepfloat:true in those situations.
comment:5 Changed 2 years ago by ppurka
Oh, now that I read the maxima ticket again, I see that sage was forcing keepfloat true and not the other way around. Sorry for the misleading comments earlier.
comment:6 Changed 19 months ago by vbraun_spam
- Milestone changed from sage-6.1 to sage-6.2
comment:7 Changed 16 months ago by vbraun_spam
- Milestone changed from sage-6.2 to sage-6.3
comment:8 Changed 13 months ago by vbraun_spam
- Milestone changed from sage-6.3 to sage-6.4
comment:9 Changed 8 months ago by rws
Original commands now give 0.6321205588285577 which seems correct so just a doctest is now needed.
Even simpler example.