MathGroup Archive 2005

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

Search the Archive

Re: TagSetDelayed and UpValues

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62368] Re: TagSetDelayed and UpValues
  • From: albert <awnl at arcor.de>
  • Date: Tue, 22 Nov 2005 04:42:09 -0500 (EST)
  • References: <dls543$n6l$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Steven T. Hatton wrote:

> The first example below is from The Mathematica Book, and the second is
> from
> TMGB-P.  Notice that g has an upvalue associated with it, whereas func
> still has the TagSetDelayed associated with it.  Why is that?  How are
> these values treated (differently) during evaluation?
> 
> In[1]:= g/:g[x_]+g[y_]:=gplus[x,y]
> 
> In[2]:= ?g
> Global`g
> 
> g[x_] + g[y_] ^:= gplus[x, y]
> 
> In[3]:= func /: D[func[x_], {x_, n_}] := derivOfFunc[x, n]
> 
> In[4]:= ?func
> Global`func
> 
> func /: D[func[x_], {x_, n_}] := derivOfFunc[x, n]
> 

This is just my guess, didn't check the documentation or anything, but I
quite sure that the difference is that in the first example there is no
ambiguity regarding the symbol to which the UpValue should be attached.
This is not the case in the second example, where both func and List could
be the symbol to which the UpValue needs to be attached. Looking at the
following example it is probably easier to understand what happens:

g /: g[x_] + h[y_] := gplus[x, y]

if still unsure, look at the FullForm of both left hand sides (always a good
idea when unsure...). Why mathematica handles these this way is not clear
to me, it could of course store different forms in the UpValues since the
ambguity is gone once the UpValues are attached to a certain symbol. Most
probably it is easier to handle things that way inernally...


albert


  • Prev by Date: Re: Re: Confusing results with N[expr]?
  • Next by Date: Re: Export[] to XLS
  • Previous by thread: TagSetDelayed and UpValues
  • Next by thread: How to View Mathematica and Hardcopy Books