This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / The Mathematica Book / Principles of Mathematica / Transformation Rules and Definitions  /

2.4.13 Advanced Topic: Manipulating Value Lists

Finding and setting values of symbols.

Mathematica effectively stores all definitions you give as lists of transformation rules. When a particular symbol is encountered, the lists of rules associated with it are tried.
Under most circumstances, you do not need direct access to the actual transformation rules associated with definitions you have given. Instead, you can simply use lhs=rhs and lhs=. to add and remove rules. In some cases, however, you may find it useful to have direct access to the actual rules.

  • Here is a definition for f.
  • In[1]:= f[x_] := x^2

  • This gives the explicit rule corresponding to the definition you made for f.
  • In[2]:= DownValues[f]


    Notice that the rules returned by DownValues and UpValues are set up so that neither their left- nor right-hand sides get evaluated. The left-hand sides are wrapped in HoldPattern, and the rules are delayed, so that the right-hand sides are not immediately evaluated.
    As discussed in Section 2.4.6, Mathematica tries to order definitions so that more specific ones appear before more general ones. In general, however, there is no unique way to make this ordering, and you may want to choose a different ordering from the one that Mathematica chooses by default. You can do this by reordering the list of rules obtained from DownValues or UpValues.

  • Here are some definitions for the object g.
  • In[3]:= g[x_ + y_] := gp[x, y] ; g[x_ y_] := gm[x, y]

  • This shows the default ordering used for the definitions.
  • In[4]:= DownValues[g]


  • This reverses the order of the definitions for g.
  • In[5]:= DownValues[g] = Reverse[DownValues[g]]