MathGroup Archive 2011

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

Search the Archive

Re: Selecting round parentheses arguments

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118046] Re: Selecting round parentheses arguments
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sat, 9 Apr 2011 17:59:44 -0400 (EDT)

On 4/9/11 at 7:12 AM, wateronwildfire at gmail.com (JJ) wrote:

>Hello again everybody, Chelly question made me think to something.
>Suppose I have a list like this:

>p={a b (c 3 d)+a c (b^2 5),b (c+d 4)-a,-(a^3 d) c}

>in which the round parentheses (except for the middle one) are
>unnecessary but play a semantic role by dividing some expressions
>from others with different meaning. Now let's say I want to extract
>the expressions inside those parentheses and obtain

>ans={{c 3 d,b^2 5},c+d 4, a^3 d}

>Is there a quick way to do that?

The problem is once you hit enter so as to make the assignment
to p, Mathematica will evaluate the RHS of your expression. That
will eliminate the unneeded paratheses and re-arrange the order
of the sub terms to a canonical order. That is

In[2]:= p = {a b (c 3 d) + a c (b^2 5), b (c + d 4) - a, -(a^3
d) c}

Out[2]= {5 a b^2 c+3 a b c d,b (c+4 d)-a,-a^3 c d}

So, the information needed to accomplish what you want is lost.

The simplest way I know to do what you are asking in Mathematica
is to enter the RHS as a string, use the various string
functions in Mathematica to extract the desired portion and
finally use ToExpression to convert the extracted portion of the
strings to expressions.

The other approach would be to use Hold to prevent evaluation of
the RHS, then manipulate the result.

But neither of these strike me as being "a quick way" to achieve
your desired goal.



  • Prev by Date: Re: Selecting round parentheses arguments
  • Next by Date: Re: CDF browser plugin and Wolfram library archive
  • Previous by thread: Re: Selecting round parentheses arguments
  • Next by thread: Re: Selecting round parentheses arguments