#14976: integration with non symbolic bounds broken
-------------------------------+--------------------------
Reporter: burcin | Owner:
Type: defect | Status: new
Priority: critical | Milestone: sage-5.12
Component: symbolics | Resolution:
Keywords: integration | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Dependencies:
Stopgaps: |
-------------------------------+--------------------------
Comment (by charpent):
The problem is that (maxima's ?) integrate needs to assert that
integration bounds are real: consider this (slightly generalized) example:
{{{
Maxima 5.30.0 http://maxima.sourceforge.net
using Lisp GNU Common Lisp (GCL) GCL 2.6.7 (a.k.a. GCL)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) display2d:false;
(%o1) false
(%i2) define(h(x), integrate(f(t), t, g1(x), g2(x)));
defint: lower limit of integration must be real; found g1(x)
-- an error. To debug this try: debugmode(true);
(%i3) declare(g1, real, g2, real);
(%o3) done
(%i4) define(h(x), integrate(f(t), t, g1(x), g2(x)));
(%o4) h(x):='integrate(f(t),t,g1(x),g2(x))
(%i5) diff(h(x), x);
(%o5) f(g2(x))*'diff(g2(x),x,1)-f(g1(x))*'diff(g1(x),x,1)
(%i6)
}}}
Maxima allows for declaring "after the fact" that g1 and g2 are sympbols
for real values, and extends this declaration to the case where g1 and 2
are symbols for functions, which are now interpreted as real-valued
functions.
As far as I know, there is no way to declare the domain of a function in
Sage.
And, since the Sage-to-Maxima interface uses arbitrary (and volatile !)
symbols, one cannot simply use "maxima('declare(g1, real, g2, real);')" to
this effect...
{{{
sage: var("x,t")
(x, t)
sage: f=function("f",t)
sage: g1=function("g1",t)
sage: g2=function("g2",t)
sage: maxima("declare(g1,real,g2,real);")
done
sage: h(x)=integrate(f(t),t,g1(x),g2(x))
/usr/local/sage-5.10/local/lib/python2.7/site-
packages/IPython/core/interactiveshell.py:2721: DeprecationWarning:
Substitution using function-call syntax and unnamed arguments is
deprecated and will be removed from a future release of Sage; you can use
named arguments instead, like EXPR(x=..., y=...)
See http://trac.sagemath.org/5930 for details.
exec code_obj in self.user_global_ns, self.user_ns
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call
last)
<ipython-input-10-7dd129794e9a> in <module>()
----> 1 __tmp__=var("x"); h =
symbolic_expression(integrate(f(t),t,g1(x),g2(x))).function(x)
/usr/local/sage-5.10/local/lib/python2.7/site-
packages/sage/misc/functional.pyc in integral(x, *args, **kwds)
738 """
739 if hasattr(x, 'integral'):
--> 740 return x.integral(*args, **kwds)
741 else:
742 from sage.symbolic.ring import SR
/usr/local/sage-5.10/local/lib/python2.7/site-
packages/sage/symbolic/expression.so in
sage.symbolic.expression.Expression.integral
(sage/symbolic/expression.cpp:39592)()
/usr/local/sage-5.10/local/lib/python2.7/site-
packages/sage/symbolic/integration/integral.pyc in integrate(expression,
v, a, b, algorithm)
686 return indefinite_integral(expression, v)
687 else:
--> 688 return definite_integral(expression, v, a, b)
689
690 integral= integrate
/usr/local/sage-5.10/local/lib/python2.7/site-
packages/sage/symbolic/function.so in
sage.symbolic.function.Function.__call__
(sage/symbolic/function.cpp:5114)()
/usr/local/sage-5.10/local/lib/python2.7/site-
packages/sage/symbolic/integration/integral.pyc in _eval_(self, f, x, a,
b)
171 for integrator in self.integrators:
172 try:
--> 173 return integrator(*args)
174 except NotImplementedError:
175 pass
/usr/local/sage-5.10/local/lib/python2.7/site-
packages/sage/symbolic/integration/external.pyc in
maxima_integrator(expression, v, a, b)
19 result = maxima.sr_integral(expression,v)
20 else:
---> 21 result = maxima.sr_integral(expression, v, a, b)
22 return result._sage_()
23
/usr/local/sage-5.10/local/lib/python2.7/site-
packages/sage/interfaces/maxima_lib.pyc in sr_integral(self, *args)
745 raise ValueError, "Computation failed since Maxima
requested additional constraints; using the 'assume' command before
integral evaluation *may* help (example of legal syntax is 'assume(" +
s[4:k] +">0)', see `assume?` for more details)\n" + s
746 else:
--> 747 raise error
748
749 def sr_sum(self,*args):
RuntimeError: ECL says: Error executing code in Maxima: defint: lower
limit of integration must be real; found g1(x)
}}}
Maxima won't, however, accept to declare a function as real :
{{{
(%i6) declare(s(x), real);
declare: improper argument: s(x)
-- an error. To debug this try: debugmode(true);
}}}
There is an *horrible* workaround : create *variables*, g1 and g2, assume
them real, then create functions f, g1 and g2:
{{{
sage: var("x, t, g1, g2")
(x, t, g1, g2)
sage: assume(g1, "real", g2, "real")
sage: f=function("f",t)
sage: g1=function("g1",x)
sage: g2=function("g2",x)
sage: h(x)=integrate(f(t), t,g1(x), g2(x))
sage: h(x)
integrate(f(t), t, g1(x), g2(x))
sage: diff(h(x),x)
-f(g1(x))*D[0](g1)(x) + f(g2(x))*D[0](g2)(x)
sage:
}}}
The core of the problem is, however, the inability to declare a function
as real. Maxima's declaration of a *symbol's* domain "happens to work",
but a cleaner solution is needed. I am afraid that it involves work both
on Sage *and* Maxima.
HTH,
Emmanuel Charpentier
--
Ticket URL: <http://trac.sagemath.org/ticket/14976#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.