MathGroup Archive 2002

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

Search the Archive

RE: Re: In order = Out order

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34574] RE: [mg34539] Re: In order = Out order
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Wed, 29 May 2002 02:44:16 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> -----Original Message-----
> From: Allan Hayes [mailto:hay at haystack.demon.co.uk]
To: mathgroup at smc.vnet.net
> Sent: Monday, May 27, 2002 7:16 AM
> To: mathgroup at smc.vnet.net
> Subject: [mg34574] [mg34539] Re: In order = Out order
> 
> 
> We can temporarilly clear the attributes Orderless, but take 
> care that non
> of your code uses it.
> 
>     a=z;b=y;c=x;
> 
>     ClearAttributes[{Plus,Times}, Orderless];
> 
>     {a b c, a+b+c}
> 
>     {z y x,z+y+x}
> 
>     SetAttributes[{Plus,Times}, Orderless];
> 
> 
> --
> Allan
> 
> ---------------------
> Allan Hayes
> Mathematica Training and Consulting
> Leicester UK
> www.haystack.demon.co.uk
> hay at haystack.demon.co.uk
> Voice: +44 (0)116 271 4198
> Fax: +44 (0)870 164 0565
> 
> 
> <Matthias.Bode at oppenheim.de> wrote in message
> news:acknpu$8ch$1 at smc.vnet.net...
> > Dear Colleagues,
> >
> > purely for readability I wish to obtain the output in the 
> same order the
> > input was presented, e.g.:
> > In:
> > a= lengthy expr one;
> > b= lengthy expr two;
> > c= lengthy expr three;
> >
> > have been deduced and are now combined:
> >
> > In: (a+b+c) * 1/2
> >
> > Out: (lengthty expr one* lengthy expr three* lengthy expr two)*1/2
> >
> > Lexicographal ordering is undesirable in this case because 
> the reader has
> > difficulties in finding what he expects intuitively. 
> Presently, I make it
> a
> > TextCell and cut and paste the expressions - which is 
> cumbersome. Better
> > method?
> >
> > Best regards,
> > Matthias Bode
> > Sal. Oppenheim jr. & Cie. KGaA
> > Koenigsberger Strasse 29
> > D-60487 Frankfurt am Main
> > GERMANY
> > Tel.: +49(0)69 71 34 53 80
> > Mobile: +49(0)172 6 74 95 77
> > Fax: +49(0)69 71 34 95 380
> > E-mail: matthias.bode at oppenheim.de
> > Internet: http://www.oppenheim.de
> >
> >
> >
> 
> 
> 

Matthias,

just a little addition to Allan's reply: you may localize resetting Plus
from the Orderless attribute by a device like this:

 
In[1]:= {a, b, c} = {z, y, x};
In[2]:=
Block[{Plus = Plus},
  Attributes[Plus] = Complement[Attributes[Plus], {Orderless}];
  With[{expr = a + b + c}, {HoldForm[expr], expr}]]

Out[2]= {z + y + x, x + y + z}

In[3]:= Attributes[Plus]
Out[3]= 
{Flat, Listable, NumericFunction, OneIdentity, Orderless, Protected}

The second part takes normal order because the expression having left block
will be evaluated again. Plus indeed works within Block as seen by
 
In[4]:= {a, b, c} = Range[3];
In[5]:= 
Block[{Plus = Plus},
  Attributes[Plus] = Complement[Attributes[Plus], {Orderless}];
  With[{expr = a + b + c}, {HoldForm[expr], expr}]]

Out[5]= {6, 6}

--
Hartmut



  • Prev by Date: Re: A question about Mathematica
  • Next by Date: RE: RE: Why do parentheses spuriously appear when I type in a formula?
  • Previous by thread: Re: In order = Out order
  • Next by thread: Re: Programming in Mathematica