MathGroup Archive 2006

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63665] Re: [mg63631] Re: Getting the small parts right or wrong. Order and Collect
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Mon, 9 Jan 2006 04:48:55 -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> <dpo3gp$gaq$1@smc.vnet.net> <200601080832.DAA02327@smc.vnet.net> <29CEA9D5-E27D-499E-92D0-6E011737B0C7@mimuw.edu.pl>
  • Sender: owner-wri-mathgroup at wolfram.com

A couple more things.  I was careless when I wrote

> The only thing you can't do is Apply Plus: which is of course what  
> I though you wanted to do, for typesetting reasons.

Of course I did not literally mean  Plus@@: what I meant is that once  
convert the list of coefficients to a sum Mathematica will order it  
according to its canonical ordering rules, which are needed to  
implement the Orderless attribute of Plus. This is how it should be.

Also,   besides CoefficientList, which is the right things to use for  
this purpose here,  Mathematica has a host of functions for  
manipulating polynomials and  it clearly they rather than general  
programing functions that should be used for this purpose. After all,  
we are talking about "computer algebra" here, aren't we?

Some of these functions functions are in the Internal context. The  
list of coefficients can be obtained with:


CoefficientList[(1 + x + y)^3, x]


{y^3 + 3*y^2 + 3*y + 1, 3*y^2 + 6*y + 3, 3*y + 3, 1}


Internal`DistributedTermsList[(1 + x + y)^3, x][[1]][[All,2]]

{1, 3*y + 3, 3*y^2 + 6*y + 3, y^3 + 3*y^2 + 3*y + 1}



Internal`NestedTermsList[Expand[(1 + x + y)^3], x][[All,2]]


{1, 3*y + 3, 3*y^2 + 6*y + 3, y^3 + 3*y^2 + 3*y + 1}



Of course using the last two would be really and overkill  here but  
they can be really useful for more complex tasks. But In any case if  
you want to work with polynomials you had better master the basic  
polynomial algebra.

Another good rule is : don't claim that Mathematica does something  
wrong before making sure that it is not your own ignorance that makes  
it seems so.

Andrzej Kozlowski


On 8 Jan 2006, at 20:59, Andrzej Kozlowski wrote:

>
> On 8 Jan 2006, at 17:32, Richard Fateman wrote:
>
>>
>> "Andrzej Kozlowski" <akoz at mimuw.edu.pl> wrote in message
>> news:dpo3gp$gaq$1 at smc.vnet.net...
>>> On 7 Jan 2006, at 18:04, Andrzej Kozlowski wrote:
>>>
>>>>
>>>>
>>>> There is one very simple thing you can do, which I think completely
>>>> deals with your problem.
>>>> You can convert the output to TraditionalForm.
>>>>
>>
>> No,  because TraditionalForm is only a hack on the display.  If  
>> you pick
>> out the parts of the expression in sequence by  using %[[1]]    
>> etc, you find
>> that the coefficients of the different powers of x  are picked out  
>> in the
>> StandardForm order, not the TraditionalForm order.
>
> What's "right" and "wrong" here is a matter of opinion. In my  
> opinion there is nothing wrong with what Mathematica does here.  I  
> assumed you were concerned with "typesetting' and in this respect  
> Mathematica behaves correctly in TraditionalForm.
> Since I always work with TraditionalForm for display I have no  
> problems here.
> On the other hand I would never try to pick terms of a polynomial  
> with %[[1]] as you suggest. This is indeed "entirely wrong". The  
> "right" thing is, of course,  to use Coefficient or for this sort  
> of thing CoefficientList. Please observe carefull:
>
>
> CoefficientList[(1 + x + y)^3, x]
>
>
> {y^3 + 3*y^2 + 3*y + 1, 3*y^2 + 6*y + 3, 3*y + 3, 1}
>
> Who needs all the typing? Now you can pick terms as you like.  You  
> can even Reverse the list. The only thing you can't do is Apply  
> Plus: which is of course what I though you wanted to do, for  
> typesetting reasons.
>
>
>>
>> Putting the coefficients in an array is plausible, but Andrzej other
>> solution, which
>> is 1 + Plus @@ Table[Coefficient[(1 + x + y)^3, x^i]*x^i, {i, 1, 3}]
>>
>> is wrong because it results in answers in the order 1, x^3, x^2, x.
>> And of course picking out the coefficient of "1".
>
> Of course I only suggested this assuming you were working in  
> TraditionalForm, like I do, and were concerned with the way things  
> looked.
>
>>
>> Along those lines it is
>> better to do ... Table[Coefficient[(1+x+y)^3,x,i] ,{i,0,3}] where  
>> i can also
>> be 0.
>> And the table keeps the coefficients from being randomly sorted.
>>
>> "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."    Eh, this one can be solved
>> with Table and Coefficient.  It is just that the EXAMPLE IN THE BOOK
>> is the mistake.
>>
>
> All of the above is a waste of time and effort  because the obvious  
> thing to do is to use CoefficientList.
>
> Andrzej Kozlowski


  • Prev by Date: Re: Re: Getting the small parts right or wrong. Order and Collect
  • Next by Date: Re: Fourier Transform Bug
  • Previous by thread: Re: Re: Getting the small parts right or wrong. Order and Collect
  • Next by thread: Re: Re: Getting the small parts right or wrong. Order and Collect