MathGroup Archive 2008

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

Search the Archive

Re: Rearranging expressions in a user-defined form

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94141] Re: Rearranging expressions in a user-defined form
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Fri, 5 Dec 2008 07:04:09 -0500 (EST)
  • Organization: University of Bergen
  • References: <gh8hms$r38$1@smc.vnet.net>

Alexei Boulbitch wrote:
> Dear MathGroup,
> 
> in symbolic transformations of mathematical expressions I often need to 
> group or transform differently different parts
> of these expression, just to make them more visible , or more easy to 
> analyze  or so.  Just to give a simplest  example, 
> assume that we have  an expression:
> 
> expr = ab + ac + cd + ca- gd - ga
> 
> and I need to have it once in the form like say,
> 
> expr=a (b + c) + (c - g) (d + a)
> 
> and another time in the form say,
> 
> expr=a (b + 2 c - g) + d (c - g)
> 
> or I will need to group it in some third, fourth ... form. You indeed 
> understand that I gave the example easily treatable without computer,
> while I have in mind much more complex transformations of real interest.
> 
> This evidently may be done by copy-pasting parts of the expression in 
> question and
> transforming then separately and then again copy-pasting and thus, 
> collecting the results together. That's exactly what I do in such a case.
> However, this may easily become a source of errors: such as copying 
> without a sign, or copying a part of the expression, rather than the 
> whole one and so on.
> Finally it considerably slows you down.
> 
> Could you think of tricks to instruct Mathematica to group only certain 
> terms and not others, and to take certain
> factors out of parentheses, while leave others, according to your choice?
> 

Hello Alexei,

I understand the need for such transformations, but the problem is not 
easy ... First, one needs to be able to describe the requirements for 
the final form of the expression in a very precise manner;  then find an 
algorithm to do the transformation (if it's not already built-in).

It is easy to see what's so special about the second form:  we need the 
coefficients of a and d:

In[2]:= Collect[expr, {a, d}]
Out[2]= d (c - g) + a (b + 2 c - g)

But with the first form it's not so clear to me what you intended to 
achieve.

In[3]:= PolynomialReduce[expr, {b + c, c - g}, {a, b, c, d, g}]
Out[3]= {{a, a + d}, 0}

In[4]:= First[%].{b + c, c - g}
Out[4]= a (b + c) + (a + d) (c - g)

-- 
Szabolcs


  • Prev by Date: Re: Newbie question: Which is more versatile, Table[] or Array[]?
  • Next by Date: Re: Newbie question: Which is more versatile, Table[] or Array[]?
  • Previous by thread: RE: Rearranging expressions in a user-defined form
  • Next by thread: How to substitute a function?