Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1996

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

Search the Archive

Re: Constant term in polynomial?

  • Subject: [mg3345] Re: [mg3326] Constant term in polynomial?
  • From: brucec (Bruce Carpenter)
  • Date: 29 Feb 1996 12:10:03 -0600
  • Approved: usenet@wri.com
  • Distribution: local
  • Newsgroups: wri.mathgroup
  • Organization: Wolfram Research, Inc.
  • Sender: daemon at wri.com

>Arrgh, I feel stupid asking this question, but I can't think how to do it:
>how do I find the constant term in a polynomial in several variables in
>Mathematica?  For example, the "7" in 7 + 3 x y + y^2 ?
>
>I suppose one way would be to use
>
>   Coefficient[Coefficient[7 + 3 x y + y^2,x,0],y,0].
>
>But that's incredibly clunky, especially since I may have fifty or more
>variables in my real-life problem.
>
>I could evaluate the expression under the rule {x->0, y->0}, with the same
>problem:  for fifty variables that's awkward.  I could build the rule using
>Variables[expr], but that's clumsy and seems inefficient.
>
>First[7 + 3 x y + y^2] will work for this one, since the 7 is present and
>appears first in the FullForm representation.  But it won't work in
>First[3 x y + y^2], which returns 3 x y.
>
>OK, so I can build a command which computes Variables[First[expr]], and
>if that's empty, returns 0; otherwise returns First[expr].  Also clunky
>IMHO, but it seems the most workable--unless there's some trap I'm missing?
>
>Or I can introduce an auxiliary variable "one", refer to the polynomial as
>"7 one + 3 x y + y^2", and ask for Coefficient[expr, one].  Gag!  If I ever
>want to EVALUATE it, I have to remember to use the rule one->1.
>
>There MUST be a standard way to do this, but I can't think of what it could be!
>
>--Ron Bruck

How about the following?  For the multivariate polynominal poly,
Select[poly, NumberQ].  For example

In[63]:=
Short[poly = Expand[(2+Sum[a[i]^i, {i,1,50}])^2],3]
Out[63]//Short=
                 2         2              2       4
4 + 4 a[1] + a[1]  + 4 a[2]  + 2 a[1] a[2]  + a[2]  +

                    48      50          49      50        100
  <<1317>> + 2 a[48]   a[50]   + 2 a[49]   a[50]   + a[50]
In[64]:=
Timing[Select[poly, NumberQ]]
Out[64]=
{0.05 Second, 4}

Cheers,

Bruce Carpenter




-----------------------
Bruce Carpenter
Courseware Coordinator         phone: (217) 398-0700
Wolfram Research, Inc.           fax: (217) 398-0747
100 Trade Centre Drive         email: brucec at wolfram.com
Champaign, IL  61820             web:  http://www.wolfram.com




  • Prev by Date: Re: Constant term in polynomial?
  • Next by Date: RE: Constant term in polynomial?
  • Previous by thread: Re: Constant term in polynomial?
  • Next by thread: RE: Constant term in polynomial?