MathGroup Archive 1997

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

Search the Archive

Re: Re: Attributes

  • To: mathgroup at smc.vnet.net
  • Subject: [mg6474] Re: [mg6449] Re: Attributes
  • From: David Withoff <withoff>
  • Date: Sun, 23 Mar 1997 13:23:00 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

> Marlies Brinksma wrote:
> 
> > > When removing the attribute Orderless of the function Times
> > > (ClearAttributes[Times, Orderless]), this attribute disappears (which is
> > > its normal behaviour;-), but reappears(!) after a function-call of a funtion I
> > > defined. I checked this function thouroughly, but I cannot find any relation
> > > to Times.
> > 
> > I performed some tests and now I know that the feature I described is due to
> > the function TableForm. So probably this function has some kind of a side
> > effect related to Times? Does anyone know more about this?
> 
> Interesting.  The attributes only got restored the first time I invoked
> TableForm.  So If I invoke TableForm first, then clear the attribute,
> then invoke TableForm more times, the attributes stay cleared.  I'm
> curious as to what is happening, even though I don't think I would
> choose to write code that depends on clearing the Orderless attribute of
> Times.
> 
> That is not to say that I wouldn't ever change the attributes of
> built-in functions. I used to routinely change the HoldAll attribute of
> If to HoldRest in version 2.2; in version 3.0 one doesn't have to do
> that any more!
> -- 
> -----------------------------
> Dick Zacher                    

The attributes of Times in this example are reset by the autoloading
of a package that, among other things, includes rules for TableForm.
This package is loaded the first time you use TableForm.  These packages
typically require or assume that the attributes are set in a certain way.

If you are curious, you can see these packages being autoloaded by
adding a magic rule to BinaryGet which has the useful side effect of
announcing that these packages are being loaded.  The following example
will maybe show how this works.

**************

In[1]:= Unprotect[BinaryGet]

Out[1]= {"BinaryGet"}

In[2]:= BinaryGet[p_] := Abort[] /; Print["BinaryGet: loading ", p]

In[3]:= Protect[BinaryGet]

Out[3]= {"BinaryGet"}

In[4]:= ClearAttributes[Times, Orderless]

In[5]:= TableForm[0]

BinaryGet: loading Typeset/OutputForms.mx

Out[5]//TableForm= 0

**************

The loading of Typeset/OutputForms.mx has reset the attributes of Times.

**************

In[6]:= Attributes[Times]

Out[6]= {Flat,Listable,NumericFunction,OneIdentity,Orderless,Protected}

**************

A second use of TableForm does not reset the attributes of Times, since
the package has already been loaded.

**************

In[7]:= ClearAttributes[Times, Orderless]

In[8]:= TableForm[0]

Out[8]//TableForm= 0

In[9]:= Attributes[Times]

Out[9]= {Flat,Listable,NumericFunction,OneIdentity,Protected}

**************

I agree with Dick Zacher that, unless you are desperate, or are just
playing around, I would certainly avoid writing code that involves
resetting a critical attribute of a basic function.  Commutativity of
multiplication is a such a basic identity that removing it could have
some rather interesting effects.

For completeness I should mention that there are many autoloaded packages
that can reset the attributes of Times.  For example, the packages that
are loaded to handle Series expansions will also do this.

**************
In[10]:= ClearAttributes[Times, Orderless]

In[11]:= Series[Sin[x], {x, 0, 4}]

BinaryGet: loading Series.mx

BinaryGet: loading InverseFunctions.mx

BinaryGet: loading Typeset/Misc.mx

              3
             x        5
Out[13]= x - -- + O[x]
             6

In[12]:= Attributes[Times]

Out[12]= {Flat,Listable,NumericFunction,OneIdentity,Orderless,Protected}

**************

Dave Withoff
Wolfram Research


  • Prev by Date: Special Functions
  • Next by Date: Re: Discontinuity
  • Previous by thread: Re: Attributes
  • Next by thread: Solving a non-lin equation system.