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: [mg94134] Re: Rearranging expressions in a user-defined form
  • From: dh <dh at metrohm.com>
  • Date: Fri, 5 Dec 2008 05:34:33 -0500 (EST)
  • References: <gh8hms$r38$1@smc.vnet.net>


Hi Alexei,

To prevent any automatic change of your expression, you may wrap it into 

Hold or if you do not want to see "Hold" printed , into HoldForm.

Further, to have an idea how your expression is parsed, use: FullForm[expr].

E.g. take expr=HoldForm[a b+a c+c d+c a-g d-g a].

To replace a b+a c by a(b+c) we may use ReplaceAll:

expr /. a b+ a c -> a(b+c)

this will reorder the expression. To prevent this you need to match all 

arguments of Plus:

expr /. a b +a c+x1___ -> a (b+c)+x1

take care that x1 does not have a value. Otherwise use RuleDelayed:

expr /. a b +a c+x1___ :> a (b+c)+x1

This is the simples way. Of course, you may use more symbolics:

expr /. a x1_+a x2_+x3___ ->a (x1+x2)+x3

e.t.c.

hope this helps, Daniel



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?

> 

> Thank you, Alexei 

> 

> 

> 

> 

> 

> 




  • Prev by Date: Re: How to substitute a function?
  • Next by Date: RE: Clever Tricky Solutions
  • Previous by thread: Re: Rearranging expressions in a user-defined form
  • Next by thread: Re: Rearranging expressions in a user-defined form