MathGroup Archive 1996

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

Search the Archive

Re: Replace/No Rearrangement

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5349] Re: Replace/No Rearrangement
  • From: Jens Potschadtke <Jens.Potschadtke at stud.uni-erlangen.de>
  • Date: Wed, 27 Nov 1996 01:48:02 -0500
  • Organization: Institute for Biomedical Engineering at the FAU Erlangen
  • Sender: owner-wri-mathgroup at wolfram.com

Susan Rempe wrote:
> 
> Hi,
>         I have an expression and I want to replace several
> parts, so I don't  want rearrangement.  For example,
> 
>         t=a+b+c+d
> 
>         t[[2]]=x
> 
> Mathematica reorders the function
>         Out[47]= a + c + d + x
> 
> Instead, I want the output this way
> 
>         a+x+c+d
> 
> Any ideas??  Thanks,
> 
>         Susan Rempe
>         rempe at u.washington.edu

The point is that Plus[] has the attribute Orderless. In any calulation
Plus[] tries any possible combination of the supplied arguments.
Take a look at 

Attributes[Plus]

To remove the attributes use something like:

Unprotect[Plus];
ClearAttributes[Plus,Orderless];
Protect[Plus];

But take care! It is not recommended to do so!!! Because any further
calculation which uses Plus[] may have another result as one may 
expect. For a closer look consult the Mathematica book on behalf
Attributes. 

Another approach:

If you really only want to replace some parts in your equation
use for your simple example:

Apply[t,List]; (* replaces the head "Plus" by "List" *)
...
any replacement
...
Apply[t,Plus];

I hope this gives you an idea how to solve even more complicated
problems.

-- 
Jens Potschadtke

Institute for biomedical engineering at the FAU Erlangen (germany).

mailto:Jens.Potschadtke at stud.uni-erlangen.de
http://www.uni-erlangen.de/~sz0438/


  • Prev by Date: Re: Formatting Output
  • Previous by thread: Re: Replace/No Rearrangement
  • Next by thread: DMUG (German Mathematica User Group)