MathGroup Archive 2007

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

Search the Archive

Re: question 1

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75873] Re: [mg75810] question 1
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sat, 12 May 2007 03:11:17 -0400 (EDT)
  • References: <200705110924.FAA05900@smc.vnet.net> <A52D6750-3017-4EF6-82F7-DFE4CB83812F@mimuw.edu.pl> <CB1CAE8E-3B30-4645-9279-14C936512446@mimuw.edu.pl>

On 12 May 2007, at 10:37, Andrzej Kozlowski wrote:

>
> On 12 May 2007, at 10:23, Andrzej Kozlowski wrote:
>
>> On 11 May 2007, at 18:24, dimitris wrote:
>>
>>> I have
>>>
>>> In[5]:=
>>> f = (o - 8)^4 - (e + 4)^8
>>>
>>> Out[5]=
>>> -(4 + e)^8 + (-8 + o)^4
>>>
>>> In[6]:=
>>> ff = Expand[f]
>>>
>>> Out[6]=
>>> -61440 - 131072*e - 114688*e^2 - 57344*e^3 - 17920*e^4 - 3584*e^5 -
>>> 448*e^6 - 32*e^7 - e^8 - 2048*o + 384*o^2 - 32*o^3 + o^4
>>>
>>> Is it possible to simplify ff to f again?
>>>
>>> Thanks!
>>>
>>>
>>
>> I don't think Mathematica can do it automatically, because the  
>> most obvious way of carrying out this simplification relies on  
>> transformations of the kind that  that Simplify or FullSimplify  
>> never use (such as adding and simultaneously subtracting some  
>> number, then rearranging the whole expression and factoring parts  
>> of it). These kind of transformations could be implemented but  
>> they would work in only a few cases, and would considerably  
>> increase the time complexity of simplifying. Here is an example of  
>> another  transformation that will work in this and some similar  
>> cases:
>>
>> transf[f_, {e_, o_}] :=
>>  With[{a = Integrate[D[f, e], e], b = Integrate[D[f, o], o]},
>>   Simplify[a] + Simplify[b] + Simplify[(f - (a + b))]]
>>
>> (one can easily implment a version with more than two variables).
>>
>> This works in your case:
>>
>> ff = Expand[(o - 8)^4 - (e + 4)^8];
>>
>> transf[ff, {e, o}]
>>  (o - 8)^4 - (e + 4)^8
>>
>> and in quite many cases like yours :
>>
>> gg = Expand[(a + 3)^5 + (x - 7)^6];
>>
>> transf[gg, {a, x}]
>>  (x - 7)^6 + (a + 3)^5
>>
>> but not in all
>>
>>  hh = Expand[(x - 5)^4 + (y - 3)^3];
>>
>>  transf[hh, {x, y}]
>>  (x - 5)^4 + y*((y - 9)*y + 27) - 27
>>
>> Even this, however,  is better than the answer FullSimplify gives:
>>
>> FullSimplify[hh]
>>
>> (x - 10)*x*((x - 10)*x + 50) + y*((y - 9)*y +  27) + 598
>>
>> Unfortunately transf also has very high complexity (it uses  
>> Integrate)  and is unlikely to be useful in cases other than sums  
>> of polynomials in different variables (without "cross terms") so I  
>> doubt that it would be worth implementing some version of it in  
>> FullSimplify.
>>
>>
>> Andrzej Kozlowski
>>
>
> I forgot that Integrate already maks use of Simplify, so (probably)  
> the folowing version of transf will work just as well and faster:
>
> transf[f_, {e_, o_}] :=
>  With[{a = Integrate[D[f, e], e], b = Integrate[D[f, o], o]},
>   a + b + Simplify[(f - (a + b))]]
>
> Andrzej Kozlowski

Sorry, that last remark just not true. Cleary Integrate uses Simplify  
before integration but does not Simplify its output (obviously to  
save time) so including Simplify does make a difference. Note also  
the following works much better, but is,, of course, much more tiem  
consuming:


transf[f_, {e_, o_}] :=
  With[{a = Integrate[D[f, e], e], b = Integrate[D[f, o], o]},
   FullSimplify[Simplify[a] + Simplify[b] + Simplify[(f - (a + b))],
    ExcludedForms -> {(x + c_)^n_, (y + d_)^m_}]]


This will deal with many cases that would not work before:

hh = Expand[(x - 5)^4 + (y - 3)^3];

  transf[hh, {x, y}]
  (x - 5)^4 + (y - 3)^3

  p = Expand[(x - 2)^4 + (y + 1)^2];

  transf[p, {x, y}]
  (x - 2)^4 + (y + 1)^2

but at least one power has to be higher than 3. This this will work

q = Expand[(x - 2)^4 +  (y + 1)^3];
  transf[q, {x, y}]
  (x - 2)^4 + (y + 1)^3

but this will not (all powers are <=3)

q = Expand[(x - 2)^3 + (y + 1)^3];

transf[q, {x, y}]

x*((x - 6)*x + 12) + y*(y*(y + 3) + 3) - 7

Andrzej Kozlowski





  • References:
  • Prev by Date: Re: mathematica player: can users input a file?
  • Next by Date: Re: question 1
  • Previous by thread: Re: question 1
  • Next by thread: Re: question 1