MathGroup Archive 2006

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

Search the Archive

Re: Getting the small parts right or wrong. Order and Collect

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63621] Re: [mg63607] Getting the small parts right or wrong. Order and Collect
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sat, 7 Jan 2006 04:59:30 -0500 (EST)
  • References: <dpg11e$pm4$1@smc.vnet.net> <dplhq9$em8$1@smc.vnet.net> <200601070729.CAA06924@smc.vnet.net> <6FCF3227-C4E1-418A-BAC1-F3981F969878@mimuw.edu.pl>
  • Sender: owner-wri-mathgroup at wolfram.com

On 7 Jan 2006, at 18:04, Andrzej Kozlowski wrote:

>
> On 7 Jan 2006, at 16:29, Richard Fateman wrote:
>
>> This example comes from the on-line help.
>>
>> Collect[(1 + x + y)^3, x]
>>
>> is supposed to collect the terms in the expression by powers of x. I
>> expected the answer to look something like
>>
>> (.....)*x^0  + (......)*x^1 +(....)*x^2 + .....   etc.
>>
>> with some simplifications like x^0 -> 1, x^1 -> x  in place, and  
>> perhaps the
>> whole thing ordered in reverse.
>>
>> But the result is
>>
>> 1 + x^3 + 3*y + 3*y^2 + y^3 + x^2*(3 + 3*y) + x*(3 + 6*y + 3*y^2)
>>
>> Yes I can explain why this answer is ordered this way, but it is  
>> not a
>> property of computer algebra systems that is reflected by this,  
>> just a
>> property of Mathematica. This is a poke to get it right.
>>
>> I even know I can do this..
>>
>> Replace[%21, {Plus :> List}, 1, Heads -> True]
>>
>> and make a list of the terms; I can then try sorting them some  
>> other way, as
>> long as I don't add them together.  Oh, I can also rename the  
>> variables;
>> Collect [(1+x+y)^3, y] works much better.
>>
>> RJF
>>
>>
>>
>
>
> There is one very simple thing you can do, which I think completely  
> deals with your problem.
> You can convert the output to TraditionalForm.
>
> Andrzej Kozlowski

There are a couple more things that I think are also relevant. First  
of all if you do not like to have your output in TraditionalForm you  
can simply do this:

Collect[(1 + x + y)^3, x] // TraditionalForm // StandardForm

Alternatively you can dispense with Collect and do this (though I  
prefer the above approach)

1 + Plus @@ Table[Coefficient[(1 + x + y)^3, x^i]*x^i, {i, 1, 3}]


Of course there is no way to make the powers of x ascend as you  
originally seems to have wanted but then we can't have everything  
even where Mathematica is concerned.

Andrzej Kozlowski



  • Prev by Date: Re: Getting the small parts right or wrong. Order and Collect
  • Next by Date: Re: Best linear Fit to slope data with Fixed starting point/value.
  • Previous by thread: Re: Getting the small parts right or wrong. Order and Collect
  • Next by thread: Re: Getting the small parts right or wrong. Order and Collect