MathGroup Archive 2007

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

Search the Archive

Re: search for an operator in an expression

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78283] Re: search for an operator in an expression
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Wed, 27 Jun 2007 05:35:52 -0400 (EDT)

On 6/26/07 at 4:05 AM, josh2499 at hotmail.com (rob) wrote:

>Sir, I tried your suggestion as follows:

>expr = 2 + a*Exp[-b x] + Sin[c + b] + d

>Count[expr, HoldPattern[Plus[__]], Infinity]

>which gives a result of "1". I count 4 "+" in expr. Please, what am
>I doing wrong? Thanks.

=46irst, there are not 4 Plus operators in your expression as can
be seen from FullForm

In[29]:= FullForm[expr]

Out[30]//FullForm= \
Plus[2,d,Times[a,Power[E,Times[-1,b,x]]],Sin[Plus[b,c]]]

I don't understand why the code above returns 1 instead of 2,
but this seems to work correctly.

In[[30]]:= Count[FullForm@expr, _Plus, Infinity]

Out[[30]]= 2

I note your expression is the sum of 4 terms. Perhaps what you
really want is the number of terms in your expression rather
than the number of times Plus occurs. If so, that can be
obtained with

In[31]:= Length[List @@ expr]

Out[31]= 4
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Re: problem with Pick
  • Next by Date: Re: Maximize with Integer constraints
  • Previous by thread: Re: search for an operator in an expression
  • Next by thread: Re: search for an operator in an expression