Getting the small parts right or wrong. Order and Collect
- To: mathgroup at smc.vnet.net
- Subject: [mg63607] Getting the small parts right or wrong. Order and Collect
- From: "Richard Fateman" <fateman at cs.berkeley.edu>
- Date: Sat, 7 Jan 2006 02:29:30 -0500 (EST)
- References: <dpg11e$pm4$1@smc.vnet.net> <dplhq9$em8$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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
- Follow-Ups:
- Re: Getting the small parts right or wrong. Order and Collect
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Getting the small parts right or wrong. Order and Collect