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: [mg84918] Re: Don't understand behavior of ClearAttributes[Plus,
  • From: Alain Cochard <alain at geophysik.uni-muenchen.de>
  • Date: Sat, 19 Jan 2008 06:03:45 -0500 (EST)
  • References: <200801160830.DAA10128@smc.vnet.net> <fmmk8b$epl$1@smc.vnet.net>

Thanks much Daniel, for your detailed answer.


Daniel Lichtblau <danl at wolfram.com> writes:

>>     In[2]:= ClearAttributes[Plus,Orderless]
>> 
>>     In[3]:= {b + a, j + 1, "/"+">"}
>> 
>>     Out[3]= {b + a, 1 + j, / + >}
>> 

> 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.

I find it difficult to understand your view.  I don't see why
advertising for the ordering rules prevents Mathematica from changing them
(advertising the new ones), leaving to the user the responsibility to
be aware of those new rules, if he cares at all.  My understanding is
that one can always determine an order by use of Sort or OrderedQ; but
seems to me it's just extra work than could be avoided.

Along the same line, the manual says that 

     "Strings are ordered as they would be in a dictionary, with the
      upper-case versions of letters coming after lower-case ones."

It says nothing about non letters, but when I see

     In[58]:= OrderedQ[{">","/"}] 

     Out[58]= True

I conclude that > comes before / in the "Mathematica alphabet of strings". But
then, how should I interpret (and anticipate) the following:

     In[70]:= OrderedQ[{">b","/a"}] 

     Out[70]= False


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

OK, but I'm only concerned with the output.  (There are probably ways
of obtaining the order I need without changing Plus' attributes, but I
don't have the abilities to do that.)

> 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").

Here too, I am a bit surprised.  I can't help thinking that if Mathematica
supports something, it has to try as best as it can to make it bug
free.  I'd be curious to know what other users think about that.


On more general grounds, I would like to know if clearing the
Orderless attribute of Plus only for some instructions (for which the
user is convinced that the output is correct), resetting the
attributes just after those instructions, can have unexpected
consequences later on.  If the answer is "no", as I expect, then I
don't see what's the big deal of doing it.

Alain




  • Prev by Date: V6 DumpSave kills kernel
  • Next by Date: Strange parsing error.
  • Previous by thread: Re: Don't understand behavior of ClearAttributes[Plus,
  • Next by thread: RE: Re: Don't understand behavior of ClearAttributes[Plus,