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: [mg43045] Re: [mg43019] Re: [mg42976] Need a better Integrate
  • From: Dr Bob <drbob at bigfoot.com>
  • Date: Sat, 9 Aug 2003 02:57:45 -0400 (EDT)
  • References: <1FC152B2-C9E3-11D7-8D38-00039311C1CC@platon.c.u-tokyo.ac.jp>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

>> This is of course not true.

It may not be true, but it's not "of course" untrue, unless

(a) there's an obvious reason it's not true or
(b) you've made some slight attempt, at least, to explain why your method 
should work and when.  (Or would that spoil your fun?)

The only examples I had found in which the method helped were of the form I 
mentioned.  For instance,

g = 1 - 3x^2 + x^4;
MyIntegrate[g, x]
Integrate[g, x]

x - x^3 + x^5/5
x - x^3 + x^5/5

Congratulations on finding an example that isn't of the form D[g, x] g^n, 
but don't strain a muscle patting yourself on the back.

Bobby

On Fri, 8 Aug 2003 22:58:55 +0200, Andrzej Kozlowski <andrzej at platon.c.u- 
tokyo.ac.jp> wrote:

>
> 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
>>
>>
>
>



-- 
majort at cox-internet.com
Bobby R. Treat


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