MathGroup Archive 1999

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

Search the Archive

RE: Standard Evaluation with UpValues

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19432] RE: Standard Evaluation with UpValues
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Tue, 24 Aug 1999 01:29:29 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

I like Allan Hayes explanation below the best.  After going over this, and
taking a careful look at evaluation steps in David Wagner's book I noticed
the mistake was mine.  I misinterpreted the description David Wagner gave in
step 12 (section 7.1.3).  I must say Wagner's explanation would be much
easier to follow if he walked us through the evaluation steps for a number
of examples.  Two such examples are given below.  Someday I might come up
with a number of examples to do just that, but I should get help from a
bonafide expert when it comes to explaining the evaluation steps.

--------------------------------

ClearAll[f, g, t];

f[x_?NumericQ] := 1 + x;  (*R1*)
f /: g[f[x_]] := x + 4;         (*R2*)

g[f[t]]
    4 + t

g[f[E]]
    g[1 + E]

The evaluation steps are

g[f[t]]
- evaluate f[t];
- look for applicable UpValues of t (ie the left side of which matche f[t]);
there are none;
- look for applicable DownValues of f; there are none, since t is not
numeric;
- get g[f[t]], unchanged;
- look for applicable UpValues of f; find R2;
-get 4+t

g[f[E]]
- evaluate f[E];
- look for applicable UpValues of t (ie the left side of which matches
f[E]); there are none;
- look for applicable DownValues of f; find R2, since E is numeric;
- get g[1+E];
- look for applicable UpValues of Plus; there are none;
- look for applicable DownValues of g; there are none;
- get g[1+E]

----------------------------------

More from Ted Ersek:

For a long time I had a hard time understanding whether evaluation starts at
the top and works down to the atoms, or the other way around.  I finally
found the answer, and came up with the trace below to illustrate.  Now if
the attributes (HoldAll, HoldFirst, HoldRest, HoldAllComplete) or the heads
(Unevaluated, Hold, HoldComplete) were involved things would be a little
different.


In[1]:=
ClearAll[a1,a,b1,b,c1,c,d1,d,e1,
  e,f1,f,g1,g,h1,h,j1,j,d2,f2,j2];
a1=a;
b1=b;
c1=c;
d1=d;
e1=e;
f1=f;
g1=g;
h1=h;
j1=j;
c[d]=d2;
e[f]=f2;
h[j]=j2;
g[x_]:=1+x
b[x_,y_]:=x+y
a[x_,y_]:={x,y}


In[17]:=
a1[b1[c1[d1],e1[f1]],g1[h1[j1]]]  //Trace

Out[17]=
{
{a1,a},{{b1,b},{{c1,c},{d1,d},c[d],d2},
{{e1,e},{f1,f},e[f],f2},b[d2,f2],d2+f2},
{{g1,g},{{h1,h},{j1,j},h[j],j2},g[j2],1+j2},
a[d2+f2,1+j2],{d2+f2,1+j2}}


--------------------
I have yet to find a good explanation of where the following fit in the
evaluation process:

- Parsing the input and checking syntax
- $SyntaxHandler
- $Echo
- $PreRead
- $Pre
- Pattern Matching
- $Post
- $PrePrint
- Using MakeBoxes to make an output cell
- $Output
- $Messages
- $Display


A discussion of how they fit in evaluation might also be good.

--------------------
Regards,
Ted Ersek

For Mathematica tips, tricks see 
http://www.dot.net.au/~elisha/ersek/Tricks.html


  • Prev by Date: RE: trouble with SurfaceColor
  • Next by Date: RE: Up-Values with GroebnerBasis
  • Previous by thread: Re: Standard Evaluation with UpValues
  • Next by thread: changing character set??