Re: Extracting Coefficients and Powers

*To*: mathgroup at smc.vnet.net*Subject*: [mg48269] Re: [mg48254] Extracting Coefficients and Powers*From*: Daniel Lichtblau <danl at wolfram.com>*Date*: Thu, 20 May 2004 04:03:45 -0400 (EDT)*References*: <200405190920.FAA15723@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Bruce W. Colletti wrote: > I have a sum of terms, each of the form "a * x^r" or "a * 1/x^r", where > a and (positive) r are real numbers (if a is missing, it's presumably 1 > or -1 and if there is no x-term, r is understood to be 0). > > In my application, the complete expression is given by Expand[p], where > p is a product of terms having form a t^b + c t^d (p is actually a > factorial moment generating function). > > I want to extract all coefficients into a list (including 1 or -1 > coefficients), and exponents into another (to include 0 for any constant > term). For instance, > > x^3.2 + 5 - 3 / x^5.2 - x^5 > > yields the coefficients' list {1, 5, -3, -1} and exponents' list {3.2, > 0, -5.2,5}. > > How would I build these lists? Must Cases[ ] be used or are there > built-in functions? > > Thanks. > > Bruce > If you are willing to work with rational exponents you can do as below to get exponent/coefficient list pairs. These can be further processed in an abvious way to get the separate lists you seek. In[15]:= InputForm[ipoly = Internal`NestedTermsList[Rationalize[x^3.2 + 5 - 3 / x^5.2 - x^5], x]] Out[15]//InputForm= {{5, -1}, {16/5, 1}, {0, 5}, {-26/5, -3}} In[16]:= InputForm[poly = Internal`FromNestedTermsList[ipoly, x]] Out[16]//InputForm= 5 - 3/x^(26/5) + x^(16/5) - x^5 Daniel Lichtblau Wolfram Research

**References**:**Extracting Coefficients and Powers***From:*"Bruce W. Colletti" <bcolletti@compuserve.com>