MathGroup Archive 2007

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

Search the Archive

Re: Re: search for an operator in an expression

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78296] Re: [mg78204] Re: search for an operator in an expression
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Wed, 27 Jun 2007 05:42:32 -0400 (EDT)
  • References: <f5iuqu$a99$1@smc.vnet.net> <f5o8jr$5jo$1@smc.vnet.net> <200706260805.EAA02477@smc.vnet.net>

In Mathematica Plus is an n-ary operation, e.g.

Plus[a, b, c, d]
a + b + c + d

So there is only one Plus operator even though you see 4 "pluses".  
Probably the easiest way to get what you want is simply to count the  
number of + characters in the expression converted to a string;

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

StringCount[ToString[expr], "+"]
4

Andrzej Kozlowski


On 26 Jun 2007, at 17:05, 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.
>
> dh wrote:
>
>> Hi Daniel,
>>
>> you may use "Count". Take care to search on all "levels" and prevent
>>
>> evaluation of the operator. Asssuming your expression is in: expr,  
>> e.g.:
>>
>> Count[expr, HoldPattern[ Plus[__] ], Infinity]
>>
>> hope this helps, Daniel
>>
>>
>>
>>
>>
>> Daniel wrote:
>>
>>
>>> Is there a way to search for an operator in a symbolic  
>>> expression? My wish is to show that there is only "+" in a very  
>>> large expression. Rather than showing an expression on multiple  
>>> pages I would like to perform a search that shows there is only  
>>> "+" between the terms. Converting to a string does not seem to  
>>> work since the expression is written on multiple lines(fractions,  
>>> exponents etc..)
>>
>>
>>
>>> Thanks
>>
>>
>>
>>
>>
>



  • Prev by Date: Re: Re: Why use Java in Mathematica?
  • Next by Date: Re: Data Export to Excel, Reals or now Strings?
  • Previous by thread: Re: Re: search for an operator in an expression
  • Next by thread: Re: search for an operator in an expression