MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Need a better Integrate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43044] Re: [mg43019] Re: [mg42976] Need a better Integrate
  • From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
  • Date: Sat, 9 Aug 2003 02:57:44 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On Friday, August 8, 2003, at 08:10 PM, Dr Bob wrote:

> As best I can tell from a few experiments, that method is useful only 
> when the integrand is of the form D[g, x] g^n, where g is a polynomial 
> in x, in which case my integration rule works much faster.

This is of course not true.

In[8]:=
FullSimplify[Integrate[D[(x - 1)^2*(x^2 + 1), x], x]]

Out[8]=
x*(-2 + x*(2 + (-2 + x)*x))

In[9]:=
MyIntegrate[D[(x - 1)^2*(x^2 + 1), x], x]

Out[9]=
(-1 + x)^2*(1 + x^2)

This is of course the whole point of my method, and the whole point of 
using Discriminant.  To program this using your approach seems pretty a 
pretty hard task (which I do not wish to try).
A method which only deals with powers seems of very little use to me.

Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/


>
> integratePower[x_] = {(b_)*(a_)^(n_) :> (b*a^(n + 1))/((n + 1)*D[a, 
> x]) /; FreeQ[D[a, x]/b, x], (a_)^(n_) :> a^(n + 1)/((n + 1)*D[a, x]) 
> /; FreeQ[D[a, x], x]}; g = 1 - 3x^2 + x^4;
> int = D[g, x] g^5;
> Timing[int /. integratePower[x]]
> Timing@MyIntegrate[int, x]
>
> {0.*Second, (1/6)*
>   (1 - 3*x^2 + x^4)^6}
> {0.45300000000000007*Second, (1/6)*(1 - 3*x^2 + x^4)^6}
>
> My rule misses the simplification, however, if g is itself the power 
> of a polynomial.
>
> g = Expand[(1 - x)^3]; int = D[g, x]*g^5; Timing[int /. 
> integratePower[x]]
> Timing[MyIntegrate[int, x]]
>
> {0.*Second, (1/6)*(1 - 3*x + 3*x^2 - x^3)^6}
> {0.203*Second, (1/6)*(-1 + x)^18}
>
> But using Factor helps:
>
> g = Expand[(1 - x)^3]; int = D[g, x]*g^5; Timing[Factor[int] /. 
> integratePower[x]]
> Timing[MyIntegrate[int, x]]
> {0.016*Second, (1/6)*(-1 + x)^18}
> {0.172*Second, (1/6)*(-1 + x)^18}
>
> (I Quit and reloaded definitions between tests.  Otherwise, the second 
> test of MyIntegrate goes faster -- but still slower than 
> integratePower[x].)
>
> MyIntegrate goes into a seemingly infinite loop if you give it 
> anything but a polynomial, so a better definition would start with
>
> MyIntegrate[f_, x_] /; PolynomialQ[f, x] :=
>
> Bobby
>
> On Fri, 8 Aug 2003 00:26:32 -0400 (EDT), Andrzej Kozlowski 
> <andrzej at platon.c.u-tokyo.ac.jp> wrote:
>
>> 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
>>>
>>>
>>>
>>>
>>
>>
>
>
>
> -- 
> majort at cox-internet.com
> Bobby R. Treat
>
>


  • Prev by Date: Re: Re: Need a better Integrate
  • Next by Date: Re: Re: Need a better Integrate
  • Previous by thread: Re: Re: Need a better Integrate
  • Next by thread: Re: Re: Need a better Integrate