This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Transformation Rules for Functions

"Values for Symbols" discussed how you can use transformation rules of the form to replace symbols by values. The notion of transformation rules in Mathematica is, however, quite general. You can set up transformation rules not only for symbols, but for any Mathematica expression.
Applying the transformation rule replaces by .
Click for copyable input
You can also use a transformation rule for . This rule does not affect .
Click for copyable input
is a pattern that stands for with any argument.
Click for copyable input
Probably the most powerful aspect of transformation rules in Mathematica is that they can involve not only literal expressions, but also patterns. A pattern is an expression such as which contains a blank (underscore). The blank can stand for any expression. Thus, a transformation rule for specifies how the function with any argument should be transformed. Notice that, in contrast, a transformation rule for without a blank, specifies only how the literal expression should be transformed, and does not, for example, say anything about the transformation of .
When you give a function definition such as , all you are doing is telling Mathematica to automatically apply the transformation rule whenever possible.
You can set up transformation rules for expressions of any form.
Click for copyable input
This uses a transformation rule for .
Click for copyable input
"Patterns" and "Transformation Rules and Definitions" will explain in detail how to set up patterns and transformation rules for any kind of expression. Suffice it to say here that in Mathematica all expressions have a definite symbolic structure; transformation rules allow you to transform parts of that structure.