# Possible bug in integrate ?

104 views

### Emmanuel Charpentier

Oct 25, 2019, 2:57:45 AM10/25/19
to sage-support
Inspired by this ask.sagemath question. Minimal case is

sage: f=function("f")
sage: F(x)=integrate(f(t),t,0,x)
sage: diff(F(x),x)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-87-d4bc7769bfb7> in <module>()
----> 1 diff(F(x),x)

/usr/local/sage-P3-2/local/lib/python3.7/site-packages/sage/calculus/functional.py in derivative(f, *args, **kwds)
134     if not isinstance(f, Expression):
135         f = SR(f)
--> 136     return f.derivative(*args, **kwds)
137
138 diff = derivative

/usr/local/sage-P3-2/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.derivative (build/cythonized/sage/symbolic/expression.cpp:25543)()
4172             ValueError: No differentiation variable specified.
4173         """
-> 4174         return multi_derivative(self, args)
4175
4176     diff = differentiate = derivative

/usr/local/sage-P3-2/local/lib/python3.7/site-packages/sage/misc/derivative.pyx in sage.misc.derivative.multi_derivative (build/cythonized/sage/misc/derivative.c:3118)()
220
221     for arg in derivative_parse(args):
--> 222         F = F._derivative(arg)
223     return F
224

/usr/local/sage-P3-2/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._derivative (build/cythonized/sage/symbolic/expression.cpp:26060)()
4244         sig_on()
4245         try:
-> 4246             x = self._gobj.diff(ex_to_symbol(symbol._gobj), deg)
4247         finally:
4248             sig_off()

/usr/local/sage-P3-2/local/lib/python3.7/site-packages/sage/symbolic/integration/integral.py in _tderivative_(self, f, x, a, b, diff_param)
254             ans = SR.zero()
255         return (ans + f.subs(x == b) * b.diff(diff_param)
--> 256                     - f.subs(x == a) * a.diff(diff_param))
257
258     def _print_latex_(self, f, x, a, b):

/usr/local/sage-P3-2/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4608)()
487             AttributeError: 'LeftZeroSemigroup_with_category.element_class' object has no attribute 'blah_blah'
488         """
--> 489         return self.getattr_from_category(name)
490
491     cdef getattr_from_category(self, name):

/usr/local/sage-P3-2/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/element.c:4717)()
500         else:
501             cls = P._abstract_element_class
--> 502         return getattr_from_other_class(self, cls, name)
503
504     def __dir__(self):

/usr/local/sage-P3-2/local/lib/python3.7/site-packages/sage/cpython/getattr.pyx in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2614)()
392         dummy_error_message.cls = type(self)
393         dummy_error_message.name = name
--> 394         raise AttributeError(dummy_error_message)
395     attribute = <object>attr
396     # Check for a descriptor (__get__ in Python)

AttributeError: 'sage.rings.rational.Rational' object has no attribute 'diff'

I donot understand this error, and I expected to see sometning along the lines of f(x)...

### Nils Bruin

Oct 25, 2019, 4:20:26 AM10/25/19
to sage-support
Yes, that's a bug. It happens in F(x).operator()._tderivative_ It differentiates the bounds in case those vary with the differentiation variable, and that does not work for "0". If you define

var('y')
F(x)=integrate(f(t),y,x)

you get the right result (with y not being a function of t).

The bounds should be checked for being constants before being differentiated.

### Emmanuel Charpentier

Oct 25, 2019, 6:27:42 AM10/25/19
to sage-support
Thanks a lot ! That's perfectly clear...

Any hints on how to file a ticket for this issue ?

### Nils Bruin

Oct 25, 2019, 12:21:48 PM10/25/19
to sage-support
On Friday, October 25, 2019 at 3:27:42 AM UTC-7, Emmanuel Charpentier wrote:
Thanks a lot ! That's perfectly clear...

Any hints on how to file a ticket for this issue ?

The minimal example excellently shows the problem, so including that would be great. It's easy to find the problematic code from it. Referencing this google groups thread and the ask.sagemath question is probably good too. And put forward references to the ticket at those places too, just to fully document.

Component can be symbolics, I think. Priority "major" seems fine too.

(the ticket filing itself would happen at trac.sagemath.org, but I think you know that)