Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1996

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

Search the Archive

Re: Thanks for Rearrangement & Format

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5490] Re: [mg5438] Thanks for Rearrangement & Format
  • From: Daniel Lichtblau <danl>
  • Date: Wed, 11 Dec 1996 03:16:06 -0500
  • Organization: wolfram.com
  • Sender: owner-wri-mathgroup at wolfram.com

Susan Rempe wrote:
> 
> 
>    Could you be more specific about the best way to
> go about this, please.
> 
> On Mon, 9 Dec 1996, Daniel Lichtblau wrote:
> 
> > Susan Rempe wrote:
> > >
> > > Thanks to all who responded to my 2 questions.
> > > The answers I liked best are the following:
> > >
> > > 1).  To replace a term in a function without
> > >      letting rearrangement occur, clear the
> > >      attributes of the operator(s) and make
> > >      orderless.  Explicitly order terms with Sort.
> > >
> > >       In[195]:= t=a+b+c+d;
> > >       In[196]:= ClearAttributes[Plus,Orderless]
> > >       In[197]:= t[[3]]=x
> > >       In[198]:= t
> > >       Out[198]= a + b + x + d
> > >       In[199]:= Sort[%]
> > >       Out[199]= a + b + d + x
> > >
> > >...
> > > Susan Rempe
> >
> > I'd recommend heavily against this method. What you want to do, it
> > appears, is reformat the expression. This can be done by a mix of
> > formatting rules and application of some dummy head e.g. ncPlus to your
> > expression (to replace the head Plus). The method you posted uses a very
> > dangerous tool, removal of Orderless attribute from Plus, to solve a
> > problem that is unrelated to the mathematics of a noncommutative
> > addition operator. Moreover, I very much doubt that the internals of
> > Mathematica will work correctly with such an operator. Which is what you
> > have, once that Orderless attribute has been cleared.
> >
> > Daniel Lichtblau
> > Wolfram Research
> > danl at wolfram.com
> >


This will work in version 2.2 or 3.0. It will use, internally, a dummy
head, but will print as "+" in infix form.

In[1]:= ??Infix
Infix[f[e1, e2, ...]] prints with f[e1, e2, ...] given in default infix
form:
   e1 ~ f ~ e2 ~ f ~ e3 .... Infix[expr, h] prints with arguments
separated by
   h: e1 h e2 h e3 ....
Attributes[Infix] = {Protected}

In[1]:= t = a + b + c + d
Out[1]= a + b + c + d

In[2]:= t2 = Apply[ncPlus, t]
Out[2]= ncPlus[a, b, c, d]

In[3]:= t3 = t2 /. c->x
Out[3]= ncPlus[a, b, x, d]

In[4]:= Infix[t3, "+"]
Out[4]= a+b+x+d

Daniel Lichtblau
Wolfram Research
danl at wolfram.com


  • Prev by Date: Re: EPS files produced by Mathematica 3.0
  • Next by Date: Re: Thanks for Rearrangement & Format
  • Previous by thread: Thanks for Rearrangement & Format
  • Next by thread: Re: Thanks for Rearrangement & Format