MathGroup Archive 2002

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

Search the Archive

Re: Split Polynom into Sum of Monomials

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34093] Re: Split Polynom into Sum of Monomials
  • From: "Carl K. Woll" <carlw at u.washington.edu>
  • Date: Thu, 2 May 2002 03:49:39 -0400 (EDT)
  • Organization: University of Washington
  • References: <aaomce$efv$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Detlef,

I wrote up a function that will do what you want a while ago:

In[1]:=
ExpandedCollect[expr_, vars_, h_:Identity] :=
  Module[{sub}, Expand[Collect[expr, vars, sub]] /.
    sub -> h]

For your example, we have

In[2]:=
L = {x, n};
In[3]:=
f = (a + b + n + x)*n;
In[6]:=
ExpandedCollect[f, L]
Out[6]=
 2
n  + (a + b) n + x n

As written, ExpandedCollect has an added bit of functionality (similar to
Collect) where an optional third argument can be included. This third
argument will be applied to each of the coefficients of the monomials. For
example:

In[7]:=
ExpandedCollect[f, L, g]
Out[7]=
      2
g[1] n  + x g[1] n + g[a + b] n

This option can be useful if you want to, for example, simplify the
coefficients, where instead of g you would use Simplify.

Carl Woll
Physics Dept
U of Washington

"Detlef Mueller" <dmueller at mathematik.uni-kassel.de> wrote in message
news:aaomce$efv$1 at smc.vnet.net...
> Hello,
>
> I have the following Problem:
>
> Given a Set of Variables, i.e.
> L = {x,n},
>
> I want transform a given expression, polynomial
> in theese variables, say
> f = (a+b+n+x)*n
>
> into Monomials in the given Variables, here
>
> f = (a+b+n+x)*n -> (a+b) n + n^2 + x n
>
> is desired.
>
> The Problem is, that
> Expand[f, x_ /; MemberQ[L, x]] yields
>
> a n + b n + n^2 + n x
>
> which is "too expanded", while
>
> Collect[f, x_ /; MemberQ[L, x]] yields
>
> n\^2 + n(a + b + x)
>
> But this is "not expanded enough", because
> collect works recursively. So I didn't find
> an implemented Command doing the thing.
>
> (The whole thing is a bit timecritical, large
>  polynomials may appear, and the Command will
>  be used frequently).
>
> Any Ideas?
>
> Greetings
>   Detlef
>




  • Prev by Date: Re: Canonical Polynomial Form w. resp. to certain Variables
  • Next by Date: Re: Weights syntax in NonlinearRegress/Fit
  • Previous by thread: Re: Split Polynom into Sum of Monomials
  • Next by thread: Re: Split Polynom into Sum of Monomials