# Integral(v,t).doit() differs from integrate(v,t) #10567

Closed
opened this Issue Feb 11, 2016 · 7 comments

Projects
None yet
4 participants

### hercidav commented Feb 11, 2016

 Integrating a vector (v=sympy.Matrix([a*t,b,c]) shall give again a vector as a result. Sympy.integrate(v,t) gives the correct answer, however sympy.Integral(v,t) gives a completely different result: ``````>>> a,b,c = symbols('a b c') >>> t = symbols('t') >>> vt = Matrix([a*t,b,c]) >>> integrate(vt,t) Matrix([ [a*t**2/2], [ b*t], [ c*t]]) >>> Integral(vt,t).doit() a*t**4/3 + b*t**2/2 + c*t ``````
Contributor

### ashutoshsaboo commented Feb 11, 2016

 In which file of the source code or equivalently which module is executed in the 4th and 5th line of the above code? Could you help on that?
Contributor

### ashutoshsaboo commented Feb 11, 2016

 Hi. I managed to find something, that maybe of use for this. If you see Line No 746 in sympy/integrals.py - `poly = f.as_poly(x) ` Now if you edit the code, and try returning that poly variable, this is what is the output for line 4 and 5 of your code, respectively - : ``````Matrix([[Poly(a*t, t, domain='ZZ[a]')], [b*t], [c*t]]) Poly(a*t*t**2 + b*t + c, t, domain='ZZ[t,a,b,c]') `````` Now, If you notice the above output, which actually explains the output you get for the 4th and 5th line of your code. This happens because, in the source code, the argument function that is passed to integrate, is only checked if it's a polynomial or not, and it isn't checked for Matrix. Although I don't understand how the the 1st line of my output (that is above) came, even though when the same functions are executed in case of integral() or Integrate()? So, could someone help me build on this? @Shekharrajak Could you help on this? @hercidav @jksuom

### hercidav commented Feb 11, 2016

 Hi @ashutoshsaboo, thanks for looking into this. It seems, that the Integral.doit() function is taking the input Matrix as a set of coefficients of a polynomial. But why it can be different for Integral and integrate(), if integrate (line 1230 of integrals.py) just calls Integral.doit(): ``````if isinstance(integral, Integral): return integral.doit(deep=False, meijerg=meijerg, conds=conds, risch=risch, manual=manual) `````` David
Member

### asmeurer commented Feb 11, 2016

 The correct behavior should be the one with the matrix output. integrate shouldn't consider an iterable to be a list of coefficients for a polynomial.
Member

### jksuom commented Feb 11, 2016

 `integrate` is defined with the decorator `xthreaded` ''intended to make it uniformly possible to apply a function to all elements of composite objects, e.g. matrices, lists, tuples and other iterable containers, or just expressions." `doit` has no decorator.
Member

### asmeurer commented Feb 11, 2016

 Ugh, I don't like that decorator. We should get rid of it.

### skirpichev added a commit to diofant/diofant that referenced this issue Feb 12, 2016

``` Don't use xthreaded decorator in integrals ```
`Fixes sympy/sympy#10567`
``` 5bf2b9c ```
Contributor

### ashutoshsaboo commented Feb 12, 2016

 Thanks @asmeurer @jksuom @hercidav . I managed to solve the issue that is happening here. @skirpichev The position where you have placed the isinstance of Matrix is I feel wrong, because it must always first check for the zero condition and the deep condition as well, and then only proceed to the condition of Matrix, otherwise in some special case your code, will give a problem. I looked into the problem that I noticed yesterday, which I pointed above more, and as @jksuom said, the xthreaded thing is the one which is causing the problem. Henceforth, I am opening a new pull request with the new code, that solves this issue. Please look into it @asmeurer @jksuom . Suggest in case if any other edits in the code are required, and if it can be merged into the master?

Merged

### skirpichev added a commit to diofant/diofant that referenced this issue Feb 12, 2016

``` Don't use xthreaded decorator in integrals ```
`Fixes sympy/sympy#10567`
``` 06f2d8b ```