MathGroup Archive 2008

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

Search the Archive

Re: Don't understand behavior of ClearAttributes[Plus,

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84850] Re: [mg84840] Don't understand behavior of ClearAttributes[Plus,
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Wed, 16 Jan 2008 23:02:12 -0500 (EST)
  • References: <200801160830.DAA10128@smc.vnet.net>

Alain Cochard wrote:
> I see from the archives that it is seldom a good idea to use
> ClearAttributes[Plus,Orderless] but I would nevertheless like to
> understand why it gives the behavior I expect in some cases and not in
> others, as exemplified below.
> 
>     Mathematica 6.0 for Linux x86 (32-bit)
>     Copyright 1988-2007 Wolfram Research, Inc.
> 
>     In[1]:= {b + a, j + 1, "/"+">"}
> 
>     Out[1]= {a + b, 1 + j, > + /}
> 
> To begin with, is it correct that the default ordering (as above) is
> defined by what is called "canonical order" in the documentation?  If
> so, I found only rudimentary (as it seemed to me anyway) descriptions
> of what canonical order is.  For example, it is said that
> 
>     "Mathematical operators appear in order of decreasing precedence."
> 
> But how am I supposed to know or to determine that "/" is "less
> preceding" than ">"?  Or maybe there are considered as strings here?
> Anyway, the question of why ">" comes before "/" remains.
> 
> Also, I did not find anything regarding ordering/comparison of
> elements from different classes of expressions, as I understand "1"
> and "j" are.
> 
> (Sorry if answers to these questions are easily found --I did search
> for them-- or if some questions don't even make sense.)
> 
>     In[2]:= ClearAttributes[Plus,Orderless]
> 
>     In[3]:= {b + a, j + 1, "/"+">"}
> 
>     Out[3]= {b + a, 1 + j, / + >}
> 
> Here I get the behavior I expect for b + a and "/"+">" (order
> unchanged in output) but not for j + 1, changed to 1 + j.  Why?
> 
> Thanks for any hint.
> Alain 

I do not know if canonical ordering is fully defined anywhere. Speaking 
for myself and not Wolfram Research, I will say that I believe it should 
NOT be defined, other than to note that such an ordering exists and is 
employed in various situations. That way we are free to change ordering 
specifics (as has happened in past) if and when we find issues in 
efficiency that can be addressed by such changes.

 From the viewpoint of programming language semantics, one would say 
that programs depending on specifics of such ordering do not have well 
defined behavior.

I will comment on the last example. It appears to be a bug in handling 
of Plus, when set not to be Orderless. This is simply an indication 
that, much as we try, we do not fully support making such a change. 
Please bear in mind that basic arithmetic operations (Plus, Times, and 
Power) are used extensively in Mathematica implementation, and 
specialized handling that places numbers before other things in Plus and 
Times is not particularly easy to undo, even when attributes change. 
Which is one reason I strongly recommend not changing attributes of 
those functions (read: It may be a bug, but I've no intention of 
investigating it, let alone attempting a "fix").


Daniel Lichtblau
Wolfram Research


  • Prev by Date: Mouse operation, slider, dynamics, plot combination
  • Next by Date: Re: Creating a Legend with ListPlot using PlotMarkers
  • Previous by thread: Don't understand behavior of ClearAttributes[Plus,Orderless]
  • Next by thread: Re: Don't understand behavior of ClearAttributes[Plus,