MathGroup Archive 1999

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

Search the Archive

Re: Evaluation with UpValues

  • To: mathgroup at
  • Subject: [mg19429] Re: [mg19355] Evaluation with UpValues
  • From: "Richard Finley" <rfinley at>
  • Date: Tue, 24 Aug 1999 01:29:27 -0400
  • Sender: owner-wri-mathgroup at

Given your example, it certainly seems the downvalue takes precedence over 
the upvalue. On the other hand, that would seem to make sense given the 
usual order of evaluation of transformation rules or if you look at the 
results with Trace. But if you define:

g[f[x_]]:= Exp[-x]

which defines a downvalue of g[f[x]] associated with g

f/:g[f[x]]:= E + x

which defines an upvalue for g[f[x]] associated with f

then the upvalue g[f[x]] associated with f will always take precedence 
over the downvalue g[f[x]] associated with g.  Perhaps that is the sense 
in which upvalues take precedence over downvalues?? 

regards,  RF

>>> "Ersek, Ted R" <ErsekTR at> 08/20/99 09:09PM >>>
Section 7.1.3 of the excellent book "Power Programming With Mathematica 
Kernel" by David B. Wagner explains the main evaluation loop.  In that
Section it indicates UpValues for a symbol are applied before DownValues 
the symbol are applied.

OK then consider the case below where (f) has both an UpValue and a
DownValue defined by the user.

At Out[4] the UpValue for (f) was used.  In that case the DownValue 
be used to evaluate f[t]. 
Then at Out[5] the DownValue for (f) is used to evaluate  f[E] --> 1+E
before the kernel checked to see if the UpValue would apply (and it would
have).  I get the same result using Versions 3 and 4.

When the kernel evaluates g[f[E]] it must figure out that the Head is (g)
before it evaluates f[E].  After determining that the Head is (g) it 
to see if (g) has any Hold* attributes, and continues with evaluation as
required.  So by the time the kernel evaluates f[E] it has all the
information it needs to know that the UpValue for (f) can be used.  
the DownValue is used instead.  Wait a minute, aren't UpValues applied
before DownValues are applied?

Can someone convince me that the main evaluation loop performs as 
by David Wagner when evaluating In[5] below?  Also can someone give a
different example that more clearly shows that UpValues are used first?






Ted Ersek

For Mathematica tips, tricks see

  • Prev by Date: RE: Up-Values with GroebnerBasis
  • Next by Date: Mathematica on linux help and Mathematica returns wrong integral result
  • Previous by thread: Re: cell question
  • Next by thread: Mathematica on linux help and Mathematica returns wrong integral result