# Definite integral returns an answer with indefinite integrals #7130

Closed
opened this Issue Sep 27, 2013 · 7 comments

Projects
None yet
5 participants
Member

### asmeurer commented Sep 27, 2013

 ``````In [1]: var("i L a b") Out[1]: (i, L, a, b) In [2]: integrand = cos(pi*i*x/L)**2/(a + b*x) In [3]: integrand = integrand.rewrite(exp) In [4]: integrate(integrand, (x, 0, L)) Out[4]: ⌠ ⌠ ⎮ 4⋅ⅈ⋅π⋅i 2⋅ⅈ⋅π⋅i ⎮ 1 ⎮ ℯ + 2⋅ℯ + 1 - ⎮ ─ dx + ⎮ ───────────────────────────── dx ⎮ a ⎮ 2⋅ⅈ⋅π⋅i 2⋅ⅈ⋅π⋅i ⌡ ⎮ 4⋅L⋅b⋅ℯ + 4⋅a⋅ℯ ⌡ The answer is obviously wrong (it should not depend on x). Also, I don't know if this is related, but integrate seems to be quite inefficient. I put a print statement at the top of integrate() to print the args, and I got In [4]: integrate(integrand, (x, 0, L)) ((exp(I*pi*i*x/L)/2 + exp(-I*pi*i*x/L)/2)**2/(a + b*x), (x, 0, L)) (4/(4*a + 4*b*x) - 1/(2*a + 2*b*x), x) (1/(2*a + 2*b*x), x) (1/(4*a + 4*b*x), x) (1/(4*a + 4*b*x), x) (0, x) (1/(4*a + 4*b*x), x) (1/(4*a + 4*b*x), x) (1/(4*a + 4*b*x), x) Out[4]: ⌠ ⌠ ⎮ 4⋅ⅈ⋅π⋅i 2⋅ⅈ⋅π⋅i ⎮ 1 ⎮ ℯ + 2⋅ℯ + 1 - ⎮ ─ dx + ⎮ ───────────────────────────── dx ⎮ a ⎮ 2⋅ⅈ⋅π⋅i 2⋅ⅈ⋅π⋅i ⌡ ⎮ 4⋅L⋅b⋅ℯ + 4⋅a⋅ℯ ⌡ In other words, it is computing that same integral (1/(4*a + 4*b*x)) six times. `````` Original issue for #7130: http://code.google.com/p/sympy/issues/detail?id=4031 Original author: https://code.google.com/u/asmeurer@gmail.com/
Member

### asmeurer commented Sep 27, 2013

 ``````This was reported at http://stackoverflow.com/q/19000967/161801 . `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=4031#c1 Original author: https://code.google.com/u/asmeurer@gmail.com/
Member

### asmeurer commented Sep 27, 2013

 ``````I think this has something to do with substitution in integrals. In https://github.com/sympy/sympy/pull/2198 , the answer is In [1]: var("i L a b") Out[1]: (i, L, a, b) In [2]: integrand = cos(pi*i*x/L)**2/(a + b*x) In [3]: integrand = integrand.rewrite(exp) In [4]: integrate(integrand, (x, 0, L)) Out[4]: 0 L ⌠ ⌠ ⎮ -2⋅ⅈ⋅π⋅i⋅x -4⋅ⅈ⋅π⋅i⋅x ⎮ -2⋅ⅈ⋅π⋅i⋅x -4⋅ⅈ⋅π⋅i⋅x ⎮ ─────────── ─────────── ⎮ ─────────── ─────────── ⎮ L L ⎮ L L ⎮ 1 + 2⋅ℯ + ℯ ⎮ 1 + 2⋅ℯ + ℯ - ⎮ ───────────────────────────────────── dx + ⎮ ───────────────────────────────────── dx ⎮ -2⋅ⅈ⋅π⋅i⋅x -2⋅ⅈ⋅π⋅i⋅x ⎮ -2⋅ⅈ⋅π⋅i⋅x -2⋅ⅈ⋅π⋅i⋅x ⎮ ─────────── ─────────── ⎮ ─────────── ─────────── ⎮ L L ⎮ L L ⎮ 4⋅a⋅ℯ + 4⋅b⋅x⋅ℯ ⎮ 4⋅a⋅ℯ + 4⋅b⋅x⋅ℯ ⌡ ⌡ In [5]: integrate(integrand, (x, 0, L)).doit() Out[5]: 0 L ⌠ ⌠ ⎮ -2⋅ⅈ⋅π⋅i⋅x -4⋅ⅈ⋅π⋅i⋅x ⎮ -2⋅ⅈ⋅π⋅i⋅x -4⋅ⅈ⋅π⋅i⋅x ⎮ ─────────── ─────────── ⎮ ─────────── ─────────── ⎮ L L ⎮ L L ⎮ 1 + 2⋅ℯ + ℯ ⎮ 1 + 2⋅ℯ + ℯ - ⎮ ───────────────────────────────────── dx + ⎮ ───────────────────────────────────── dx ⎮ -2⋅ⅈ⋅π⋅i⋅x -2⋅ⅈ⋅π⋅i⋅x ⎮ -2⋅ⅈ⋅π⋅i⋅x -2⋅ⅈ⋅π⋅i⋅x ⎮ ─────────── ─────────── ⎮ ─────────── ─────────── ⎮ L L ⎮ L L ⎮ 4⋅a⋅ℯ + 4⋅b⋅x⋅ℯ ⎮ 4⋅a⋅ℯ + 4⋅b⋅x⋅ℯ ⌡ ⌡ which is no longer incorect (though not helpful; it should just return the original integral unchanged). `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=4031#c2 Original author: https://code.google.com/u/asmeurer@gmail.com/

Member

### smichr commented Jan 30, 2015

 The result no longer depends on x: ```>>> i=integrate(integrand, (x, 0, L)) >>> i.free_symbols set([a, L, b, i])``` So perhaps this can be closed with a test.

Member

### asmeurer commented Jan 30, 2015

 Yeah, I seem to remember a PR that fixed Integral.subs and this was probably fixed by it. ``````In [5]: integrate(integrand, (x, 0, L)) Out[5]: 0 L 0 L ⌠ ⌠ ⌠ ⌠ ⎮ 2⋅ⅈ⋅π⋅i⋅x ⎮ 2⋅ⅈ⋅π⋅i⋅x ⎮ 4⋅ⅈ⋅π⋅i⋅x ⎮ 4⋅ⅈ⋅π⋅i⋅x ⎮ ───────── ⎮ ───────── ⎮ ───────── ⎮ ───────── ⎮ L ⎮ L ⎮ L ⎮ L ⎮ 2⋅ℯ ⎮ 2⋅ℯ ⎮ ℯ ⎮ ℯ ⎮ ───────────────────────────── dx ⎮ ───────────────────────────── dx ⎮ ───────────────────────────── dx ⎮ ────────────────────── ⎮ 2⋅ⅈ⋅π⋅i⋅x 2⋅ⅈ⋅π⋅i⋅x ⎮ 2⋅ⅈ⋅π⋅i⋅x 2⋅ⅈ⋅π⋅i⋅x ⎮ 2⋅ⅈ⋅π⋅i⋅x 2⋅ⅈ⋅π⋅i⋅x ⎮ 2⋅ⅈ⋅π⋅i⋅x 2⋅ ⎮ ───────── ───────── ⎮ ───────── ───────── ⎮ ───────── ───────── ⎮ ───────── ── ⎮ L L ⎮ L L ⎮ L L ⎮ L ⎮ a⋅ℯ + b⋅x⋅ℯ ⎮ a⋅ℯ + b⋅x⋅ℯ ⎮ a⋅ℯ + b⋅x⋅ℯ ⎮ a⋅ℯ + b⋅x⋅ℯ ⌡ ⌡ ⌡ ⌡ - ────────────────────────────────── + ────────────────────────────────── - ────────────────────────────────── + ──────────────────────── 4 4 4 4 0 L ⌠ ⌠ ⎮ 1 ⎮ 1 ─────── dx ⎮ ───────────────────────────── dx ⎮ ───────────────────────────── dx ⅈ⋅π⋅i⋅x ⎮ 2⋅ⅈ⋅π⋅i⋅x 2⋅ⅈ⋅π⋅i⋅x ⎮ 2⋅ⅈ⋅π⋅i⋅x 2⋅ⅈ⋅π⋅i⋅x ─────── ⎮ ───────── ───────── ⎮ ───────── ───────── L ⎮ L L ⎮ L L ⎮ a⋅ℯ + b⋅x⋅ℯ ⎮ a⋅ℯ + b⋅x⋅ℯ ⌡ ⌡ ────────── - ────────────────────────────────── + ────────────────────────────────── 4 4 ``````

