       Re: search for an operator in an expression

• To: mathgroup at smc.vnet.net
• Subject: [mg78261] Re: search for an operator in an expression
• From: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
• Date: Wed, 27 Jun 2007 05:24:36 -0400 (EDT)
• References: <f5iuqu\$a99\$1@smc.vnet.net> <467D2013.6040903@gmail.com>

```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

Hi Daniel,

If I have correctly understood what you want, the easiest way should be
everything is an expression, that is something with a head and some
elements: head[e1, e2, ...] .) For instance, say we have the following
expression

In:=
expr = Expand[(a + I*b)^5]

Out=
a^5 + 5*I*a^4*b - 10*a^3*b^2 - 10*I*a^2*b^3 +
5*a*b^4 + I*b^5

In:=

Out=
Plus

We can also look at the full form of the expression and see that it
contains many sub-expressions (with head Times or Complex for example);
however the head of the overall expression is Plus.

In:=
FullForm[expr]

Out//FullForm=
Plus[Power[a,5],Times[Complex[0,
5],Power[a,4],b],Times[-1,10,Power[a,3],Power[b,2]],Times[Complex[
0,-10],Power[a,2],Power[b,3]],Times[5,a,Power[
b,4]],Times[Complex[0,1],Power[b,5]]]

In:=
TreeForm[expr] (*TreeForm is mores appealing in version 6.0 *)

To summarize, the differences among the list {a, b, c}, the sum a + b +
c, and the product a * b * c are just in their respective heads.

In:=
FullForm[{a, b, c}]

Out//FullForm=
List[a,b,c]

In:=
FullForm[a + b + c]

Out//FullForm=
Plus[a,b,c]

In:=
FullForm[a*b*c]

Out//FullForm=
Times[a,b,c]

Finally, Apply is used to change the head of an expression. Below we
transform a product into a sum by changing its head.

In:=
Plus @@ (a*b*c)

Out=
a + b + c

HTH,
Jean-Marc

```

• Prev by Date: Is "Find Currently Evaluating Cell" really "Find Topmost Cell in Evaluation Queue"?
• Next by Date: Re: Summations
• Previous by thread: Re: search for an operator in an expression
• Next by thread: Re: search for an operator in an expression