Re: Need a better Integrate
- To: mathgroup at smc.vnet.net
- Subject: [mg43019] Re: [mg42976] Need a better Integrate
- From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
- Date: Fri, 8 Aug 2003 00:26:32 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
This seems quite hopeless except in the case when you are dealing with polynomials (as in your example). That is because for general functions "constants" can be "disguised" as all kinds of complicated expressions involving identities such as Cos[x]^2+Sin[x]^2==1 etc, and there is not general procedure for simplifying them, (although FullSimplify is pretty good at it). Even for polynomials you can't hope for very much. In order to apply "some clever algebra" you need an algebraic criterion of simplicity, and LeafCount is not algebraic enough. So given a polynomial f, which of the polynomials f+C (where C is a constant) will be the simplest? Well, I propose the following very imperfect choice: if there is a C such that f+C has discriminant 0 and FullSimplify[f+C] has LeafCount less than f, we choose f+C, otherwise we stick with f. To implement this we first define Discriminant ((borrowed from Daniel Lichtblau) Discriminant[p_?PolynomialQ, x_] := With[{n = Exponent[p, x]}, Cancel[((-1)^(n(n - 1)/2)Resultant[p, D[p, x], x])/Coefficient[ p, x, n]^(2n - 1)]] and now here is a rather clumsy first version of MyIntegrate: MyIntegrate[f_, x_] := Module[{ g = Integrate[f, x], ls}, First[Select[ls = FullSimplify[Append[g + C /. Solve[Discriminant[g + C, x] == 0, C], g]], (LeafCount[#] == Min[LeafCount /@ ls]) &]]] In the case of your example it behaves as you wanted: MyIntegrate[x*(-5 + x^2)^3, x] (1/8)*(-5 + x^2)^4 Of course , in many cases you will get the same answer as Integrate gives, when a "simpler one" may be possible but at least you will never get a more complicated one. Andrzej Kozlowski Yokohama, Japan http://www.mimuw.edu.pl/~akoz/ http://platon.c.u-tokyo.ac.jp/andrzej/ On Thursday, August 7, 2003, at 06:53 AM, Ersek, Ted R wrote: > A user sent me an email with an interesting problem. See below. > > In[1]:= deriv = D[(-5 + x^2)^4/8, x] > > Out[1]= x*(-5 + x^2)^3 > > > In[2]:= int = FullSimplify[Integrate[x*(-5 + x^2)^3, x]]; > > Out[2]= (x^2*(-10 + x^2)*(50 - 10*x^2 + x^4)) > > > Why doesn't FullSimplify return (-5 + x^2)^4/8 which is simpler? > It doesn't because the expression Integrate returned is different from > (-5 + x^2)^4/8 by 625/8. Of course both answers are correct because > the > result of an indefinite integral includes an arbitrary constant. > However, > Mathematica never includes the constant in the result Integrate > returns. > In the next line we get the result we expected above. > > In[3]:= Factor[int + 625/8] > > Out[3]= (-5+x^2)^4/8 > > > I wonder if somebody can figure out how to define a better integrate > that > would do the following: > > MyIntegrate[f_,x_]:= FullSimplify[Integrate[f,x]+const] > (* Through some clever algebra find the value of (const) that will > give > the simplest answer. *) > > > We would then get: > In[4]:= MyIntegrate[x*(-5 + x^2)^3, x] > > Out[4]= (-5+x^2)^4/8 > > > ------------------- > Regards, > Ted Ersek > > > >
- Follow-Ups:
- Re: Re: Need a better Integrate
- From: Dr Bob <drbob@bigfoot.com>
- Re: Re: Need a better Integrate