### Jawadh-Salih commented Mar 5, 2015

 Hi. I would like on this bug. So could you please help me with this. When I went through this. I saw like the final answer of an Integral gives a functions (depend on a varialble) instead of a constant value. Am I correct?
Member

### asmeurer commented Mar 8, 2015

 I believe the issue has already been fixed so only a test needs to be added for it.

### lucjon added a commit to lucjon/sympy that referenced this issue Mar 15, 2015

``` Add test to ensure integral in sympy#7130 doesn't depend on x ```
``` 9ebc182 ```

Merged

### debugger22 added a commit that referenced this issue Mar 18, 2015

``` Merge pull request #9161 from lucjon/issue-7130-test ```
`Add test to ensure integral in #7130 doesn't depend on x`
``` 3860573 ```

Member

### mcho421 added a commit to mcho421/sympy that referenced this issue May 4, 2015

``` Add test to ensure integral in sympy#7130 doesn't depend on x ```
``` 9086359 ```

### skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 2, 2016

``` Add regression tests & mention closed issues ```
```    close sympy/sympy#3112 (MrvAsympt was added in diofant#6)
close sympy/sympy#9173 (test was added in 5a510ac)
close sympy/sympy#9808 (fixed in 09e539b)
close sympy/sympy#9341 (fixed in af98a00)
close sympy/sympy#9908 (fixed in cc3fa8d)
close sympy/sympy#6171 (test added in d278031)
close sympy/sympy#9276 (diagnose_imports.py removed in ab8c535)
close sympy/sympy#10201 (fixed in 0d0fc5f)
close sympy/sympy#9057 (test was added in 8290a0c)
close sympy/sympy#11159 (test was added in ffb76cb)
close sympy/sympy#2839 (new AST transformers are used, see diofant#278 and diofant#167)
close sympy/sympy#11081 (see ed01e16 and bb92329)
close sympy/sympy#10974 (see 73fc425)
close sympy/sympy#10806 (test in 539929a)
close sympy/sympy#10801 (test in 2fe3da5)
close sympy/sympy#9549 (test in 88bdefa)
close sympy/sympy#4231 (test was added in fb411d5)
close sympy/sympy#8634 (see 2fcbb58)
close sympy/sympy#8481 (see 1ef20d3)
close sympy/sympy#9956 (fixed in a34735f)
close sympy/sympy#9747 (see e117c60)
close sympy/sympy#7853 (see 3e4fbed)
close sympy/sympy#9634 (see 2be03f5)
close sympy/sympy#8500 (fixed in diofant#104 and finally in diofant#316)
close sympy/sympy#9192 (see 9bf622f)
close sympy/sympy#7130 (see e068fa3)
close sympy/sympy#8514 (see b2d543b)
close sympy/sympy#9334 (see 90de625)
close sympy/sympy#8229 (see 9755b89)
close sympy/sympy#8061 (see 7054f06)
close sympy/sympy#7872 (tested in diofant#6)
close sympy/sympy#3496 (tested in test_log_symbolic)
close sympy/sympy#2929 (see da7db7a)
close sympy/sympy#8203 (oo is not a real, see diofant#36)
close sympy/sympy#7649 (0 is imaginary since diofant#8)
close sympy/sympy#7256 (fixed in c0a4549)
close sympy/sympy#6783 (see cb28d63)
close sympy/sympy#5662 (is_integer issue fixed in 6bfa9f8, there is no is_bounded anymore)
close sympy/sympy#5295 (fixed with diofant#354)
close sympy/sympy#4856 (we now have flake/pep tests)
close sympy/sympy#4555 (flake8 enabled after diofant#214)
close sympy/sympy#5773 (cmp_to_key removed after diofant#164 and c9acbf0)
close sympy/sympy#5484 (see above)

fixes sympy/sympy#8825 (probably via diofant#209)
fixes sympy/sympy#8635
fixes sympy/sympy#8157
fixes sympy/sympy#7872
fixes sympy/sympy#7599
fixes sympy/sympy#6179
fixes sympy/sympy#5415
fixes sympy/sympy#2865
fixes sympy/sympy#5907
fixes sympy/sympy#11722

Closes diofant#347```
``` 74ade76 ```

### skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 2, 2016

``` Add regression tests & mention closed issues ```
```    close sympy/sympy#3112 (MrvAsympt was added in diofant#6)
close sympy/sympy#9173 (test was added in 5a510ac)
close sympy/sympy#9808 (fixed in 09e539b)
close sympy/sympy#9341 (fixed in af98a00)
close sympy/sympy#9908 (fixed in cc3fa8d)
close sympy/sympy#6171 (test added in d278031)
close sympy/sympy#9276 (diagnose_imports.py removed in ab8c535)
close sympy/sympy#10201 (fixed in 0d0fc5f)
close sympy/sympy#9057 (test was added in 8290a0c)
close sympy/sympy#11159 (test was added in ffb76cb)
close sympy/sympy#2839 (new AST transformers are used, see diofant#278 and diofant#167)
close sympy/sympy#11081 (see ed01e16 and bb92329)
close sympy/sympy#10974 (see 73fc425)
close sympy/sympy#10806 (test in 539929a)
close sympy/sympy#10801 (test in 2fe3da5)
close sympy/sympy#9549 (test in 88bdefa)
close sympy/sympy#4231 (test was added in fb411d5)
close sympy/sympy#8634 (see 2fcbb58)
close sympy/sympy#8481 (see 1ef20d3)
close sympy/sympy#9956 (fixed in a34735f)
close sympy/sympy#9747 (see e117c60)
close sympy/sympy#7853 (see 3e4fbed)
close sympy/sympy#9634 (see 2be03f5)
close sympy/sympy#8500 (fixed in diofant#104 and finally in diofant#316)
close sympy/sympy#9192 (see 9bf622f)
close sympy/sympy#7130 (see e068fa3)
close sympy/sympy#8514 (see b2d543b)
close sympy/sympy#9334 (see 90de625)
close sympy/sympy#8229 (see 9755b89)
close sympy/sympy#8061 (see 7054f06)
close sympy/sympy#7872 (tested in diofant#6)
close sympy/sympy#3496 (tested in test_log_symbolic)
close sympy/sympy#2929 (see da7db7a)
close sympy/sympy#8203 (oo is not a real, see diofant#36)
close sympy/sympy#7649 (0 is imaginary since diofant#8)
close sympy/sympy#7256 (fixed in c0a4549)
close sympy/sympy#6783 (see cb28d63)
close sympy/sympy#5662 (is_integer issue fixed in 6bfa9f8, there is no is_bounded anymore)
close sympy/sympy#5295 (fixed with diofant#354)
close sympy/sympy#4856 (we now have flake/pep tests)
close sympy/sympy#4555 (flake8 enabled after diofant#214)
close sympy/sympy#5773 (cmp_to_key removed after diofant#164 and c9acbf0)
close sympy/sympy#5484 (see above)

fixes sympy/sympy#8825 (probably via diofant#209)
fixes sympy/sympy#8635
fixes sympy/sympy#8157
fixes sympy/sympy#7872
fixes sympy/sympy#7599
fixes sympy/sympy#6179
fixes sympy/sympy#5415
fixes sympy/sympy#2865
fixes sympy/sympy#5907
fixes sympy/sympy#11722

Closes diofant#347```
``` 48c035e ```