sympy - integral.Numbers 的奇怪行为,在解决方案中有很多数字

sympy - Strange behaviour into integral.Numbers with a lot of digits in solution find

感谢您给我这个机会征求宝贵意见 我是 sympy 工具包的新手,我尝试执行一些硬积分来测试该工具。 在其中一个中,它在解决方案中返回奇怪的长数字。 下面积分计算:

integrate((atan(1/(1-x^2)),x).

我没有添加解决方案,因为太大 link 无法添加到我的 post 中。 所以我想知道为什么以及我们是否可以操纵开始表达式以获得最佳的符号最终解决方案。 我希望我的例子对发现奇怪的行为有用。 祝你2021年更好。 再见 A.

我认为这是“heurisch”算法的输出,该算法有时会生成看起来很复杂的解决方案。该算法采用相对间接的方法来寻找基本反导数。

我得到的完整输出是:

In [156]: i = integrate(atan(1/(1-x**2)), x)

In [157]: i
Out[157]: 
                                                                                                                                             
                             ________   ________     ⎛  1   ⎞                                             ________   ________     ⎛  1   ⎞   
              3156404596⋅x⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 ⋅atan⎜──────⎟                           2231915094⋅√2⋅x⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 ⋅atan⎜──────⎟   
                                                     ⎜     2⎟                                                                     ⎜     2⎟   
                                                     ⎝1 - x ⎠                                                                     ⎝1 - x ⎠   
- ──────────────────────────────────────────────────────────────────────── + ────────────────────────────────────────────────────────────────
                 ________   ________                   ________   ________                  ________   ________                   ________   
  - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2  + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2    - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2  + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱

                                                                                                                                             
                                                                                                                                             
                                                                                                                                             
                        4 ___   ________    ⎛   2     4 ___     ________       ⎞                    3/4   ________    ⎛   2     4 ___     ___
             1115957547⋅╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x  - 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2  + 4⋅√2⎠         789101149⋅2   ⋅╲╱ 2 - √2 ⋅log⎝4⋅x  - 4⋅╲╱ 2 ⋅x⋅╲╱ √2
──────── - ──────────────────────────────────────────────────────────────────────── + ───────────────────────────────────────────────────────
________                  ________   ________                   ________   ________                  ________   ________                   __
 √2 + 2    - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2  + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2    - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2  + 2231915094⋅√2⋅╲╱ 2

                                                                                                                                             
                                                                                                                                             
                                                                                                                                             
_____       ⎞                     3/4   ________    ⎛   2     4 ___     ________       ⎞                    4 ___   ________    ⎛   2     4 _
 + 2  + 4⋅√2⎠          789101149⋅2   ⋅╲╱ 2 - √2 ⋅log⎝4⋅x  + 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2  + 4⋅√2⎠         1115957547⋅╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x  + 4⋅╲╱ 
───────────────── - ──────────────────────────────────────────────────────────────────────── + ──────────────────────────────────────────────
______   ________                  ________   ________                   ________   ________                  ________   ________            
 - √2 ⋅╲╱ √2 + 2    - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2  + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2    - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2  + 223191509

                                                                                                                                             
                                                       4 ___   ________     ⎛  1   ⎞                                                3/4   ___
                                             924489502⋅╲╱ 2 ⋅╲╱ 2 - √2 ⋅atan⎜──────⎟                                     653712796⋅2   ⋅╲╱ 2 
__     ________       ⎞                                                     ⎜     2⎟                                                         
2 ⋅x⋅╲╱ √2 + 2  + 4⋅√2⎠                                                     ⎝1 - x ⎠                                                         
────────────────────────── - ──────────────────────────────────────────────────────────────────────── + ─────────────────────────────────────
       ________   ________                  ________   ________                   ________   ________                  ________   ________   
4⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2    - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2  + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2    - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2  + 

                                                                             ⎛   3/4         ________⎞                                       
_____     ⎛  1   ⎞                                      4 ___   ________     ⎜  2   ⋅x     ╲╱ √2 + 2 ⎟                               3/4   __
- √2 ⋅atan⎜──────⎟                           4463830188⋅╲╱ 2 ⋅╲╱ √2 + 2 ⋅atan⎜────────── - ──────────⎟                   3156404596⋅2   ⋅╲╱ √
          ⎜     2⎟                                                           ⎜  ________     ________⎟                                       
          ⎝1 - x ⎠                                                           ⎝╲╱ 2 - √2    ╲╱ 2 - √2 ⎠                                       
─────────────────────────────────── - ──────────────────────────────────────────────────────────────────────── + ────────────────────────────
                ________   ________                  ________   ________                   ________   ________                  ________   __
2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2    - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2  + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2    - 3156404596⋅╲╱ 2 - √2 ⋅╲╱ √

           ⎛   3/4         ________⎞        
______     ⎜  2   ⋅x     ╲╱ √2 + 2 ⎟        
2 + 2 ⋅atan⎜────────── - ──────────⎟        
           ⎜  ________     ________⎟        
           ⎝╲╱ 2 - √2    ╲╱ 2 - √2 ⎠        
────────────────────────────────────────────
______                   ________   ________
2 + 2  + 2231915094⋅√2⋅╲╱ 2 - √2 ⋅╲╱ √2 + 2 

我们可以简化它:

In [158]: i2 = powsimp(radsimp(i), deep=True)

In [159]: i2
Out[159]: 
                                                                                                                                          3/4
                                                                                                                                         2   
                   4 ___   ________    ⎛   2     4 ___     ________       ⎞   4 ___   ________    ⎛   2     4 ___     ________       ⎞       
        ⎛  1   ⎞   ╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x  - 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2  + 4⋅√2⎠   ╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x  + 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2  + 4⋅√2⎠       
- x⋅atan⎜──────⎟ - ──────────────────────────────────────────────────────── + ──────────────────────────────────────────────────────── - ────
        ⎜ 2    ⎟                              4                                                          4                                   
        ⎝x  - 1⎠                                                                                                                             

   ________     ⎛  1   ⎞   4 ___   ________     ⎛  1   ⎞                                                                           
⋅╲╱ 2 - √2 ⋅atan⎜──────⎟   ╲╱ 2 ⋅╲╱ 2 - √2 ⋅atan⎜──────⎟                                                                           
                ⎜ 2    ⎟                        ⎜ 2    ⎟                                                                           
                ⎝x  - 1⎠                        ⎝x  - 1⎠   4 ___   ________     ⎛   3/4     ________   4 ___     ________         ⎞
──────────────────────── - ───────────────────────────── + ╲╱ 2 ⋅╲╱ √2 + 2 ⋅atan⎝- 2   ⋅x⋅╲╱ 2 - √2  - ╲╱ 2 ⋅x⋅╲╱ 2 - √2  + 1 + √2⎠
         2                               2                                                                                         

In [160]: i2.collect(i2.atoms(log, atan))
Out[160]: 
⎛      3/4   ________   4 ___   ________⎞                4 ___   ________    ⎛   2     4 ___     ________       ⎞   4 ___   ________    ⎛   2
⎜     2   ⋅╲╱ 2 - √2    ╲╱ 2 ⋅╲╱ 2 - √2 ⎟     ⎛  1   ⎞   ╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x  - 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2  + 4⋅√2⎠   ╲╱ 2 ⋅╲╱ 2 - √2 ⋅log⎝4⋅x 
⎜-x - ─────────────── - ────────────────⎟⋅atan⎜──────⎟ - ──────────────────────────────────────────────────────── + ─────────────────────────
⎝            2                 2        ⎠     ⎜ 2    ⎟                              4                                                        
                                              ⎝x  - 1⎠                                                                                       

     4 ___     ________       ⎞                                                                           
 + 4⋅╲╱ 2 ⋅x⋅╲╱ √2 + 2  + 4⋅√2⎠   4 ___   ________     ⎛   3/4     ________   4 ___     ________         ⎞
─────────────────────────────── + ╲╱ 2 ⋅╲╱ √2 + 2 ⋅atan⎝- 2   ⋅x⋅╲╱ 2 - √2  - ╲╱ 2 ⋅x⋅╲╱ 2 - √2  + 1 + √2⎠
  4    

我们可以通过微分来检查结果(尽管还需要一些简化):

In [190]: cancel(cancel(i2.diff(x), extension=True))
Out[190]: 
     ⎛  1   ⎞
-atan⎜──────⎟
     ⎜ 2    ⎟
     ⎝x  - 1⎠

除了去掉减号(atan(-y) = -atan(y))外,这和原来的被积函数一样。

Wolfram Alpha 有一个更简单的结果,尽管它使用复数,即使在积分是实数的情况下也是如此: https://www.wolframalpha.com/input/?i=integrate%28atan%281%2F%281-x**2%29%29%2C+x%29