       Re: Re: question 1

• To: mathgroup at smc.vnet.net
• Subject: [mg75900] Re: [mg75873] Re: [mg75810] question 1
• From: DrMajorBob <drmajorbob at bigfoot.com>
• Date: Sun, 13 May 2007 05:40:44 -0400 (EDT)
• References: <200705110924.FAA05900@smc.vnet.net> <A52D6750-3017-4EF6-82F7-DFE4CB83812F@mimuw.edu.pl> <CB1CAE8E-3B30-4645-9279-14C936512446@mimuw.edu.pl> <3201069.1178958084224.JavaMail.root@m35>

```I see why it's doing that now. Not sure what to do about it, though.

Bobby

>>>>>>>>>>>>>>>

With my second solver below, I get a couple of very strange results:

powerSum[Expand[(a - x)^3 - (b - y)^4], {a, b}]

(a - x)^3 - (b - y)^4

powerSum[Expand[(x - a)^3 - (y - b)^4], {x, y}]

(-r\$6963 + x)^3 - (-r\$6964 + y)^4

The two problems are identical, except for a switch of x with a, y with b.

What's going on??

Bobby

>>>>>>>>

This works for the examples mentioned so far:

Clear[powerSum, test]
powerSum[polynomial_, vars_List] /; PolynomialQ[polynomial, vars] :=
Module[{powers, coefficients, roots, soln},
powers = Exponent[polynomial, #] & /@ vars;
coefficients = Table[Unique[c], {Length@vars}];
roots = Table[Unique[r], {Length@vars}];
soln = SolveAlways[coefficients.(vars - roots)^powers == polynomial,
vars][];
{roots, coefficients} = {roots, coefficients} /. soln;
coefficients.(vars - roots)^powers
]
test[p_] := powerSum[Expand@p, Variables@p]

test /@ {(-2 + x)^3 + (1 +
y)^3, (x - 5)^4 + (y - 3)^3, (x - 2)^4 + (y + 1)^2, (a +
3)^5 + (x - 7)^6, (o - 8)^4 - (e + 4)^8}

{(-2 + x)^3 + (1 + y)^3, (-5 + x)^4 + (-3 + y)^3, (-2 + x)^4 + (1 +
y)^2, (3 + a)^5 + (-7 + x)^6, -(4 + e)^8 + (-8 + o)^4}

We don't have to solve for the coefficients, so this also works:

Clear[powerSum]
powerSum[polynomial_, vars_List] /; PolynomialQ[polynomial, vars] :=
Module[{powers = Exponent[polynomial, #] & /@ vars, coefficients,
roots = Table[Unique[r], {Length@vars}], soln},
coefficients = Coefficient[polynomial, #] & /@ vars^powers;
soln = SolveAlways[coefficients.(vars - roots)^powers == polynomial,
vars][];
roots = roots /. soln;
coefficients.(vars - roots)^powers
]
test /@ {(-2 + x)^3 + (1 +
y)^3, (x - 5)^4 + (y - 3)^3, (x - 2)^4 + (y + 1)^2, (a +
3)^5 + (x - 7)^6, (o - 8)^4 - (e + 4)^8}

{(-2 + x)^3 + (1 + y)^3, (-5 + x)^4 + (-3 + y)^3, (-2 + x)^4 + (1 +
y)^2, (3 + a)^5 + (-7 + x)^6, -(4 + e)^8 + (-8 + o)^4}

Bobby

On Sat, 12 May 2007 02:11:17 -0500, Andrzej Kozlowski <akoz at mimuw.edu.pl>
wrote:

>
> 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:=
>>>> f = (o - 8)^4 - (e + 4)^8
>>>>
>>>> Out=
>>>> -(4 + e)^8 + (-8 + o)^4
>>>>
>>>> In:=
>>>> ff = Expand[f]
>>>>
>>>> Out=
>>>> -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
>
>
>
>
>

-- =

DrMajorBob at bigfoot.com

```

• References:
• Prev by Date: Re: Re: question 1
• Next by Date: Re: drawing with mathematica
• Previous by thread: Re: Re: question 1
• Next by thread: Re: question 1 (Integrate and simplification)