Re: Extracting polynomial coefficients?
- To: mathgroup@smc.vnet.net
- Subject: [mg11602] Re: Extracting polynomial coefficients?
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Tue, 17 Mar 1998 10:43:36 -0500
- References: <6e87es$nlo@smc.vnet.net>
Apologies if this posting is a repeat - it has not come through to me
(posted Sat, 14 Mar 1998 14:05:32 +0000), though later ones have.
Thomas Bell wrote:
>
> I have a very long polynomial that's a function of four variables, a, b,
> c, d. I would like Mathematica to (1) tell me what combinations of a,
> b, c, and d are in my polynomial, and (2) tell me what the coefficients
> are for each of the variable terms.
>
> For example, say I have constant terms r and q. My polynomial might
> look something like
>
> 4 a^2 b^3 c + r q d^5 + a d^3 + q c^2 a^2 + r^2 a d^3
>
> I would like to have Mathematica output something like:
>
> a^2 b^3 => 4
> d^5 => r q
> a d^3 => 1 + r^2
> c^2 a^2 => q
Thomas:
poly=4 a^2 b^3 c + r q d^5 + a d^3 + q c^2 a^2 + r^2 a d^3;
vars= {a,b,c,d};
Cases[
MapIndexed[
List,
CoefficientList[poly, vars],
{Length[vars]}
],
{(c_)?(#1 =!= 0 & ), ind_} :>
Times @@ (vars^(ind - 1)) -> c,
{Length[vars]}
]
5 3 2 2 2 2 3 {d -> q r, a d -> 1 + r
, a c -> q, a b c -> 4}
--
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642