Re: Re: question 1
- To: mathgroup at smc.vnet.net
- Subject: [mg75902] Re: [mg75873] Re: [mg75810] question 1
- From: DrMajorBob <drmajorbob at bigfoot.com>
- Date: Sun, 13 May 2007 05:41:45 -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> <op.tr8w3vygqu6oor@monster.ma.dl.cox.net>
- Reply-to: drmajorbob at bigfoot.com
OK, this is better: Clear[powerSum, ruleReverse, test] ruleReverse[var_List][Rule[a_, b_]] /; MemberQ[var, a] := Rule[b, a] ruleReverse[var_List][Rule[a_, b_]] := Rule[a, b] powerSum[polynomial_, vars_List] /; PolynomialQ[polynomial, vars] := Module[{powers = Exponent[polynomial, #] & /@ vars, coefficients, roots, soln}, roots = Table[Unique[a], {Length@vars}]; coefficients = Coefficient[polynomial, #] & /@ vars^powers; soln = ruleReverse[Variables@polynomial] /@ SolveAlways[coefficients.(vars - roots)^powers == polynomial, vars][[1]]; roots = roots /. 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} 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}] (-a + x)^3 - (-b + y)^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[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 >> >> >> >> >> > > > -- = DrMajorBob at bigfoot.com
- References:
- question 1
- From: dimitris <dimmechan@yahoo.com>
- question 1