简体   繁体   中英

Advanced symbolic integration using python

I want to evaluate the following integral

1/(a(1+x)^3+(1+x)^2)^0.5 from 0 to z symbolically.

I know that sympy is unable to give the result of such advanced integrals and scipy is able to give only numerical result. Is there any python libraries or any way in which I can evaluate this integral symbolically?

Here's what I get with Maxima ( https://maxima.sourceforge.io ).

(%i8) 1/(a*(1+x)^3+(1+x)^2)^(1/2);
                                       1
(%o8)                     ---------------------------
                                        3          2
                          sqrt(a (x + 1)  + (x + 1) )
(%i9) integrate (%, x, 0, z);
Is z positive, negative or zero?

p;
Is a (a z + a + 1) positive, negative or zero?

p;
Is a (a + 1) positive, negative or zero?

p;
(%o9) (- log(sqrt(a z + a + 1) + 1)) + log(sqrt(a z + a + 1) - 1)
                                  + log(sqrt(a + 1) + 1) - log(sqrt(a + 1) - 1)
(%i10) %o9, a=2, z=3;
(%o10)       log(sqrt(3) + 1) - log(sqrt(3) - 1) - log(4) + log(2)
(%i11) %,numer;
(%o11)                        0.6238107163648715
(%i12) quad_qags (%o8, x, 0, 3), a=2;
(%o12)        [0.6238107163648713, 7.303549411489493E-11, 21, 0]
(%i13) quad_qags (%o8, x, 0, 7/11), a=3/5;
(%o13)        [0.3701449212628929, 4.109434140341295E-15, 21, 0]
(%i14) %o9, a=3/5, z=7/11;
                                                           3/2
              sqrt(109)             sqrt(109)             2
(%o14) (- log(--------- + 1)) + log(--------- - 1) + log(------- + 1)
              sqrt(55)              sqrt(55)             sqrt(5)
                                                                     3/2
                                                                    2
                                                             - log(------- - 1)
                                                                   sqrt(5)
(%i15) %,numer;
(%o15)                        0.3701449212628927

The result is plausible, given that it agrees with numerical integration for some specific values. However, unfortunately I must warn you that Maxima's integration code has known bugs in which the wrong branch cut is chosen, or a discontinuity in the interval of integration is ignored, such that the result is valid only for some subset of parameters. So if you want to use the result in something else, you would have to verify it.

Notice that Maxima asks some questions about the sign (positive/negative/zero) of some expressions in order to get to a result.

Maxima applies pattern matching (ie, looking at the parts of an internal representation of the expression) to find a template for the integral and then plugs specific values from the problem into the template. How "powerful" that approach is is entirely dependent on how big the set of patterns is. I assume Sympy and, yes, Wolfram Alpha are doing something conceptually similar.

You might be interested in a project called Rubi by, I think, Albert Rich, which has a very large set of patterns. I don't know much about it but a web search will probably find it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM